Skip to content

Commit f4b9e45

Browse files
committed
test
1 parent ccc5be0 commit f4b9e45

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

src/passes/GlobalStructInference.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,7 @@ struct GlobalStructInference : public Pass {
543543
// casts are usually more efficient than normal ones (and even more so
544544
// if we get lucky and are in a loop, where the global.get of the
545545
// descriptor can be hoisted).
546+
// TODO: only do this when shrinkLevel == 0?
546547

547548
// Check if we have a descriptor.
548549
auto type = curr->type;

test/lit/passes/gsi-desc.wast

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,3 +186,55 @@
186186
)
187187
)
188188

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+

0 commit comments

Comments
 (0)