parent
1f2042411a
commit
034dad8e32
2 changed files with 34 additions and 2 deletions
|
|
@ -602,6 +602,9 @@ proc pVarTopLevel(v: PNode; c: var Con; ri, res: PNode) =
|
||||||
res.add newTree(nkFastAsgn, v, genDefaultCall(v.typ, c, v.info))
|
res.add newTree(nkFastAsgn, v, genDefaultCall(v.typ, c, v.info))
|
||||||
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:
|
||||||
|
c.graph.globalDestructors.add genDestroy(c, v)
|
||||||
|
else:
|
||||||
c.destroys.add genDestroy(c, v)
|
c.destroys.add genDestroy(c, 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)
|
res.add moveOrCopy(v, genDefaultCall(v.typ, c, v.info), c)
|
||||||
|
|
@ -616,7 +619,7 @@ proc pVarScoped(v: PNode; c: var Con; ri, res: PNode) =
|
||||||
# unpacked tuple needs reset at every loop iteration
|
# unpacked tuple needs reset at every loop iteration
|
||||||
res.add newTree(nkFastAsgn, v, genDefaultCall(v.typ, c, v.info))
|
res.add newTree(nkFastAsgn, v, genDefaultCall(v.typ, c, v.info))
|
||||||
elif {sfGlobal, sfThread} * v.sym.flags == {sfGlobal}:
|
elif {sfGlobal, sfThread} * v.sym.flags == {sfGlobal}:
|
||||||
c.destroys.add genDestroy(c, v)
|
c.graph.globalDestructors.add genDestroy(c, v)
|
||||||
else:
|
else:
|
||||||
# We always translate 'var v = f()' into bitcopies. If 'v' is in a loop,
|
# We always translate 'var v = f()' into bitcopies. If 'v' is in a loop,
|
||||||
# the destruction at the loop end will free the resources. Other assignments
|
# the destruction at the loop end will free the resources. Other assignments
|
||||||
|
|
|
||||||
29
tests/arc/tarcmisc.nim
Normal file
29
tests/arc/tarcmisc.nim
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
discard """
|
||||||
|
output: '''
|
||||||
|
destroyed: false
|
||||||
|
destroyed: false
|
||||||
|
destroying variable'''
|
||||||
|
cmd: "nim c --gc:arc $file"
|
||||||
|
"""
|
||||||
|
|
||||||
|
# bug #13691
|
||||||
|
type Variable = ref object
|
||||||
|
value: int
|
||||||
|
|
||||||
|
proc `=destroy`(self: var typeof(Variable()[])) =
|
||||||
|
echo "destroying variable"
|
||||||
|
|
||||||
|
proc newVariable(value: int): Variable =
|
||||||
|
result = Variable()
|
||||||
|
result.value = value
|
||||||
|
|
||||||
|
proc test(count: int) =
|
||||||
|
var v {.global.} = newVariable(10)
|
||||||
|
|
||||||
|
var count = count - 1
|
||||||
|
if count == 0: return
|
||||||
|
|
||||||
|
test(count)
|
||||||
|
echo "destroyed: ", v.isNil
|
||||||
|
|
||||||
|
test(3)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue