-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[GR-63376] Implement new Wasm Polyglot API. #11558
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
Open
graalvmbot
wants to merge
23
commits into
master
Choose a base branch
from
fh/GR-63376
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
+1,656
−566
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
b44a688
to
0c2862c
Compare
…ests accordingly. Added exports, references, and linkReferences to instance.
Fix detectEntryPoint. Fix reading exports in WasmMemoryLeakSuite. Simplify linkReferences. Pass non-null import object to moduleInstantiate. Remove unnecessary try-catch(NumberFormatException).
Instantiate newInstance() receiver module first, so that WASI will import its memory. Allow all module arguments to resolve imports from the importObject. Add test with WASI, an import object, and another module instantiated at once.
Get store from WasmInstance instead.
Link WASIp1 "memory" import to the importing module (rather than the first instance in the store).
… arguments. Use newInstance(importObject) with the exports of the required modules passed via the importObject instead. Extract common sources to static fields.
0f785a9
to
43f81a9
Compare
Data segment value may be undefined. Fix memory index decoding.
Reading a global export now returns a WasmGlobal instance instead of its value.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 PR introduces a breaking change to the implementation of the Polyglot API in GraalWasm!
Rationale
The current implementation of the Polyglot API in GraalWasm is fairly limited, in that it does not allow users to provide custom imports to WebAssembly modules. While there is a workaround via the JS API, I think there should be a way to provide custom imports via the Polyglot API as well.
Furthermore, the current implementation has some compatibility issues with the JS API. Currently, JS has to provide a hidden flag (string value) when evaluating a WebAssembly source to get a Wasm module (symbolic representation) instead of a Wasm instance (runtime representation). In addition, the layout of Wasm instances produced by the Polyglot API is structurally different from Wasm instances provided via the JS API.
Implementation
To address this issue, the following changes are made to the Polyglot API in GraalWasm.
Context.eval
on a WebAssembly source no longer returns a Wasm Instance, but a Wasm Module. This is necessary to provide custom imports when instantiating the module into an instance. In case the old behavior is needed, the new experimental optionwasm.EvalReturnsInstance
can be set totrue
for the time being.newInstance
on the modules returned byContext.eval
to instantiate the module into a Wasm instance.newInstance
supports a single optional import object parameter. The import object has the format:{ "module-1-name": { "member-1-name": func | value, "member-2-name": func | val, ... }, ... }
.instance.getMember("exports").getMember("member-name")
.