summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2024-08-01 12:48:41 -0700
committerGitHub <noreply@github.com>2024-08-01 12:48:41 -0700
commit8d2c9ffc6d2cc89d53403986fb330a3953ddf3b8 (patch)
treede9e83cde3fa3f0f62407a91d7e77d750b781552
parent2a7c0931edf681076e678a0e8092e170333c6e86 (diff)
downloadbinaryen-8d2c9ffc6d2cc89d53403986fb330a3953ddf3b8.tar.gz
binaryen-8d2c9ffc6d2cc89d53403986fb330a3953ddf3b8.tar.bz2
binaryen-8d2c9ffc6d2cc89d53403986fb330a3953ddf3b8.zip
Fix shareability handling in TypeSSA collision logic (#6798)
-rw-r--r--src/passes/TypeSSA.cpp1
-rw-r--r--test/lit/passes/type-ssa-shared.wast39
2 files changed, 40 insertions, 0 deletions
diff --git a/src/passes/TypeSSA.cpp b/src/passes/TypeSSA.cpp
index dcd56f5d6..1d00efb5b 100644
--- a/src/passes/TypeSSA.cpp
+++ b/src/passes/TypeSSA.cpp
@@ -111,6 +111,7 @@ std::vector<HeapType> ensureTypesAreInNewRecGroup(RecGroup recGroup,
builder[i].subTypeOf(*super);
}
builder[i].setOpen(type.isOpen());
+ builder[i].setShared(type.getShared());
}
// Implement the hash as a struct with "random" fields, and add it.
diff --git a/test/lit/passes/type-ssa-shared.wast b/test/lit/passes/type-ssa-shared.wast
index d6266f7d9..e3e1db2f2 100644
--- a/test/lit/passes/type-ssa-shared.wast
+++ b/test/lit/passes/type-ssa-shared.wast
@@ -70,3 +70,42 @@
)
)
)
+
+;; We end up needing to do some extra work to ensure types are in a new rec
+;; group, that is, that it does not overlap with an existing rec group. While
+;; doing so we should apply shareability properly and not error. (Specifically,
+;; when we create a new subtype of $A, it must differ from $B.)
+(module
+ ;; CHECK: (type $0 (func))
+
+ ;; CHECK: (type $A (sub (shared (array (mut i32)))))
+ (type $A (sub (shared (array (mut i32)))))
+ ;; CHECK: (type $B (sub $A (shared (array (mut i32)))))
+ (type $B (sub $A (shared (array (mut i32)))))
+
+ ;; CHECK: (rec
+ ;; CHECK-NEXT: (type $A_1 (sub $A (shared (array (mut i32)))))
+
+ ;; CHECK: (type $4 (struct (field (mut i32)) (field (mut i32)) (field (mut f64)) (field (mut f64)) (field (mut i32)) (field (mut f64)) (field (mut f64)) (field (mut i32)) (field (mut i32)) (field (mut i32)) (field (mut i32))))
+
+ ;; CHECK: (func $func (type $0)
+ ;; CHECK-NEXT: (local $local (ref $B))
+ ;; CHECK-NEXT: (drop
+ ;; CHECK-NEXT: (array.new_default $A_1
+ ;; CHECK-NEXT: (i32.const 0)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ (func $func
+ ;; Keep the type $B alive.
+ (local $local (ref $B))
+
+ ;; Create an $A, which TypeSSA can specialize.
+ (drop
+ (array.new_default $A
+ (i32.const 0)
+ )
+ )
+ )
+)
+