diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2019-11-01 09:59:10 +0100 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2019-11-01 09:59:18 +0100 |
commit | 3761e62fde84ba882a87f449d649c74913b6a70b (patch) | |
tree | 0c6d181c161b66c403202391c91eb1e3e8c03684 /compiler/injectdestructors.nim | |
parent | d914e9a65f5be0c7495fdba943d469afe2963ef8 (diff) | |
download | Nim-3761e62fde84ba882a87f449d649c74913b6a70b.tar.gz |
improve codegen quality for --gc:destructors
Diffstat (limited to 'compiler/injectdestructors.nim')
-rw-r--r-- | compiler/injectdestructors.nim | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/compiler/injectdestructors.nim b/compiler/injectdestructors.nim index 146309bbe..f1823bf64 100644 --- a/compiler/injectdestructors.nim +++ b/compiler/injectdestructors.nim @@ -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}) @@ -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 @@ -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 |