Skip to content

Commit 225564f

Browse files
Work on subtyping
1 parent 2fbd478 commit 225564f

File tree

1 file changed

+78
-8
lines changed

1 file changed

+78
-8
lines changed

test/lit/passes/global-effects-closed-world.wast

Lines changed: 78 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,26 @@
33

44
(module
55
;; CHECK: (type $maybe-has-effects (func (param i32 i32)))
6+
(type $maybe-has-effects (func (param i32 i32)))
67

78
;; CHECK: (type $nopType (func (param i32)))
89
(type $nopType (func (param i32)))
910

10-
(type $maybe-has-effects (func (param i32 i32)))
11+
;; CHECK: (type $super (sub (struct)))
12+
(type $super (sub (struct)))
13+
;; CHECK: (type $sub (sub $super (struct)))
14+
(type $sub (sub $super (struct)))
15+
16+
;; CHECK: (type $func-with-sub-param (func (param (ref $sub))))
17+
18+
;; CHECK: (type $uninhabited (func (param f32)))
19+
(type $uninhabited (func (param f32)))
20+
21+
;; Subtype
22+
;; CHECK: (type $func-with-super-param (func (param (ref $super))))
23+
(type $func-with-super-param (func (param (ref $super))))
24+
;; Supertype
25+
(type $func-with-sub-param (func (param (ref $sub))))
1126

1227
;; CHECK: (global $g (mut i32) (i32.const 0))
1328
(global $g (mut i32) (i32.const 0))
@@ -33,7 +48,7 @@
3348
(nop)
3449
)
3550

36-
;; CHECK: (func $calls-nop-via-ref (type $2) (param $ref (ref $nopType))
51+
;; CHECK: (func $calls-nop-via-ref (type $6) (param $ref (ref $nopType))
3752
;; CHECK-NEXT: (call_ref $nopType
3853
;; CHECK-NEXT: (i32.const 1)
3954
;; CHECK-NEXT: (local.get $ref)
@@ -47,17 +62,16 @@
4762
(call_ref $nopType (i32.const 1) (local.get $ref))
4863
)
4964

50-
;; CHECK: (func $f (type $3) (param $ref (ref $nopType)) (result i32)
51-
;; CHECK-NEXT: (i32.const 1)
65+
;; CHECK: (func $f (type $6) (param $ref (ref $nopType))
66+
;; CHECK-NEXT: (nop)
5267
;; CHECK-NEXT: )
53-
(func $f (param $ref (ref $nopType)) (result i32)
68+
(func $f (param $ref (ref $nopType))
5469
;; $calls-nop-via-ref has no effects because we determined that it can only
5570
;; call $nop. We can optimize this call out.
5671
(call $calls-nop-via-ref (local.get $ref))
57-
(i32.const 1)
5872
)
5973

60-
;; CHECK: (func $calls-effectful-function-via-ref (type $4) (param $ref (ref $maybe-has-effects))
74+
;; CHECK: (func $calls-effectful-function-via-ref (type $9) (param $ref (ref $maybe-has-effects))
6175
;; CHECK-NEXT: (call_ref $maybe-has-effects
6276
;; CHECK-NEXT: (i32.const 1)
6377
;; CHECK-NEXT: (i32.const 2)
@@ -68,7 +82,7 @@
6882
(call_ref $maybe-has-effects (i32.const 1) (i32.const 2) (local.get $ref))
6983
)
7084

71-
;; CHECK: (func $g (type $5) (param $ref (ref $maybe-has-effects)) (result i32)
85+
;; CHECK: (func $g (type $10) (param $ref (ref $maybe-has-effects)) (result i32)
7286
;; CHECK-NEXT: (call $calls-effectful-function-via-ref
7387
;; CHECK-NEXT: (local.get $ref)
7488
;; CHECK-NEXT: )
@@ -80,4 +94,60 @@
8094
(call $calls-effectful-function-via-ref (local.get $ref))
8195
(i32.const 1)
8296
)
97+
98+
;; CHECK: (func $calls-uninhabited (type $7) (param $ref (ref $uninhabited))
99+
;; CHECK-NEXT: (call_ref $uninhabited
100+
;; CHECK-NEXT: (f32.const 0)
101+
;; CHECK-NEXT: (local.get $ref)
102+
;; CHECK-NEXT: )
103+
;; CHECK-NEXT: )
104+
(func $calls-uninhabited (param $ref (ref $uninhabited))
105+
(call_ref $uninhabited (f32.const 0) (local.get $ref))
106+
)
107+
108+
;; CHECK: (func $h (type $7) (param $ref (ref $uninhabited))
109+
;; CHECK-NEXT: (nop)
110+
;; CHECK-NEXT: )
111+
(func $h (param $ref (ref $uninhabited))
112+
;; There's no function with this type, so it's impossible to create a ref to
113+
;; call this function with and there are no effects to aggregate.
114+
;; Remove this call.
115+
(call $calls-uninhabited (local.get $ref))
116+
)
117+
118+
;; CHECK: (func $nop-with-supertype (type $func-with-sub-param) (param $0 (ref $sub))
119+
;; CHECK-NEXT: (nop)
120+
;; CHECK-NEXT: )
121+
(func $nop-with-supertype (type $func-with-sub-param) (param (ref $sub))
122+
)
123+
124+
;; CHECK: (func $effectful-with-subtype (type $func-with-super-param) (param $0 (ref $super))
125+
;; CHECK-NEXT: (unreachable)
126+
;; CHECK-NEXT: )
127+
(func $effectful-with-subtype (type $func-with-super-param) (param (ref $super))
128+
(unreachable)
129+
)
130+
131+
;; CHECK: (func $calls-ref-with-subtype (type $8) (param $func (ref $func-with-sub-param)) (param $sub (ref $sub))
132+
;; CHECK-NEXT: (call_ref $func-with-sub-param
133+
;; CHECK-NEXT: (local.get $sub)
134+
;; CHECK-NEXT: (local.get $func)
135+
;; CHECK-NEXT: )
136+
;; CHECK-NEXT: )
137+
(func $calls-ref-with-subtype (param $func (ref $func-with-sub-param)) (param $sub (ref $sub))
138+
(call_ref $func-with-sub-param (local.get $sub) (local.get $func))
139+
)
140+
141+
;; CHECK: (func $asdf (type $8) (param $func (ref $func-with-sub-param)) (param $sub (ref $sub))
142+
;; CHECK-NEXT: (nop)
143+
;; CHECK-NEXT: )
144+
(func $asdf (param $func (ref $func-with-sub-param)) (param $sub (ref $sub))
145+
;; Check that we account for subtyping correctly.
146+
;; The type $func-with-sub-param (the supertype) has no effects (i.e. the
147+
;; union of all effects of functions with this type is empty).
148+
;; However, a subtype of $func-with-sub-param ($func-with-super-param) does
149+
;; have effects, and we can call_ref with that subtype, so we need to
150+
;; include the unreachable effect and we can't optimize out this call.
151+
(call $calls-ref-with-subtype (local.get $func) (local.get $sub))
152+
)
83153
)

0 commit comments

Comments
 (0)