diff options
-rw-r--r-- | compiler/ccgexprs.nim | 4 | ||||
-rw-r--r-- | compiler/injectdestructors.nim | 10 | ||||
-rw-r--r-- | compiler/liftdestructors.nim | 10 | ||||
-rw-r--r-- | lib/system/seqs_v2.nim | 3 | ||||
-rw-r--r-- | lib/system/widestrs.nim | 1 |
5 files changed, 9 insertions, 19 deletions
diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index c194ce326..dc9617fe2 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -2100,14 +2100,14 @@ proc genDestroy(p: BProc; n: PNode) = initLocExpr(p, arg, a) linefmt(p, cpsStmts, "if ($1.p && !($1.p->cap & NIM_STRLIT_FLAG)) {$n" & " #deallocShared($1.p);$n" & - " $1.p = NIM_NIL; $1.len = 0; }$n", + "}$n", [rdLoc(a)]) of tySequence: var a: TLoc initLocExpr(p, arg, a) linefmt(p, cpsStmts, "if ($1.p && !($1.p->cap & NIM_STRLIT_FLAG)) {$n" & " #deallocShared($1.p);$n" & - " $1.p = NIM_NIL; $1.len = 0; }$n", + "}$n", [rdLoc(a), getTypeDesc(p.module, t.lastSon)]) else: discard "nothing to do" else: diff --git a/compiler/injectdestructors.nim b/compiler/injectdestructors.nim index 41f195d43..f1284f523 100644 --- a/compiler/injectdestructors.nim +++ b/compiler/injectdestructors.nim @@ -93,7 +93,7 @@ proc optimize(s: var Scope) = proc findCorrespondingDestroy(final: seq[PNode]; moved: PNode): int = # remember that it's destroy(addr(x)) for i in 0 ..< final.len: - if final[i] != nil and exprStructuralEquivalent(final[i][1].skipAddr, moved, strictSymEquality = true): + if final[i] != nil and exprStructuralEquivalent(final[i][0][1].skipAddr, moved, strictSymEquality = true): return i return -1 @@ -549,12 +549,12 @@ proc ensureDestruction(arg: PNode; c: var Con; s: var Scope): PNode = let tmp = c.getTemp(s.parent[], arg.typ, arg.info) result.add c.genSink(s, tmp, arg, isDecl = true) result.add tmp - s.parent[].final.add c.genDestroy(tmp) + s.parent[].final.add newTree(nkStmtList, c.genDestroy(tmp), c.genWasMoved(tmp)) else: let tmp = c.getTemp(s, arg.typ, arg.info) result.add c.genSink(s, tmp, arg, isDecl = true) result.add tmp - s.final.add c.genDestroy(tmp) + s.final.add newTree(nkStmtList, c.genDestroy(tmp), c.genWasMoved(tmp)) else: result = arg @@ -631,9 +631,9 @@ proc pVarTopLevel(v: PNode; c: var Con; s: var Scope; ri, res: PNode) = elif sfThread notin v.sym.flags: # do not destroy thread vars for now at all for consistency. if sfGlobal in v.sym.flags and s.parent == nil: - c.graph.globalDestructors.add c.genDestroy(v) + c.graph.globalDestructors.add c.genDestroy(v) #No need to genWasMoved here else: - owningScope[].final.add c.genDestroy(v) + owningScope[].final.add newTree(nkStmtList, c.genDestroy(v), c.genWasMoved(v)) if ri.kind == nkEmpty and c.inLoop > 0: res.add moveOrCopy(v, genDefaultCall(v.typ, c, v.info), c, s, isDecl = true) elif ri.kind != nkEmpty: diff --git a/compiler/liftdestructors.nim b/compiler/liftdestructors.nim index 0346f6c67..21fef1d61 100644 --- a/compiler/liftdestructors.nim +++ b/compiler/liftdestructors.nim @@ -535,7 +535,6 @@ proc atomicRefOp(c: var TLiftCtx; t: PType; body, x, y: PNode) = body.add newAsgnStmt(x, y) of attachedDestructor: body.add genIf(c, cond, actions) - body.add newAsgnStmt(x, newNodeIT(nkNilLit, body.info, t)) of attachedDeepCopy: assert(false, "cannot happen") of attachedTrace: if isFinal(elemType): @@ -584,7 +583,6 @@ proc atomicClosureOp(c: var TLiftCtx; t: PType; body, x, y: PNode) = body.add newAsgnStmt(x, y) of attachedDestructor: body.add genIf(c, cond, actions) - body.add newAsgnStmt(xenv, newNodeIT(nkNilLit, body.info, xenv.typ)) of attachedDeepCopy: assert(false, "cannot happen") of attachedTrace: body.add callCodegenProc(c.g, "nimTraceRefDyn", c.info, genAddrOf(xenv), y) @@ -613,7 +611,6 @@ proc weakrefOp(c: var TLiftCtx; t: PType; body, x, y: PNode) = # prevent wrong "dangling refs exist" problems: var actions = newNodeI(nkStmtList, c.info) actions.add callCodegenProc(c.g, "nimDecWeakRef", c.info, x) - actions.add newAsgnStmt(x, newNodeIT(nkNilLit, body.info, t)) let des = genIf(c, x, actions) if body.len == 0: body.add des @@ -642,7 +639,6 @@ proc ownedRefOp(c: var TLiftCtx; t: PType; body, x, y: PNode) = body.add newAsgnStmt(x, y) of attachedDestructor: body.add genIf(c, x, actions) - body.add newAsgnStmt(x, newNodeIT(nkNilLit, body.info, t)) of attachedDeepCopy: assert(false, "cannot happen") of attachedTrace, attachedDispose: discard @@ -672,10 +668,7 @@ proc closureOp(c: var TLiftCtx; t: PType; body, x, y: PNode) = body.add genIf(c, xx, callCodegenProc(c.g, "nimDecWeakRef", c.info, xx)) body.add newAsgnStmt(x, y) of attachedDestructor: - var actions = newNodeI(nkStmtList, c.info) - actions.add callCodegenProc(c.g, "nimDecWeakRef", c.info, xx) - actions.add newAsgnStmt(xx, newNodeIT(nkNilLit, body.info, xx.typ)) - let des = genIf(c, xx, actions) + let des = genIf(c, xx, callCodegenProc(c.g, "nimDecWeakRef", c.info, xx)) if body.len == 0: body.add des else: @@ -695,7 +688,6 @@ proc ownedClosureOp(c: var TLiftCtx; t: PType; body, x, y: PNode) = body.add newAsgnStmt(x, y) of attachedDestructor: body.add genIf(c, xx, actions) - body.add newAsgnStmt(xx, newNodeIT(nkNilLit, body.info, xx.typ)) of attachedDeepCopy: assert(false, "cannot happen") of attachedTrace, attachedDispose: discard diff --git a/lib/system/seqs_v2.nim b/lib/system/seqs_v2.nim index 1b40c00ab..4001e97c3 100644 --- a/lib/system/seqs_v2.nim +++ b/lib/system/seqs_v2.nim @@ -73,11 +73,10 @@ proc shrink*[T](x: var seq[T]; newLen: Natural) = when nimvm: setLen(x, newLen) else: - mixin `=destroy` #sysAssert newLen <= x.len, "invalid newLen parameter for 'shrink'" when not supportsCopyMem(T): for i in countdown(x.len - 1, newLen): - `=destroy`(x[i]) + reset x[i] # XXX This is wrong for const seqs that were moved into 'x'! cast[ptr NimSeqV2[T]](addr x).len = newLen diff --git a/lib/system/widestrs.nim b/lib/system/widestrs.nim index aabcbdc90..83c11eb79 100644 --- a/lib/system/widestrs.nim +++ b/lib/system/widestrs.nim @@ -28,7 +28,6 @@ when defined(nimv2): proc `=destroy`(a: var WideCStringObj) = if a.data != nil: deallocShared(a.data) - a.data = nil proc `=`(a: var WideCStringObj; b: WideCStringObj) {.error.} |