summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Lively <tlively@google.com>2022-10-13 16:41:02 -0500
committerGitHub <noreply@github.com>2022-10-13 14:41:02 -0700
commitbc23c8f45bd1c2808d0871e7f1c9dbbdb3bc4ae8 (patch)
tree38638c72347176a1893a65f5236333b44c60d16f
parent9c3b95a388d48cfd2430e138606f781c831fb2f2 (diff)
downloadbinaryen-bc23c8f45bd1c2808d0871e7f1c9dbbdb3bc4ae8.tar.gz
binaryen-bc23c8f45bd1c2808d0871e7f1c9dbbdb3bc4ae8.tar.bz2
binaryen-bc23c8f45bd1c2808d0871e7f1c9dbbdb3bc4ae8.zip
Add "struct" and "structref" as an alias for "data" and "dataref" (#5141)
In the upstream spec, `data` has been replaced with a type called `struct`. To allow for a graceful update in Binaryen, start by introducing "struct" as an alias for "data". Once users have stopped emitting `data` directly, future PRs will remove `data` and update the subtyping so that arrays are no longer subtypes of `struct`.
-rw-r--r--src/wasm/wasm-s-parser.cpp6
-rw-r--r--test/lit/structref.wast13
2 files changed, 17 insertions, 2 deletions
diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp
index 64d7a21a2..91d4c129c 100644
--- a/src/wasm/wasm-s-parser.cpp
+++ b/src/wasm/wasm-s-parser.cpp
@@ -1190,7 +1190,8 @@ Type SExpressionWasmBuilder::stringToType(std::string_view str,
if (str.substr(0, 6) == "i31ref" && (prefix || str.size() == 6)) {
return Type(HeapType::i31, Nullable);
}
- if (str.substr(0, 7) == "dataref" && (prefix || str.size() == 7)) {
+ if ((str.substr(0, 7) == "dataref" && (prefix || str.size() == 7)) ||
+ (str.substr(0, 9) == "structref" && (prefix || str.size() == 9))) {
return Type(HeapType::data, Nullable);
}
if (str.substr(0, 9) == "stringref" && (prefix || str.size() == 9)) {
@@ -1238,7 +1239,8 @@ HeapType SExpressionWasmBuilder::stringToHeapType(std::string_view str,
if (str.substr(0, 3) == "i31" && (prefix || str.size() == 3)) {
return HeapType::i31;
}
- if (str.substr(0, 4) == "data" && (prefix || str.size() == 4)) {
+ if ((str.substr(0, 4) == "data" && (prefix || str.size() == 4)) ||
+ (str.substr(0, 6) == "struct" && (prefix || str.size() == 6))) {
return HeapType::data;
}
if (str.substr(0, 6) == "string" && (prefix || str.size() == 6)) {
diff --git a/test/lit/structref.wast b/test/lit/structref.wast
new file mode 100644
index 000000000..5e674eb26
--- /dev/null
+++ b/test/lit/structref.wast
@@ -0,0 +1,13 @@
+;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited.
+
+;; RUN: wasm-opt -all %s -S -o - | filecheck %s
+
+;; Check that `struct` is correctly parsed as an alias for `data`.
+(module
+ ;; CHECK: (func $foo (param $x dataref) (param $y (ref data))
+ ;; CHECK-NEXT: (unreachable)
+ ;; CHECK-NEXT: )
+ (func $foo (param $x structref) (param $y (ref struct))
+ (unreachable)
+ )
+)