-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
esm: --experimental-wasm-modules integration support #27659
Conversation
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.
Note that this is slightly different than the standards track semantics, as it doesn't take a turn on the event loop during Instantiation. However, I don't expect this to affect most programs. I would also encourage you to write several more tests before landing.
const exports = WebAssembly.Module.exports(compiled).map(({ name }) => name); | ||
|
||
return createDynamicModule(imports, exports, url, (reflect) => { | ||
const { exports } = new WebAssembly.Instance(compiled, reflect.imports); |
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.
In a cycle-closing edge, will reflect.imports usually be an empty object? If so, this will be basically the right semantics.
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.
On the unexecuted cycle edge, reflect.imports
would contain all the imported module namespaces, with their named exports, but all of those named exports would be undefined. Function exports would be supported in cycles here though just like ES modules.
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.
Actually cycles would throw for any accesses to uninitialized let bindings on the namespaces, since these would be in TDZ.
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.
To summarize:
- Unexecuted cycle edge with function exports: fine - function is defined
- Unexecuted cycle edge with let binding: throws - TDZ error
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.
And specifically these errors are only thrown if the WASM module actually attempts to access the given binding.
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, so in particular, Wasm exports should always act like const bindings, and all imports are accessed during Instantiate (in the ESM evaluate phase). Does this implementation do that?
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.
yep! reflect.imports
is namespace objects so the imports are accessed 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.
please upload a wat source for simple.wasm with a comment in the top with the command used to produce simple.wasm
example: https://github.com/nodejs/node/blob/master/test/fixtures/shared-memory.wat
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.
- How might one have an entry point that's directly in wasm, without the need for an ESM wrapper?
- how might one consume wasm modules in CJS?
declare a wasm start function in your wasm module this reminds me, @guybedford can you make a test which verifies that start functions run at the correct time?
at the moment, |
@devsnek so I'll rephrase the question - how might one synchronously consume wasm modules in cjs? |
yes
not possible atm. if |
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.
actually... can you add a test that verifies that the wasm start function runs during the evaluate phase? in wat, you can specify it with (start $funcname)
Sure, I've added a start function test. |
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.
LGTM
CommonJS loader. Additional formats such as _"wasm"_ or _"addon"_ can be | ||
extended in future updates. | ||
CommonJS loader. Additional formats such as _"addon"_ can be extended in future | ||
updates. |
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.
There's one additional mention of the non-existent --entry-type
CLI flag 7 lines below this one. Is this the right PR to remove or update that material?
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.
Nice work @guybedford!
Landed in bbc254d. |
PR-URL: #27659 Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Myles Borins <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
PR-URL: #27659 Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Myles Borins <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
Notable changes: * esm: * Added the `--experimental-wasm-modules` flag to support WebAssembly modules (Myles Borins & Guy Bedford) #27659 * process: * Log errors using `util.inspect` in case of fatal exceptions (Ruben Bridgewater) #27243 * repl: * Add `process.on('uncaughtException')` support (Ruben Bridgewater) #27151 * stream: * Implemented `Readable.from` async iterator utility (Guy Bedford) #27660 * tls: * Expose built-in root certificates (Ben Noordhuis) #26415 * Support `net.Server` options (Luigi Pinca) #27665 * Expose `keylog` event on TLSSocket (Alba Mendez) #27654 * worker: * Added the ability to unshift messages from the `MessagePort` (Anna Henningsen) #27294 PR-URL: #27799
Notable changes: * esm: * Added the `--experimental-wasm-modules` flag to support WebAssembly modules (Myles Borins & Guy Bedford) #27659 * process: * Log errors using `util.inspect` in case of fatal exceptions (Ruben Bridgewater) #27243 * repl: * Add `process.on('uncaughtException')` support (Ruben Bridgewater) #27151 * stream: * Implemented `Readable.from` async iterator utility (Guy Bedford) #27660 * tls: * Expose built-in root certificates (Ben Noordhuis) #26415 * Support `net.Server` options (Luigi Pinca) #27665 * Expose `keylog` event on TLSSocket (Alba Mendez) #27654 * worker: * Added the ability to unshift messages from the `MessagePort` (Anna Henningsen) #27294 PR-URL: #27799
Ahem, very interesting! 😄 Any guidelines or examples on how to start playing with it in Node.js? |
I've created an example project using '--experimental-wasm-modules' for those who're interested. |
PR-URL: #27948 Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Guy Bedford <[email protected]> Reviewed-By: Shingo Inoue <[email protected]> Reviewed-By: James M Snell <[email protected]>
This PR provides support for
node --experimental-modules --experimental-wasm-modules
to support the ES module integration of WebAssembly modules through egimport './module.wasm'
.The semantics match the proposed ES module integration semantics for Web Assembly as specified in https://github.com/webassembly/esm-integration.
At the previous modules group meeting we got consensus approval for upstreaming this feature under the
--experimental-wasm-modules
flag.//cc @nodejs/modules
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes