From 586ebb090b3c7fd2fedbaa24e2b00b7caae4e009 Mon Sep 17 00:00:00 2001 From: cooldome Date: Sat, 21 Mar 2020 06:12:10 +0000 Subject: [PATCH] fixes #13708 (#13711) * fixes #13708 * differentiate between arc and rest of GC Co-authored-by: cooldome --- compiler/lowerings.nim | 4 ++-- compiler/spawn.nim | 26 ++++++++++++++++++-------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/compiler/lowerings.nim b/compiler/lowerings.nim index d569c4dc98cb4..091b291c2e403 100644 --- a/compiler/lowerings.nim +++ b/compiler/lowerings.nim @@ -312,10 +312,10 @@ proc indirectAccess*(a: PNode, b: PSym, info: TLineInfo): PNode = proc indirectAccess*(a, b: PSym, info: TLineInfo): PNode = result = indirectAccess(newSymNode(a), b, info) -proc genAddrOf*(n: PNode): PNode = +proc genAddrOf*(n: PNode, typeKind = tyPtr): PNode = result = newNodeI(nkAddr, n.info, 1) result[0] = n - result.typ = newType(tyPtr, n.typ.owner) + result.typ = newType(typeKind, n.typ.owner) result.typ.rawAddSon(n.typ) proc genDeref*(n: PNode; k = nkHiddenDeref): PNode = diff --git a/compiler/spawn.nim b/compiler/spawn.nim index 382237e70b3a3..2c206b599edba 100644 --- a/compiler/spawn.nim +++ b/compiler/spawn.nim @@ -65,14 +65,24 @@ proc addLocalVar(g: ModuleGraph; varSection, varInit: PNode; owner: PSym; typ: P vpart[2] = if varInit.isNil: v else: vpart[1] varSection.add vpart if varInit != nil: - if useShallowCopy and typeNeedsNoDeepCopy(typ) or optTinyRtti in g.config.globalOptions: - varInit.add newFastAsgnStmt(newSymNode(result), v) - else: - let deepCopyCall = newNodeI(nkCall, varInit.info, 3) - deepCopyCall[0] = newSymNode(getSysMagic(g, varSection.info, "deepCopy", mDeepCopy)) - deepCopyCall[1] = newSymNode(result) - deepCopyCall[2] = v - varInit.add deepCopyCall + if g.config.selectedGC in {gcArc, gcOrc}: + if typ.attachedOps[attachedAsgn] != nil: + var call = newNode(nkCall) + call.add newSymNode(typ.attachedOps[attachedAsgn]) + call.add genAddrOf(newSymNode(result), tyVar) + call.add v + varInit.add call + else: + varInit.add newFastAsgnStmt(newSymNode(result), v) + else: + if useShallowCopy and typeNeedsNoDeepCopy(typ) or optTinyRtti in g.config.globalOptions: + varInit.add newFastAsgnStmt(newSymNode(result), v) + else: + let deepCopyCall = newNodeI(nkCall, varInit.info, 3) + deepCopyCall[0] = newSymNode(getSysMagic(g, varSection.info, "deepCopy", mDeepCopy)) + deepCopyCall[1] = newSymNode(result) + deepCopyCall[2] = v + varInit.add deepCopyCall discard """ We generate roughly this: