diff options
Diffstat (limited to 'compiler/liftdestructors.nim')
-rw-r--r-- | compiler/liftdestructors.nim | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/compiler/liftdestructors.nim b/compiler/liftdestructors.nim index def557402..64dc3ad45 100644 --- a/compiler/liftdestructors.nim +++ b/compiler/liftdestructors.nim @@ -775,18 +775,26 @@ proc produceSym(g: ModuleGraph; c: PContext; typ: PType; kind: TTypeAttachedOp; # register this operation already: typ.attachedOps[kind] = result - var tk: TTypeKind - if g.config.selectedGC in {gcArc, gcOrc, gcHooks}: - tk = skipTypes(typ, {tyOrdinal, tyRange, tyInferred, tyGenericInst, tyStatic, tyAlias, tySink}).kind - else: - tk = tyNone # no special casing for strings and seqs - case tk - of tySequence: - fillSeqOp(a, typ, body, d, newSymNode(src)) - of tyString: - fillStrOp(a, typ, body, d, newSymNode(src)) + + if kind == attachedSink and typ.attachedOps[attachedDestructor] != nil and + sfOverriden in typ.attachedOps[attachedDestructor].flags: + ## compiler can use a combination of `=destroy` and memCopy for sink op + dest.flags.incl sfCursor + body.add newOpCall(typ.attachedOps[attachedDestructor], d[0]) + body.add newAsgnStmt(d, newSymNode(src)) else: - fillBody(a, typ, body, d, newSymNode(src)) + var tk: TTypeKind + if g.config.selectedGC in {gcArc, gcOrc, gcHooks}: + tk = skipTypes(typ, {tyOrdinal, tyRange, tyInferred, tyGenericInst, tyStatic, tyAlias, tySink}).kind + else: + tk = tyNone # no special casing for strings and seqs + case tk + of tySequence: + fillSeqOp(a, typ, body, d, newSymNode(src)) + of tyString: + fillStrOp(a, typ, body, d, newSymNode(src)) + else: + fillBody(a, typ, body, d, newSymNode(src)) var n = newNodeI(nkProcDef, info, bodyPos+1) for i in 0..<n.len: n[i] = newNodeI(nkEmpty, info) |