Vale icon indicating copy to clipboard operation
Vale copied to clipboard

Make GM weak references use WRC control blocks

Open Verdagon opened this issue 2 years ago • 0 comments

A weak ref should be a pointer to a malloc'd 16B "control block" with a weak ref count ("WRC") and a pointer to the actual object ("ObjPtr").

A weakable object should have an implicit field: a pointer to this control block ("ControlPtr").

When the object is destroyed, ControlPtr != null, and WRC == 0, deallocate the control block.

When the object is destroyed, ControlPtr != null, and WRC > 0, don't deallocate the control block but set ObjPtr to null.

When we alias a weak ref, we should increment the WRC.

When we dealias a weak ref, we should decrement the WRC. If WRC == 0 and ObjPtr == null, deallocate the control block.

Later, when we have inline data, when we move something inline, update the ObjPtr to point to the moved data.

We could make a new region where everything is weakable and normal non-owning refs will contain not generations, but pointers to these control blocks, and instead of doing a gen check, we'll check that ptr == ObjPtr. If it's different, we can say that it moved. We could even have a code location to show who moved it, and another code location to show where it now lives (like, which local or member). This could be the new assist mode, that doesn't rely on constraint refs.

Verdagon avatar May 29 '22 14:05 Verdagon