-
Notifications
You must be signed in to change notification settings - Fork 36
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
exnref <: anyref allows cyclical references to exceptions #85
Comments
If you take dynamic lifetime management for functions and instances into account, then you cannot prohibit cycles in general. Even in the MVP, you can create a cycle between a table M1.t and two functions M1.f and M2.f from different modules M1, M2, by putting M2.f into M1.t. So cycles involving functions are not new. I think the statement from the proposal is meant to say that there cannot be cycles between "dynamically" allocated values (where functions and instances are considered "static" in some suitable sense). Also note that the situation is simply a consequence of exnref being a value type, which allows storing it in a global (and which is intentional). Whether exnref is also a subtype of anyref makes no difference AFAICS. |
It's true that
I don't see how this distinction makes it easier to reference count exceptions that are part of a cycle that includes "static" objects.
I'm only saying that making |
It means that you only need to worry about cycles in situations where you already have to, namely when wanting to deallocate modules or functions. That is, an engine can handle exnrefs per se with reference counting; a global may hold a reference. If the engine has no mechanism for deallocating modules (which may be the case in offline VMs, for example), then that's enough. OTOH, a system that wants to deallocate modules already needs to have a mechanism to detect cycles between module-level objects. All that changes is that this mechanism now also needs to look through exnrefs, not just funcrefs. Either can occur in globals or tables. |
It's possible to eagerly free an exception by storing two separate reference counts: one for locals and value stack slots, and one for globals and table elements. When both reference counts reach zero, the exception may be eagerly freed. When only the local/stack reference count is zero, it may still be possible to free the exception by scanning for unreachable anyref cycles. Nevertheless, I think some clarification to the proposal is warranted. |
Closing this, as we decided to remove |
From the proposal:
If
exnref
<:anyref
, then it's possible to form cycles including an exception object. For example, you can throw an exception with an argument that references a function, catch the exception, and store theexnref
in a global accessible by the function referenced by the exception. The function must implicitly hold a reference to the global that it may access, so there's a cycle from exception->function->global->exception.I can't see how it's possible to prohibit
exnref
cycles as long as they are subtypes ofanyref
and can stored in tables, mutable globals, etc. Am I missing something?The text was updated successfully, but these errors were encountered: