alexcrichton opened PR #2806 from multi-return
to main
:
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 useFunc::wrap
with functions that return multiple
values. Even recently whereFunc::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 twoi32
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
orWindowsFastcall
) 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 thatFunc::wrap
can now wrap functions that return
multiple values andFunc::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 nativeSystemV
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 withref.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 #1178
<!--
Please ensure that the following steps are all taken care of before submitting
the PR.
[ ] This has been discussed in issue #..., or if not, please tell us why
here.[ ] A short description of what this does, why it is needed; if the
description becomes long, the matter should probably be discussed in an issue
first.[ ] This PR contains test cases, if meaningful.
- [ ] A reviewer from the core maintainer team has been assigned for this PR.
If you don't know who could review this, please indicate so. The list of
suggested reviewers on the right can help you.Please ensure all communication adheres to the code of conduct.
-->
alexcrichton updated PR #2806 from multi-return
to main
.
alexcrichton updated PR #2806 from multi-return
to main
.
alexcrichton updated PR #2806 from multi-return
to main
.
alexcrichton updated PR #2806 from multi-return
to main
.
alexcrichton updated PR #2806 from multi-return
to main
.
bjorn3 submitted PR Review.
bjorn3 created PR Review Comment:
Can you please avoid this wildcard arm? This makes it harder to find all places that need updates when adding a new call conv.
alexcrichton updated PR #2806 from multi-return
to main
.
alexcrichton updated PR #2806 from multi-return
to main
.
alexcrichton updated PR #2806 from multi-return
to main
.
alexcrichton updated PR #2806 from multi-return
to main
.
alexcrichton updated PR #2806 from multi-return
to main
.
cfallin submitted PR Review.
cfallin submitted PR Review.
cfallin created PR Review Comment:
s/impleemnted/implemented/
alexcrichton updated PR #2806 from multi-return
to main
.
alexcrichton updated PR #2806 from multi-return
to main
.
alexcrichton requested peterhuene for a review on PR #2806.
alexcrichton updated PR #2806 from multi-return
to main
.
peterhuene submitted PR Review.
peterhuene submitted PR Review.
alexcrichton updated PR #2806 from multi-return
to main
.
alexcrichton updated PR #2806 from multi-return
to main
.
alexcrichton merged PR #2806.
peterhuene submitted PR Review.
Last updated: Nov 22 2024 at 16:03 UTC