Re:ORC – Nim's new memory managment
by throwaway_pdp09 on Wednesday December 09, 2020 @10:49AM
(#25359799)
> easy to tell if a type can have cycles or not at compile-time, you just need to check if it refers to itself
Certainly useful at times as I suppose it may be used to ensure you don't have cycles (I imagine that could be useful for resource management) but 'can have cycles' is definitely not 'does have cycles'. It's the latter that's important here.
And the ``{.acyclic.}`` hint applies to the later.
In the future we might have formal verification helping as well: https://nim-lang.org/docs/drnim.html
Otherwise traditional GC use a copying mechanism, what doesn't end up copied is dead.
The old reference counting GC in Nim had that extra copying pass when a type could have cycles.
That said, it's very easy to tell if a type can have cycles or not at compile-time, you just need to check if it refers to itself i.e. does the Node type has a Node field (or a field that can recursively contain a Node field).