Skip to content

Commit d42160b

Browse files
committed
Stabilize WebAssembly multivalue and reference-types target features
This commit is similar to #117457 in that it's stabilizing target features specific to WebAssembly targets. The previous PR left out these features because they weren't expected to change much about compiled code so it was unclear what the rationale was. It has [since been discovered][blog] that `reference-types` can be useful as it changes the binary format of the `call_indirect` instruction. Additionally [on Zulip][zulip] there's a use case of detecting these features at compile time and generating a compile error to better warn users about features not supported on engines. A test has been added here not only for these two features but other WebAssembly features as well to showcase that they're usable without feature gates in stable Rust. [blog]: https://blog.rust-lang.org/2024/09/24/webassembly-targets-change-in-default-target-features.html [zulip]: https://rust-lang.zulipchat.com/#narrow/stream/122651-general/topic/wasm32.20reference-types.20.2F.20multivalue.20in.201.2E82-beta.20not.20enabled/near/473893987
1 parent fb4aebd commit d42160b

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

compiler/rustc_target/src/target_features.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -414,10 +414,10 @@ const WASM_ALLOWED_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
414414
("bulk-memory", Stable, &[]),
415415
("exception-handling", Unstable(sym::wasm_target_feature), &[]),
416416
("extended-const", Stable, &[]),
417-
("multivalue", Unstable(sym::wasm_target_feature), &[]),
417+
("multivalue", Stable, &[]),
418418
("mutable-globals", Stable, &[]),
419419
("nontrapping-fptoint", Stable, &[]),
420-
("reference-types", Unstable(sym::wasm_target_feature), &[]),
420+
("reference-types", Stable, &[]),
421421
("relaxed-simd", Stable, &["simd128"]),
422422
("sign-ext", Stable, &[]),
423423
("simd128", Stable, &[]),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//@ only-wasm32
2+
//@ build-pass
3+
4+
// Test that a variety of WebAssembly features are all stable and can be used in
5+
// `#[target_feature]`. That should mean they're also available via
6+
// `#[cfg(target_feature)]` as well.
7+
8+
#[target_feature(enable = "multivalue")]
9+
fn foo1() {}
10+
11+
#[target_feature(enable = "reference-types")]
12+
fn foo2() {}
13+
14+
#[target_feature(enable = "bulk-memory")]
15+
fn foo3() {}
16+
17+
#[target_feature(enable = "extended-const")]
18+
fn foo4() {}
19+
20+
#[target_feature(enable = "mutable-globals")]
21+
fn foo5() {}
22+
23+
#[target_feature(enable = "nontrapping-fptoint")]
24+
fn foo6() {}
25+
26+
#[target_feature(enable = "simd128")]
27+
fn foo7() {}
28+
29+
#[target_feature(enable = "relaxed-simd")]
30+
fn foo8() {}
31+
32+
#[target_feature(enable = "sign-ext")]
33+
fn foo9() {}
34+
35+
fn main() {
36+
foo1();
37+
foo2();
38+
foo3();
39+
foo4();
40+
foo5();
41+
foo6();
42+
foo7();
43+
foo8();
44+
foo9();
45+
}

0 commit comments

Comments
 (0)