Skip to content

Commit 8d2c9ff

Browse files
authored
Fix shareability handling in TypeSSA collision logic (#6798)
1 parent 2a7c093 commit 8d2c9ff

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

src/passes/TypeSSA.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ std::vector<HeapType> ensureTypesAreInNewRecGroup(RecGroup recGroup,
111111
builder[i].subTypeOf(*super);
112112
}
113113
builder[i].setOpen(type.isOpen());
114+
builder[i].setShared(type.getShared());
114115
}
115116

116117
// Implement the hash as a struct with "random" fields, and add it.

test/lit/passes/type-ssa-shared.wast

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,42 @@
7070
)
7171
)
7272
)
73+
74+
;; We end up needing to do some extra work to ensure types are in a new rec
75+
;; group, that is, that it does not overlap with an existing rec group. While
76+
;; doing so we should apply shareability properly and not error. (Specifically,
77+
;; when we create a new subtype of $A, it must differ from $B.)
78+
(module
79+
;; CHECK: (type $0 (func))
80+
81+
;; CHECK: (type $A (sub (shared (array (mut i32)))))
82+
(type $A (sub (shared (array (mut i32)))))
83+
;; CHECK: (type $B (sub $A (shared (array (mut i32)))))
84+
(type $B (sub $A (shared (array (mut i32)))))
85+
86+
;; CHECK: (rec
87+
;; CHECK-NEXT: (type $A_1 (sub $A (shared (array (mut i32)))))
88+
89+
;; 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))))
90+
91+
;; CHECK: (func $func (type $0)
92+
;; CHECK-NEXT: (local $local (ref $B))
93+
;; CHECK-NEXT: (drop
94+
;; CHECK-NEXT: (array.new_default $A_1
95+
;; CHECK-NEXT: (i32.const 0)
96+
;; CHECK-NEXT: )
97+
;; CHECK-NEXT: )
98+
;; CHECK-NEXT: )
99+
(func $func
100+
;; Keep the type $B alive.
101+
(local $local (ref $B))
102+
103+
;; Create an $A, which TypeSSA can specialize.
104+
(drop
105+
(array.new_default $A
106+
(i32.const 0)
107+
)
108+
)
109+
)
110+
)
111+

0 commit comments

Comments
 (0)