Skip to content

Commit 50ce531

Browse files
committed
Review comments
1 parent 82e29bf commit 50ce531

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

posts/2024-08-26-webassembly-targets-change-in-default-target-features.md

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ disabled.
3737

3838
There is a loose coupling between the name of a proposal (often the name of the
3939
github repository of the proposal) and the feature name LLVM/Rust use. For
40-
example there is the [`multi-value`
40+
example there is the [multi-value
4141
proposal](https://github.com/webAssembly/multi-value) but a `multivalue`
4242
feature.
4343

@@ -64,7 +64,8 @@ host-defined GC resource that WebAssembly cannot access but can pass around.
6464
Rust does not have support for the WebAssembly `externref` type and LLVM 19 does
6565
not change that. WebAssembly modules produced from Rust will continue to not use
6666
the `externref` type nor have a means of being able to do so. This may be
67-
enabled in the future, but it will mostly likely only be done on an opt-in basis
67+
enabled in the future (e.g. a hypothetical `core::arch::wasm32::Externref` type
68+
or similar), but it will mostly likely only be done on an opt-in basis
6869
and will not affect preexisting code by default.
6970

7071
Also included in the reference-types proposal, however, was the ability to have
@@ -81,7 +82,7 @@ was encoded with a fixed zero byte in its instruction (required to be exactly
8182
0x00). This fixed zero byte was relaxed to a 32-bit [LEB] to indicate which
8283
table the `call_indirect` instruction was using. For those unfamiliar [LEB] is a
8384
way of encoding multi-byte integers in a smaller number of bytes for smaller
84-
integers. For example the 32-gbit integer 0 can be encoded as `0x00` with a
85+
integers. For example the 32-bit integer 0 can be encoded as `0x00` with a
8586
[LEB]. [LEB]s are flexible to additionally allow "overlong" encodings so the
8687
integer 0 can additionally be encoded as `0x80 0x00`.
8788

@@ -102,7 +103,7 @@ do not support the reference-types proposal. It is expected that this change
102103
will have a low impact due to the age of the reference-types proposal and
103104
breadth of implementation in engines. Given the multitude of WebAssembly
104105
engines, however, it's recommended that any WebAssembly users test out
105-
Nightly Rust and see if the produced module still runs on the engine of
106+
Nightly Rust and see if the produced module still runs on their engine of
106107
choice.
107108

108109
### LLVM, Rust, and Multiple Tables
@@ -144,9 +145,11 @@ original MVP and has been implemented in many engines for quite some time.
144145
The consequences of enabling this feature by default in LLVM are more minor for
145146
Rust, however, than enabling the `reference-types` feature by default. LLVM's
146147
default C ABI for WebAssembly code is not changing even when `multivalue` is
147-
enabled. Additionally Rust's `extern "C"` ABI is not changing either and
148-
continues to match LLVM's. Despite this though the change has the possibility
149-
of still affecting Nightly users of Rust.
148+
enabled. Additionally Rust's `extern "C"` ABI for WebAssembly is not changing
149+
either and continues to match LLVM's (or strives to, [differences to
150+
LLVM](https://github.com/rust-lang/rust/issues/115666) are considered bugs to
151+
fix). Despite this though the change has the possibility of still affecting
152+
Nightly users of Rust.
150153

151154
Rust for some time has supported an `extern "wasm"` ABI on Nightly which was an
152155
experimental means of exposing the ability of defining a function in Rust which
@@ -166,11 +169,11 @@ from suitably motivated contributors.
166169

167170
### Aside: ABI Stability and WebAssembly
168171

169-
While on the topics of ABIs and the `multi-value` feature it's perhaps worth
172+
While on the topic of ABIs and the `multivalue` feature it's perhaps worth
170173
also going over a bit what ABIs mean for WebAssembly. Currently there's
171174
effectively only one ABI implemented by LLVM and the Rust compiler meaning that
172175
at the WebAssembly module level `extern "C"` and `extern "Rust"` are
173-
more-or-less the same. Despite this though there's no need for this to be true.
176+
more-or-less the same. It is **not** guaranteed for the ABIs to match, however.
174177

175178
The `extern "C"` ABI, what C code uses by default as well, is difficult to
176179
change because stability is often required across different compiler versions.
@@ -180,12 +183,14 @@ task that requires version fields, explicit markers, etc, to help prevent
180183
mismatches.
181184

182185
The `extern "Rust"` ABI, however, is entirely within the control of the Rust
183-
compiler and can change from version to version. Just because it happens to work
184-
like `extern "C"` today doesn't mean it will continue to do so in the future. A
185-
great example of this is that when the `multi-value` feature is enabled the
186+
compiler and can change from version to version (there are no stability
187+
guarantees across compiler versions and this is applicable to all platforms, not
188+
just WebAssembly). Just because `extern "Rust"` happens to work like `extern
189+
"C"` in WebAssembly today doesn't mean it will continue to do so in the future.
190+
A great example of this is that when the `multivalue` feature is enabled the
186191
`extern "Rust"` ABI could be redefined to use the multiple-return-values that
187-
WebAssembly would then support. This would enable much more efficient returns of
188-
values larger than 64-bits. Implementing this would require support in LLVM
192+
WebAssembly would then support. This would enable much more efficient returns
193+
of values larger than 64-bits. Implementing this would require support in LLVM
189194
though which is not currently present.
190195

191196
## Enabling Future Proposals to WebAssembly
@@ -226,9 +231,9 @@ For a variety of reasons you might be motivated to disable on-by-default
226231
WebAssembly features: for example maybe your engine is difficult to update or
227232
doesn't support a new feature. Disabling on-by-default features is unfortunately
228233
not the easiest task. It is notably not sufficient to use
229-
`-Ctarget-features=-foo` to disable features for just your own project's
234+
`-Ctarget-features=-sign-ext` to disable a feature for just your own project's
230235
compilation because the Rust standard library, shipped in precompiled form, is
231-
compiled with this features enabled.
236+
still compiled with the feature enabled.
232237

233238
To disable on-by-default WebAssembly proposal it's required that you use Cargo's
234239
[`-Zbuild-std`](https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#build-std)

0 commit comments

Comments
 (0)