Wasm re-export bindings support #105
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is an addition to #104, split out from and based to that branch.
With this change, it is possible for Wasm modules to participate in reexports (
export { binding } from './other.wasm'
) exactly the same as JS does, while supporting cycles for those reexports (although the hoisting of cyclic Wasm bindings is not included here).In particular we classify Wasm exports that export an imported address as "indirect exports" (reexports), distinct from direct exports which are exports of bindings defined by that Wasm module's own instantiation.
With this, we then fully support the JS reexports logic through a complete
ResolveExport
implementation including resolvingexport *
exports to JS with ambiguous logic and handling cycles, while still retaining the import snapshotting behaviour defined for Wasm imports.Only direct exports and indirect exports to snapshotted JS imports then need to be defined in the environment record for the Wasm module record, avoiding unnecessary snapshotting and reducing the size of the environment record. A Wasm module reexporting a binding from another Wasm module can avoid an intermediate snapshot. When resolving an import from Wasm through a JS
export { binding } from './other.wasm'
module, we resolve that Wasm binding through JS reexports directly to the source binding in the other Wasm module, without the wrapping and unwrapping through JS requiring performing an intermediate wrapping of the value at the time the JS module was inspected.This change also benefits the direct global unwrapping in #104 since in this case, a mutable global binding could be supported when reexported through JS per the example above, as resolving directly to its mutable global address in the final Wasm binding resolution per the example, whereas without this change it wouldn't be supported and would throw a linking error when trying to make a snapshot of the JS module exports (since Wasm wouldn't trace the reexport without the first-class ResolveExport implementation added in ~12 lines of spec text here).
While not completely trivial, it is fairly simple and falls out very naturally from the JS module integration semantics if we want to support it as a closer ESM integration implementation, so seems worth a discussion at least to me.