|
6 | 6 | (module
|
7 | 7 | (rec
|
8 | 8 | ;; CHECK: (rec
|
9 |
| - ;; CHECK-NEXT: (type $B (sub (descriptor $A (struct)))) |
10 |
| - (type $B (sub (descriptor $A (struct)))) |
11 |
| - ;; CHECK: (type $A (sub (describes $B (struct)))) |
12 |
| - (type $A (sub (describes $B (struct)))) |
| 9 | + ;; CHECK-NEXT: (type $struct (descriptor $desc (struct))) |
| 10 | + (type $struct (descriptor $desc (struct))) |
| 11 | + ;; CHECK: (type $desc (describes $struct (struct))) |
| 12 | + (type $desc (describes $struct (struct))) |
13 | 13 | )
|
14 | 14 |
|
15 | 15 | ;; CHECK: (type $2 (func))
|
16 | 16 |
|
17 |
| - ;; CHECK: (global $global (ref (exact $A)) (struct.new_default $A)) |
18 |
| - (global $global (ref (exact $A)) (struct.new $A)) |
| 17 | + ;; CHECK: (global $desc (ref (exact $desc)) (struct.new_default $desc)) |
| 18 | + (global $desc (ref (exact $desc)) (struct.new $desc)) |
19 | 19 |
|
20 | 20 | ;; CHECK: (export "export" (func $export))
|
21 | 21 |
|
22 | 22 | ;; CHECK: (func $export (type $2)
|
23 | 23 | ;; CHECK-NEXT: (drop
|
24 |
| - ;; CHECK-NEXT: (struct.new_default $B |
25 |
| - ;; CHECK-NEXT: (global.get $global) |
| 24 | + ;; CHECK-NEXT: (struct.new_default $struct |
| 25 | + ;; CHECK-NEXT: (global.get $desc) |
26 | 26 | ;; CHECK-NEXT: )
|
27 | 27 | ;; CHECK-NEXT: )
|
28 | 28 | ;; CHECK-NEXT: )
|
29 | 29 | (func $export (export "export")
|
30 | 30 | (drop
|
31 |
| - (struct.new $B |
32 |
| - (global.get $global) |
| 31 | + (struct.new $struct |
| 32 | + (global.get $desc) |
33 | 33 | )
|
34 | 34 | )
|
35 | 35 | )
|
36 | 36 | )
|
37 | 37 |
|
| 38 | +;; We cannot optimize out globals whose initializers might trap due to a null |
| 39 | +;; descriptor (or conservatively even just a nullable descriptor). |
| 40 | +(module |
| 41 | + (rec |
| 42 | + ;; CHECK: (rec |
| 43 | + ;; CHECK-NEXT: (type $struct (descriptor $desc (struct))) |
| 44 | + (type $struct (descriptor $desc (struct))) |
| 45 | + ;; CHECK: (type $desc (describes $struct (struct))) |
| 46 | + (type $desc (describes $struct (struct))) |
| 47 | + ;; CHECK: (type $list (struct (field (ref $struct)) (field (ref null $list)))) |
| 48 | + (type $list (struct (field (ref $struct)) (field (ref null $list)))) |
| 49 | + ) |
| 50 | + |
| 51 | + ;; CHECK: (global $null nullref (ref.null none)) |
| 52 | + (global $null nullref (ref.null none)) |
| 53 | + ;; CHECK: (global $nullable-desc (ref null (exact $desc)) (struct.new_default $desc)) |
| 54 | + (global $nullable-desc (ref null (exact $desc)) (struct.new $desc)) |
| 55 | + ;; CHECK: (global $desc (ref (exact $desc)) (struct.new_default $desc)) |
| 56 | + (global $desc (ref (exact $desc)) (struct.new $desc)) |
| 57 | + |
| 58 | + ;; Trapping globals must be kept, but non-trapping globals can be removed. |
| 59 | + ;; CHECK: (global $trap (ref $struct) (struct.new_default $struct |
| 60 | + ;; CHECK-NEXT: (ref.null none) |
| 61 | + ;; CHECK-NEXT: )) |
| 62 | + (global $trap (ref $struct) (struct.new $struct (ref.null none))) |
| 63 | + (global $no-trap (ref $struct) (struct.new $struct (struct.new $desc))) |
| 64 | + |
| 65 | + ;; CHECK: (global $trap-get-null (ref $struct) (struct.new_default $struct |
| 66 | + ;; CHECK-NEXT: (global.get $null) |
| 67 | + ;; CHECK-NEXT: )) |
| 68 | + (global $trap-get-null (ref $struct) (struct.new $struct (global.get $null))) |
| 69 | + ;; CHECK: (global $trap-get-nullable (ref $struct) (struct.new_default $struct |
| 70 | + ;; CHECK-NEXT: (global.get $nullable-desc) |
| 71 | + ;; CHECK-NEXT: )) |
| 72 | + (global $trap-get-nullable (ref $struct) (struct.new $struct (global.get $nullable-desc))) |
| 73 | + (global $no-trap-get (ref $struct) (struct.new $struct (global.get $desc))) |
| 74 | + |
| 75 | + ;; CHECK: (global $trap-nested (ref $list) (struct.new $list |
| 76 | + ;; CHECK-NEXT: (struct.new_default $struct |
| 77 | + ;; CHECK-NEXT: (struct.new_default $desc) |
| 78 | + ;; CHECK-NEXT: ) |
| 79 | + ;; CHECK-NEXT: (struct.new $list |
| 80 | + ;; CHECK-NEXT: (struct.new_default $struct |
| 81 | + ;; CHECK-NEXT: (global.get $desc) |
| 82 | + ;; CHECK-NEXT: ) |
| 83 | + ;; CHECK-NEXT: (struct.new $list |
| 84 | + ;; CHECK-NEXT: (struct.new_default $struct |
| 85 | + ;; CHECK-NEXT: (ref.null none) |
| 86 | + ;; CHECK-NEXT: ) |
| 87 | + ;; CHECK-NEXT: (ref.null none) |
| 88 | + ;; CHECK-NEXT: ) |
| 89 | + ;; CHECK-NEXT: ) |
| 90 | + ;; CHECK-NEXT: )) |
| 91 | + (global $trap-nested (ref $list) |
| 92 | + (struct.new $list |
| 93 | + (struct.new $struct (struct.new $desc)) |
| 94 | + (struct.new $list |
| 95 | + (struct.new $struct (global.get $desc)) |
| 96 | + (struct.new $list |
| 97 | + (struct.new $struct (ref.null none)) |
| 98 | + (ref.null none) |
| 99 | + ) |
| 100 | + ) |
| 101 | + ) |
| 102 | + ) |
| 103 | + |
| 104 | + (global $no-trap-nested (ref $list) |
| 105 | + (struct.new $list |
| 106 | + (struct.new $struct (struct.new $desc)) |
| 107 | + (struct.new $list |
| 108 | + (struct.new $struct (global.get $desc)) |
| 109 | + (ref.null none) |
| 110 | + ) |
| 111 | + ) |
| 112 | + ) |
| 113 | + |
| 114 | + ;; CHECK: (elem $trap anyref (item (struct.new_default $struct |
| 115 | + ;; CHECK-NEXT: (ref.null none) |
| 116 | + ;; CHECK-NEXT: ))) |
| 117 | + (elem $trap anyref (item (struct.new $struct (ref.null none)))) |
| 118 | + (elem $no-trap anyref (item (struct.new $struct (struct.new $desc)))) |
| 119 | + ;; CHECK: (elem $trap-get-null anyref (item (struct.new_default $struct |
| 120 | + ;; CHECK-NEXT: (global.get $null) |
| 121 | + ;; CHECK-NEXT: ))) |
| 122 | + (elem $trap-get-null anyref (item (struct.new $struct (global.get $null)))) |
| 123 | + ;; CHECK: (elem $trap-get-nullable anyref (item (struct.new_default $struct |
| 124 | + ;; CHECK-NEXT: (global.get $nullable-desc) |
| 125 | + ;; CHECK-NEXT: ))) |
| 126 | + (elem $trap-get-nullable anyref (item (struct.new $struct (global.get $nullable-desc)))) |
| 127 | + (elem $no-trap-get anyref (item (struct.new $struct (global.get $desc)))) |
| 128 | +) |
| 129 | + |
0 commit comments