Skip to content

Commit 4dee6fe

Browse files
authored
Revert "[threads] Allow i31refs of mixed shareability to compare equal (#6752)" (#6761)
Allowing Literals with different types to compare equal causes problems for passes that want equality to mean real equality, e.g. because they are using literals as map keys or because they otherwise need to use them interchangeably. At a minimum, we would need to differentiate a `refEq` operation where mixed-shareability i31refs can compare equal from physical equality on Literals, but there is also appetite to disallow mixed-shareability ref.eq at the spec level. See WebAssembly/shared-everything-threads#76.
1 parent a9758b8 commit 4dee6fe

File tree

2 files changed

+3
-20
lines changed

2 files changed

+3
-20
lines changed

src/wasm/literal.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -412,14 +412,6 @@ void Literal::getBits(uint8_t (&buf)[16]) const {
412412
}
413413

414414
bool Literal::operator==(const Literal& other) const {
415-
// As a special case, shared and unshared i31 can compare equal even if their
416-
// types are different (because one is shared and the other is not).
417-
if (type.isRef() && other.type.isRef() && type.getHeapType().isBasic() &&
418-
other.type.getHeapType().isBasic() &&
419-
type.getHeapType().getBasic(Unshared) == HeapType::i31 &&
420-
other.type.getHeapType().getBasic(Unshared) == HeapType::i31) {
421-
return i32 == other.i32;
422-
}
423415
if (type != other.type) {
424416
return false;
425417
}
@@ -453,7 +445,9 @@ bool Literal::operator==(const Literal& other) const {
453445
if (type.isData()) {
454446
return gcData == other.gcData;
455447
}
456-
// i31 already handled.
448+
if (type.getHeapType() == HeapType::i31) {
449+
return i32 == other.i32;
450+
}
457451
WASM_UNREACHABLE("unexpected type");
458452
}
459453
WASM_UNREACHABLE("unexpected type");

test/spec/shared-polymorphism.wast

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,3 @@
2323
(extern.convert_any (local.get 0))
2424
)
2525
)
26-
27-
(module
28-
(func (export "eq") (param i32 i32) (result i32)
29-
(ref.eq (ref.i31 (local.get 0)) (ref.i31_shared (local.get 1)))
30-
)
31-
)
32-
33-
(assert_return (invoke "eq" (i32.const 0) (i32.const 0)) (i32.const 1))
34-
(assert_return (invoke "eq" (i32.const 0) (i32.const 1)) (i32.const 0))
35-
(assert_return (invoke "eq" (i32.const 1) (i32.const 0)) (i32.const 0))
36-
(assert_return (invoke "eq" (i32.const 1) (i32.const 1)) (i32.const 1))

0 commit comments

Comments
 (0)