more arc improvements (#12690)
* ARC: bugfix for =destroy for inherited objects * added code useful for debugging
This commit is contained in:
parent
a88004114d
commit
85ffcd80c0
4 changed files with 32 additions and 5 deletions
|
|
@ -150,11 +150,18 @@ proc createObj*(g: ModuleGraph; owner: PSym, info: TLineInfo; final=true): PType
|
||||||
s.typ = result
|
s.typ = result
|
||||||
result.sym = s
|
result.sym = s
|
||||||
|
|
||||||
|
template fieldCheck {.dirty.} =
|
||||||
|
when false:
|
||||||
|
if tfCheckedForDestructor in obj.flags:
|
||||||
|
echo "missed field ", field.name.s
|
||||||
|
writeStackTrace()
|
||||||
|
|
||||||
proc rawAddField*(obj: PType; field: PSym) =
|
proc rawAddField*(obj: PType; field: PSym) =
|
||||||
assert field.kind == skField
|
assert field.kind == skField
|
||||||
field.position = len(obj.n)
|
field.position = len(obj.n)
|
||||||
addSon(obj.n, newSymNode(field))
|
addSon(obj.n, newSymNode(field))
|
||||||
propagateToOwner(obj, field.typ)
|
propagateToOwner(obj, field.typ)
|
||||||
|
fieldCheck()
|
||||||
|
|
||||||
proc rawIndirectAccess*(a: PNode; field: PSym; info: TLineInfo): PNode =
|
proc rawIndirectAccess*(a: PNode; field: PSym; info: TLineInfo): PNode =
|
||||||
# returns a[].field as a node
|
# returns a[].field as a node
|
||||||
|
|
@ -208,6 +215,7 @@ proc addField*(obj: PType; s: PSym; cache: IdentCache) =
|
||||||
propagateToOwner(obj, t)
|
propagateToOwner(obj, t)
|
||||||
field.position = len(obj.n)
|
field.position = len(obj.n)
|
||||||
addSon(obj.n, newSymNode(field))
|
addSon(obj.n, newSymNode(field))
|
||||||
|
fieldCheck()
|
||||||
|
|
||||||
proc addUniqueField*(obj: PType; s: PSym; cache: IdentCache): PSym {.discardable.} =
|
proc addUniqueField*(obj: PType; s: PSym; cache: IdentCache): PSym {.discardable.} =
|
||||||
result = lookupInRecord(obj.n, s.id)
|
result = lookupInRecord(obj.n, s.id)
|
||||||
|
|
|
||||||
|
|
@ -855,6 +855,8 @@ proc track(tracked: PEffects, n: PNode) =
|
||||||
if x.sons[0].kind == nkSym and sfDiscriminant in x.sons[0].sym.flags:
|
if x.sons[0].kind == nkSym and sfDiscriminant in x.sons[0].sym.flags:
|
||||||
addDiscriminantFact(tracked.guards, x)
|
addDiscriminantFact(tracked.guards, x)
|
||||||
setLen(tracked.guards.s, oldFacts)
|
setLen(tracked.guards.s, oldFacts)
|
||||||
|
if tracked.owner.kind != skMacro:
|
||||||
|
createTypeBoundOps(tracked, n.typ, n.info)
|
||||||
of nkPragmaBlock:
|
of nkPragmaBlock:
|
||||||
let pragmaList = n.sons[0]
|
let pragmaList = n.sons[0]
|
||||||
let oldLocked = tracked.locked.len
|
let oldLocked = tracked.locked.len
|
||||||
|
|
@ -885,6 +887,7 @@ proc track(tracked: PEffects, n: PNode) =
|
||||||
if n.len == 1: track(tracked, n.sons[0])
|
if n.len == 1: track(tracked, n.sons[0])
|
||||||
of nkBracket:
|
of nkBracket:
|
||||||
for i in 0 ..< safeLen(n): track(tracked, n.sons[i])
|
for i in 0 ..< safeLen(n): track(tracked, n.sons[i])
|
||||||
|
if tracked.owner.kind != skMacro:
|
||||||
createTypeBoundOps(tracked, n.typ, n.info)
|
createTypeBoundOps(tracked, n.typ, n.info)
|
||||||
else:
|
else:
|
||||||
for i in 0 ..< safeLen(n): track(tracked, n.sons[i])
|
for i in 0 ..< safeLen(n): track(tracked, n.sons[i])
|
||||||
|
|
|
||||||
|
|
@ -68,6 +68,7 @@ proc nimIncRef(p: pointer) {.compilerRtl, inl.} =
|
||||||
atomicInc head(p).rc
|
atomicInc head(p).rc
|
||||||
else:
|
else:
|
||||||
inc head(p).rc
|
inc head(p).rc
|
||||||
|
#cprintf("[INCREF] %p\n", p)
|
||||||
|
|
||||||
proc nimRawDispose(p: pointer) {.compilerRtl.} =
|
proc nimRawDispose(p: pointer) {.compilerRtl.} =
|
||||||
when not defined(nimscript):
|
when not defined(nimscript):
|
||||||
|
|
@ -113,13 +114,15 @@ proc nimDecRefIsLast(p: pointer): bool {.compilerRtl, inl.} =
|
||||||
if atomicLoadN(addr head(p).rc, ATOMIC_RELAXED) == 0:
|
if atomicLoadN(addr head(p).rc, ATOMIC_RELAXED) == 0:
|
||||||
result = true
|
result = true
|
||||||
else:
|
else:
|
||||||
if atomicDec(head(p).rc) <= 0:
|
discard atomicDec(head(p).rc)
|
||||||
result = true
|
|
||||||
else:
|
else:
|
||||||
if head(p).rc == 0:
|
if head(p).rc == 0:
|
||||||
result = true
|
result = true
|
||||||
|
#cprintf("[DESTROY] %p\n", p)
|
||||||
else:
|
else:
|
||||||
dec head(p).rc
|
dec head(p).rc
|
||||||
|
# According to Lins it's correct to do nothing else here.
|
||||||
|
#cprintf("[DeCREF] %p\n", p)
|
||||||
|
|
||||||
proc GC_unref*[T](x: ref T) =
|
proc GC_unref*[T](x: ref T) =
|
||||||
## New runtime only supports this operation for 'ref T'.
|
## New runtime only supports this operation for 'ref T'.
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ discard """
|
||||||
Success
|
Success
|
||||||
@["a", "b", "c"]
|
@["a", "b", "c"]
|
||||||
0'''
|
0'''
|
||||||
cmd: '''nim c --gc:destructors $file'''
|
cmd: '''nim c --gc:arc $file'''
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
@ -69,10 +69,23 @@ proc take3 =
|
||||||
for x in infinite.take(3):
|
for x in infinite.take(3):
|
||||||
discard
|
discard
|
||||||
|
|
||||||
|
|
||||||
|
type
|
||||||
|
A = ref object of RootObj
|
||||||
|
x: int
|
||||||
|
|
||||||
|
B = ref object of A
|
||||||
|
more: string
|
||||||
|
|
||||||
|
proc inheritanceBug(param: string) =
|
||||||
|
var s: (A, A)
|
||||||
|
s[0] = B(more: "a" & param)
|
||||||
|
s[1] = B(more: "a" & param)
|
||||||
|
|
||||||
let startMem = getOccupiedMem()
|
let startMem = getOccupiedMem()
|
||||||
take3()
|
take3()
|
||||||
tlazyList()
|
tlazyList()
|
||||||
|
inheritanceBug("whatever")
|
||||||
mkManyLeaks()
|
mkManyLeaks()
|
||||||
tsimpleClosureIterator()
|
tsimpleClosureIterator()
|
||||||
tleakingNewStmt()
|
tleakingNewStmt()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue