Open mneumann opened 1 year ago
Yes, finalizers are still missing. The mechanism is there in the Pony runtime (which we leverage in Savi), but the Savi language/compiler is not set up to use it yet.
What do you think of the following syntax?
:class GLFW
:finalizer
_FFI.glfwTerminate
A few things at top of mind that the compiler needs to take care of to make finalizers work:
Allow only one :finalizer
declaration per type
Allow :finalizer
only on heap-allocated types (i.e. :class
and :actor
, or a :trait
that gets folded into a :class
or :actor
)
Ensure :is
and :copies
declaration can copy a finalizer to a destination type
Ensure a finalizer body has a box
reference to the class it is owned by
Analysis to know whether a given function "can send a message"
Prevent finalizers (via a compilation error) that "can send a message"
In the future, when fat pointers are added, prevent fat-pointer "transmutation" if either the source type or destination type has a finalizer
With all that done, then it's just a matter of hooking into the finalizer desc slot in the Pony runtime in the LLVM IR generation pass to make it happen.
The syntax would work perfectly!
In my case this would be useful so that
GLFW.terminate
will be called once all references go out of scope / get recyled (there will only ever be one instance...). Meaning, you cannot terminate GLFW while there are still references to it. Atm, this is not possible, or I didn't find the appropriate functionality.