diff options
author | Clyybber <darkmine956@gmail.com> | 2020-07-08 20:48:17 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2020-07-10 13:36:02 +0200 |
commit | 4a1128d16c68437463c385645e65ef3d61fa30da (patch) | |
tree | db8696c3bed9ad41f3305875dd1e7d0f6d13bc11 /compiler | |
parent | 3e52136f262b9700713eb10594f18e42a2f2af65 (diff) | |
download | Nim-4a1128d16c68437463c385645e65ef3d61fa30da.tar.gz |
Move `wasMoved` out of `=destroy`
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/ccgexprs.nim | 4 | ||||
-rw-r--r-- | compiler/injectdestructors.nim | 10 | ||||
-rw-r--r-- | compiler/liftdestructors.nim | 10 |
3 files changed, 8 insertions, 16 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 |