From ae4800bebd0d479813d99e31e098296c9167e34a Mon Sep 17 00:00:00 2001 From: Thomas Lively Date: Thu, 11 Jul 2024 17:25:54 -0400 Subject: [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. --- src/wasm/wasm-validator.cpp | 18 ++++++++++-------- src/wasm/wasm.cpp | 9 ++++++--- 2 files changed, 16 insertions(+), 11 deletions(-) (limited to 'src') 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_*"); -- cgit v1.2.3