-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Export mutable wasm globals as JS objects. NFC #25530
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
Conversation
acef802
to
906bef0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can yo remind me what we wanted to use this for?
$isImmutableGlobal: (val) => { | ||
if (val instanceof WebAssembly.Global) { | ||
try { | ||
val.value = val.value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this particular method of checking for the presence of the value
property? Wouldn't it be easier to do hasOwnProperty
or something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check is only checking for mutability, which is not something that the JS spec exposes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah right. Since we expose immutable globals as numbers, should we have some kind of assertion that there aren't any immutable globals exported as wasm globals?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah right. Since we expose immutable globals as numbers, should we have some kind of assertion that there aren't any immutable globals exported as wasm globals?
But we do have such exports. All data symbols (addresses) are exported in this way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I guess you are saying, do we have tests that confirm if data exports are working? I assume we have many such tests.. basically any test that does EMSCRIPTEN_KEEPALIVE
on a data symbol, or included a data symbols in EXPORTED_FUNCTIONS
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More like, we expect everything exported as a WebAssembly.Global to be mutable (because up until now, all data exports are immutable and exported as numbers and we never exported anything as a mutable global other than the stack pointer). So if we ever see an immutable WebAssembly.Global it would be an error, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, but this function (isImmutableGlobal
) is used to disciminate bewtween those two types of exports.
Type 1: Mutable globals that we are exporting with the intent that they are exported as first class globals (e.g. __stack_pointer
.
Type 2: Immutable globals that are exported as addresses, and are visible on the outside a simply numbers. These one also get relocated (+= __memory_base) so they can be used to index into the HEAP directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i.e. at this point in the code we expect to see both types.
Remind me what the use you had in mind for this was? Just so users could export their own globals? |
My initial use case was to make exporting the But I can imagine we maybe have other mutable globals that also want to be import/exported between modules. |
For immutable wasm globals we currently export them as simple JS numbers at build time. This is because data symbol addresses are exported as immutable globals. However, its also useful to export real wasm globals. For now we treat mutable globals and immutable global differently here but we should look into perhaps changing that in the future.
For immutable wasm globals we currently export them as simple JS numbers at build time. This is because data symbol addresses are exported as immutable globals.
However, its also useful to export real wasm globals. For now we treat mutable globals and immutable global differently here but we should look into perhaps changing that in the future.