Skip to content

Commit

Permalink
Revert "[threads] Allow i31refs of mixed shareability to compare equal (
Browse files Browse the repository at this point in the history
#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.
  • Loading branch information
tlively authored Jul 17, 2024
1 parent a9758b8 commit 4dee6fe
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 20 deletions.
12 changes: 3 additions & 9 deletions src/wasm/literal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,14 +412,6 @@ void Literal::getBits(uint8_t (&buf)[16]) const {
}

bool Literal::operator==(const Literal& other) const {
// As a special case, shared and unshared i31 can compare equal even if their
// types are different (because one is shared and the other is not).
if (type.isRef() && other.type.isRef() && type.getHeapType().isBasic() &&
other.type.getHeapType().isBasic() &&
type.getHeapType().getBasic(Unshared) == HeapType::i31 &&
other.type.getHeapType().getBasic(Unshared) == HeapType::i31) {
return i32 == other.i32;
}
if (type != other.type) {
return false;
}
Expand Down Expand Up @@ -453,7 +445,9 @@ bool Literal::operator==(const Literal& other) const {
if (type.isData()) {
return gcData == other.gcData;
}
// i31 already handled.
if (type.getHeapType() == HeapType::i31) {
return i32 == other.i32;
}
WASM_UNREACHABLE("unexpected type");
}
WASM_UNREACHABLE("unexpected type");
Expand Down
11 changes: 0 additions & 11 deletions test/spec/shared-polymorphism.wast
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,3 @@
(extern.convert_any (local.get 0))
)
)

(module
(func (export "eq") (param i32 i32) (result i32)
(ref.eq (ref.i31 (local.get 0)) (ref.i31_shared (local.get 1)))
)
)

(assert_return (invoke "eq" (i32.const 0) (i32.const 0)) (i32.const 1))
(assert_return (invoke "eq" (i32.const 0) (i32.const 1)) (i32.const 0))
(assert_return (invoke "eq" (i32.const 1) (i32.const 0)) (i32.const 0))
(assert_return (invoke "eq" (i32.const 1) (i32.const 1)) (i32.const 1))

0 comments on commit 4dee6fe

Please sign in to comment.