summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xscripts/fuzz_opt.py4
-rw-r--r--src/parser/contexts.h3
-rw-r--r--src/wasm-binary.h1
-rw-r--r--src/wasm/wasm-binary.cpp7
-rw-r--r--test/lit/basic/shared-types.wast47
-rw-r--r--test/lit/passes/type-merging-shared.wast9
6 files changed, 67 insertions, 4 deletions
diff --git a/scripts/fuzz_opt.py b/scripts/fuzz_opt.py
index 2a97af64a..0804c0387 100755
--- a/scripts/fuzz_opt.py
+++ b/scripts/fuzz_opt.py
@@ -350,6 +350,10 @@ INITIAL_CONTENTS_IGNORE = [
'exception-handling.wast',
'translate-to-new-eh.wast',
'rse-eh.wast',
+ # Shared types implementation in progress
+ 'type-merging-shared.wast',
+ 'shared-types.wast',
+ 'shared-struct.wast',
]
diff --git a/src/parser/contexts.h b/src/parser/contexts.h
index 351f6a208..4acfc981a 100644
--- a/src/parser/contexts.h
+++ b/src/parser/contexts.h
@@ -1118,7 +1118,8 @@ struct ParseImplicitTypeDefsCtx : TypeParserCtx<ParseImplicitTypeDefsCtx> {
: TypeParserCtx<ParseImplicitTypeDefsCtx>(typeIndices), in(in),
types(types), implicitTypes(implicitTypes) {
for (auto type : types) {
- if (type.isSignature() && type.getRecGroup().size() == 1) {
+ if (type.isSignature() && type.getRecGroup().size() == 1 &&
+ !type.isShared()) {
sigTypes.insert({type.getSignature(), type});
}
}
diff --git a/src/wasm-binary.h b/src/wasm-binary.h
index ebfc27b1f..9a79a4c8b 100644
--- a/src/wasm-binary.h
+++ b/src/wasm-binary.h
@@ -377,6 +377,7 @@ enum EncodedType {
Array = -0x22, // 0x5e
Sub = -0x30, // 0x50
SubFinal = -0x31, // 0x4f
+ Shared = -0x24, // 0x65
// isorecursive recursion groups
Rec = -0x32, // 0x4e
// block_type
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index 7b88bdd76..924bf1601 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -285,6 +285,9 @@ void WasmBinaryWriter::writeTypes() {
o << U32LEB(0);
}
}
+ if (type.isShared()) {
+ o << S32LEB(BinaryConsts::EncodedType::Shared);
+ }
if (type.isSignature()) {
o << S32LEB(BinaryConsts::EncodedType::Func);
auto sig = type.getSignature();
@@ -2391,6 +2394,10 @@ void WasmBinaryReader::readTypes() {
}
form = getS32LEB();
}
+ if (form == BinaryConsts::Shared) {
+ builder[i].setShared();
+ form = getS32LEB();
+ }
if (form == BinaryConsts::EncodedType::Func) {
builder[i] = readSignatureDef();
} else if (form == BinaryConsts::EncodedType::Cont) {
diff --git a/test/lit/basic/shared-types.wast b/test/lit/basic/shared-types.wast
new file mode 100644
index 000000000..d3720c2e9
--- /dev/null
+++ b/test/lit/basic/shared-types.wast
@@ -0,0 +1,47 @@
+;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.
+
+;; RUN: wasm-opt %s -all -S -o - | filecheck %s
+;; RUN: wasm-opt %s -all --roundtrip -S -o - | filecheck %s
+
+(module
+ (rec
+ ;; CHECK: (rec
+ ;; CHECK-NEXT: (type $final (shared (struct )))
+ (type $final (shared (struct)))
+ ;; CHECK: (type $top (sub (shared (struct ))))
+ (type $top (sub (shared (struct))))
+ ;; CHECK: (type $mid (sub $top (shared (struct (field i32)))))
+ (type $mid (sub $top (shared (struct i32))))
+ ;; CHECK: (type $bot (sub final $mid (shared (struct (field i32) (field i32)))))
+ (type $bot (sub final $mid (shared (struct i32 i32))))
+
+ ;; CHECK: (type $func (shared (func)))
+ (type $func (shared (func)))
+ ;; CHECK: (type $array (shared (array i8)))
+ (type $array (shared (array i8)))
+ ;; CHECK: (type $cont (shared (cont $func)))
+ (type $cont (shared (cont $func)))
+ )
+
+ ;; CHECK: (type $7 (func))
+
+ ;; CHECK: (func $use-types (type $7)
+ ;; CHECK-NEXT: (local $0 (ref $final))
+ ;; CHECK-NEXT: (local $1 (ref $top))
+ ;; CHECK-NEXT: (local $2 (ref $mid))
+ ;; CHECK-NEXT: (local $3 (ref $bot))
+ ;; CHECK-NEXT: (local $4 (ref $func))
+ ;; CHECK-NEXT: (local $5 (ref $array))
+ ;; CHECK-NEXT: (local $6 (ref $cont))
+ ;; CHECK-NEXT: (nop)
+ ;; CHECK-NEXT: )
+ (func $use-types
+ (local (ref $final))
+ (local (ref $top))
+ (local (ref $mid))
+ (local (ref $bot))
+ (local (ref $func))
+ (local (ref $array))
+ (local (ref $cont))
+ )
+)
diff --git a/test/lit/passes/type-merging-shared.wast b/test/lit/passes/type-merging-shared.wast
index aefeccc3b..2d3bcdc21 100644
--- a/test/lit/passes/type-merging-shared.wast
+++ b/test/lit/passes/type-merging-shared.wast
@@ -43,18 +43,21 @@
(module
;; But two shared types can be merged.
;; CHECK: (rec
- ;; CHECK-NEXT: (type $B (shared (array i8)))
+ ;; CHECK-NEXT: (type $C (shared (func)))
+
+ ;; CHECK: (type $B (shared (array i8)))
;; CHECK: (type $A (shared (struct )))
(type $A (shared (struct)))
(type $A' (shared (struct)))
(type $B (shared (array i8)))
(type $B' (shared (array i8)))
- ;; CHECK: (type $C (shared (func)))
(type $C (shared (func)))
(type $C' (shared (func)))
- ;; CHECK: (func $foo (type $C)
+ ;; CHECK: (type $3 (func))
+
+ ;; CHECK: (func $foo (type $3)
;; CHECK-NEXT: (local $a (ref null $A))
;; CHECK-NEXT: (local $a' (ref null $A))
;; CHECK-NEXT: (local $b (ref null $B))