Skip to content

Commit 88a090d

Browse files
authored
threads: fix ref.i31_shared encoding (#1724)
* threads: fix `ref.i31_shared` encoding In the initial implementation, this encoding was incorrectly emitted as `0xFE 0x1F`, clobbering the encoding for `i64.atomic.rmw.add` (probably a copy-paste error). This change updates `wasm-encoder` to use the correct `0xFE 0x72` encoding. * threads: fix `ref.i31_shared` stack type This instruction should return the `shared` version of `ref.i31`. * Add a simple re-encodable test
1 parent eb997df commit 88a090d

5 files changed

Lines changed: 26 additions & 2 deletions

File tree

crates/wasm-encoder/src/core/code.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3693,7 +3693,7 @@ impl Encode for Instruction<'_> {
36933693
}
36943694
Instruction::RefI31Shared => {
36953695
sink.push(0xFE);
3696-
sink.push(0x1F);
3696+
sink.push(0x72);
36973697
}
36983698
}
36993699
}

crates/wasmparser/src/validator/operators.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4534,7 +4534,9 @@ where
45344534
}
45354535
fn visit_ref_i31_shared(&mut self) -> Self::Output {
45364536
self.pop_operand(Some(ValType::I32))?;
4537-
self.push_operand(ValType::Ref(RefType::I31)) // TODO: handle shared--is this correct?
4537+
self.push_operand(ValType::Ref(
4538+
RefType::I31.shared().expect("i31 is abstract"),
4539+
))
45384540
}
45394541
fn visit_i31_get_s(&mut self) -> Self::Output {
45404542
self.pop_operand(Some(ValType::Ref(RefType::I31REF)))?;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
(module
2+
(func (result (ref null (shared i31)))
3+
(ref.i31_shared (i32.const 0))
4+
)
5+
)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"source_filename": "tests/local/shared-everything-threads/i31.wast",
3+
"commands": [
4+
{
5+
"type": "module",
6+
"line": 1,
7+
"filename": "i31.0.wasm"
8+
}
9+
]
10+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
(module
2+
(type (;0;) (func (result (ref null (shared i31)))))
3+
(func (;0;) (type 0) (result (ref null (shared i31)))
4+
i32.const 0
5+
ref.i31_shared
6+
)
7+
)

0 commit comments

Comments
 (0)