This commit is contained in:
Araq
2019-11-29 11:55:50 +01:00
committed by Andreas Rumpf
parent a114a40b57
commit b688250202
3 changed files with 96 additions and 8 deletions

View File

@@ -239,7 +239,7 @@ proc getTemp(c: var Con; typ: PType; info: TLineInfo): PNode =
proc genWasMoved(n: PNode; c: var Con): PNode =
result = newNodeI(nkCall, n.info)
result.add(newSymNode(createMagic(c.graph, "wasMoved", mWasMoved)))
result.add n #mWasMoved does not take the address
result.add copyTree(n) #mWasMoved does not take the address
proc genDefaultCall(t: PType; c: Con; info: TLineInfo): PNode =
result = newNodeI(nkCall, info)
@@ -401,6 +401,7 @@ proc pArg(arg: PNode; c: var Con; isSink: bool): PNode =
# different and can deal with 'const string sunk into var'.
result = passCopyToSink(arg, c)
elif arg.kind in nkLiterals:
# literals are save to share accross ASTs (for now!)
result = arg # literal to sink parameter: nothing to do
elif arg.kind in {nkBracket, nkObjConstr, nkTupleConstr, nkClosure}:
# object construction to sink parameter: nothing to do
@@ -497,19 +498,22 @@ proc p(n: PNode; c: var Con; consumed = false): PNode =
of nkCallKinds:
let parameters = n[0].typ
let L = if parameters != nil: parameters.len else: 0
result = shallowCopy(n)
for i in 1..<n.len:
n[i] = pArg(n[i], c, i < L and isSinkTypeForParam(parameters[i]))
result = n
if result[0].kind == nkSym and result[0].sym.magic in {mNew, mNewFinalize}:
result[i] = pArg(n[i], c, i < L and isSinkTypeForParam(parameters[i]))
if n[0].kind == nkSym and n[0].sym.magic in {mNew, mNewFinalize}:
result[0] = copyTree(n[0])
if c.graph.config.selectedGC in {gcHooks, gcDestructors}:
let destroyOld = genDestroy(c, result[1])
result = newTree(nkStmtList, destroyOld, result)
else:
result[0] = pArg(result[0], c, isSink = false)
result[0] = pArg(n[0], c, isSink = false)
of nkDiscardStmt: # Small optimization
result = shallowCopy(n)
if n[0].kind != nkEmpty:
n[0] = pArg(n[0], c, false)
result = n
result[0] = pArg(n[0], c, false)
else:
result[0] = copyNode(n[0])
of nkBracket:
result = copyTree(n)
for i in 0..<n.len:
@@ -580,7 +584,7 @@ proc p(n: PNode; c: var Con; consumed = false): PNode =
result = moveOrCopy(n[0], n[1], c)
else:
result = copyNode(n)
result.add n[0]
result.add copyTree(n[0])
result.add p(n[1], c)
of nkRaiseStmt:
if optOwnedRefs in c.graph.config.globalOptions and n[0].kind != nkEmpty: