Skip to content

Commit 6009cb7

Browse files
committed
v.gen.wasm: make wasm_relaxed_simd imply wasm_simd
Address the review on #27526: relaxed SIMD extends the SIMD/v128 feature, but passing only -d wasm_relaxed_simd enabled .relaxed_simd without .simd. That made wabt_validate_args() emit '--disable-simd --enable-relaxed-simd' and wasm-opt run from -mvp without --enable-simd, so the advertised opt-in still failed under -wasm-validate/-prod unless the user also guessed -d wasm_simd. Add apply_feature_implications() so .relaxed_simd pulls in .simd, and cover it with features_test.v (feature set + rendered wasm-opt/wasm-validate flags).
1 parent abd230e commit 6009cb7

2 files changed

Lines changed: 46 additions & 1 deletion

File tree

vlib/v/gen/wasm/features.v

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,20 @@ fn (g &Gen) enabled_wasm_features() []WasmFeature {
180180
feats << feat
181181
}
182182
}
183-
return feats
183+
return apply_feature_implications(feats)
184+
}
185+
186+
// apply_feature_implications expands `feats` with any feature implied by another.
187+
// Relaxed SIMD extends the SIMD/v128 feature, so requesting it must also enable
188+
// SIMD. Otherwise wabt_validate_args() emits `--disable-simd --enable-relaxed-simd`
189+
// and wasm-opt runs from `-mvp` without `--enable-simd`, so a `-d wasm_relaxed_simd`
190+
// build still fails under `-wasm-validate`/`-prod`.
191+
fn apply_feature_implications(feats []WasmFeature) []WasmFeature {
192+
mut res := feats.clone()
193+
if WasmFeature.relaxed_simd in res && WasmFeature.simd !in res {
194+
res << .simd
195+
}
196+
return res
184197
}
185198

186199
// binaryen_feature_flags renders the feature set into `wasm-opt` flags. It

vlib/v/gen/wasm/features_test.v

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
module wasm
2+
3+
fn test_relaxed_simd_implies_simd() {
4+
// requesting relaxed SIMD on its own must also pull in the base SIMD feature
5+
feats := apply_feature_implications([WasmFeature.relaxed_simd])
6+
assert WasmFeature.simd in feats
7+
assert WasmFeature.relaxed_simd in feats
8+
}
9+
10+
fn test_relaxed_simd_does_not_duplicate_simd() {
11+
// when SIMD is already present, the implication must not add a duplicate
12+
feats := apply_feature_implications([WasmFeature.simd, .relaxed_simd])
13+
assert feats.filter(it == WasmFeature.simd).len == 1
14+
}
15+
16+
fn test_simd_without_relaxed_is_unchanged() {
17+
feats := apply_feature_implications([WasmFeature.simd])
18+
assert WasmFeature.simd in feats
19+
assert WasmFeature.relaxed_simd !in feats
20+
}
21+
22+
fn test_relaxed_simd_renders_simd_in_tool_flags() {
23+
feats := apply_feature_implications([WasmFeature.relaxed_simd])
24+
// wasm-opt must be told to enable SIMD as well as relaxed SIMD
25+
binaryen := binaryen_feature_flags(feats)
26+
assert binaryen.contains('--enable-simd')
27+
assert binaryen.contains('--enable-relaxed-simd')
28+
// wasm-validate must not disable SIMD while enabling relaxed SIMD
29+
wabt := wabt_validate_args(feats)
30+
assert '--disable-simd' !in wabt
31+
assert '--enable-relaxed-simd' in wabt
32+
}

0 commit comments

Comments
 (0)