File tree Expand file tree Collapse file tree 2 files changed +53
-0
lines changed Expand file tree Collapse file tree 2 files changed +53
-0
lines changed Original file line number Diff line number Diff line change @@ -543,6 +543,7 @@ struct GlobalStructInference : public Pass {
543
543
// casts are usually more efficient than normal ones (and even more so
544
544
// if we get lucky and are in a loop, where the global.get of the
545
545
// descriptor can be hoisted).
546
+ // TODO: only do this when shrinkLevel == 0?
546
547
547
548
// Check if we have a descriptor.
548
549
auto type = curr->type ;
Original file line number Diff line number Diff line change 186
186
)
187
187
)
188
188
189
+ ;; Two types with descriptors and subtyping between them.
190
+ (module
191
+ (rec
192
+ ;; CHECK: (rec
193
+ ;; CHECK-NEXT: (type $super (sub (descriptor $super.desc (struct))))
194
+ (type $super (sub (descriptor $super.desc (struct ))))
195
+ ;; CHECK: (type $super.desc (sub (describes $super (struct))))
196
+ (type $super.desc (sub (describes $super (struct ))))
197
+
198
+ ;; CHECK: (type $sub (sub $super (descriptor $sub.desc (struct))))
199
+ (type $sub (sub $super (descriptor $sub.desc (struct ))))
200
+ ;; CHECK: (type $sub.desc (sub $super.desc (describes $sub (struct))))
201
+ (type $sub.desc (sub $super.desc (describes $sub (struct ))))
202
+ )
203
+
204
+ ;; CHECK: (type $4 (func (param anyref)))
205
+
206
+ ;; CHECK: (global $sub.desc (ref $sub.desc) (struct.new_default $sub.desc))
207
+ (global $sub.desc (ref $sub.desc ) (struct.new $sub.desc ))
208
+
209
+ ;; CHECK: (global $super.desc (ref $super.desc) (struct.new_default $super.desc))
210
+ (global $super.desc (ref $super.desc ) (struct.new $super.desc ))
211
+
212
+ ;; CHECK: (func $test (type $4) (param $any anyref)
213
+ ;; CHECK-NEXT: (drop
214
+ ;; CHECK-NEXT: (ref.cast (ref $super)
215
+ ;; CHECK-NEXT: (local.get $any)
216
+ ;; CHECK-NEXT: )
217
+ ;; CHECK-NEXT: )
218
+ ;; CHECK-NEXT: (drop
219
+ ;; CHECK-NEXT: (ref.cast_desc (ref $sub)
220
+ ;; CHECK-NEXT: (local.get $any)
221
+ ;; CHECK-NEXT: (global.get $sub.desc)
222
+ ;; CHECK-NEXT: )
223
+ ;; CHECK-NEXT: )
224
+ ;; CHECK-NEXT: )
225
+ (func $test (param $any anyref )
226
+ ;; The second cast here is optimizable: it can only be to a single type with
227
+ ;; no subtypes, so we can use ref.cast_desc.
228
+ (drop
229
+ (ref.cast (ref $super )
230
+ (local.get $any )
231
+ )
232
+ )
233
+ (drop
234
+ (ref.cast (ref $sub )
235
+ (local.get $any )
236
+ )
237
+ )
238
+ )
239
+ )
240
+
You can’t perform that action at this time.
0 commit comments