-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Fully support multiple returns in Wasmtime #2806
Merged
alexcrichton
merged 16 commits into
bytecodealliance:main
from
alexcrichton:multi-return
Apr 7, 2021
Merged
Fully support multiple returns in Wasmtime #2806
alexcrichton
merged 16 commits into
bytecodealliance:main
from
alexcrichton:multi-return
Apr 7, 2021
Commits on Apr 5, 2021
-
Fully support multiple returns in Wasmtime
For quite some time now Wasmtime has "supported" multiple return values, but only in the mose bare bones ways. Up until recently you couldn't get a typed version of functions with multiple return values, and never have you been able to use `Func::wrap` with functions that return multiple values. Even recently where `Func::typed` can call functions that return multiple values it uses a double-indirection by calling a trampoline which calls the real function. The underlying reason for this lack of support is that cranelift's ABI for returning multiple values is not possible to write in Rust. For example if a wasm function returns two `i32` values there is no Rust (or C!) function you can write to correspond to that. This commit, however fixes that. This commit adds two new ABIs to Cranelift: `WasmtimeSystemV` and `WasmtimeFastcall`. The intention is that these Wasmtime-specific ABIs match their corresponding ABI (e.g. `SystemV` or `WindowsFastcall`) for everything *except* how multiple values are returned. For multiple return values we simply define our own version of the ABI which Wasmtime implements, which is that for N return values the first is returned as if the function only returned that and the latter N-1 return values are returned via an out-ptr that's the last parameter to the function. These custom ABIs provides the ability for Wasmtime to bind these in Rust meaning that `Func::wrap` can now wrap functions that return multiple values and `Func::typed` no longer uses trampolines when calling functions that return multiple values. Although there's lots of internal changes there's no actual changes in the API surface area of Wasmtime, just a few more impls of more public traits which means that more types are supported in more places! Another change made with this PR is a consolidation of how the ABI of each function in a wasm module is selected. The native `SystemV` ABI, for example, is more efficient at returning multiple values than the wasmtime version of the ABI (since more things are in more registers). To continue to take advantage of this Wasmtime will now classify some functions in a wasm module with the "fast" ABI. Only functions that are not reachable externally from the module are classified with the fast ABI (e.g. those not exported, used in tables, or used with `ref.func`). This should enable purely internal functions of modules to have a faster calling convention than those which might be exposed to Wasmtime itself. Closes bytecodealliance#1178
Configuration menu - View commit details
-
Copy full SHA for 81e96c0 - Browse repository at this point
Copy the full SHA 81e96c0View commit details -
Configuration menu - View commit details
-
Copy full SHA for ee18cbd - Browse repository at this point
Copy the full SHA ee18cbdView commit details -
Configuration menu - View commit details
-
Copy full SHA for 7ae86d9 - Browse repository at this point
Copy the full SHA 7ae86d9View commit details -
Configuration menu - View commit details
-
Copy full SHA for a676461 - Browse repository at this point
Copy the full SHA a676461View commit details -
Configuration menu - View commit details
-
Copy full SHA for 97bf807 - Browse repository at this point
Copy the full SHA 97bf807View commit details -
Configuration menu - View commit details
-
Copy full SHA for 4f9dbb6 - Browse repository at this point
Copy the full SHA 4f9dbb6View commit details -
Configuration menu - View commit details
-
Copy full SHA for f768433 - Browse repository at this point
Copy the full SHA f768433View commit details -
Configuration menu - View commit details
-
Copy full SHA for 386623b - Browse repository at this point
Copy the full SHA 386623bView commit details -
Configuration menu - View commit details
-
Copy full SHA for 5445469 - Browse repository at this point
Copy the full SHA 5445469View commit details
Commits on Apr 6, 2021
-
Don't always do 64-bit stores with cranelift
This was overwriting upper bits when 32-bit registers were being stored into return values, so fix the code inline to do a sized store instead of one-size-fits-all store.
Configuration menu - View commit details
-
Copy full SHA for 95f86be - Browse repository at this point
Copy the full SHA 95f86beView commit details -
Configuration menu - View commit details
-
Copy full SHA for 51fe59a - Browse repository at this point
Copy the full SHA 51fe59aView commit details -
Configuration menu - View commit details
-
Copy full SHA for 1020005 - Browse repository at this point
Copy the full SHA 1020005View commit details -
Configuration menu - View commit details
-
Copy full SHA for 5962d4c - Browse repository at this point
Copy the full SHA 5962d4cView commit details
Commits on Apr 7, 2021
-
Configuration menu - View commit details
-
Copy full SHA for 213613a - Browse repository at this point
Copy the full SHA 213613aView commit details -
Configuration menu - View commit details
-
Copy full SHA for 4a379c2 - Browse repository at this point
Copy the full SHA 4a379c2View commit details -
Configuration menu - View commit details
-
Copy full SHA for 9dda311 - Browse repository at this point
Copy the full SHA 9dda311View 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.