-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Top-level-await, new WASM modules and async modules based on import await and import async #9177
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
For maintainers only:
|
8d56afb
to
fae4598
Compare
So I added WASM-ESM-integration based on WASM being async modules according to the proposal here: https://github.com/WebAssembly/esm-integration/tree/master/proposals/esm-integration Here are a few examples:
There are a few functional changes compared to the old wasm implementation:
Implementation-wise:
A note on wasm-bindgen: It will break for two reasons:
|
214e645
to
544d3e1
Compare
Wow @sokra that's an awesome update! Thanks for the work. From a Wasm viewpoint it's mostly lgtm, apart from:
This should still be disallowed, as it will throw when called from JS. A proposal exists already for that: https://github.com/WebAssembly/JS-BigInt-integration. Do you think this can still land this week? |
Before this change we throw a build error when using i64-signatures, but as this will be soonish supported, I feel a build error is to much. Using an i64-signature might not even be an error, as somebody could have a browser with BigInt support. |
Not sure. I actually wait for some feedback from @littledan about the Unrelated from this: I want to move this and other things behind experiments: {
mjs: true,
topLevelAwait: true,
asyncWasm: true,
// ...
} |
Opt in sounds important to do before landing this. I am excited to see the Webpack leading with experimentation here. However, the current TC39 proposal is based on |
I could also implement this, but it's a bit more involved since the async-or-not status of a module no longer only depends on itself, but on all dependencies too. So async status need to be inferred in a separate step after building the module graph. (That's also what I'm criticizing on the proposal. This is confusing for the developer too) |
That's very true, I agree.
Would that allow Webpack to iterate faster, aka break code? |
I would use relaxed SemVer for |
544d3e1
to
f4c133f
Compare
type: "webassembly/async-experimental" remove i64 importing limitation since it will have BigInt integration eventually update wasm example
Hey All, We put together a small doc as an explainer for why the champions of Thank you for thanking the time to work on this alternative approach, it really helped us improve the algorithm for https://gist.github.com/MylesBorins/ae97abab4a4144411c12240bb09dc7dd How the current specification works
Concerns with
|
@MylesBorins Here is my answer to this: https://gist.github.com/sokra/34d2afe7555eb9a687e2c7566e9a9646 I'm currently in progress of implementing the original top-level-await proposal in this PR in addition to I'm currently pushing towards One thing I have a bit trouble with is understanding the exact behavior of async cycles. I would love to hear some plaintext explanation about that. |
To clarify, cycles of modules which have static |
// entry.js
import x from "a";
import y from "b";
console.log(x);
console.log(y);
// a.js
import { hello, world } from "b";
export default hello + world;
await 1;
export function f() {
return "hello";
}
// b.js
import value, { f } from "a";
export const hello = f();
await 1;
export const world = "world";
export default (() => { try { value } catch(e) { return e; } })(); So am I correct that this example prints:
|
f4c133f
to
a14c6fb
Compare
So both proposals are now supported on opt-in:
|
Thank you for your pull request! The most important CI builds succeeded, we’ll review the pull request soon. |
c752dd6
to
11fb0a9
Compare
So this landed in 5.0.0-alpha.15 |
import await
supportimport
async supportexports await from
supportexports from
async supportsee example: https://github.com/webpack/webpack/tree/feature/top-level-await/examples/top-level-await
cc @littledan @jhnns @lukastaegert @TheLarkInn
based on https://gist.github.com/sokra/33f3db1b2714e9a6720f890842c47ae6
What kind of change does this PR introduce?
feature
Did you add tests for your changes?
yes
Does this PR introduce a breaking change?
yes, wasm is now opt-in by default
What needs to be documented once your changes are merged?
New experiments:
experiments.importAwait
->import/export await
is enabledexperiments.importAsync
->import/export
allows to use async module tooexperiments.topLevelAwait
-> allows to useawait
on top-levelexperiments.asyncWebAssembly
-> WebAssembly Modules are async modulesexperiments.syncWebAssembly
-> The webpack 4 WebAssembly Modules implementation (outdated)