mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-31 02:12:11 +00:00
cursor fields cannot form reference cycles (#21832)
* cursor fields cannot form a reference cycle
* fixes typo
* fixes position
(cherry picked from commit ebbad9e960)
This commit is contained in:
@@ -372,15 +372,18 @@ proc canFormAcycleAux(g: ModuleGraph; marker: var IntSet, typ: PType, orig: PTyp
|
||||
proc canFormAcycleNode(g: ModuleGraph; marker: var IntSet, n: PNode, orig: PType, withRef: bool, hasTrace: bool): bool =
|
||||
result = false
|
||||
if n != nil:
|
||||
result = canFormAcycleAux(g, marker, n.typ, orig, withRef, hasTrace)
|
||||
if not result:
|
||||
case n.kind
|
||||
of nkNone..nkNilLit:
|
||||
discard
|
||||
else:
|
||||
for i in 0..<n.len:
|
||||
result = canFormAcycleNode(g, marker, n[i], orig, withRef, hasTrace)
|
||||
if result: return
|
||||
var hasCursor = n.kind == nkSym and sfCursor in n.sym.flags
|
||||
# cursor fields don't own the refs, which cannot form reference cycles
|
||||
if hasTrace or not hasCursor:
|
||||
result = canFormAcycleAux(g, marker, n.typ, orig, withRef, hasTrace)
|
||||
if not result:
|
||||
case n.kind
|
||||
of nkNone..nkNilLit:
|
||||
discard
|
||||
else:
|
||||
for i in 0..<n.len:
|
||||
result = canFormAcycleNode(g, marker, n[i], orig, withRef, hasTrace)
|
||||
if result: return
|
||||
|
||||
|
||||
proc sameBackendType*(x, y: PType): bool
|
||||
|
||||
@@ -51,10 +51,7 @@ cyclicNo((Cyclone, ))
|
||||
cyclicNo(Acyclic)
|
||||
|
||||
cyclicYes(LinkedNode)
|
||||
|
||||
when false:
|
||||
# todo fix me
|
||||
cyclicNo(LinkedNodeWithCursor)
|
||||
cyclicNo(LinkedNodeWithCursor) # cursor doesn't increase rc, cannot form a cycle
|
||||
|
||||
type
|
||||
ObjectWithoutCycles = object
|
||||
@@ -121,3 +118,18 @@ block:
|
||||
proc `=trace`(x: var myseq[Node]; env: pointer) = discard
|
||||
|
||||
cyclicYes(Node)
|
||||
|
||||
block:
|
||||
type
|
||||
Foo = object
|
||||
id: ptr ref Foo
|
||||
|
||||
cyclicNo(Foo)
|
||||
|
||||
block:
|
||||
type
|
||||
InheritableObj = object of RootObj
|
||||
InheritableRef = ref object of RootObj
|
||||
|
||||
cyclicYes(InheritableObj)
|
||||
cyclicYes(InheritableRef)
|
||||
|
||||
Reference in New Issue
Block a user