Skip to content

Commit 586ebb0

Browse files
cooldomecooldome
andauthored
fixes #13708 (#13711)
* fixes #13708 * differentiate between arc and rest of GC Co-authored-by: cooldome <ariabushenko@bk.ru>
1 parent b6e04ea commit 586ebb0

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

compiler/lowerings.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,10 +312,10 @@ proc indirectAccess*(a: PNode, b: PSym, info: TLineInfo): PNode =
312312
proc indirectAccess*(a, b: PSym, info: TLineInfo): PNode =
313313
result = indirectAccess(newSymNode(a), b, info)
314314

315-
proc genAddrOf*(n: PNode): PNode =
315+
proc genAddrOf*(n: PNode, typeKind = tyPtr): PNode =
316316
result = newNodeI(nkAddr, n.info, 1)
317317
result[0] = n
318-
result.typ = newType(tyPtr, n.typ.owner)
318+
result.typ = newType(typeKind, n.typ.owner)
319319
result.typ.rawAddSon(n.typ)
320320

321321
proc genDeref*(n: PNode; k = nkHiddenDeref): PNode =

compiler/spawn.nim

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,24 @@ proc addLocalVar(g: ModuleGraph; varSection, varInit: PNode; owner: PSym; typ: P
6565
vpart[2] = if varInit.isNil: v else: vpart[1]
6666
varSection.add vpart
6767
if varInit != nil:
68-
if useShallowCopy and typeNeedsNoDeepCopy(typ) or optTinyRtti in g.config.globalOptions:
69-
varInit.add newFastAsgnStmt(newSymNode(result), v)
70-
else:
71-
let deepCopyCall = newNodeI(nkCall, varInit.info, 3)
72-
deepCopyCall[0] = newSymNode(getSysMagic(g, varSection.info, "deepCopy", mDeepCopy))
73-
deepCopyCall[1] = newSymNode(result)
74-
deepCopyCall[2] = v
75-
varInit.add deepCopyCall
68+
if g.config.selectedGC in {gcArc, gcOrc}:
69+
if typ.attachedOps[attachedAsgn] != nil:
70+
var call = newNode(nkCall)
71+
call.add newSymNode(typ.attachedOps[attachedAsgn])
72+
call.add genAddrOf(newSymNode(result), tyVar)
73+
call.add v
74+
varInit.add call
75+
else:
76+
varInit.add newFastAsgnStmt(newSymNode(result), v)
77+
else:
78+
if useShallowCopy and typeNeedsNoDeepCopy(typ) or optTinyRtti in g.config.globalOptions:
79+
varInit.add newFastAsgnStmt(newSymNode(result), v)
80+
else:
81+
let deepCopyCall = newNodeI(nkCall, varInit.info, 3)
82+
deepCopyCall[0] = newSymNode(getSysMagic(g, varSection.info, "deepCopy", mDeepCopy))
83+
deepCopyCall[1] = newSymNode(result)
84+
deepCopyCall[2] = v
85+
varInit.add deepCopyCall
7686

7787
discard """
7888
We generate roughly this:

0 commit comments

Comments
 (0)