Debian Codegraph @

tests/cli/gc/type-subtyping.wast

raw
1 ;; RUN: wast --assert default --snapshot tests/snapshots %
2
3 ;; Definitions
4
5 (module
6 (type $e0 (sub (array i32)))
7 (type $e1 (sub $e0 (array i32)))
8
9 (type $e2 (sub (array anyref)))
10 (type $e3 (sub (array (ref null $e0))))
11 (type $e4 (sub (array (ref $e1))))
12
13 (type $m1 (sub (array (mut i32))))
14 (type $m2 (sub $m1 (array (mut i32))))
15 )
16
17 (module
18 (type $e0 (sub (struct)))
19 (type $e1 (sub $e0 (struct)))
20 (type $e2 (sub $e1 (struct (field i32))))
21 (type $e3 (sub $e2 (struct (field i32 (ref null $e0)))))
22 (type $e4 (sub $e3 (struct (field i32 (ref $e0) (mut i64)))))
23 (type $e5 (sub $e4 (struct (field i32 (ref $e1) (mut i64)))))
24 )
25
26 (module
27 (type $s (sub (struct)))
28 (type $s' (sub $s (struct)))
29
30 (type $f1 (sub (func (param (ref $s')) (result anyref))))
31 (type $f2 (sub $f1 (func (param (ref $s)) (result (ref any)))))
32 (type $f3 (sub $f2 (func (param (ref null $s)) (result (ref $s)))))
33 (type $f4 (sub $f3 (func (param (ref null struct)) (result (ref $s')))))
34 )
35
36
37 ;; Recursive definitions
38
39 (module
40 (type $t (sub (struct (field anyref))))
41 (rec (type $r (sub $t (struct (field (ref $r))))))
42 (type $t' (sub $r (struct (field (ref $r) i32))))
43 )
44
45 (module
46 (rec
47 (type $r1 (sub (struct (field i32 (ref $r1)))))
48 )
49 (rec
50 (type $r2 (sub $r1 (struct (field i32 (ref $r3)))))
51 (type $r3 (sub $r1 (struct (field i32 (ref $r2)))))
52 )
53 )
54
55 (module
56 (rec
57 (type $a1 (sub (struct (field i32 (ref $a2)))))
58 (type $a2 (sub (struct (field i64 (ref $a1)))))
59 )
60 (rec
61 (type $b1 (sub $a2 (struct (field i64 (ref $a1) i32))))
62 (type $b2 (sub $a1 (struct (field i32 (ref $a2) i32))))
63 (type $b3 (sub $a2 (struct (field i64 (ref $b2) i32))))
64 )
65 )
66
67
68 ;; Subsumption
69
70 (module
71 (rec
72 (type $t1 (sub (func (param i32 (ref $t3)))))
73 (type $t2 (sub $t1 (func (param i32 (ref $t2)))))
74 (type $t3 (sub $t2 (func (param i32 (ref $t1)))))
75 )
76
77 (func $f1 (param $r (ref $t1))
78 (call $f1 (local.get $r))
79 )
80 (func $f2 (param $r (ref $t2))
81 (call $f1 (local.get $r))
82 (call $f2 (local.get $r))
83 )
84 (func $f3 (param $r (ref $t3))
85 (call $f1 (local.get $r))
86 (call $f2 (local.get $r))
87 (call $f3 (local.get $r))
88 )
89 )
90
91 (module
92 (rec
93 (type $t1 (sub (func (result i32 (ref $u1)))))
94 (type $u1 (sub (func (result f32 (ref $t1)))))
95 )
96
97 (rec
98 (type $t2 (sub $t1 (func (result i32 (ref $u3)))))
99 (type $u2 (sub $u1 (func (result f32 (ref $t3)))))
100 (type $t3 (sub $t1 (func (result i32 (ref $u2)))))
101 (type $u3 (sub $u1 (func (result f32 (ref $t2)))))
102 )
103
104 (func $f1 (param $r (ref $t1))
105 (call $f1 (local.get $r))
106 )
107 (func $f2 (param $r (ref $t2))
108 (call $f1 (local.get $r))
109 (call $f2 (local.get $r))
110 )
111 (func $f3 (param $r (ref $t3))
112 (call $f1 (local.get $r))
113 (call $f3 (local.get $r))
114 )
115 )
116
117 (module
118 (rec (type $f1 (sub (func))) (type (struct (field (ref $f1)))))
119 (rec (type $f2 (sub (func))) (type (struct (field (ref $f2)))))
120 (rec (type $g1 (sub $f1 (func))) (type (struct)))
121 (rec (type $g2 (sub $f2 (func))) (type (struct)))
122 (func $g (type $g2))
123 (global (ref $g1) (ref.func $g))
124 )
125
126 (module
127 (rec (type $f1 (sub (func))) (type $s1 (sub (struct (field (ref $f1))))))
128 (rec (type $f2 (sub (func))) (type $s2 (sub (struct (field (ref $f2))))))
129 (rec
130 (type $g1 (sub $f1 (func)))
131 (type (sub $s1 (struct (field (ref $f1) (ref $f1) (ref $f2) (ref $f2) (ref $g1)))))
132 )
133 (rec
134 (type $g2 (sub $f2 (func)))
135 (type (sub $s2 (struct (field (ref $f1) (ref $f2) (ref $f1) (ref $f2) (ref $g2)))))
136 )
137 (func $g (type $g2))
138 (global (ref $g1) (ref.func $g))
139 )
140
141 (assert_invalid
142 (module
143 (rec (type $f1 (sub (func))) (type (struct (field (ref $f1)))))
144 (rec (type $f2 (sub (func))) (type (struct (field (ref $f1)))))
145 (rec (type $g1 (sub $f1 (func))) (type (struct)))
146 (rec (type $g2 (sub $f2 (func))) (type (struct)))
147 (func $g (type $g2))
148 (global (ref $g1) (ref.func $g))
149 )
150 "type mismatch"
151 )
152
153 (module
154 (rec (type $f1 (sub (func))) (type (struct (field (ref $f1)))))
155 (rec (type $f2 (sub (func))) (type (struct (field (ref $f2)))))
156 (rec (type $g (sub $f1 (func))) (type (struct)))
157 (func $g (type $g))
158 (global (ref $f1) (ref.func $g))
159 )
160
161 (module
162 (rec (type $f1 (sub (func))) (type $s1 (sub (struct (field (ref $f1))))))
163 (rec (type $f2 (sub (func))) (type $s2 (sub (struct (field (ref $f2))))))
164 (rec
165 (type $g1 (sub $f1 (func)))
166 (type (sub $s1 (struct (field (ref $f1) (ref $f1) (ref $f2) (ref $f2) (ref $g1)))))
167 )
168 (rec
169 (type $g2 (sub $f2 (func)))
170 (type (sub $s2 (struct (field (ref $f1) (ref $f2) (ref $f1) (ref $f2) (ref $g2)))))
171 )
172 (rec (type $h (sub $g2 (func))) (type (struct)))
173 (func $h (type $h))
174 (global (ref $f1) (ref.func $h))
175 (global (ref $g1) (ref.func $h))
176 )
177
178
179 (module
180 (rec (type $f11 (sub (func (result (ref func))))) (type $f12 (sub $f11 (func (result (ref $f11))))))
181 (rec (type $f21 (sub (func (result (ref func))))) (type $f22 (sub $f21 (func (result (ref $f21))))))
182 (func $f11 (type $f11) (unreachable))
183 (func $f12 (type $f12) (unreachable))
184 (global (ref $f11) (ref.func $f11))
185 (global (ref $f21) (ref.func $f11))
186 (global (ref $f12) (ref.func $f12))
187 (global (ref $f22) (ref.func $f12))
188 )
189
190 (module
191 (rec (type $f11 (sub (func (result (ref func))))) (type $f12 (sub $f11 (func (result (ref $f11))))))
192 (rec (type $f21 (sub (func (result (ref func))))) (type $f22 (sub $f21 (func (result (ref $f21))))))
193 (rec (type $g11 (sub $f11 (func (result (ref func))))) (type $g12 (sub $g11 (func (result (ref $g11))))))
194 (rec (type $g21 (sub $f21 (func (result (ref func))))) (type $g22 (sub $g21 (func (result (ref $g21))))))
195 (func $g11 (type $g11) (unreachable))
196 (func $g12 (type $g12) (unreachable))
197 (global (ref $f11) (ref.func $g11))
198 (global (ref $f21) (ref.func $g11))
199 (global (ref $f11) (ref.func $g12))
200 (global (ref $f21) (ref.func $g12))
201 (global (ref $g11) (ref.func $g11))
202 (global (ref $g21) (ref.func $g11))
203 (global (ref $g12) (ref.func $g12))
204 (global (ref $g22) (ref.func $g12))
205 )
206
207 (assert_invalid
208 (module
209 (rec (type $f11 (sub (func))) (type $f12 (sub $f11 (func))))
210 (rec (type $f21 (sub (func))) (type $f22 (sub $f11 (func))))
211 (func $f (type $f21))
212 (global (ref $f11) (ref.func $f))
213 )
214 "type mismatch"
215 )
216
217 (assert_invalid
218 (module
219 (rec (type $f01 (sub (func))) (type $f02 (sub $f01 (func))))
220 (rec (type $f11 (sub (func))) (type $f12 (sub $f01 (func))))
221 (rec (type $f21 (sub (func))) (type $f22 (sub $f11 (func))))
222 (func $f (type $f21))
223 (global (ref $f11) (ref.func $f))
224 )
225 "type mismatch"
226 )
227
228
229 ;; Runtime types
230
231 (module
232 (type $t0 (sub (func (result (ref null func)))))
233 (rec (type $t1 (sub $t0 (func (result (ref null $t1))))))
234 (rec (type $t2 (sub $t1 (func (result (ref null $t2))))))
235
236 (func $f0 (type $t0) (ref.null func))
237 (func $f1 (type $t1) (ref.null $t1))
238 (func $f2 (type $t2) (ref.null $t2))
239 (table funcref (elem $f0 $f1 $f2))
240
241 (func (export "run")
242 (block (result (ref null func)) (call_indirect (type $t0) (i32.const 0)))
243 (block (result (ref null func)) (call_indirect (type $t0) (i32.const 1)))
244 (block (result (ref null func)) (call_indirect (type $t0) (i32.const 2)))
245 (block (result (ref null $t1)) (call_indirect (type $t1) (i32.const 1)))
246 (block (result (ref null $t1)) (call_indirect (type $t1) (i32.const 2)))
247 (block (result (ref null $t2)) (call_indirect (type $t2) (i32.const 2)))
248
249 (block (result (ref null $t0)) (ref.cast (ref $t0) (table.get (i32.const 0))))
250 (block (result (ref null $t0)) (ref.cast (ref $t0) (table.get (i32.const 1))))
251 (block (result (ref null $t0)) (ref.cast (ref $t0) (table.get (i32.const 2))))
252 (block (result (ref null $t1)) (ref.cast (ref $t1) (table.get (i32.const 1))))
253 (block (result (ref null $t1)) (ref.cast (ref $t1) (table.get (i32.const 2))))
254 (block (result (ref null $t2)) (ref.cast (ref $t2) (table.get (i32.const 2))))
255 (br 0)
256 )
257
258 (func (export "fail1")
259 (block (result (ref null $t1)) (call_indirect (type $t1) (i32.const 0)))
260 (br 0)
261 )
262 (func (export "fail2")
263 (block (result (ref null $t1)) (call_indirect (type $t2) (i32.const 0)))
264 (br 0)
265 )
266 (func (export "fail3")
267 (block (result (ref null $t1)) (call_indirect (type $t2) (i32.const 1)))
268 (br 0)
269 )
270
271 (func (export "fail4")
272 (ref.cast (ref $t1) (table.get (i32.const 0)))
273 (br 0)
274 )
275 (func (export "fail5")
276 (ref.cast (ref $t2) (table.get (i32.const 0)))
277 (br 0)
278 )
279 (func (export "fail6")
280 (ref.cast (ref $t2) (table.get (i32.const 1)))
281 (br 0)
282 )
283 )
284 (assert_return (invoke "run"))
285 (assert_trap (invoke "fail1") "indirect call")
286 (assert_trap (invoke "fail2") "indirect call")
287 (assert_trap (invoke "fail3") "indirect call")
288 (assert_trap (invoke "fail4") "cast")
289 (assert_trap (invoke "fail5") "cast")
290 (assert_trap (invoke "fail6") "cast")
291
292 (module
293 (type $t1 (sub (func)))
294 (type $t2 (sub final (func)))
295
296 (func $f1 (type $t1))
297 (func $f2 (type $t2))
298 (table funcref (elem $f1 $f2))
299
300 (func (export "fail1")
301 (block (call_indirect (type $t1) (i32.const 1)))
302 )
303 (func (export "fail2")
304 (block (call_indirect (type $t2) (i32.const 0)))
305 )
306
307 (func (export "fail3")
308 (ref.cast (ref $t1) (table.get (i32.const 1)))
309 (drop)
310 )
311 (func (export "fail4")
312 (ref.cast (ref $t2) (table.get (i32.const 0)))
313 (drop)
314 )
315 )
316 (assert_trap (invoke "fail1") "indirect call")
317 (assert_trap (invoke "fail2") "indirect call")
318 (assert_trap (invoke "fail3") "cast")
319 (assert_trap (invoke "fail4") "cast")
320
321
322 (module
323 (rec (type $f1 (sub (func))) (type (struct (field (ref $f1)))))
324 (rec (type $f2 (sub (func))) (type (struct (field (ref $f2)))))
325 (rec (type $g1 (sub $f1 (func))) (type (struct)))
326 (rec (type $g2 (sub $f2 (func))) (type (struct)))
327 (func $g (type $g2)) (elem declare func $g)
328 (func (export "run") (result i32)
329 (ref.test (ref $g1) (ref.func $g))
330 )
331 )
332 (assert_return (invoke "run") (i32.const 1))
333
334 (module
335 (rec (type $f1 (sub (func))) (type $s1 (sub (struct (field (ref $f1))))))
336 (rec (type $f2 (sub (func))) (type $s2 (sub (struct (field (ref $f2))))))
337 (rec
338 (type $g1 (sub $f1 (func)))
339 (type (sub $s1 (struct (field (ref $f1) (ref $f1) (ref $f2) (ref $f2) (ref $g1)))))
340 )
341 (rec
342 (type $g2 (sub $f2 (func)))
343 (type (sub $s2 (struct (field (ref $f1) (ref $f2) (ref $f1) (ref $f2) (ref $g2)))))
344 )
345 (func $g (type $g2)) (elem declare func $g)
346 (func (export "run") (result i32)
347 (ref.test (ref $g1) (ref.func $g))
348 )
349 )
350 (assert_return (invoke "run") (i32.const 1))
351
352 ;; (module
353 ;; (rec (type $f1 (sub (func))) (type (struct (field (ref $f1)))))
354 ;; (rec (type $f2 (sub (func))) (type (struct (field (ref $f1)))))
355 ;; (rec (type $g1 (sub $f1 (func))) (type (struct)))
356 ;; (rec (type $g2 (sub $f2 (func))) (type (struct)))
357 ;; (func $g (type $g2)) (elem declare func $g)
358 ;; (func (export "run") (result i32)
359 ;; (ref.test (ref $g1) (ref.func $g))
360 ;; )
361 ;; )
362 ;; (assert_return (invoke "run") (i32.const 0))
363
364 ;; (module
365 ;; (rec (type $f1 (sub (func))) (type (struct (field (ref $f1)))))
366 ;; (rec (type $f2 (sub (func))) (type (struct (field (ref $f2)))))
367 ;; (rec (type $g (sub $f1 (func))) (type (struct)))
368 ;; (func $g (type $g)) (elem declare func $g)
369 ;; (func (export "run") (result i32)
370 ;; (ref.test (ref $f1) (ref.func $g))
371 ;; )
372 ;; )
373 ;; (assert_return (invoke "run") (i32.const 1))
374
375 ;; (module
376 ;; (rec (type $f1 (sub (func))) (type $s1 (sub (struct (field (ref $f1))))))
377 ;; (rec (type $f2 (sub (func))) (type $s2 (sub (struct (field (ref $f2))))))
378 ;; (rec
379 ;; (type $g1 (sub $f1 (func)))
380 ;; (type (sub $s1 (struct (field (ref $f1) (ref $f1) (ref $f2) (ref $f2) (ref $g1)))))
381 ;; )
382 ;; (rec
383 ;; (type $g2 (sub $f2 (func)))
384 ;; (type (sub $s2 (struct (field (ref $f1) (ref $f2) (ref $f1) (ref $f2) (ref $g2)))))
385 ;; )
386 ;; (rec (type $h (sub $g2 (func))) (type (struct)))
387 ;; (func $h (type $h)) (elem declare func $h)
388 ;; (func (export "run") (result i32 i32)
389 ;; (ref.test (ref $f1) (ref.func $h))
390 ;; (ref.test (ref $g1) (ref.func $h))
391 ;; )
392 ;; )
393 ;; (assert_return (invoke "run") (i32.const 1) (i32.const 1))
394
395
396 (module
397 (rec (type $f11 (sub (func (result (ref func))))) (type $f12 (sub $f11 (func (result (ref $f11))))))
398 (rec (type $f21 (sub (func (result (ref func))))) (type $f22 (sub $f21 (func (result (ref $f21))))))
399 (func $f11 (type $f11) (unreachable)) (elem declare func $f11)
400 (func $f12 (type $f12) (unreachable)) (elem declare func $f12)
401 (func (export "run") (result i32 i32 i32 i32)
402 (ref.test (ref $f11) (ref.func $f11))
403 (ref.test (ref $f21) (ref.func $f11))
404 (ref.test (ref $f12) (ref.func $f12))
405 (ref.test (ref $f22) (ref.func $f12))
406 )
407 )
408 (assert_return (invoke "run")
409 (i32.const 1) (i32.const 1) (i32.const 1) (i32.const 1)
410 )
411
412 ;; (module
413 ;; (rec (type $f11 (sub (func (result (ref func))))) (type $f12 (sub $f11 (func (result (ref $f11))))))
414 ;; (rec (type $f21 (sub (func (result (ref func))))) (type $f22 (sub $f21 (func (result (ref $f21))))))
415 ;; (rec (type $g11 (sub $f11 (func (result (ref func))))) (type $g12 (sub $g11 (func (result (ref $g11))))))
416 ;; (rec (type $g21 (sub $f21 (func (result (ref func))))) (type $g22 (sub $g21 (func (result (ref $g21))))))
417 ;; (func $g11 (type $g11) (unreachable)) (elem declare func $g11)
418 ;; (func $g12 (type $g12) (unreachable)) (elem declare func $g12)
419 ;; (func (export "run") (result i32 i32 i32 i32 i32 i32 i32 i32)
420 ;; (ref.test (ref $f11) (ref.func $g11))
421 ;; (ref.test (ref $f21) (ref.func $g11))
422 ;; (ref.test (ref $f11) (ref.func $g12))
423 ;; (ref.test (ref $f21) (ref.func $g12))
424 ;; (ref.test (ref $g11) (ref.func $g11))
425 ;; (ref.test (ref $g21) (ref.func $g11))
426 ;; (ref.test (ref $g12) (ref.func $g12))
427 ;; (ref.test (ref $g22) (ref.func $g12))
428 ;; )
429 ;; )
430 ;; (assert_return (invoke "run")
431 ;; (i32.const 1) (i32.const 1) (i32.const 1) (i32.const 1)
432 ;; (i32.const 1) (i32.const 1) (i32.const 1) (i32.const 1)
433 ;; )
434
435 ;; (module
436 ;; (rec (type $f11 (sub (func))) (type $f12 (sub $f11 (func))))
437 ;; (rec (type $f21 (sub (func))) (type $f22 (sub $f11 (func))))
438 ;; (func $f (type $f21)) (elem declare func $f)
439 ;; (func (export "run") (result i32)
440 ;; (ref.test (ref $f11) (ref.func $f))
441 ;; )
442 ;; )
443 ;; (assert_return (invoke "run") (i32.const 0))
444
445 ;; (module
446 ;; (rec (type $f01 (sub (func))) (type $f02 (sub $f01 (func))))
447 ;; (rec (type $f11 (sub (func))) (type $f12 (sub $f01 (func))))
448 ;; (rec (type $f21 (sub (func))) (type $f22 (sub $f11 (func))))
449 ;; (func $f (type $f21)) (elem declare func $f)
450 ;; (func (export "run") (result i32)
451 ;; (ref.test (ref $f11) (ref.func $f))
452 ;; )
453 ;; )
454 ;; (assert_return (invoke "run") (i32.const 0))
455
456
457
458 ;; Linking
459
460 (module
461 (type $t0 (sub (func (result (ref null func)))))
462 (rec (type $t1 (sub $t0 (func (result (ref null $t1))))))
463 (rec (type $t2 (sub $t1 (func (result (ref null $t2))))))
464
465 (func (export "f0") (type $t0) (ref.null func))
466 (func (export "f1") (type $t1) (ref.null $t1))
467 (func (export "f2") (type $t2) (ref.null $t2))
468 )
469 (register "M")
470
471 (module
472 (type $t0 (sub (func (result (ref null func)))))
473 (rec (type $t1 (sub $t0 (func (result (ref null $t1))))))
474 (rec (type $t2 (sub $t1 (func (result (ref null $t2))))))
475
476 (func (import "M" "f0") (type $t0))
477 (func (import "M" "f1") (type $t0))
478 (func (import "M" "f1") (type $t1))
479 (func (import "M" "f2") (type $t0))
480 (func (import "M" "f2") (type $t1))
481 (func (import "M" "f2") (type $t2))
482 )
483
484 (assert_unlinkable
485 (module
486 (type $t0 (sub (func (result (ref null func)))))
487 (rec (type $t1 (sub $t0 (func (result (ref null $t1))))))
488 (rec (type $t2 (sub $t1 (func (result (ref null $t2))))))
489 (func (import "M" "f0") (type $t1))
490 )
491 "incompatible import type"
492 )
493
494 (assert_unlinkable
495 (module
496 (type $t0 (sub (func (result (ref null func)))))
497 (rec (type $t1 (sub $t0 (func (result (ref null $t1))))))
498 (rec (type $t2 (sub $t1 (func (result (ref null $t2))))))
499 (func (import "M" "f0") (type $t2))
500 )
501 "incompatible import type"
502 )
503
504 (assert_unlinkable
505 (module
506 (type $t0 (sub (func (result (ref null func)))))
507 (rec (type $t1 (sub $t0 (func (result (ref null $t1))))))
508 (rec (type $t2 (sub $t1 (func (result (ref null $t2))))))
509 (func (import "M" "f1") (type $t2))
510 )
511 "incompatible import type"
512 )
513
514 (module
515 (type $t1 (sub (func)))
516 (type $t2 (sub final (func)))
517 (func (export "f1") (type $t1))
518 (func (export "f2") (type $t2))
519 )
520 (register "M2")
521
522 (assert_unlinkable
523 (module
524 (type $t1 (sub (func)))
525 (type $t2 (sub final (func)))
526 (func (import "M2" "f1") (type $t2))
527 )
528 "incompatible import type"
529 )
530 (assert_unlinkable
531 (module
532 (type $t1 (sub (func)))
533 (type $t2 (sub final (func)))
534 (func (import "M2" "f2") (type $t1))
535 )
536 "incompatible import type"
537 )
538
539
540 (module
541 (rec (type $f2 (sub (func))) (type (struct (field (ref $f2)))))
542 (rec (type $g2 (sub $f2 (func))) (type (struct)))
543 (func (export "g") (type $g2))
544 )
545 (register "M3")
546 (module
547 (rec (type $f1 (sub (func))) (type (struct (field (ref $f1)))))
548 (rec (type $g1 (sub $f1 (func))) (type (struct)))
549 (func (import "M3" "g") (type $g1))
550 )
551
552 (module
553 (rec (type $f1 (sub (func))) (type $s1 (sub (struct (field (ref $f1))))))
554 (rec (type $f2 (sub (func))) (type $s2 (sub (struct (field (ref $f2))))))
555 (rec
556 (type $g2 (sub $f2 (func)))
557 (type (sub $s2 (struct (field (ref $f1) (ref $f2) (ref $f1) (ref $f2) (ref $g2)))))
558 )
559 (func (export "g") (type $g2))
560 )
561 (register "M4")
562 (module
563 (rec (type $f1 (sub (func))) (type $s1 (sub (struct (field (ref $f1))))))
564 (rec (type $f2 (sub (func))) (type $s2 (sub (struct (field (ref $f2))))))
565 (rec
566 (type $g1 (sub $f1 (func)))
567 (type (sub $s1 (struct (field (ref $f1) (ref $f1) (ref $f2) (ref $f2) (ref $g1)))))
568 )
569 (func (import "M4" "g") (type $g1))
570 )
571
572 (module
573 (rec (type $f1 (sub (func))) (type (struct (field (ref $f1)))))
574 (rec (type $f2 (sub (func))) (type (struct (field (ref $f1)))))
575 (rec (type $g2 (sub $f2 (func))) (type (struct)))
576 (func (export "g") (type $g2))
577 )
578 (register "M5")
579 (assert_unlinkable
580 (module
581 (rec (type $f1 (sub (func))) (type (struct (field (ref $f1)))))
582 (rec (type $g1 (sub $f1 (func))) (type (struct)))
583 (func (import "M5" "g") (type $g1))
584 )
585 "incompatible import"
586 )
587
588 (module
589 (rec (type $f1 (sub (func))) (type (struct (field (ref $f1)))))
590 (rec (type $f2 (sub (func))) (type (struct (field (ref $f2)))))
591 (rec (type $g (sub $f1 (func))) (type (struct)))
592 (func (export "g") (type $g))
593 )
594 (register "M6")
595 (module
596 (rec (type $f1 (sub (func))) (type (struct (field (ref $f1)))))
597 (rec (type $f2 (sub (func))) (type (struct (field (ref $f2)))))
598 (rec (type $g (sub $f1 (func))) (type (struct)))
599 (func (import "M6" "g") (type $f1))
600 )
601
602 (module
603 (rec (type $f1 (sub (func))) (type $s1 (sub (struct (field (ref $f1))))))
604 (rec (type $f2 (sub (func))) (type $s2 (sub (struct (field (ref $f2))))))
605 (rec
606 (type $g2 (sub $f2 (func)))
607 (type (sub $s2 (struct (field (ref $f1) (ref $f2) (ref $f1) (ref $f2) (ref $g2)))))
608 )
609 (rec (type $h (sub $g2 (func))) (type (struct)))
610 (func (export "h") (type $h))
611 )
612 (register "M7")
613 (module
614 (rec (type $f1 (sub (func))) (type $s1 (sub (struct (field (ref $f1))))))
615 (rec (type $f2 (sub (func))) (type $s2 (sub (struct (field (ref $f2))))))
616 (rec
617 (type $g1 (sub $f1 (func)))
618 (type (sub $s1 (struct (field (ref $f1) (ref $f1) (ref $f2) (ref $f2) (ref $g1)))))
619 )
620 (rec (type $h (sub $g1 (func))) (type (struct)))
621 (func (import "M7" "h") (type $f1))
622 (func (import "M7" "h") (type $g1))
623 )
624
625
626 (module
627 (rec (type $f11 (sub (func (result (ref func))))) (type $f12 (sub $f11 (func (result (ref $f11))))))
628 (rec (type $f21 (sub (func (result (ref func))))) (type $f22 (sub $f21 (func (result (ref $f21))))))
629 (func (export "f11") (type $f11) (unreachable))
630 (func (export "f12") (type $f12) (unreachable))
631 )
632 (register "M8")
633 (module
634 (rec (type $f11 (sub (func (result (ref func))))) (type $f12 (sub $f11 (func (result (ref $f11))))))
635 (rec (type $f21 (sub (func (result (ref func))))) (type $f22 (sub $f21 (func (result (ref $f21))))))
636 (func (import "M8" "f11") (type $f11))
637 (func (import "M8" "f11") (type $f21))
638 (func (import "M8" "f12") (type $f12))
639 (func (import "M8" "f12") (type $f22))
640 )
641
642 (module
643 (rec (type $f11 (sub (func (result (ref func))))) (type $f12 (sub $f11 (func (result (ref $f11))))))
644 (rec (type $f21 (sub (func (result (ref func))))) (type $f22 (sub $f21 (func (result (ref $f21))))))
645 (rec (type $g11 (sub $f11 (func (result (ref func))))) (type $g12 (sub $g11 (func (result (ref $g11))))))
646 (rec (type $g21 (sub $f21 (func (result (ref func))))) (type $g22 (sub $g21 (func (result (ref $g21))))))
647 (func (export "g11") (type $g11) (unreachable))
648 (func (export "g12") (type $g12) (unreachable))
649 )
650 (register "M9")
651 (module
652 (rec (type $f11 (sub (func (result (ref func))))) (type $f12 (sub $f11 (func (result (ref $f11))))))
653 (rec (type $f21 (sub (func (result (ref func))))) (type $f22 (sub $f21 (func (result (ref $f21))))))
654 (rec (type $g11 (sub $f11 (func (result (ref func))))) (type $g12 (sub $g11 (func (result (ref $g11))))))
655 (rec (type $g21 (sub $f21 (func (result (ref func))))) (type $g22 (sub $g21 (func (result (ref $g21))))))
656 (func (import "M9" "g11") (type $f11))
657 (func (import "M9" "g11") (type $f21))
658 (func (import "M9" "g12") (type $f11))
659 (func (import "M9" "g12") (type $f21))
660 (func (import "M9" "g11") (type $g11))
661 (func (import "M9" "g11") (type $g21))
662 (func (import "M9" "g12") (type $g12))
663 (func (import "M9" "g12") (type $g22))
664 )
665
666 (module
667 (rec (type $f11 (sub (func))) (type $f12 (sub $f11 (func))))
668 (rec (type $f21 (sub (func))) (type $f22 (sub $f11 (func))))
669 (func (export "f") (type $f21))
670 )
671 (register "M10")
672 (assert_unlinkable
673 (module
674 (rec (type $f11 (sub (func))) (type $f12 (sub $f11 (func))))
675 (func (import "M10" "f") (type $f11))
676 )
677 "incompatible import"
678 )
679
680 (module
681 (rec (type $f01 (sub (func))) (type $f02 (sub $f01 (func))))
682 (rec (type $f11 (sub (func))) (type $f12 (sub $f01 (func))))
683 (rec (type $f21 (sub (func))) (type $f22 (sub $f11 (func))))
684 (func (export "f") (type $f21))
685 )
686 (register "M11")
687 (assert_unlinkable
688 (module
689 (rec (type $f01 (sub (func))) (type $f02 (sub $f01 (func))))
690 (rec (type $f11 (sub (func))) (type $f12 (sub $f01 (func))))
691 (func (import "M11" "f") (type $f11))
692 )
693 "incompatible import"
694 )
695
696
697
698 ;; Finality violation
699
700 (assert_invalid
701 (module
702 (type $t (func))
703 (type $s (sub $t (func)))
704 )
705 "sub type"
706 )
707
708 (assert_invalid
709 (module
710 (type $t (struct))
711 (type $s (sub $t (struct)))
712 )
713 "sub type"
714 )
715
716 (assert_invalid
717 (module
718 (type $t (sub final (func)))
719 (type $s (sub $t (func)))
720 )
721 "sub type"
722 )
723
724 (assert_invalid
725 (module
726 (type $t (sub (func)))
727 (type $s (sub final $t (func)))
728 (type $u (sub $s (func)))
729 )
730 "sub type"
731 )
732
733
734
735 ;; Invalid subtyping definitions
736
737 (assert_invalid
738 (module
739 (type $a0 (sub (array i32)))
740 (type $s0 (sub $a0 (struct)))
741 )
742 "sub type"
743 )
744
745 (assert_invalid
746 (module
747 (type $f0 (sub (func (param i32) (result i32))))
748 (type $s0 (sub $f0 (struct)))
749 )
750 "sub type"
751 )
752
753 (assert_invalid
754 (module
755 (type $s0 (sub (struct)))
756 (type $a0 (sub $s0 (array i32)))
757 )
758 "sub type"
759 )
760
761 (assert_invalid
762 (module
763 (type $f0 (sub (func (param i32) (result i32))))
764 (type $a0 (sub $f0 (array i32)))
765 )
766 "sub type"
767 )
768
769 (assert_invalid
770 (module
771 (type $s0 (sub (struct)))
772 (type $f0 (sub $s0 (func (param i32) (result i32))))
773 )
774 "sub type"
775 )
776
777 (assert_invalid
778 (module
779 (type $a0 (sub (array i32)))
780 (type $f0 (sub $a0 (func (param i32) (result i32))))
781 )
782 "sub type"
783 )
784
785 (assert_invalid
786 (module
787 (type $a0 (sub (array i32)))
788 (type $a1 (sub $a0 (array i64)))
789 )
790 "sub type"
791 )
792
793 (assert_invalid
794 (module
795 (type $s0 (sub (struct (field i32))))
796 (type $s1 (sub $s0 (struct (field i64))))
797 )
798 "sub type"
799 )
800
801 (assert_invalid
802 (module
803 (type $f0 (sub (func)))
804 (type $f1 (sub $f0 (func (param i32))))
805 )
806 "sub type"
807 )