Sink and assignment operations are never called when appearing as top-level statements.
The transformation is only done for function body nodes (see here).
Uncommenting these lines fixes this.
I suppose there is a reason why this is disabled. Would re-enabling it, and checking for global scope, have the expected behavior?
I suppose there is a reason why this is disabled. Would re-enabling it, and checking for global scope, have the expected behavior?
Obviously not. :-) Problem is we need a "top level statements collector" in order to support this properly and that requires a (minor?) compiler refactoring.
we worked this around for now with cpp shared pointers: https://github.com/fragcolor-xyz/fragments/commit/9982e45278edf91961cabda4cf59cab4c9d86871
Would be nice to have a fix tho but I suspect it's related to the remaining work on destructors/gcdestructors I guess, so better do things at the right pace.
Er, isn't the obvious workaround to put your code in a main proc? Top level statements are rarely required, they are mostly a convenience.
Generally speaking obviously yes.
But we are trying to drag people from python to nim with our project so I completely see users writing stuff in the global scope.
Those variables will hold tensors that possibly are owning GPU memory and so GC refs ( which are unaware of the actual weight in memory) are not viable. Using objects is our only best clean solution.
We will migrate to gc destructors possibly tho finally, so we could just have a special allocator for tensors.
This has been fixed.
Most helpful comment
This has been fixed.