diff options
author | Thomas Lively <tlively@google.com> | 2024-07-11 17:25:54 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-11 14:25:54 -0700 |
commit | ae4800bebd0d479813d99e31e098296c9167e34a (patch) | |
tree | e675041374e8411372b21ca3f6551a13acd63170 | |
parent | c64ac5d5a676fdbb9b108e0ad16c293a32a9b611 (diff) | |
download | binaryen-ae4800bebd0d479813d99e31e098296c9167e34a.tar.gz binaryen-ae4800bebd0d479813d99e31e098296c9167e34a.tar.bz2 binaryen-ae4800bebd0d479813d99e31e098296c9167e34a.zip |
[threads] Shared polymorphism for extern conversions (#6730)
`any.convert_extern` and `extern.convert_any` return references to
shared heap types iff their operands are references to shared heap
types.
-rw-r--r-- | src/wasm/wasm-validator.cpp | 18 | ||||
-rw-r--r-- | src/wasm/wasm.cpp | 9 | ||||
-rw-r--r-- | test/spec/shared-polymorphism.wast | 13 |
3 files changed, 29 insertions, 11 deletions
diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp index 9732f54a9..eb2f949b2 100644 --- a/src/wasm/wasm-validator.cpp +++ b/src/wasm/wasm-validator.cpp @@ -2222,10 +2222,11 @@ void FunctionValidator::visitRefAs(RefAs* curr) { if (curr->type == Type::unreachable) { return; } - shouldBeSubType(curr->value->type, - Type(HeapType::ext, Nullable), - curr->value, - "any.convert_extern value should be an externref"); + shouldBeSubTypeIgnoringShared( + curr->value->type, + Type(HeapType::ext, Nullable), + curr->value, + "any.convert_extern value should be an externref"); break; } case ExternConvertAny: { @@ -2235,10 +2236,11 @@ void FunctionValidator::visitRefAs(RefAs* curr) { if (curr->type == Type::unreachable) { return; } - shouldBeSubType(curr->value->type, - Type(HeapType::any, Nullable), - curr->value, - "extern.convert_any value should be an anyref"); + shouldBeSubTypeIgnoringShared( + curr->value->type, + Type(HeapType::any, Nullable), + curr->value, + "extern.convert_any value should be an anyref"); break; } } diff --git a/src/wasm/wasm.cpp b/src/wasm/wasm.cpp index 58699ad8b..8a2b4755c 100644 --- a/src/wasm/wasm.cpp +++ b/src/wasm/wasm.cpp @@ -1227,15 +1227,18 @@ void RefAs::finalize() { type = Type::unreachable; return; } + auto valHeapType = value->type.getHeapType(); switch (op) { case RefAsNonNull: - type = Type(value->type.getHeapType(), NonNullable); + type = Type(valHeapType, NonNullable); break; case AnyConvertExtern: - type = Type(HeapType::any, value->type.getNullability()); + type = Type(HeapTypes::any.getBasic(valHeapType.getShared()), + value->type.getNullability()); break; case ExternConvertAny: - type = Type(HeapType::ext, value->type.getNullability()); + type = Type(HeapTypes::ext.getBasic(valHeapType.getShared()), + value->type.getNullability()); break; default: WASM_UNREACHABLE("invalid ref.as_*"); diff --git a/test/spec/shared-polymorphism.wast b/test/spec/shared-polymorphism.wast index 547829f11..be8b5e467 100644 --- a/test/spec/shared-polymorphism.wast +++ b/test/spec/shared-polymorphism.wast @@ -9,4 +9,17 @@ (func (param (ref null (shared i31))) (drop (i31.get_u (local.get 0)))) (func (param (ref null (shared array))) (drop (array.len (local.get 0)))) + + (func (param (ref null (shared extern))) (result (ref null (shared any))) + (any.convert_extern (local.get 0)) + ) + (func (param (ref (shared extern))) (result (ref (shared any))) + (any.convert_extern (local.get 0)) + ) + (func (param (ref null (shared any))) (result (ref null (shared extern))) + (extern.convert_any (local.get 0)) + ) + (func (param (ref (shared any))) (result (ref (shared extern))) + (extern.convert_any (local.get 0)) + ) ) |