mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-22 04:20:44 +00:00
Move wasMoved out of =destroy
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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.}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user