So I have code that looks like this:
let myobj = objectFactory() # returns ref object
myseq = @[myobj]
When checking the containing method with expandArc I see that nimMarkCyclic is called on the variable. This object is moved to another thread and the ORC code crashes after a destructor is called. Sorry if that's just noise but that's the high level context.
I changed the code to use var instead of let and then called move when adding to the sequence and that removes the nimMarkCyclic call. I'm just wondering why this is marked "cyclic" because it seems to me that it's just 2 references to something not something referencing itself. I'm wondering if this is the intended behavior and I'm just not understanding how the memory management works or if there is possibly a bug.
This is actually not my code. It's here: https://github.com/Vindaar/ginger/blob/master/src/ginger.nim#L1850-L1861
If it helps the here is a block of code from the compiler output:
chUp = initLine(view, Coord(x: pLeft, y: errorUp),
Coord(x: pRight, y: errorUp), style, "line")
chDown = initLine(view, Coord(x: pLeft, y: errorDown),
Coord(x: pRight, y: errorDown), style, "line")
add(result.children):
:tmpD_11 = @[
let blitTmp = chUp
nimMarkCyclic(chUp)
wasMoved(chUp)
blitTmp,
let blitTmp_1 = chDown
nimMarkCyclic(chDown)
wasMoved(chDown)
blitTmp_1]
:tmpD_11
I'm just wondering why this is marked "cyclic" because it seems to me that it's just 2 references to something not something referencing itself.
It's marked cyclic because the compiler thinks it could potentially create a cycle. I suppose the naming could be improved, the semantics are actually markAsPotentiallyCyclic.