Skip to content

Commit

Permalink
improve codegen quality for --gc:destructors
Browse files Browse the repository at this point in the history
  • Loading branch information
Araq committed Nov 1, 2019
1 parent d914e9a commit 3761e62
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions compiler/injectdestructors.nim
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,12 @@ when false:
let rhs = ri.typ.skipTypes({tyGenericInst, tyAlias, tySink})
result = lhs.kind == tyRef and rhs.kind == tyOwned

proc canBeMoved(t: PType): bool {.inline.} =
proc canBeMoved(c: Con; t: PType): bool {.inline.} =
let t = t.skipTypes({tyGenericInst, tyAlias, tySink})
result = t.kind != tyRef and t.attachedOps[attachedSink] != nil
if optOwnedRefs in c.graph.config.globalOptions:
result = t.kind != tyRef and t.attachedOps[attachedSink] != nil
else:
result = t.attachedOps[attachedSink] != nil

proc genSink(c: Con; dest, ri: PNode): PNode =
let t = dest.typ.skipTypes({tyGenericInst, tyAlias, tySink})
Expand Down Expand Up @@ -566,7 +569,7 @@ proc moveOrCopy(dest, ri: PNode; c: var Con): PNode =
snk.add ri
result = newTree(nkStmtList, snk, genWasMoved(ri, c))
elif ri.sym.kind != skParam and ri.sym.owner == c.owner and
isLastRead(ri, c) and canBeMoved(dest.typ):
isLastRead(ri, c) and canBeMoved(c, dest.typ):
# Rule 3: `=sink`(x, z); wasMoved(z)
var snk = genSink(c, dest, ri)
snk.add ri
Expand All @@ -589,7 +592,7 @@ proc moveOrCopy(dest, ri: PNode; c: var Con): PNode =
handleNested(ri): moveOrCopy(dest, node, c)
else:
if isAnalysableFieldAccess(ri, c.owner) and isLastRead(ri, c) and
canBeMoved(dest.typ):
canBeMoved(c, dest.typ):
# Rule 3: `=sink`(x, z); wasMoved(z)
var snk = genSink(c, dest, ri)
snk.add ri
Expand Down

0 comments on commit 3761e62

Please sign in to comment.