Skip to content

Commit f26927a

Browse files
alexcrichtonRalfJungehuss
committed
Apply suggestions from code review
Co-authored-by: Ralf Jung <[email protected]> Co-authored-by: Eric Huss <[email protected]>
1 parent eb848bf commit f26927a

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

content/c-abi-changes-for-wasm32-unknown-unknown.md

+12-12
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ Rust compiler and the [official C ABI][tool-conventions] will be used instead.
1818
## History of `wasm32-unknown-unknown`'s C ABI
1919

2020
When the `wasm32-unknown-unknown` target [was originally added][inception] in
21-
2017 not much care was given to the exact definition of the `extern "C"` ABI at
22-
the time. In 2018 [an ABI definition wasm added just for wasm][orig-abi] and the
21+
2017, not much care was given to the exact definition of the `extern "C"` ABI at
22+
the time. In 2018 [an ABI definition was added just for wasm][orig-abi] and the
2323
target is still using this definition [to this day][current-abi]. This
2424
definitions has become more and more problematic over time and while some issues
2525
have been fixed, the root cause still remains.
2626

2727
Notably this ABI definition does not match the [tool-conventions] definition of
2828
the C API, which is the current standard for how WebAssembly toolchains should
2929
talk to one another. Originally this non-standard definition was used for all
30-
WebAssembly based target except Emscripten, but [this changed in 2021][fix-wasi]
30+
WebAssembly based targets except Emscripten, but [this changed in 2021][fix-wasi]
3131
where the WASI targets for Rust use a corrected ABI definition. Still, however,
3232
the non-standard definition remained in use for `wasm32-unknown-unknown`.
3333

@@ -48,7 +48,7 @@ The definition of an ABI answers questions along the lines of:
4848
* What is the size and alignment of a type in memory?
4949

5050
For WebAssembly these answers are a little different than native platforms.
51-
WebAssembly does not have physical registers for example and functions must all
51+
For example, WebAssembly does not have physical registers and functions must all
5252
be annotated with a type. What WebAssembly does have is types such as `i32`,
5353
`i64`, `f32`, and `f64`. This means that for WebAssembly an ABI needs to define
5454
how to represent values in these types.
@@ -61,14 +61,14 @@ is passed directly as a parameter as a function argument. If the Rust structure
6161
`#[repr(C)] struct Pair(f32, f64)` is returned from a function then a return
6262
pointer is used which must have alignment 8 and size of 16 bytes.
6363

64-
In essence the WebAssembly C ABI is acting as a bridge between C's type system
64+
In essence, the WebAssembly C ABI is acting as a bridge between C's type system
6565
and the WebAssembly type system. This includes details such as in-memory layouts
6666
and translations of a C function signature to a WebAssembly function signature.
6767

6868
## How is `wasm32-unknown-unknown` non-standard?
6969

70-
Despite the ABI definition today being non-standard many aspects of it are
71-
still the same as what [tool-conventions] specifies. For example size/alignment
70+
Despite the ABI definition today being non-standard, many aspects of it are
71+
still the same as what [tool-conventions] specifies. For example, size/alignment
7272
of types is the same as it is in C. The main difference is how function
7373
signatures are calculated. An example (where you can follow along on [godbolt])
7474
is:
@@ -133,17 +133,17 @@ The Diplomat project has [compiled a much more comprehensive overview][quirks]
133133
than this and it's recommended to check that out if you're curious for an even
134134
deeper dive.
135135

136-
## What hasn't this been fixed?
136+
## Why hasn't this been fixed long ago already?
137137

138138
For `wasm32-unknown-unknown` it was well-known at the time in 2021 when WASI's
139-
ABI was updated that the ABI was non-standard. Why then, in the 4 years within
140-
that duration and 4 years afterward has the ABI not been fixed like with WASI?
139+
ABI was updated that the ABI was non-standard. Why then has the ABI not been
140+
fixed like with WASI?
141141
The main reason originally for this was the [wasm-bindgen
142142
project][wasm-bindgen].
143143

144144
In `wasm-bindgen` the goal is to make it easy to integrate Rust into a web
145145
browser with WebAssembly. JavaScript is used to interact with host APIs and the
146-
Rust module itself. Naturally this communication touches on a lot of ABI
146+
Rust module itself. Naturally, this communication touches on a lot of ABI
147147
details! The problem was that `wasm-bindgen` relied on the above example,
148148
specifically having `Pair` "splatted" across arguments instead of passed
149149
indirectly. The generated JS wouldn't work correctly if the argument was passed
@@ -160,7 +160,7 @@ gotten greater that there are more unknown projects relying on the non-standard
160160
behavior.
161161

162162
In late 2023 [the wasm-bindgen project fixed bindings generation][wbgfix] to be
163-
compatible with the standard definition of `extern "C"`. In the following months
163+
unaffected by the transition to the standard definition of `extern "C"`. In the following months
164164
a [future-incompat lint was added to rustc][fcw1] to specifically migrate users
165165
of old `wasm-bindgen` versions to a "fixed" version. This was in anticipation of
166166
changing the ABI of `wasm32-unknown-unknown` once enough time had passed. Since

0 commit comments

Comments
 (0)