-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Use multi-value with interface types #1764
Merged
Merged
Commits on Sep 11, 2019
-
Configuration menu - View commit details
-
Copy full SHA for 582b733 - Browse repository at this point
Copy the full SHA 582b733View commit details -
Introduce the
multi-value-xform
crateThis crate provides a transformation to turn exported functions that use a return pointer into exported functions that use multi-value. Consider the following function: ```rust pub extern "C" fn pair(a: u32, b: u32) -> [u32; 2] { [a, b] } ``` LLVM will by default compile this down into the following Wasm: ```wasm (func $pair (param i32 i32 i32) local.get 0 local.get 2 i32.store offset=4 local.get 0 local.get 1 i32.store) ``` What's happening here is that the function is not directly returning the pair at all, but instead the first `i32` parameter is a pointer to some scratch space, and the return value is written into the scratch space. LLVM does this because it doesn't yet have support for multi-value Wasm, and so it only knows how to return a single value at a time. Ideally, with multi-value, what we would like instead is this: ```wasm (func $pair (param i32 i32) (result i32 i32) local.get 0 local.get 1) ``` However, that's not what this transformation does at the moment. This transformation is a little simpler than mutating existing functions to produce a multi-value result, instead it introduces new functions that wrap the original function and translate the return pointer to multi-value results in this wrapper function. With our running example, we end up with this: ```wasm ;; The original function. (func $pair (param i32 i32 i32) local.get 0 local.get 2 i32.store offset=4 local.get 0 local.get 1 i32.store) (func $pairWrapper (param i32 i32) (result i32 i32) ;; Our return pointer that points to the scratch space we are allocating ;; on the shadow stack for calling `$pair`. (local i32) ;; Allocate space on the shadow stack for the result. global.get $shadowStackPointer i32.const 8 i32.sub local.tee 2 global.set $shadowStackPointer ;; Call `$pair` with our allocated shadow stack space for its results. local.get 2 local.get 0 local.get 1 call $pair ;; Copy the return values from the shadow stack to the wasm stack. local.get 2 i32.load local.get 2 offset=4 i32.load ;; Finally, restore the shadow stack pointer. local.get 2 i32.const 8 i32.add global.set $shadowStackPointer) ``` This `$pairWrapper` function is what we actually end up exporting instead of `$pair`.
Configuration menu - View commit details
-
Copy full SHA for 44c3f8a - Browse repository at this point
Copy the full SHA 44c3f8aView commit details -
Configuration menu - View commit details
-
Copy full SHA for fc2c502 - Browse repository at this point
Copy the full SHA fc2c502View commit details -
Configuration menu - View commit details
-
Copy full SHA for 5f90951 - Browse repository at this point
Copy the full SHA 5f90951View commit details -
Configuration menu - View commit details
-
Copy full SHA for 908fc61 - Browse repository at this point
Copy the full SHA 908fc61View commit details -
Configuration menu - View commit details
-
Copy full SHA for 68af85d - Browse repository at this point
Copy the full SHA 68af85dView commit details
Commits on Sep 16, 2019
-
Create the
wasm-bindgen-wasm-conventions
crateThis tiny crate provides utilities for working with Wasm codegen conventions (typically established by LLVM or lld) such as getting the shadow stack pointer. It also de-duplicates all the places in the codebase where we were implementing these conventions in one-off ways.
Configuration menu - View commit details
-
Copy full SHA for 2fbb835 - Browse repository at this point
Copy the full SHA 2fbb835View commit details -
Configuration menu - View commit details
-
Copy full SHA for d9c4164 - Browse repository at this point
Copy the full SHA d9c4164View commit details -
Configuration menu - View commit details
-
Copy full SHA for a0582cd - Browse repository at this point
Copy the full SHA a0582cdView commit details -
CI: Temporarily disable
sccache
usageIt is failing to install / setup on CI.
Configuration menu - View commit details
-
Copy full SHA for b2d1165 - Browse repository at this point
Copy the full SHA b2d1165View commit details
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.