1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
|
;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.
;; RUN: foreach %s %t wasm-opt --nominal --signature-refining -all -S -o - | filecheck %s
(module
;; $func is defined with an anyref parameter but always called with a $struct,
;; and we can specialize the heap type to that. That will both update the
;; heap type's definition as well as the types of the parameters as printed
;; on the function (which are derived from the heap type).
;; CHECK: (type $struct (struct_subtype data))
(type $struct (struct_subtype data))
;; CHECK: (type $sig (func_subtype (param (ref $struct)) func))
(type $sig (func_subtype (param anyref) func))
;; CHECK: (type $none_=>_none (func_subtype func))
;; CHECK: (func $func (type $sig) (param $x (ref $struct))
;; CHECK-NEXT: (nop)
;; CHECK-NEXT: )
(func $func (type $sig) (param $x anyref)
)
;; CHECK: (func $caller (type $none_=>_none)
;; CHECK-NEXT: (call $func
;; CHECK-NEXT: (struct.new_default $struct)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $caller
(call $func
(struct.new $struct)
)
)
)
(module
;; As above, but the call is via call_ref.
;; CHECK: (type $struct (struct_subtype data))
(type $struct (struct_subtype data))
;; CHECK: (type $sig (func_subtype (param (ref $struct)) func))
(type $sig (func_subtype (param anyref) func))
;; CHECK: (type $none_=>_none (func_subtype func))
;; CHECK: (elem declare func $func)
;; CHECK: (func $func (type $sig) (param $x (ref $struct))
;; CHECK-NEXT: (nop)
;; CHECK-NEXT: )
(func $func (type $sig) (param $x anyref)
)
;; CHECK: (func $caller (type $none_=>_none)
;; CHECK-NEXT: (call_ref
;; CHECK-NEXT: (struct.new_default $struct)
;; CHECK-NEXT: (ref.func $func)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $caller
(call_ref
(struct.new $struct)
(ref.func $func)
)
)
)
(module
;; A combination of call types, and the LUB is affected by all of them: one
;; call uses a nullable $struct, the other a non-nullable dataref, so the LUB
;; is a nullable dataref.
;; CHECK: (type $struct (struct_subtype data))
(type $struct (struct_subtype data))
;; CHECK: (type $sig (func_subtype (param (ref null data)) func))
(type $sig (func_subtype (param anyref) func))
;; CHECK: (type $none_=>_none (func_subtype func))
;; CHECK: (elem declare func $func)
;; CHECK: (func $func (type $sig) (param $x (ref null data))
;; CHECK-NEXT: (nop)
;; CHECK-NEXT: )
(func $func (type $sig) (param $x anyref)
)
;; CHECK: (func $caller (type $none_=>_none)
;; CHECK-NEXT: (local $struct (ref null $struct))
;; CHECK-NEXT: (call $func
;; CHECK-NEXT: (local.get $struct)
;; CHECK-NEXT: )
;; CHECK-NEXT: (call_ref
;; CHECK-NEXT: (ref.as_data
;; CHECK-NEXT: (struct.new_default $struct)
;; CHECK-NEXT: )
;; CHECK-NEXT: (ref.func $func)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $caller
(local $struct (ref null $struct))
(call $func
;; Use a local to avoid a ref.null being updated.
(local.get $struct)
)
(call_ref
(ref.as_data
(struct.new $struct)
)
(ref.func $func)
)
)
)
(module
;; Multiple functions with the same heap type. Again, the LUB is in the
;; middle, this time the parent $struct and not a subtype.
;; CHECK: (type $sig (func_subtype (param (ref $struct)) func))
(type $sig (func_subtype (param anyref) func))
;; CHECK: (type $none_=>_none (func_subtype func))
;; CHECK: (type $struct (struct_subtype data))
;; CHECK: (type $struct-sub1 (struct_subtype $struct))
(type $struct-sub1 (struct_subtype $struct))
;; CHECK: (type $struct-sub2 (struct_subtype $struct))
(type $struct-sub2 (struct_subtype $struct))
(type $struct (struct_subtype data))
;; CHECK: (func $func-1 (type $sig) (param $x (ref $struct))
;; CHECK-NEXT: (nop)
;; CHECK-NEXT: )
(func $func-1 (type $sig) (param $x anyref)
)
;; CHECK: (func $func-2 (type $sig) (param $x (ref $struct))
;; CHECK-NEXT: (nop)
;; CHECK-NEXT: )
(func $func-2 (type $sig) (param $x anyref)
)
;; CHECK: (func $caller (type $none_=>_none)
;; CHECK-NEXT: (call $func-1
;; CHECK-NEXT: (struct.new_default $struct-sub1)
;; CHECK-NEXT: )
;; CHECK-NEXT: (call $func-2
;; CHECK-NEXT: (struct.new_default $struct-sub2)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $caller
(call $func-1
(struct.new $struct-sub1)
)
(call $func-2
(struct.new $struct-sub2)
)
)
)
(module
;; As above, but now only one of the functions is called. The other is still
;; updated, though, as they share a heap type.
;; CHECK: (type $sig (func_subtype (param (ref $struct)) func))
(type $sig (func_subtype (param anyref) func))
;; CHECK: (type $struct (struct_subtype data))
(type $struct (struct_subtype data))
;; CHECK: (type $none_=>_none (func_subtype func))
;; CHECK: (func $func-1 (type $sig) (param $x (ref $struct))
;; CHECK-NEXT: (nop)
;; CHECK-NEXT: )
(func $func-1 (type $sig) (param $x anyref)
)
;; CHECK: (func $func-2 (type $sig) (param $x (ref $struct))
;; CHECK-NEXT: (nop)
;; CHECK-NEXT: )
(func $func-2 (type $sig) (param $x anyref)
)
;; CHECK: (func $caller (type $none_=>_none)
;; CHECK-NEXT: (call $func-1
;; CHECK-NEXT: (struct.new_default $struct)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $caller
(call $func-1
(struct.new $struct)
)
)
)
(module
;; Define a field in the struct of the signature type that will be updated,
;; to check for proper validation after the update.
;; CHECK: (type $sig (func_subtype (param (ref $struct) (ref $sig)) func))
(type $sig (func_subtype (param anyref funcref) func))
;; CHECK: (type $struct (struct_subtype (field (ref $sig)) data))
(type $struct (struct_subtype (field (ref $sig)) data))
;; CHECK: (type $none_=>_none (func_subtype func))
;; CHECK: (elem declare func $func)
;; CHECK: (func $func (type $sig) (param $x (ref $struct)) (param $f (ref $sig))
;; CHECK-NEXT: (local $temp (ref null $sig))
;; CHECK-NEXT: (local $3 funcref)
;; CHECK-NEXT: (local.set $3
;; CHECK-NEXT: (local.get $f)
;; CHECK-NEXT: )
;; CHECK-NEXT: (block
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (local.get $x)
;; CHECK-NEXT: )
;; CHECK-NEXT: (local.set $3
;; CHECK-NEXT: (local.get $temp)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $func (type $sig) (param $x anyref) (param $f funcref)
;; Define a local of the signature type that is updated.
(local $temp (ref null $sig))
;; Do a local.get of the param, to verify its type is valid.
(drop
(local.get $x)
)
;; Copy from a funcref local to the formerly funcref param to verify their
;; types are still compatible after the update. Note that we will need to
;; add a fixup local here, as $f's new type becomes too specific to be
;; assigned the value here.
(local.set $f
(local.get $temp)
)
)
;; CHECK: (func $caller (type $none_=>_none)
;; CHECK-NEXT: (call $func
;; CHECK-NEXT: (struct.new $struct
;; CHECK-NEXT: (ref.func $func)
;; CHECK-NEXT: )
;; CHECK-NEXT: (ref.func $func)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $caller
(call $func
(struct.new $struct
(ref.func $func)
)
(ref.func $func)
)
)
)
(module
;; An unreachable value does not prevent optimization: we will update the
;; param to be $struct.
;; CHECK: (type $struct (struct_subtype data))
(type $struct (struct_subtype data))
;; CHECK: (type $sig (func_subtype (param (ref $struct)) func))
(type $sig (func_subtype (param anyref) func))
;; CHECK: (type $none_=>_none (func_subtype func))
;; CHECK: (elem declare func $func)
;; CHECK: (func $func (type $sig) (param $x (ref $struct))
;; CHECK-NEXT: (nop)
;; CHECK-NEXT: )
(func $func (type $sig) (param $x anyref)
)
;; CHECK: (func $caller (type $none_=>_none)
;; CHECK-NEXT: (call $func
;; CHECK-NEXT: (struct.new_default $struct)
;; CHECK-NEXT: )
;; CHECK-NEXT: (call_ref
;; CHECK-NEXT: (unreachable)
;; CHECK-NEXT: (ref.func $func)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $caller
(call $func
(struct.new $struct)
)
(call_ref
(unreachable)
(ref.func $func)
)
)
)
(module
;; When we have only unreachable values, there is nothing to optimize, and we
;; should not crash.
(type $struct (struct_subtype data))
;; CHECK: (type $sig (func_subtype (param anyref) func))
(type $sig (func_subtype (param anyref) func))
;; CHECK: (type $none_=>_none (func_subtype func))
;; CHECK: (elem declare func $func)
;; CHECK: (func $func (type $sig) (param $x anyref)
;; CHECK-NEXT: (nop)
;; CHECK-NEXT: )
(func $func (type $sig) (param $x anyref)
)
;; CHECK: (func $caller (type $none_=>_none)
;; CHECK-NEXT: (call_ref
;; CHECK-NEXT: (unreachable)
;; CHECK-NEXT: (ref.func $func)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $caller
(call_ref
(unreachable)
(ref.func $func)
)
)
)
(module
;; When we have no calls, there is nothing to optimize, and we should not
;; crash.
(type $struct (struct_subtype data))
;; CHECK: (type $sig (func_subtype (param anyref) func))
(type $sig (func_subtype (param anyref) func))
;; CHECK: (func $func (type $sig) (param $x anyref)
;; CHECK-NEXT: (nop)
;; CHECK-NEXT: )
(func $func (type $sig) (param $x anyref)
)
)
(module
;; Test multiple fields in multiple types.
;; CHECK: (type $struct (struct_subtype data))
(type $struct (struct_subtype data))
;; CHECK: (type $sig-1 (func_subtype (param (ref null data) anyref) func))
(type $sig-1 (func_subtype (param anyref) (param anyref) func))
;; CHECK: (type $sig-2 (func_subtype (param eqref (ref $struct)) func))
(type $sig-2 (func_subtype (param anyref) (param anyref) func))
;; CHECK: (type $none_=>_none (func_subtype func))
;; CHECK: (elem declare func $func-2)
;; CHECK: (func $func-1 (type $sig-1) (param $x (ref null data)) (param $y anyref)
;; CHECK-NEXT: (nop)
;; CHECK-NEXT: )
(func $func-1 (type $sig-1) (param $x anyref) (param $y anyref)
)
;; CHECK: (func $func-2 (type $sig-2) (param $x eqref) (param $y (ref $struct))
;; CHECK-NEXT: (nop)
;; CHECK-NEXT: )
(func $func-2 (type $sig-2) (param $x anyref) (param $y anyref)
)
;; CHECK: (func $caller (type $none_=>_none)
;; CHECK-NEXT: (local $any anyref)
;; CHECK-NEXT: (local $data (ref null data))
;; CHECK-NEXT: (local $i31 (ref null i31))
;; CHECK-NEXT: (call $func-1
;; CHECK-NEXT: (struct.new_default $struct)
;; CHECK-NEXT: (local.get $data)
;; CHECK-NEXT: )
;; CHECK-NEXT: (call $func-1
;; CHECK-NEXT: (local.get $data)
;; CHECK-NEXT: (local.get $any)
;; CHECK-NEXT: )
;; CHECK-NEXT: (call $func-2
;; CHECK-NEXT: (struct.new_default $struct)
;; CHECK-NEXT: (struct.new_default $struct)
;; CHECK-NEXT: )
;; CHECK-NEXT: (call_ref
;; CHECK-NEXT: (local.get $i31)
;; CHECK-NEXT: (struct.new_default $struct)
;; CHECK-NEXT: (ref.func $func-2)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $caller
(local $any (ref null any))
(local $data (ref null data))
(local $i31 (ref null i31))
(call $func-1
(struct.new $struct)
(local.get $data)
)
(call $func-1
(local.get $data)
(local.get $any)
)
(call $func-2
(struct.new $struct)
(struct.new $struct)
)
(call_ref
(local.get $i31)
(struct.new $struct)
(ref.func $func-2)
)
)
)
(module
;; The presence of a table prevents us from doing any optimizations.
;; CHECK: (type $sig (func_subtype (param anyref) func))
(type $sig (func_subtype (param anyref) func))
;; CHECK: (type $none_=>_none (func_subtype func))
;; CHECK: (type $struct (struct_subtype data))
(type $struct (struct_subtype data))
(table 1 1 anyref)
;; CHECK: (table $0 1 1 anyref)
;; CHECK: (func $func (type $sig) (param $x anyref)
;; CHECK-NEXT: (nop)
;; CHECK-NEXT: )
(func $func (type $sig) (param $x anyref)
)
;; CHECK: (func $caller (type $none_=>_none)
;; CHECK-NEXT: (call $func
;; CHECK-NEXT: (struct.new_default $struct)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $caller
(call $func
(struct.new $struct)
)
)
)
(module
;; Pass a null in one call to the function. The null can be updated which
;; allows us to refine (but the new type must be nullable).
;; CHECK: (type $struct (struct_subtype data))
;; CHECK: (type $sig (func_subtype (param (ref null $struct)) func))
(type $sig (func_subtype (param anyref) func))
(type $struct (struct_subtype data))
;; CHECK: (type $none_=>_none (func_subtype func))
;; CHECK: (func $func (type $sig) (param $x (ref null $struct))
;; CHECK-NEXT: (nop)
;; CHECK-NEXT: )
(func $func (type $sig) (param $x anyref)
)
;; CHECK: (func $caller (type $none_=>_none)
;; CHECK-NEXT: (call $func
;; CHECK-NEXT: (struct.new_default $struct)
;; CHECK-NEXT: )
;; CHECK-NEXT: (call $func
;; CHECK-NEXT: (ref.null $struct)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $caller
(call $func
(struct.new $struct)
)
(call $func
(ref.null data)
)
)
)
(module
;; CHECK: (type $struct (struct_subtype data))
(type $struct (struct_subtype data))
;; This signature has a single function using it, which returns a more
;; refined type, and we can refine to that.
;; CHECK: (type $sig-can-refine (func_subtype (result (ref $struct)) func))
(type $sig-can-refine (func_subtype (result anyref) func))
;; Also a single function, but no refinement is possible.
;; CHECK: (type $sig-cannot-refine (func_subtype (result anyref) func))
(type $sig-cannot-refine (func_subtype (result anyref) func))
;; The single function never returns, so no refinement is possible.
;; CHECK: (type $sig-unreachable (func_subtype (result anyref) func))
(type $sig-unreachable (func_subtype (result anyref) func))
;; CHECK: (type $none_=>_none (func_subtype func))
;; CHECK: (elem declare func $func-can-refine)
;; CHECK: (func $func-can-refine (type $sig-can-refine) (result (ref $struct))
;; CHECK-NEXT: (struct.new_default $struct)
;; CHECK-NEXT: )
(func $func-can-refine (type $sig-can-refine) (result anyref)
(struct.new $struct)
)
;; CHECK: (func $func-cannot-refine (type $sig-cannot-refine) (result anyref)
;; CHECK-NEXT: (ref.null any)
;; CHECK-NEXT: )
(func $func-cannot-refine (type $sig-cannot-refine) (result anyref)
(ref.null any)
)
;; CHECK: (func $func-unreachable (type $sig-unreachable) (result anyref)
;; CHECK-NEXT: (unreachable)
;; CHECK-NEXT: )
(func $func-unreachable (type $sig-unreachable) (result anyref)
(unreachable)
)
;; CHECK: (func $caller (type $none_=>_none)
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (if (result (ref $struct))
;; CHECK-NEXT: (i32.const 1)
;; CHECK-NEXT: (call $func-can-refine)
;; CHECK-NEXT: (unreachable)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (if (result (ref $struct))
;; CHECK-NEXT: (i32.const 1)
;; CHECK-NEXT: (call_ref
;; CHECK-NEXT: (ref.func $func-can-refine)
;; CHECK-NEXT: )
;; CHECK-NEXT: (unreachable)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $caller
;; Add a call to see that we update call types properly.
;; Put the call in an if so the refinalize will update the if type and get
;; printed out conveniently.
(drop
(if (result anyref)
(i32.const 1)
(call $func-can-refine)
(unreachable)
)
)
;; The same with a call_ref.
(drop
(if (result anyref)
(i32.const 1)
(call_ref
(ref.func $func-can-refine)
)
(unreachable)
)
)
)
)
(module
;; CHECK: (type $struct (struct_subtype data))
(type $struct (struct_subtype data))
;; This signature has multiple functions using it, and some of them have nulls
;; which should be updated when we refine.
;; CHECK: (type $sig (func_subtype (result (ref null $struct)) func))
(type $sig (func_subtype (result anyref) func))
;; CHECK: (func $func-1 (type $sig) (result (ref null $struct))
;; CHECK-NEXT: (struct.new_default $struct)
;; CHECK-NEXT: )
(func $func-1 (type $sig) (result anyref)
(struct.new $struct)
)
;; CHECK: (func $func-2 (type $sig) (result (ref null $struct))
;; CHECK-NEXT: (ref.null $struct)
;; CHECK-NEXT: )
(func $func-2 (type $sig) (result anyref)
(ref.null any)
)
;; CHECK: (func $func-3 (type $sig) (result (ref null $struct))
;; CHECK-NEXT: (ref.null $struct)
;; CHECK-NEXT: )
(func $func-3 (type $sig) (result anyref)
(ref.null eq)
)
;; CHECK: (func $func-4 (type $sig) (result (ref null $struct))
;; CHECK-NEXT: (if
;; CHECK-NEXT: (i32.const 1)
;; CHECK-NEXT: (return
;; CHECK-NEXT: (ref.null $struct)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: (unreachable)
;; CHECK-NEXT: )
(func $func-4 (type $sig) (result anyref)
(if
(i32.const 1)
(return
(ref.null any)
)
)
(unreachable)
)
)
;; Exports prevent optimization, so $func's type will not change here.
(module
;; CHECK: (type $sig (func_subtype (param anyref) func))
;; CHECK: (type $none_=>_none (func_subtype func))
;; CHECK: (type $struct (struct_subtype data))
(type $struct (struct_subtype data))
(type $sig (func_subtype (param anyref) func))
;; CHECK: (export "prevent-opts" (func $func))
;; CHECK: (func $func (type $sig) (param $x anyref)
;; CHECK-NEXT: (nop)
;; CHECK-NEXT: )
(func $func (export "prevent-opts") (type $sig) (param $x anyref)
)
;; CHECK: (func $caller (type $none_=>_none)
;; CHECK-NEXT: (call $func
;; CHECK-NEXT: (struct.new_default $struct)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $caller
(call $func
(struct.new $struct)
)
)
)
(module
;; CHECK: (type $A (func_subtype (param i32) func))
(type $A (func_subtype (param i32) func))
;; CHECK: (type $B (func_subtype (param i32) $A))
(type $B (func_subtype (param i32) $A))
;; CHECK: (func $bar (type $B) (param $x i32)
;; CHECK-NEXT: (nop)
;; CHECK-NEXT: )
(func $bar (type $B) (param $x i32)
;; The parameter to this function can be pruned. But while doing so we must
;; properly preserve the subtyping of $B from $A, which means we cannot just
;; remove it - we'd need to remove it from $A as well, which we don't
;; attempt to do in the pass atm. So we do not optimize here.
(nop)
)
)
(module
;; CHECK: (type $ref|${}|_i32_=>_none (func_subtype (param (ref ${}) i32) func))
;; CHECK: (type ${} (struct_subtype data))
(type ${} (struct_subtype data))
;; CHECK: (func $foo (type $ref|${}|_i32_=>_none) (param $ref (ref ${})) (param $i32 i32)
;; CHECK-NEXT: (local $2 eqref)
;; CHECK-NEXT: (local.set $2
;; CHECK-NEXT: (local.get $ref)
;; CHECK-NEXT: )
;; CHECK-NEXT: (block
;; CHECK-NEXT: (call $foo
;; CHECK-NEXT: (block
;; CHECK-NEXT: (unreachable)
;; CHECK-NEXT: )
;; CHECK-NEXT: (i32.const 0)
;; CHECK-NEXT: )
;; CHECK-NEXT: (local.set $2
;; CHECK-NEXT: (ref.null eq)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $foo (param $ref eqref) (param $i32 i32)
(call $foo
;; The only reference to the ${} type is in this block signature. Even
;; this will go away in the internal ReFinalize (which makes the block
;; type unreachable).
(block (result (ref ${}))
(unreachable)
)
(i32.const 0)
)
;; Write something of type eqref into $ref. When we refine the type of the
;; parameter from eqref to ${} we must do something here, as we can no
;; longer just write this (ref.null eq) into a parameter of the more
;; refined type. While doing so, we must not be confused by the fact that
;; the only mention of ${} in the original module gets removed during our
;; processing, as mentioned in the earlier comment. This is a regression
;; test for a crash because of that.
(local.set $ref
(ref.null eq)
)
)
)
;; Do not modify the types used on imported functions (until the spec and VM
;; support becomes stable).
(module
;; CHECK: (type $ref?|data|_=>_none (func_subtype (param (ref null data)) func))
;; CHECK: (type $none_=>_none (func_subtype func))
;; CHECK: (type $struct (struct_subtype data))
(type $struct (struct_subtype data))
;; CHECK: (import "a" "b" (func $import (param (ref null data))))
(import "a" "b" (func $import (param (ref null data))))
;; CHECK: (func $test (type $none_=>_none)
;; CHECK-NEXT: (call $import
;; CHECK-NEXT: (struct.new_default $struct)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $test
(call $import
(struct.new $struct)
)
)
)
|