-
Notifications
You must be signed in to change notification settings - Fork 472
where are instantiation-time initializers documented? #694
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
Comments
Hm, I'm not sure what you mean. The description states that:
That's why you have a byte vector, not an expression. |
My apologies, I mixed up some of the terminology - please see the updated issue text which just focusses on the offset for data segments. |
That is checked as part of validation. When you click on "constant" in that sentence it takes you to the rules defining it, which enforce the constraints you mentioned. |
Ah, fantastic - thanks. |
The constant expressions are somewhat underspecified, I have to agree. The spec says what one is, but not really how to evaluate it at runtime. There is a sentence describing how instantiation works, that says "evaluate the expression representing the global's initializer" (which must be single instruction due to prior type validation). Yet, the execution context is hazy here. For example, what if two globals are each initialized to each other's value with a get-global opcode? Or what if a global references itself? And finally, what if there are no recursive or self-referential initializers, but the first global references the second one (which seems to be ruled out by the spec describing the globals being initialized one by one in order). Edit: or is it saying actually that the get-global instructions can only reference imported globals, to rule out any dependency problems among the initializers for defined globals? |
@NWilson, yes, what your edit says. Global initializers cannot access other non-imported globals, which is already ensured by module validation, specifically through the introduction of a restricted context C' for validating these initializer expressions. Correspondingly, during module instantiation, steps 5a-c set up a frame for evaluating the initializers with an auxiliary module instance that only gives access to imported globals. For evaluation of constant expressions in segments the full module instance is already in place and a frame set up, see steps 6-8 of instantiation. |
The syntax for data segments includes an offset expression:
Which is described as:
However, in practice, this can either be a constant, or an (imported) global:
I cannot find the this documented anywhere other than in the unofficial spec:
https://github.com/sunfishcode/wasm-reference-manual/blob/master/WebAssembly.md#instantiation-time-initializers
The text was updated successfully, but these errors were encountered: