-
Notifications
You must be signed in to change notification settings - Fork 517
Description
https://github.com/WebAssembly/design/blob/master/Modules.md#initializer-expression says that the only globals allowed in get_global initializer expressions should be immutable imports:
- get_global, where the global index must refer to an immutable import.
There are tests in memory.wast that use module-defined globals in get_global initializer expressions:
https://github.com/WebAssembly/spec/blob/master/interpreter/test/memory.wast#L13-L16
In particular, since globals can be initialized with initializer expressions, we can have cycles:
(module
(global $foo i32 (get_global $bar))
(global $bar i32 (get_global $foo))
)
The spec interpreter refuses this because it follows initialization order, and $bar is not known when we define $foo. I just found out there's actually a test for this in globals.wast, so this is probably intended behavior here, and probably the reasonable choice if we want to allow module-defined globals to appear in global initializer expressions.
What if we have an imported global, and another global is initialized by get_global on this imported global? (that's equivalent to the second global importing the same field, modulo JS strange behavior (if there's a proxy/getter on the imported object field))
In general, instead of doing a get_global with a module-defined global $foo as an operand, in an initializer expression of global $bar, a wasm generator can just use the initializer expression of $foo for initializing $bar, preventing a spurious indirection here.
In any cases, it seems that either the design repository is not up to date, or the ml-proto is drifting a bit away from the design.