-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dependency on Symbols as WeakMap keys proposal #341
Comments
Why? You can make a Map of Symbols to WeakRefs, and put the object in the weakref. |
See this comment in the original idea for primitives only (+function wrappers), @erights may need to clarify what situations become uncollectable. |
Could you clarify why? The object graphs of multiple shadow realms are fully entangled through the closures that any wrapped callable exotic has in its context, so it's not an implementation requirement. From a program perspective, you actually don't need any |
It's possible this doesn't apply anymore, but I recall seeing a few people assuming that symbols as weakmap keys would work in #289 and #299 so I was mostly raising this issue as I assumed that they would be still be required.
As membranes are the main reference to symbols as weakmap keys in the aforementioned issues, this is possibly a non-issue then. The implementation of that is a bit much for me to be able to follow, but does that guarantee collectability of cross-realm cycles? |
Engines have a single GC per agent (and I actually hear they're moving to a single GC per agent cluster), which means they're able to identify direct cycles across realms, and they already do today. A membrane implementation using the callable wrapper trick in effect creates a reference from a proxy representative in one shadow realm to the real target object in the other realm, and a reference to the proxy from the other realm so that it can be "selected" by the boundary. WeakMap are in fact used to remember which selection / "pointer" wrapped callable to use for each exported object. All that to say it's possible to implement a membrane without anchoring anything in any realm's root, so a single GC can perform cycle detection. |
I'm gonna close this as implementations are starting to appear for both symbols as weakmap keys and shadow realms, so people should be able to use them together to implement object tracking fairly easily. |
So for the new
ShadowRealm
to be able to handle GC across the realm boundary we need the symbols as WeakMap keys, as otherwise we are unable to provide a collectable identity for an object in aShadowRealm
.But we have a situation at the moment where implementers seem to be willing to implement this design of
ShadowRealm
and the API is even at Stage 3. However the symbols-as-WeakMap-keys proposal is still at Stage 2 and I don't see as much activity on it so it's hard to tell if there is agreement that that will ship also ifShadowRealm
does.Do we consider this dependency on symbols-as-weakmap-keys as a problem? Or would shipping
ShadowRealm
without that proposal still be acceptable?The text was updated successfully, but these errors were encountered: