@@ -2850,8 +2850,12 @@ proc genTypeInfoInit(
2850
2850
]
2851
2851
2852
2852
if isDefined (g.config, " nimSeqsV2" ):
2853
- values.add (typeInfoV2)
2854
-
2853
+ values.add (
2854
+ if typeInfoV2 == nil :
2855
+ constNull (g.ptrTy)
2856
+ else :
2857
+ typeInfoV2
2858
+ )
2855
2859
if isDefined (g.config, " nimTypeNames" ):
2856
2860
var typename = typeToString (if t.typeInst != nil : t.typeInst else : t, preferName)
2857
2861
if typename == " ref object" and t.skipTypes (skipPtrs).sym != nil :
@@ -2864,6 +2868,7 @@ proc genTypeInfoInit(
2864
2868
proc genNodeInfo (g: LLGen , typ: PType ): llvm.ValueRef
2865
2869
proc genObjectNodeInfo (g: LLGen , typ: PType , n: PNode , suffix: string ): llvm.ValueRef
2866
2870
proc genTypeInfo (g: LLGen , typ: PType ): llvm.ValueRef
2871
+ proc genTypeInfoV1 (g: LLGen , typ: PType , typeInfoV2: llvm.ValueRef = nil ): llvm.ValueRef
2867
2872
2868
2873
proc constNimNodeNone (g: LLGen , length: int ): llvm.ValueRef =
2869
2874
let
@@ -3003,12 +3008,16 @@ proc genObjectNodeInfoInit(
3003
3008
fields[i] = constNull (g.ptrTy) # ptr TNimNode
3004
3009
3005
3010
result = g.constNimNodeCase (
3006
- g.constOffsetOf (typ, tags), g.genTypeInfo (tags.typ), tags.name.s, variants, fields
3011
+ g.constOffsetOf (typ, tags),
3012
+ g.genTypeInfoV1 (tags.typ),
3013
+ tags.name.s,
3014
+ variants,
3015
+ fields,
3007
3016
)
3008
3017
of nkSym:
3009
3018
let field = n.sym
3010
3019
result = g.constNimNodeSlot (
3011
- g.constOffsetOf (typ, field), g.genTypeInfo (field.typ), field.name.s
3020
+ g.constOffsetOf (typ, field), g.genTypeInfoV1 (field.typ), field.name.s
3012
3021
)
3013
3022
else :
3014
3023
g.config.internalError (n.info, " genObjectNodeInfoInit" )
@@ -3042,7 +3051,7 @@ proc genTupleNodeInfoInit(g: LLGen, t: PType): llvm.ValueRef =
3042
3051
constGEP2 (g.llType (t), constNull (g.ptrTy), [g.gep0, g.constGEPIdx (i)]),
3043
3052
g.int64Ty,
3044
3053
)
3045
- fieldInit = g.constNimNodeSlot (offset, g.genTypeInfo (t.sons[i]), " Field" & $ i)
3054
+ fieldInit = g.constNimNodeSlot (offset, g.genTypeInfoV1 (t.sons[i]), " Field" & $ i)
3046
3055
3047
3056
field.setInitializer (fieldInit)
3048
3057
fields.add (field)
@@ -3145,7 +3154,7 @@ proc genNodeInfo(g: LLGen, typ: PType): llvm.ValueRef =
3145
3154
3146
3155
proc genTypeInfoV1Base (g: LLGen , typ: PType ): llvm.ValueRef =
3147
3156
if typ.kind == tyArray:
3148
- g.genTypeInfo (typ[1 ])
3157
+ g.genTypeInfoV1 (typ[1 ])
3149
3158
elif typ.kind in {
3150
3159
tyUncheckedArray, tySequence, tyRef, tyPtr, tyRange, tySet, tyObject
3151
3160
} and typ.len > 0 and typ[0 ] != nil :
@@ -3158,7 +3167,7 @@ proc genTypeInfoV1Base(g: LLGen, typ: PType): llvm.ValueRef =
3158
3167
if typ.kind == tyPtr and base.kind == tyObject and incompleteType (base):
3159
3168
constNull (g.ptrTy)
3160
3169
else :
3161
- g.genTypeInfo (base)
3170
+ g.genTypeInfoV1 (base)
3162
3171
else :
3163
3172
constNull (g.ptrTy) # g.llMagicType("TNimType").pointerType().constNull()
3164
3173
@@ -3169,11 +3178,34 @@ proc genTypeInfoV1(
3169
3178
typ = typ.skipTypes (irrelevantForBackend + tyUserTypeClasses)
3170
3179
sig = hashType (typ, g.config)
3171
3180
if sig in g.typeInfos:
3181
+ let ti = g.typeInfos[sig]
3182
+
3183
+ if typeInfoV2 != nil :
3184
+ let init = getInitializer (ti)
3185
+ if init.getAggregateElement (8 ).isNull () == llvm.True :
3186
+ var values =
3187
+ @ [
3188
+ init.getAggregateElement (0 ),
3189
+ init.getAggregateElement (1 ),
3190
+ init.getAggregateElement (2 ),
3191
+ init.getAggregateElement (3 ),
3192
+ init.getAggregateElement (4 ),
3193
+ init.getAggregateElement (5 ),
3194
+ init.getAggregateElement (6 ),
3195
+ init.getAggregateElement (7 ),
3196
+ init.getAggregateElement (8 ),
3197
+ typeInfoV2,
3198
+ ]
3199
+
3200
+ if isDefined (g.config, " nimTypeNames" ):
3201
+ values.add init.getAggregateElement (10 )
3202
+
3203
+ ti.setInitializer (llvm.constNamedStruct (init.typeOfX (), values))
3172
3204
return g.typeInfos[sig]
3173
3205
3174
3206
let name = " .typeinfo." & g.llName (typ, sig)
3175
3207
3176
- p (" genTypeInfo " , typ, g.depth + 1 )
3208
+ p (" genTypeInfoV1 " , typ, g.depth + 1 )
3177
3209
3178
3210
let
3179
3211
ntlt = g.llMagicType (" TNimType" )
@@ -3421,6 +3453,9 @@ proc llPassAsPtr(g: LLGen, s: PSym, retType: PType): bool =
3421
3453
if s.typ.sym != nil and sfForward in s.typ.sym.flags:
3422
3454
# forwarded objects are *always* passed by pointers for consistency!
3423
3455
true
3456
+ elif s.typ.kind == tySink and
3457
+ g.config.selectedGC notin {gcArc, gcAtomicArc, gcOrc, gcHooks}:
3458
+ false
3424
3459
elif (optByRef in s.options) or
3425
3460
(getSize (g.config, pt) > g.config.target.floatSize * 3 ):
3426
3461
true # requested anyway
@@ -3562,7 +3597,7 @@ proc fieldIndexFields(
3562
3597
3563
3598
proc fieldIndex (g: LLGen , typ: PType , sym: PSym ): seq [FieldPath ] =
3564
3599
let
3565
- typ = typ.skipTypes (abstractInst )
3600
+ typ = typ.skipTypes (skipPtrs )
3566
3601
ty = g.llType (typ)
3567
3602
3568
3603
assert typ.kind in {tyObject, tyTuple}, $ typ
@@ -4015,7 +4050,7 @@ proc callIsObj(g: LLGen, v: llvm.ValueRef, typ: PType): llvm.ValueRef =
4015
4050
4016
4051
g.callCompilerProc (" isObjDisplayCheck" , [mtype, cmpTo, elem])
4017
4052
else :
4018
- let cmpTo = g.genTypeInfo (typ)
4053
+ let cmpTo = g.genTypeInfoV1 (typ)
4019
4054
g.callCompilerProc (" isObj" , [mtype, cmpTo])
4020
4055
4021
4056
# These are taken from cgen and take care of some of the fallout from the
@@ -4581,7 +4616,7 @@ proc genAssign(g: LLGen, typ: PType, dest, src, shallow: llvm.ValueRef) =
4581
4616
srcphi = g.withNotNilOrNull (seqlen, g.ptrTy):
4582
4617
if supportsCopyMem (elemTyp):
4583
4618
let srcc =
4584
- g.callCompilerProc (" nimNewSeqOfCap" , [g.genTypeInfo (typ), seqlen])
4619
+ g.callCompilerProc (" nimNewSeqOfCap" , [g.genTypeInfoV1 (typ), seqlen])
4585
4620
discard g.b.buildStore (seqlen, srcc)
4586
4621
4587
4622
let
@@ -4593,7 +4628,7 @@ proc genAssign(g: LLGen, typ: PType, dest, src, shallow: llvm.ValueRef) =
4593
4628
g.callMemcpy (destp, srcp, byteLen)
4594
4629
srcc
4595
4630
else :
4596
- let srcc = g.callCompilerProc (" newSeq" , [g.genTypeInfo (typ), seqlen])
4631
+ let srcc = g.callCompilerProc (" newSeq" , [g.genTypeInfoV1 (typ), seqlen])
4597
4632
if elemTyp.kind != tyEmpty:
4598
4633
g.withLoop (seqlen, " asgn.seq" ):
4599
4634
let
@@ -4685,7 +4720,7 @@ proc callAssign(
4685
4720
if checkType and typ.kind == tyObject and not isObjLackingTypeField (typ):
4686
4721
let mtype = g.b.buildLoad2 (g.ptrTy, src)
4687
4722
g.withNotNil (mtype):
4688
- discard g.callCompilerProc (" chckObjAsgn" , [mtype, g.genTypeInfo (typ)])
4723
+ discard g.callCompilerProc (" chckObjAsgn" , [mtype, g.genTypeInfoV1 (typ)])
4689
4724
4690
4725
if supportsCopyMem (typ): # Fast path
4691
4726
let size = g.constStoreSize (g.llType (typ))
@@ -6535,7 +6570,7 @@ proc rawGenNew(g: LLGen, dest: LLValue, sizeExpr: llvm.ValueRef, typ: PType) =
6535
6570
src = g.callCompilerProc (" nimNewObj" , [sizeExpr, alignExpr])
6536
6571
g.genRefAssign (dest, src)
6537
6572
else :
6538
- let ti = g.genTypeInfo (typ)
6573
+ let ti = g.genTypeInfoV1 (typ)
6539
6574
if dest.storage == OnHeap and usesWriteBarrier (g.config):
6540
6575
let destl = g.buildLoadValue (g.llType (refType), dest)
6541
6576
g.withNotNil (destl.v):
@@ -6607,7 +6642,7 @@ proc genMagicNewFinalize(g: LLGen, n: PNode) =
6607
6642
proc genNewSeqAux (g: LLGen , dest: LLValue , destTyp: PType , len: llvm.ValueRef ) =
6608
6643
let
6609
6644
seqType = destTyp.skipTypes (abstractVarRange)
6610
- ti = g.genTypeInfo (seqType)
6645
+ ti = g.genTypeInfoV1 (seqType)
6611
6646
args = [ti, len]
6612
6647
6613
6648
if dest.storage == OnHeap and usesWriteBarrier (g.config):
@@ -6685,7 +6720,7 @@ proc genMagicNewSeqOfCap(g: LLGen, n: PNode): LLValue =
6685
6720
)
6686
6721
g.b.buildLoad2 (ty, tmp)
6687
6722
else :
6688
- let ti = g.genTypeInfo (seqtype)
6723
+ let ti = g.genTypeInfoV1 (seqtype)
6689
6724
g.callCompilerProc (" nimNewSeqOfCap" , [ti, ax])
6690
6725
6691
6726
LLValue (v: v, storage: OnHeap )
@@ -7091,7 +7126,7 @@ proc genMagicEnumToStr(g: LLGen, n: PNode): LLValue =
7091
7126
LLValue (
7092
7127
v: g.callCompilerProc (
7093
7128
" reprEnum" ,
7094
- [g.buildTruncOrExt (ax, g.primitives[tyInt], typ), g.genTypeInfo (typ)],
7129
+ [g.buildTruncOrExt (ax, g.primitives[tyInt], typ), g.genTypeInfoV1 (typ)],
7095
7130
)
7096
7131
)
7097
7132
@@ -7492,7 +7527,7 @@ proc genMagicAppendSeqElem(g: LLGen, n: PNode) =
7492
7527
# old instance when it grows!
7493
7528
bx = g.genNode (n[2 ], g.loadAssignment (seqTyp.elemType))
7494
7529
a = g.b.buildLoad2 (ty, ax.v)
7495
- newseq = g.callCompilerProc (" incrSeqV3" , [a, g.genTypeInfo (seqTyp)])
7530
+ newseq = g.callCompilerProc (" incrSeqV3" , [a, g.genTypeInfoV1 (seqTyp)])
7496
7531
tgt = LLValue (v: newseq, storage: OnHeap )
7497
7532
lenp = g.buildNimSeqLenGEP (tgt.v) # guaranteed not nil!
7498
7533
len = g.b.buildLoad2 (g.primitives[tyInt], lenp)
@@ -7625,30 +7660,30 @@ proc genMagicRepr(g: LLGen, n: PNode): LLValue =
7625
7660
of tyEnum, tyOrdinal:
7626
7661
let ax = g.genNode (n[1 ], true ).v
7627
7662
let a = g.buildTruncOrExt (ax, g.primitives[tyInt], t)
7628
- g.callCompilerProc (" reprEnum" , [a, g.genTypeInfo (t)])
7663
+ g.callCompilerProc (" reprEnum" , [a, g.genTypeInfoV1 (t)])
7629
7664
of tyString:
7630
7665
let ax = g.genNode (n[1 ], true ).v
7631
7666
g.callCompilerProc (" reprStr" , [ax])
7632
7667
of tySet:
7633
7668
let ax = g.genNode (n[1 ], false ).v
7634
- g.callCompilerProc (" reprSet" , [ax, g.genTypeInfo (t)])
7669
+ g.callCompilerProc (" reprSet" , [ax, g.genTypeInfoV1 (t)])
7635
7670
of tyOpenArray, tyVarargs:
7636
7671
let
7637
7672
ax = g.buildLoadVar (n[1 ].typ, g.genNode (n[1 ], false ).v)
7638
7673
data = g.b.buildLoad2 (g.ptrTy, g.buildOpenArrayDataGEP (ax))
7639
7674
len = g.b.buildLoad2 (g.intTy, g.buildOpenArrayLenGEP (ax))
7640
- g.callCompilerProc (" reprOpenArray" , [data, len, g.genTypeInfo (t.elemType)])
7675
+ g.callCompilerProc (" reprOpenArray" , [data, len, g.genTypeInfoV1 (t.elemType)])
7641
7676
of tyCString, tyArray, tyUncheckedArray, tyRef, tyPtr, tyPointer, tyNil, tySequence:
7642
7677
let ax = g.genNode (
7643
7678
n[1 ], t.kind in {tyCString, tyRef, tyPtr, tyVar, tyPointer, tyLent, tySequence}
7644
7679
).v
7645
- g.callCompilerProc (" reprAny" , [ax, g.genTypeInfo (t)])
7680
+ g.callCompilerProc (" reprAny" , [ax, g.genTypeInfoV1 (t)])
7646
7681
of tyEmpty, tyVoid:
7647
7682
g.config.localError (n.info, " 'repr' doesn't support 'void' type" )
7648
7683
nil
7649
7684
else :
7650
7685
let ax = g.genNode (n[1 ], false ).v
7651
- g.callCompilerProc (" reprAny" , [ax, g.genTypeInfo (t)])
7686
+ g.callCompilerProc (" reprAny" , [ax, g.genTypeInfoV1 (t)])
7652
7687
LLValue (v: v)
7653
7688
7654
7689
proc genMagicSetLengthStr (g: LLGen , n: PNode ) =
@@ -7688,7 +7723,7 @@ proc genMagicSetLengthSeq(g: LLGen, n: PNode) =
7688
7723
ax.v
7689
7724
else :
7690
7725
g.b.buildLoad2 (ty, ax.v)
7691
- x = g.callCompilerProc (" setLengthSeqV2" , [a, g.genTypeInfo (typ), bx])
7726
+ x = g.callCompilerProc (" setLengthSeqV2" , [a, g.genTypeInfoV1 (typ), bx])
7692
7727
7693
7728
g.genRefAssign (ax, x)
7694
7729
@@ -7755,7 +7790,12 @@ proc genMagicMove(g: LLGen, n: PNode, load: bool): LLValue =
7755
7790
7756
7791
g.buildStoreNull (ty, tmpx.v)
7757
7792
g.genObjectInit (n[1 ].typ, tmpx.v)
7758
- g.genAssignment (tmpx, g.maybeLoadValue (ty, ax, lx), n[1 ].typ, {})
7793
+ let flags =
7794
+ if not canMove (g, n[1 ]):
7795
+ {needToCopy}
7796
+ else :
7797
+ {}
7798
+ g.genAssignment (tmpx, g.maybeLoadValue (ty, ax, lx), n[1 ].typ, flags)
7759
7799
g.callReset (n[1 ].skipAddr.typ, ax)
7760
7800
g.maybeLoadValue (ty, tmpx, load)
7761
7801
@@ -7917,10 +7957,10 @@ proc genMagicDeepCopy(g: LLGen, n: PNode) =
7917
7957
case ty.kind
7918
7958
of tyPtr, tyRef, tyProc, tyTuple, tyObject, tyArray, tyUncheckedArray:
7919
7959
let bx = g.genNode (n[2 ], false ).v
7920
- discard g.callCompilerProc (" genericDeepCopy" , [ax, bx, g.genTypeInfo (ty)])
7960
+ discard g.callCompilerProc (" genericDeepCopy" , [ax, bx, g.genTypeInfoV1 (ty)])
7921
7961
of tySequence, tyString:
7922
7962
let bx = g.genNode (n[2 ], true ).v
7923
- discard g.callCompilerProc (" genericSeqDeepCopy" , [ax, bx, g.genTypeInfo (ty)])
7963
+ discard g.callCompilerProc (" genericSeqDeepCopy" , [ax, bx, g.genTypeInfoV1 (ty)])
7924
7964
of tyOpenArray, tyVarargs:
7925
7965
g.config.internalError (n.info, " todo" )
7926
7966
of tySet:
@@ -8814,7 +8854,7 @@ proc genNodeBracketExpr(g: LLGen, n: PNode, load, prepareMutation: bool): LLValu
8814
8854
g.config.internalError (n.info, " Unhandled nodebracketexpr kind: " & $ typ.kind)
8815
8855
LLValue ()
8816
8856
8817
- proc genNodeDot (g: LLGen , n: PNode , load: bool ): LLValue =
8857
+ proc genNodeDotExpr (g: LLGen , n: PNode , load: bool ): LLValue =
8818
8858
p (" genDotExpr" , n[1 ].sym, g.depth + 1 )
8819
8859
let
8820
8860
v = g.genNode (n[0 ], false )
@@ -9885,7 +9925,7 @@ proc genNode(
9885
9925
of nkBracketExpr:
9886
9926
result = g.genNodeBracketExpr (n, load, prepareMutation)
9887
9927
of nkDotExpr:
9888
- result = g.genNodeDot (n, load)
9928
+ result = g.genNodeDotExpr (n, load)
9889
9929
of nkCheckedFieldExpr:
9890
9930
result = g.genNodeCheckedField (n, load)
9891
9931
of nkDerefExpr, nkHiddenDeref:
0 commit comments