-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Tracking issue for the unstable "wasm" ABI #83788
Comments
For folks wanting to give this a try, is there an experimental branch of |
There is not a branch at this time, no. |
What is the current state of this? Is there wasm-bindgen support or tooling support for this? Is anything using this? |
Searching sourcegraph and github, I've so far only found one project previously using it then switched to "C" ABI due to a couple of issues oasisprotocol/oasis-sdk#561
|
The |
@alexcrichton Is there a chicken and egg problem there? I think we were waiting to consider stabilization until it was clear this was being used. :) |
Personally I think this is more of a "what is C going to do" problem for stabilization. I don't think Rust is in the position to blaze a trail here when C/C++ otherwise can't access it. One of the main purposes of this ABI is to give access to the ability to define a multi-return function in WebAssembly, but C/C++ have no corresponding mechanism to do that. Until C/C++ figure out how they're going to return multiple values then multi-return is unlikely to be used in the wasm ecosystem so stabilizing this wouldn't provide much benefit. Additionally if this were stabilized and then C/C++ picked a different way to use multi-return then that would be yet-another ABI that Rust would have to implement. |
Rust isn’t C. Rust is Rust and Rust shouldn’t care what C (clang) does for anything not explicitly using the term Rust on wasm’s first priority will always be compatibility with wasm and web standards not with C/C++ on wasm, especially considering wasm doesn’t even have a good way of interoperating betweeen Rust and C that isn’t already mangled through javascript. multiple returns are natively supported by wasm, and Rust should take advantage of this whether clang likes it or not. perhaps we should maintain i also see absolutely no reason that Rust shouldn’t be a trailblazer in this field, as it’s at least as favourable as C/C++ in the wasm community. i don’t think C or C++ even belong in this discussion. |
just wanted to know if this affects rustwasm/team#291 where we can't compile c/cpp binding crates to |
Yes - adding the A different way to fix it would be to change |
This suggests that maybe there’s a way to use something other than the default C ABI. Is there a way to opt-in to using a C ABI that isn’t the default but does match clang? I’m targeting Please forgive my ignorance on this. I’m in way over my head here 😄 |
I'm not aware of any mechanism at this time to use something else to match clang. That's the purpose of the |
is there a place i can track the progress of this clang's C multi-return ABI thing? |
Have there been any attempts to form a committee around this? Ideally this would be a W3C subgroup. |
This is not how
#76916 is likely caused by this. |
@alexcrichton I was going down the rabbit hole of why
But stabilizing this has a huge benefit even without any multivalue support: be compatible with C!
So that's the part I'm confused about, I thought the whole point of this new ABI is to separate C and Wasm ABI concerns. If the concern is to support both a C ABI with and without multivalue support, then that should probably be gated by |
There is no "Wasm ABI". |
Thanks for the clarification! I went back and read your last comment again too: #83788 (comment). So does this effectively mean that we can never stabilize Honestly I'm not too sure how else to proceed on the issue of Wasm and C incompatibility. The other alternative is to just drop all enhancements |
In my opinion Wasm-bindgen currently attempts to pass |
The way to make wasm-bindgen work even if we start using the official C abi for webassembly on wasm32-unknown-unknown would be to either do the decomposition of |
I believe there is: https://github.com/WebAssembly/tool-conventions/blob/main/BasicCABI.md, I'm not sure if it differs from the C ABI, but presumably this is v1 and they planned to add multivalue support to it. In any case, the ABI
If this really is the whole issue, then I would argue this is fixable. I will proceed to figure out what needs to be done on |
That is the C abi I was talking about. |
So after finding and reading https://github.com/rust-lang/lang-team/blob/master/design-meeting-minutes/2021-04-21-wasm-abi.md, which basically answers and explains all questions I had, I'm coming to the following conclusions:
I think the path forward is to drop splatting in |
I don't have much more to add over what's been said already. I would concur that the ideal course of action would be to get As for the Changing the C ABI or adding a new one is not trivial due to the number of people using it. In that sense by far the easiest thing to do is to update |
We could leave |
I want to point out that the "wasm_abi" feature is currently buggy. An This is because LLVM target-features like +multivalue apply to the whole module, not just a single function: Godbolt. I had a discussion on the LLVM forums, and for the time being this seems to be the intended behaviour of target-features. The tests/run-make/wasm-abi test uses the |
In case anyone is following the breadcrumbs, the LLVM code that coalesces Wasm target-features is here: https://github.com/llvm/llvm-project/blob/fa8e74073762300d07b02adec42c629daf82c44b/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp#L181 |
I agree with @bjorn3 that the wasm ABI needs to be fixed before it can be stabilized. Currently it is (as far as I know) the only ABI that uses |
IOW, I think stabilizing this should be blocked on resolving #115666 (at least for the "wasm" ABI). |
Remove the unstable `extern "wasm"` ABI (`wasm_abi` feature tracked in rust-lang#83788). As discussed in rust-lang#127513 (comment) and following, this ABI is a failed experiment that did not end up being used for anything. Keeping support for this ABI in LLVM 19 would require us to switch wasm targets to the `experimental-mv` ABI, which we do not want to do. It should be noted that `Abi::Wasm` was internally used for two things: The `-Z wasm-c-abi=legacy` ABI that is still used by default on some wasm targets, and the `extern "wasm"` ABI. Despite both being `Abi::Wasm` internally, they were not the same. An explicit `extern "wasm"` additionally enabled the `+multivalue` feature. I've opted to remove `Abi::Wasm` in this patch entirely, instead of keeping it as an ABI with only internal usage. Both `-Z wasm-c-abi` variants are now treated as part of the normal C ABI, just with different different treatment in adjust_for_foreign_abi.
Remove the unstable `extern "wasm"` ABI (`wasm_abi` feature tracked in rust-lang#83788). As discussed in rust-lang#127513 (comment) and following, this ABI is a failed experiment that did not end up being used for anything. Keeping support for this ABI in LLVM 19 would require us to switch wasm targets to the `experimental-mv` ABI, which we do not want to do. It should be noted that `Abi::Wasm` was internally used for two things: The `-Z wasm-c-abi=legacy` ABI that is still used by default on some wasm targets, and the `extern "wasm"` ABI. Despite both being `Abi::Wasm` internally, they were not the same. An explicit `extern "wasm"` additionally enabled the `+multivalue` feature. I've opted to remove `Abi::Wasm` in this patch entirely, instead of keeping it as an ABI with only internal usage. Both `-Z wasm-c-abi` variants are now treated as part of the normal C ABI, just with different different treatment in adjust_for_foreign_abi.
Remove extern "wasm" ABI Remove the unstable `extern "wasm"` ABI (`wasm_abi` feature tracked in rust-lang#83788). As discussed in rust-lang#127513 (comment) and following, this ABI is a failed experiment that did not end up being used for anything. Keeping support for this ABI in LLVM 19 would require us to switch wasm targets to the `experimental-mv` ABI, which we do not want to do. It should be noted that `Abi::Wasm` was internally used for two things: The `-Z wasm-c-abi=legacy` ABI that is still used by default on some wasm targets, and the `extern "wasm"` ABI. Despite both being `Abi::Wasm` internally, they were not the same. An explicit `extern "wasm"` additionally enabled the `+multivalue` feature. I've opted to remove `Abi::Wasm` in this patch entirely, instead of keeping it as an ABI with only internal usage. Both `-Z wasm-c-abi` variants are now treated as part of the normal C ABI, just with different different treatment in adjust_for_foreign_abi.
Rollup merge of rust-lang#127605 - nikic:remove-extern-wasm, r=oli-obk Remove extern "wasm" ABI Remove the unstable `extern "wasm"` ABI (`wasm_abi` feature tracked in rust-lang#83788). As discussed in rust-lang#127513 (comment) and following, this ABI is a failed experiment that did not end up being used for anything. Keeping support for this ABI in LLVM 19 would require us to switch wasm targets to the `experimental-mv` ABI, which we do not want to do. It should be noted that `Abi::Wasm` was internally used for two things: The `-Z wasm-c-abi=legacy` ABI that is still used by default on some wasm targets, and the `extern "wasm"` ABI. Despite both being `Abi::Wasm` internally, they were not the same. An explicit `extern "wasm"` additionally enabled the `+multivalue` feature. I've opted to remove `Abi::Wasm` in this patch entirely, instead of keeping it as an ABI with only internal usage. Both `-Z wasm-c-abi` variants are now treated as part of the normal C ABI, just with different different treatment in adjust_for_foreign_abi.
Yes, this one should be closed. We have a separate tracking issue for wasm-c-abi (#122532). |
Great, so #115666 only affects wasm32-u-u now :) |
This issue is intended to track the stabilization of the
"wasm"
ABI added in #83763. This new ABI is notably different from the "C" ABI where the "C" ABI's purpose is to match whatever the C ABI for the platform is (in this case whatever clang does). The "wasm" ABI, however, is intended to match the WebAssembly specification and should be used for functions that need to be exported/imported from a wasm module to precisely match a desired WebAssembly signature.One of the main features of the "wasm" ABI is that it automatically enables the multi-value feature in LLVM which means that functions can return more than one value. Additionally parameters are never passed indirectly and are always passed by-value when possible to ensure that what was written is what shows up in the ABI on the other end.
It's expected that one day the "C" ABI will be updated within clang to use multi-value, but even if that happens the ABI is likely to optimize for the performance of C itself rather than for binding the WebAssembly platform. The presence of a "wasm" ABI in Rust guarantees that there will always be an ABI to match the exact WebAssembly signature desired.
Another nice effect of stabilizing this ABI is that the
wasm32-unknown-unknown
target's default C ABI can be switched back to matching clang. This longstanding mismatch is due to my own personal mistake with the original definition and the reliance on the mistake inwasm-bindgen
. Once the "wasm" ABI is stable, however, I can switchwasm-bindgen
to using the "wasm" ABI everywhere and then the compiler can switch the default ABI of thewasm32-unknown-unknown
target to match the C ABI of clang.The text was updated successfully, but these errors were encountered: