Move wasMoved out of =destroy
This commit is contained in:
parent
3e52136f26
commit
4a1128d16c
5 changed files with 9 additions and 19 deletions
|
|
@ -2100,14 +2100,14 @@ proc genDestroy(p: BProc; n: PNode) =
|
||||||
initLocExpr(p, arg, a)
|
initLocExpr(p, arg, a)
|
||||||
linefmt(p, cpsStmts, "if ($1.p && !($1.p->cap & NIM_STRLIT_FLAG)) {$n" &
|
linefmt(p, cpsStmts, "if ($1.p && !($1.p->cap & NIM_STRLIT_FLAG)) {$n" &
|
||||||
" #deallocShared($1.p);$n" &
|
" #deallocShared($1.p);$n" &
|
||||||
" $1.p = NIM_NIL; $1.len = 0; }$n",
|
"}$n",
|
||||||
[rdLoc(a)])
|
[rdLoc(a)])
|
||||||
of tySequence:
|
of tySequence:
|
||||||
var a: TLoc
|
var a: TLoc
|
||||||
initLocExpr(p, arg, a)
|
initLocExpr(p, arg, a)
|
||||||
linefmt(p, cpsStmts, "if ($1.p && !($1.p->cap & NIM_STRLIT_FLAG)) {$n" &
|
linefmt(p, cpsStmts, "if ($1.p && !($1.p->cap & NIM_STRLIT_FLAG)) {$n" &
|
||||||
" #deallocShared($1.p);$n" &
|
" #deallocShared($1.p);$n" &
|
||||||
" $1.p = NIM_NIL; $1.len = 0; }$n",
|
"}$n",
|
||||||
[rdLoc(a), getTypeDesc(p.module, t.lastSon)])
|
[rdLoc(a), getTypeDesc(p.module, t.lastSon)])
|
||||||
else: discard "nothing to do"
|
else: discard "nothing to do"
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -93,7 +93,7 @@ proc optimize(s: var Scope) =
|
||||||
proc findCorrespondingDestroy(final: seq[PNode]; moved: PNode): int =
|
proc findCorrespondingDestroy(final: seq[PNode]; moved: PNode): int =
|
||||||
# remember that it's destroy(addr(x))
|
# remember that it's destroy(addr(x))
|
||||||
for i in 0 ..< final.len:
|
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 i
|
||||||
return -1
|
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)
|
let tmp = c.getTemp(s.parent[], arg.typ, arg.info)
|
||||||
result.add c.genSink(s, tmp, arg, isDecl = true)
|
result.add c.genSink(s, tmp, arg, isDecl = true)
|
||||||
result.add tmp
|
result.add tmp
|
||||||
s.parent[].final.add c.genDestroy(tmp)
|
s.parent[].final.add newTree(nkStmtList, c.genDestroy(tmp), c.genWasMoved(tmp))
|
||||||
else:
|
else:
|
||||||
let tmp = c.getTemp(s, arg.typ, arg.info)
|
let tmp = c.getTemp(s, arg.typ, arg.info)
|
||||||
result.add c.genSink(s, tmp, arg, isDecl = true)
|
result.add c.genSink(s, tmp, arg, isDecl = true)
|
||||||
result.add tmp
|
result.add tmp
|
||||||
s.final.add c.genDestroy(tmp)
|
s.final.add newTree(nkStmtList, c.genDestroy(tmp), c.genWasMoved(tmp))
|
||||||
else:
|
else:
|
||||||
result = arg
|
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:
|
elif sfThread notin v.sym.flags:
|
||||||
# do not destroy thread vars for now at all for consistency.
|
# do not destroy thread vars for now at all for consistency.
|
||||||
if sfGlobal in v.sym.flags and s.parent == nil:
|
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:
|
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:
|
if ri.kind == nkEmpty and c.inLoop > 0:
|
||||||
res.add moveOrCopy(v, genDefaultCall(v.typ, c, v.info), c, s, isDecl = true)
|
res.add moveOrCopy(v, genDefaultCall(v.typ, c, v.info), c, s, isDecl = true)
|
||||||
elif ri.kind != nkEmpty:
|
elif ri.kind != nkEmpty:
|
||||||
|
|
|
||||||
|
|
@ -535,7 +535,6 @@ proc atomicRefOp(c: var TLiftCtx; t: PType; body, x, y: PNode) =
|
||||||
body.add newAsgnStmt(x, y)
|
body.add newAsgnStmt(x, y)
|
||||||
of attachedDestructor:
|
of attachedDestructor:
|
||||||
body.add genIf(c, cond, actions)
|
body.add genIf(c, cond, actions)
|
||||||
body.add newAsgnStmt(x, newNodeIT(nkNilLit, body.info, t))
|
|
||||||
of attachedDeepCopy: assert(false, "cannot happen")
|
of attachedDeepCopy: assert(false, "cannot happen")
|
||||||
of attachedTrace:
|
of attachedTrace:
|
||||||
if isFinal(elemType):
|
if isFinal(elemType):
|
||||||
|
|
@ -584,7 +583,6 @@ proc atomicClosureOp(c: var TLiftCtx; t: PType; body, x, y: PNode) =
|
||||||
body.add newAsgnStmt(x, y)
|
body.add newAsgnStmt(x, y)
|
||||||
of attachedDestructor:
|
of attachedDestructor:
|
||||||
body.add genIf(c, cond, actions)
|
body.add genIf(c, cond, actions)
|
||||||
body.add newAsgnStmt(xenv, newNodeIT(nkNilLit, body.info, xenv.typ))
|
|
||||||
of attachedDeepCopy: assert(false, "cannot happen")
|
of attachedDeepCopy: assert(false, "cannot happen")
|
||||||
of attachedTrace:
|
of attachedTrace:
|
||||||
body.add callCodegenProc(c.g, "nimTraceRefDyn", c.info, genAddrOf(xenv), y)
|
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:
|
# prevent wrong "dangling refs exist" problems:
|
||||||
var actions = newNodeI(nkStmtList, c.info)
|
var actions = newNodeI(nkStmtList, c.info)
|
||||||
actions.add callCodegenProc(c.g, "nimDecWeakRef", c.info, x)
|
actions.add callCodegenProc(c.g, "nimDecWeakRef", c.info, x)
|
||||||
actions.add newAsgnStmt(x, newNodeIT(nkNilLit, body.info, t))
|
|
||||||
let des = genIf(c, x, actions)
|
let des = genIf(c, x, actions)
|
||||||
if body.len == 0:
|
if body.len == 0:
|
||||||
body.add des
|
body.add des
|
||||||
|
|
@ -642,7 +639,6 @@ proc ownedRefOp(c: var TLiftCtx; t: PType; body, x, y: PNode) =
|
||||||
body.add newAsgnStmt(x, y)
|
body.add newAsgnStmt(x, y)
|
||||||
of attachedDestructor:
|
of attachedDestructor:
|
||||||
body.add genIf(c, x, actions)
|
body.add genIf(c, x, actions)
|
||||||
body.add newAsgnStmt(x, newNodeIT(nkNilLit, body.info, t))
|
|
||||||
of attachedDeepCopy: assert(false, "cannot happen")
|
of attachedDeepCopy: assert(false, "cannot happen")
|
||||||
of attachedTrace, attachedDispose: discard
|
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 genIf(c, xx, callCodegenProc(c.g, "nimDecWeakRef", c.info, xx))
|
||||||
body.add newAsgnStmt(x, y)
|
body.add newAsgnStmt(x, y)
|
||||||
of attachedDestructor:
|
of attachedDestructor:
|
||||||
var actions = newNodeI(nkStmtList, c.info)
|
let des = genIf(c, xx, callCodegenProc(c.g, "nimDecWeakRef", c.info, xx))
|
||||||
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)
|
|
||||||
if body.len == 0:
|
if body.len == 0:
|
||||||
body.add des
|
body.add des
|
||||||
else:
|
else:
|
||||||
|
|
@ -695,7 +688,6 @@ proc ownedClosureOp(c: var TLiftCtx; t: PType; body, x, y: PNode) =
|
||||||
body.add newAsgnStmt(x, y)
|
body.add newAsgnStmt(x, y)
|
||||||
of attachedDestructor:
|
of attachedDestructor:
|
||||||
body.add genIf(c, xx, actions)
|
body.add genIf(c, xx, actions)
|
||||||
body.add newAsgnStmt(xx, newNodeIT(nkNilLit, body.info, xx.typ))
|
|
||||||
of attachedDeepCopy: assert(false, "cannot happen")
|
of attachedDeepCopy: assert(false, "cannot happen")
|
||||||
of attachedTrace, attachedDispose: discard
|
of attachedTrace, attachedDispose: discard
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -73,11 +73,10 @@ proc shrink*[T](x: var seq[T]; newLen: Natural) =
|
||||||
when nimvm:
|
when nimvm:
|
||||||
setLen(x, newLen)
|
setLen(x, newLen)
|
||||||
else:
|
else:
|
||||||
mixin `=destroy`
|
|
||||||
#sysAssert newLen <= x.len, "invalid newLen parameter for 'shrink'"
|
#sysAssert newLen <= x.len, "invalid newLen parameter for 'shrink'"
|
||||||
when not supportsCopyMem(T):
|
when not supportsCopyMem(T):
|
||||||
for i in countdown(x.len - 1, newLen):
|
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'!
|
# XXX This is wrong for const seqs that were moved into 'x'!
|
||||||
cast[ptr NimSeqV2[T]](addr x).len = newLen
|
cast[ptr NimSeqV2[T]](addr x).len = newLen
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,6 @@ when defined(nimv2):
|
||||||
proc `=destroy`(a: var WideCStringObj) =
|
proc `=destroy`(a: var WideCStringObj) =
|
||||||
if a.data != nil:
|
if a.data != nil:
|
||||||
deallocShared(a.data)
|
deallocShared(a.data)
|
||||||
a.data = nil
|
|
||||||
|
|
||||||
proc `=`(a: var WideCStringObj; b: WideCStringObj) {.error.}
|
proc `=`(a: var WideCStringObj; b: WideCStringObj) {.error.}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue