summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas Lively <7121787+tlively@users.noreply.github.com>2022-08-26 12:11:29 -0700
committerGitHub <noreply@github.com>2022-08-26 12:11:29 -0700
commit9d20a4e129dc6666f873d84566ea504dfc46ccdc (patch)
tree99be367933aaddeffa4805f0493cb84d01c0d5a0 /src
parent3777624e19f22a6eb80d995408329d789593e427 (diff)
downloadbinaryen-9d20a4e129dc6666f873d84566ea504dfc46ccdc.tar.gz
binaryen-9d20a4e129dc6666f873d84566ea504dfc46ccdc.tar.bz2
binaryen-9d20a4e129dc6666f873d84566ea504dfc46ccdc.zip
Make `i31ref` and `dataref` nullable (#4843)
Match the latest version of the GC spec. This change does not depend on V8 changing its interpretation of the shorthands because we are still temporarily not emitting the binary shorthands, but all Binaryen users will have to update their interpretations along with this change if they use the text or binary shorthands.
Diffstat (limited to 'src')
-rw-r--r--src/passes/Print.cpp82
-rw-r--r--src/wasm-type.h4
-rw-r--r--src/wasm/wasm-binary.cpp4
-rw-r--r--src/wasm/wasm-s-parser.cpp4
-rw-r--r--src/wasm/wat-parser.cpp4
5 files changed, 40 insertions, 58 deletions
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp
index 81ae1bfc6..7385c18ea 100644
--- a/src/passes/Print.cpp
+++ b/src/passes/Print.cpp
@@ -85,56 +85,38 @@ static bool maybePrintRefShorthand(std::ostream& o, Type type) {
return false;
}
auto heapType = type.getHeapType();
- if (heapType.isBasic()) {
- if (type.isNullable()) {
- switch (heapType.getBasic()) {
- case HeapType::ext:
- o << "externref";
- return true;
- case HeapType::func:
- o << "funcref";
- return true;
- case HeapType::any:
- o << "anyref";
- return true;
- case HeapType::eq:
- o << "eqref";
- return true;
- case HeapType::i31:
- case HeapType::data:
- break;
- case HeapType::string:
- o << "stringref";
- return true;
- case HeapType::stringview_wtf8:
- o << "stringview_wtf8";
- return true;
- case HeapType::stringview_wtf16:
- o << "stringview_wtf16";
- return true;
- case HeapType::stringview_iter:
- o << "stringview_iter";
- return true;
- }
- } else {
- switch (heapType.getBasic()) {
- case HeapType::ext:
- case HeapType::func:
- case HeapType::any:
- case HeapType::eq:
- break;
- case HeapType::i31:
- o << "i31ref";
- return true;
- case HeapType::data:
- o << "dataref";
- return true;
- case HeapType::string:
- case HeapType::stringview_wtf8:
- case HeapType::stringview_wtf16:
- case HeapType::stringview_iter:
- break;
- }
+ if (heapType.isBasic() && type.isNullable()) {
+ switch (heapType.getBasic()) {
+ case HeapType::ext:
+ o << "externref";
+ return true;
+ case HeapType::func:
+ o << "funcref";
+ return true;
+ case HeapType::any:
+ o << "anyref";
+ return true;
+ case HeapType::eq:
+ o << "eqref";
+ return true;
+ case HeapType::i31:
+ o << "i31ref";
+ return true;
+ case HeapType::data:
+ o << "dataref";
+ return true;
+ case HeapType::string:
+ o << "stringref";
+ return true;
+ case HeapType::stringview_wtf8:
+ o << "stringview_wtf8";
+ return true;
+ case HeapType::stringview_wtf16:
+ o << "stringview_wtf16";
+ return true;
+ case HeapType::stringview_iter:
+ o << "stringview_iter";
+ return true;
}
}
return false;
diff --git a/src/wasm-type.h b/src/wasm-type.h
index 7235cda8b..778318794 100644
--- a/src/wasm-type.h
+++ b/src/wasm-type.h
@@ -143,8 +143,8 @@ public:
// │ funcref ║ x │ │ x │ x │ f n │ ┐ Ref
// │ anyref ║ x │ │ x │ x │ f? n │ │ f_unc
// │ eqref ║ x │ │ x │ x │ n │ │ n_ullable
- // │ i31ref ║ x │ │ x │ x │ │ │
- // │ dataref ║ x │ │ x │ x │ │ │
+ // │ i31ref ║ x │ │ x │ x │ n │ │
+ // │ dataref ║ x │ │ x │ x │ n │ │
// ├─ Compound ──╫───┼───┼───┼───┤───────┤ │
// │ Ref ║ │ x │ x │ x │ f? n? │◄┘
// │ Tuple ║ │ x │ │ x │ │
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index 1fb43c884..685ad978d 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -1849,10 +1849,10 @@ bool WasmBinaryBuilder::getBasicType(int32_t code, Type& out) {
out = Type(HeapType::eq, Nullable);
return true;
case BinaryConsts::EncodedType::i31ref:
- out = Type(HeapType::i31, NonNullable);
+ out = Type(HeapType::i31, Nullable);
return true;
case BinaryConsts::EncodedType::dataref:
- out = Type(HeapType::data, NonNullable);
+ out = Type(HeapType::data, Nullable);
return true;
case BinaryConsts::EncodedType::stringref:
out = Type(HeapType::string, Nullable);
diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp
index 362ba25f9..a7d63a7c6 100644
--- a/src/wasm/wasm-s-parser.cpp
+++ b/src/wasm/wasm-s-parser.cpp
@@ -1179,10 +1179,10 @@ Type SExpressionWasmBuilder::stringToType(const char* str,
return Type(HeapType::eq, Nullable);
}
if (strncmp(str, "i31ref", 6) == 0 && (prefix || str[6] == 0)) {
- return Type(HeapType::i31, NonNullable);
+ return Type(HeapType::i31, Nullable);
}
if (strncmp(str, "dataref", 7) == 0 && (prefix || str[7] == 0)) {
- return Type(HeapType::data, NonNullable);
+ return Type(HeapType::data, Nullable);
}
if (strncmp(str, "stringref", 9) == 0 && (prefix || str[9] == 0)) {
return Type(HeapType::string, Nullable);
diff --git a/src/wasm/wat-parser.cpp b/src/wasm/wat-parser.cpp
index 843e26d08..9e843271f 100644
--- a/src/wasm/wat-parser.cpp
+++ b/src/wasm/wat-parser.cpp
@@ -1343,10 +1343,10 @@ MaybeResult<typename Ctx::TypeT> reftype(Ctx& ctx, ParseInput& in) {
return ctx.makeRefType(ctx.makeEq(), Nullable);
}
if (in.takeKeyword("i31ref"sv)) {
- return ctx.makeRefType(ctx.makeI31(), NonNullable);
+ return ctx.makeRefType(ctx.makeI31(), Nullable);
}
if (in.takeKeyword("dataref"sv)) {
- return ctx.makeRefType(ctx.makeData(), NonNullable);
+ return ctx.makeRefType(ctx.makeData(), Nullable);
}
if (in.takeKeyword("arrayref"sv)) {
return in.err("arrayref not yet supported");