summaryrefslogtreecommitdiff
path: root/src/wasm/wasm-validator.cpp
diff options
context:
space:
mode:
authorThomas Lively <7121787+tlively@users.noreply.github.com>2022-08-29 12:48:46 -0700
committerGitHub <noreply@github.com>2022-08-29 12:48:46 -0700
commitbd630d707253a9838a3d0306e4be680942ff0715 (patch)
treeb51a786d3afd3ee97a78eb0d3923fb6ad59565d5 /src/wasm/wasm-validator.cpp
parent8108ce28e66f1002932f6e5dc9dd4f23c8b8a9f3 (diff)
downloadbinaryen-bd630d707253a9838a3d0306e4be680942ff0715.tar.gz
binaryen-bd630d707253a9838a3d0306e4be680942ff0715.tar.bz2
binaryen-bd630d707253a9838a3d0306e4be680942ff0715.zip
Implement `extern.externalize` and `extern.internalize` (#4975)
These new GC instructions infallibly convert between `extern` and `any` references now that those types are not in the same hierarchy.
Diffstat (limited to 'src/wasm/wasm-validator.cpp')
-rw-r--r--src/wasm/wasm-validator.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp
index 532529d2a..75cbcf53a 100644
--- a/src/wasm/wasm-validator.cpp
+++ b/src/wasm/wasm-validator.cpp
@@ -424,6 +424,7 @@ public:
void visitMemoryGrow(MemoryGrow* curr);
void visitRefNull(RefNull* curr);
void visitRefIs(RefIs* curr);
+ void visitRefAs(RefAs* curr);
void visitRefFunc(RefFunc* curr);
void visitRefEq(RefEq* curr);
void visitTableGet(TableGet* curr);
@@ -2125,6 +2126,40 @@ void FunctionValidator::visitRefIs(RefIs* curr) {
"ref.is_*'s argument should be a reference type");
}
+void FunctionValidator::visitRefAs(RefAs* curr) {
+ switch (curr->op) {
+ default:
+ // TODO: validate all the other ref.as_*
+ break;
+ case ExternInternalize: {
+ shouldBeTrue(getModule()->features.hasGC(),
+ curr,
+ "extern.internalize requries GC to be enabled");
+ if (curr->type == Type::unreachable) {
+ return;
+ }
+ shouldBeSubType(curr->value->type,
+ Type(HeapType::ext, Nullable),
+ curr->value,
+ "extern.internalize value should be an externref");
+ break;
+ }
+ case ExternExternalize: {
+ shouldBeTrue(getModule()->features.hasGC(),
+ curr,
+ "extern.externalize requries GC to be enabled");
+ if (curr->type == Type::unreachable) {
+ return;
+ }
+ shouldBeSubType(curr->value->type,
+ Type(HeapType::any, Nullable),
+ curr->value,
+ "extern.externalize value should be an anyref");
+ break;
+ }
+ }
+}
+
void FunctionValidator::visitRefFunc(RefFunc* curr) {
// If we are not in a function, this is a global location like a table. We
// allow RefFunc there as we represent tables that way regardless of what