You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 25, 2025. It is now read-only.
Repository navigation
This repository was archived by the owner on Apr 25, 2025. It is now read-only.
Spec module global instantiation is incorrect #571
As globals can now have initial expressions that point to other globals, it's not possible to compute all the initialiser expressions into a vector ahead of global allocation.
If you allocate the vector to hold the globals and then evaluate the initializer expressions, there's no problem, right? Is there a specific part of the spec that says something incorrect?
The Instantiation section actually has a note addressing this:
[...] Similarly, module allocation and the evaluation of global and table initializers as well as element segments are mutually recursive because the global initialization values val*g, ref t, and element segment contents (ref ) are passed to the module allocator while depending on the module instance moduleinst and store 𝑆′ returned by allo- cation. Again, this recursion is just a specification device. In practice, the initialization values can be determined beforehand by staging module allocation such that first, the module’s own function instances are pre-allocated in the store, then the initializer expressions are evaluated in order, allocating globals on the way, then the rest of the module instance is allocated, and finally the new function instances’ module fields are set to that module instance. This is possible because validation ensures that initialization expressions cannot actually call a function, only take their reference.
That said, I have plans to refactor the module rules to be more sequential, but that's currently low priority.
Sure so here on allocation it mentions passing in the global initializer values as a prior, it's impossible to compute these before allocation because their expressions can call global get and globals are not yet allocated.
Let
be the module to allocate and
the vector of external values providing the module’s imports,
the initialization values of the module’s globals,
the initializer reference of the module’s tables, and
the reference vectors of the module’s element segments.
...
For each global
in
, do:
Let
be the global type obtained by instantiating
in
defined below.
Let
be the global address resulting from allocating
with initializer value
.
This also applies to element segment initial expressions also in the spec, data segments are already after module allocation so they are fine as they are.
@rossberg
It's actually a slightly different problem to what you linked, the allocation depending on a partial instance problem has been the case prior to the gc spec. This issue specifically relates global initializer values and element segment values now including global.get as a const express and thus having to come after global allocation
Activity
tlively commentedon Nov 1, 2024
If you allocate the vector to hold the globals and then evaluate the initializer expressions, there's no problem, right? Is there a specific part of the spec that says something incorrect?
rossberg commentedon Nov 2, 2024
The Instantiation section actually has a note addressing this:
That said, I have plans to refactor the module rules to be more sequential, but that's currently low priority.
CharlieTap commentedon Nov 2, 2024
Hey @tlively
Sure so here on allocation it mentions passing in the global initializer values as a prior, it's impossible to compute these before allocation because their expressions can call global get and globals are not yet allocated.
...
CharlieTap commentedon Nov 2, 2024
This also applies to element segment initial expressions also in the spec, data segments are already after module allocation so they are fine as they are.
@rossberg
It's actually a slightly different problem to what you linked, the allocation depending on a partial instance problem has been the case prior to the gc spec. This issue specifically relates global initializer values and element segment values now including global.get as a const express and thus having to come after global allocation