1
Fork 0
rust/compiler/rustc_codegen_llvm/src
Alex Crichton 482a3d06c3 rustc: Add a new wasm ABI
This commit implements the idea of a new ABI for the WebAssembly target,
one called `"wasm"`. This ABI is entirely of my own invention
and has no current precedent, but I think that the addition of this ABI
might help solve a number of issues with the WebAssembly targets.

When `wasm32-unknown-unknown` was first added to Rust I naively
"implemented an abi" for the target. I then went to write `wasm-bindgen`
which accidentally relied on details of this ABI. Turns out the ABI
definition didn't match C, which is causing issues for C/Rust interop.
Currently the compiler has a "wasm32 bindgen compat" ABI which is the
original implementation I added, and it's purely there for, well,
`wasm-bindgen`.

Another issue with the WebAssembly target is that it's not clear to me
when and if the default C ABI will change to account for WebAssembly's
multi-value feature (a feature that allows functions to return multiple
values). Even if this does happen, though, it seems like the C ABI will
be guided based on the performance of WebAssembly code and will likely
not match even what the current wasm-bindgen-compat ABI is today. This
leaves a hole in Rust's expressivity in binding WebAssembly where given
a particular import type, Rust may not be able to import that signature
with an updated C ABI for multi-value.

To fix these issues I had the idea of a new ABI for WebAssembly, one
called `wasm`. The definition of this ABI is "what you write
maps straight to wasm". The goal here is that whatever you write down in
the parameter list or in the return values goes straight into the
function's signature in the WebAssembly file. This special ABI is for
intentionally matching the ABI of an imported function from the
environment or exporting a function with the right signature.

With the addition of a new ABI, this enables rustc to:

* Eventually remove the "wasm-bindgen compat hack". Once this
  ABI is stable wasm-bindgen can switch to using it everywhere.
  Afterwards the wasm32-unknown-unknown target can have its default ABI
  updated to match C.

* Expose the ability to precisely match an ABI signature for a
  WebAssembly function, regardless of what the C ABI that clang chooses
  turns out to be.

* Continue to evolve the definition of the default C ABI to match what
  clang does on all targets, since the purpose of that ABI will be
  explicitly matching C rather than generating particular function
  imports/exports.

Naturally this is implemented as an unstable feature initially, but it
would be nice for this to get stabilized (if it works) in the near-ish
future to remove the wasm32-unknown-unknown incompatibility with the C
ABI. Doing this, however, requires the feature to be on stable because
wasm-bindgen works with stable Rust.
2021-04-08 08:03:18 -07:00
..
back Rollup merge of #82483 - tmiasko:option-from-str, r=matthewjasper 2021-04-05 13:03:37 +02:00
coverageinfo Translate counters from Rust 1-based to LLVM 0-based counter ids 2021-04-02 17:16:36 -07:00
debuginfo Rollup merge of #80525 - devsnek:wasm64, r=nagisa 2021-04-05 00:24:23 +02:00
llvm Auto merge of #83592 - nagisa:nagisa/dso_local, r=davidtwco 2021-04-06 02:09:01 +00:00
abi.rs Enable mutable noalias by default for LLVM 12 2021-03-21 20:10:54 +01:00
allocator.rs Remove redundant to_string calls 2021-02-17 11:25:55 +01:00
asm.rs Allow clobbering unsupported registers in asm! 2021-04-04 10:42:32 +01:00
attributes.rs rustc: Add a new wasm ABI 2021-04-08 08:03:18 -07:00
base.rs Move SanitizerSet to rustc_target 2021-04-03 00:37:49 +03:00
builder.rs Use iter::zip in compiler/ 2021-03-26 09:32:31 -07:00
callee.rs Manually set dso_local when its valid to do so 2021-04-03 00:00:29 +03:00
common.rs Update and improve rustc_codegen_{llvm,ssa} docs 2020-12-22 19:42:23 -08:00
consts.rs Replace const_cstr with cstr crate 2021-02-14 09:45:35 +11:00
context.rs Auto merge of #83387 - cuviper:min-llvm-10, r=nagisa 2021-03-25 13:11:18 +00:00
declare.rs Make declare_cfn more flexible 2021-01-23 17:19:49 -05:00
intrinsic.rs correct macro names 2021-03-19 03:47:13 +08:00
lib.rs Use iter::zip in compiler/ 2021-03-26 09:32:31 -07:00
llvm_util.rs Auto merge of #82980 - tmiasko:import-cold-multiplier, r=michaelwoerister 2021-03-26 11:57:44 +00:00
metadata.rs fix review 2021-02-25 04:21:12 +03:00
mono_item.rs Manually set dso_local when its valid to do so 2021-04-03 00:00:29 +03:00
type_.rs Use ty::{IntTy,UintTy,FloatTy} in rustc 2021-01-18 21:09:30 +01:00
type_of.rs Revert "cg_llvm: fewer_names in uncached_llvm_type" 2020-12-17 16:40:47 +00:00
va_arg.rs Add big-endian support for AArch64 va_arg 2021-01-27 22:47:56 +00:00
value.rs mv compiler to compiler/ 2020-08-30 18:45:07 +03:00