|
| 1 | +;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited. |
| 2 | + |
| 3 | +;; RUN: foreach %s %t wasm-opt -all --closed-world --preserve-type-order \ |
| 4 | +;; RUN: --merge-j2cl-itables -all -S -o - | filecheck %s |
| 5 | + |
| 6 | +;; Custom descriptors - Shared itable instance. |
| 7 | +(module |
| 8 | + (rec |
| 9 | + ;; CHECK: (rec |
| 10 | + ;; CHECK-NEXT: (type $Object (sub (descriptor $Object.vtable (struct (field $itable (ref $Object.itable)))))) |
| 11 | + (type $Object (sub (descriptor $Object.vtable (struct |
| 12 | + (field $itable (ref $Object.itable)))))) |
| 13 | + |
| 14 | + ;; CHECK: (type $SubObject (sub $Object (descriptor $SubObject.vtable (struct (field $itable (ref $Object.itable)))))) |
| 15 | + (type $SubObject (sub $Object (descriptor $SubObject.vtable (struct |
| 16 | + (field $itable (ref $Object.itable)))))) |
| 17 | + |
| 18 | + ;; CHECK: (type $function (func)) |
| 19 | + (type $function (func)) |
| 20 | + |
| 21 | + ;; The $Object.itable field (a structref) will be added as a field after |
| 22 | + ;; the first field of this vtable. |
| 23 | + ;; CHECK: (type $Object.vtable (sub (describes $Object (struct (field externref) (field structref))))) |
| 24 | + (type $Object.vtable (sub (describes $Object (struct |
| 25 | + (field externref))))) |
| 26 | + |
| 27 | + ;; The $Object.itable field (a structref) will be added as a field after |
| 28 | + ;; the first field of this vtable. |
| 29 | + ;; CHECK: (type $SubObject.vtable (sub $Object.vtable (describes $SubObject (struct (field externref) (field structref) (field (ref $function)))))) |
| 30 | + (type $SubObject.vtable (sub $Object.vtable (describes $SubObject (struct |
| 31 | + (field externref) |
| 32 | + (field (ref $function)))))) |
| 33 | + |
| 34 | + ;; CHECK: (type $Object.itable (struct (field structref))) |
| 35 | + (type $Object.itable (struct |
| 36 | + (field (ref null struct)))) |
| 37 | + ) |
| 38 | + |
| 39 | + ;; CHECK: (type $6 (func)) |
| 40 | + |
| 41 | + ;; CHECK: (global $Object.itable (ref $Object.itable) (struct.new_default $Object.itable)) |
| 42 | + (global $Object.itable (ref $Object.itable) |
| 43 | + (struct.new_default $Object.itable)) |
| 44 | + |
| 45 | + ;; CHECK: (global $SubObject.itable (ref $Object.itable) (global.get $Object.itable)) |
| 46 | + (global $SubObject.itable (ref $Object.itable) |
| 47 | + (global.get $Object.itable)) ;; uses shared empty itable instance. |
| 48 | + |
| 49 | + ;; The initialization for the itable field (null struct) will be added to this |
| 50 | + ;; vtable instance. |
| 51 | + ;; CHECK: (global $SubObject.vtable (ref (exact $SubObject.vtable)) (struct.new $SubObject.vtable |
| 52 | + ;; CHECK-NEXT: (ref.null noextern) |
| 53 | + ;; CHECK-NEXT: (ref.null none) |
| 54 | + ;; CHECK-NEXT: (ref.func $SubObject.f) |
| 55 | + ;; CHECK-NEXT: )) |
| 56 | + (global $SubObject.vtable (ref (exact $SubObject.vtable)) |
| 57 | + (struct.new $SubObject.vtable (ref.null extern) (ref.func $SubObject.f))) |
| 58 | + |
| 59 | + |
| 60 | + ;; The initialization for the itable field (null struct) will be added to this |
| 61 | + ;; vtable instance. |
| 62 | + ;; CHECK: (global $Object.vtable (ref (exact $Object.vtable)) (struct.new $Object.vtable |
| 63 | + ;; CHECK-NEXT: (ref.null noextern) |
| 64 | + ;; CHECK-NEXT: (ref.null none) |
| 65 | + ;; CHECK-NEXT: )) |
| 66 | + (global $Object.vtable (ref (exact $Object.vtable)) |
| 67 | + (struct.new $Object.vtable (ref.null extern))) |
| 68 | + |
| 69 | + ;; CHECK: (func $SubObject.f (type $function) |
| 70 | + ;; CHECK-NEXT: ) |
| 71 | + (func $SubObject.f |
| 72 | + (type $function) |
| 73 | + ) |
| 74 | + |
| 75 | + ;; CHECK: (func $usages (type $6) |
| 76 | + ;; CHECK-NEXT: (local $o (ref null $SubObject)) |
| 77 | + ;; CHECK-NEXT: (local.set $o |
| 78 | + ;; CHECK-NEXT: (struct.new $SubObject |
| 79 | + ;; CHECK-NEXT: (global.get $SubObject.itable) |
| 80 | + ;; CHECK-NEXT: (global.get $SubObject.vtable) |
| 81 | + ;; CHECK-NEXT: ) |
| 82 | + ;; CHECK-NEXT: ) |
| 83 | + ;; CHECK-NEXT: (drop |
| 84 | + ;; CHECK-NEXT: (struct.get $SubObject.vtable 0 |
| 85 | + ;; CHECK-NEXT: (ref.get_desc $SubObject |
| 86 | + ;; CHECK-NEXT: (local.get $o) |
| 87 | + ;; CHECK-NEXT: ) |
| 88 | + ;; CHECK-NEXT: ) |
| 89 | + ;; CHECK-NEXT: ) |
| 90 | + ;; CHECK-NEXT: (drop |
| 91 | + ;; CHECK-NEXT: (struct.get $SubObject.vtable 2 |
| 92 | + ;; CHECK-NEXT: (ref.get_desc $SubObject |
| 93 | + ;; CHECK-NEXT: (local.get $o) |
| 94 | + ;; CHECK-NEXT: ) |
| 95 | + ;; CHECK-NEXT: ) |
| 96 | + ;; CHECK-NEXT: ) |
| 97 | + ;; CHECK-NEXT: (drop |
| 98 | + ;; CHECK-NEXT: (struct.get $SubObject.vtable 1 |
| 99 | + ;; CHECK-NEXT: (ref.get_desc $SubObject |
| 100 | + ;; CHECK-NEXT: (local.get $o) |
| 101 | + ;; CHECK-NEXT: ) |
| 102 | + ;; CHECK-NEXT: ) |
| 103 | + ;; CHECK-NEXT: ) |
| 104 | + ;; CHECK-NEXT: ) |
| 105 | + (func $usages |
| 106 | + (local $o (ref null $SubObject)) |
| 107 | + (local.set $o |
| 108 | + (struct.new $SubObject |
| 109 | + (global.get $SubObject.itable) |
| 110 | + (global.get $SubObject.vtable))) |
| 111 | + (drop |
| 112 | + ;; The access to vtable field 0 is NOT offset and will remain an |
| 113 | + ;; access to field 0. |
| 114 | + (struct.get $SubObject.vtable 0 |
| 115 | + (ref.get_desc $SubObject |
| 116 | + (local.get $o)))) |
| 117 | + (drop |
| 118 | + ;; The access to vtable field 1 is offset by the itable size and |
| 119 | + ;; will be an access to field 2. |
| 120 | + (struct.get $SubObject.vtable 1 |
| 121 | + (ref.get_desc $SubObject |
| 122 | + (local.get $o)))) |
| 123 | + (drop |
| 124 | + ;; The access to itable field 0 will be rerouted to be an access to |
| 125 | + ;; vtable field 1. |
| 126 | + (struct.get $Object.itable 0 |
| 127 | + (struct.get $SubObject $itable |
| 128 | + (local.get $o)))) |
| 129 | + ) |
| 130 | +) |
| 131 | + |
| 132 | +;; Custom descriptors - Each type has its own itable. |
| 133 | +(module |
| 134 | + (rec |
| 135 | + ;; CHECK: (rec |
| 136 | + ;; CHECK-NEXT: (type $Object (sub (descriptor $Object.vtable (struct (field $itable (ref $Object.itable)))))) |
| 137 | + (type $Object (sub (descriptor $Object.vtable (struct |
| 138 | + (field $itable (ref $Object.itable)))))) |
| 139 | + |
| 140 | + ;; CHECK: (type $SubObject (sub $Object (descriptor $SubObject.vtable (struct (field $itable (ref $SubObject.itable)))))) |
| 141 | + (type $SubObject (sub $Object (descriptor $SubObject.vtable (struct |
| 142 | + (field $itable (ref $SubObject.itable)))))) |
| 143 | + |
| 144 | + ;; CHECK: (type $function (func)) |
| 145 | + (type $function (func)) |
| 146 | + |
| 147 | + ;; CHECK: (type $Object.itable (sub (struct (field structref)))) |
| 148 | + (type $Object.itable (sub (struct |
| 149 | + (field (ref null struct))))) |
| 150 | + |
| 151 | + ;; CHECK: (type $SubObject.itable (sub $Object.itable (struct (field structref)))) |
| 152 | + (type $SubObject.itable (sub $Object.itable |
| 153 | + (struct (field (ref null struct))))) |
| 154 | + |
| 155 | + ;; The $Object.itable field (a structref) will be added as a field after |
| 156 | + ;; the first field of this vtable. |
| 157 | + ;; CHECK: (type $Object.vtable (sub (describes $Object (struct (field externref) (field structref))))) |
| 158 | + (type $Object.vtable (sub (describes $Object (struct |
| 159 | + (field externref))))) |
| 160 | + |
| 161 | + ;; The $SubObject.itable field (a structref) will be added as a field after |
| 162 | + ;; the first field of this vtable. |
| 163 | + ;; CHECK: (type $SubObject.vtable (sub $Object.vtable (describes $SubObject (struct (field externref) (field structref) (field (ref $function)))))) |
| 164 | + (type $SubObject.vtable (sub $Object.vtable (describes $SubObject (struct |
| 165 | + (field externref) |
| 166 | + (field (ref $function)))))) |
| 167 | + ) |
| 168 | + |
| 169 | + ;; The initialization for the itable field (null struct) will be added to this |
| 170 | + ;; vtable instance. |
| 171 | + ;; CHECK: (type $7 (func)) |
| 172 | + |
| 173 | + ;; CHECK: (global $SubObject.vtable (ref (exact $SubObject.vtable)) (struct.new $SubObject.vtable |
| 174 | + ;; CHECK-NEXT: (ref.null noextern) |
| 175 | + ;; CHECK-NEXT: (ref.null none) |
| 176 | + ;; CHECK-NEXT: (ref.func $SubObject.f) |
| 177 | + ;; CHECK-NEXT: )) |
| 178 | + (global $SubObject.vtable (ref (exact $SubObject.vtable)) |
| 179 | + (struct.new $SubObject.vtable (ref.null extern) (ref.func $SubObject.f))) |
| 180 | + |
| 181 | + ;; CHECK: (global $SubObject.itable (ref $SubObject.itable) (struct.new_default $SubObject.itable)) |
| 182 | + (global $SubObject.itable (ref $SubObject.itable) |
| 183 | + (struct.new_default $SubObject.itable)) |
| 184 | + |
| 185 | + ;; The initialization for the itable field (null struct) will be added to this |
| 186 | + ;; vtable instance. |
| 187 | + ;; CHECK: (global $Object.vtable (ref (exact $Object.vtable)) (struct.new $Object.vtable |
| 188 | + ;; CHECK-NEXT: (ref.null noextern) |
| 189 | + ;; CHECK-NEXT: (ref.null none) |
| 190 | + ;; CHECK-NEXT: )) |
| 191 | + (global $Object.vtable (ref (exact $Object.vtable)) |
| 192 | + (struct.new $Object.vtable (ref.null extern))) |
| 193 | + |
| 194 | + ;; CHECK: (global $Object.itable (ref $Object.itable) (struct.new_default $Object.itable)) |
| 195 | + (global $Object.itable (ref $Object.itable) |
| 196 | + (struct.new_default $Object.itable)) |
| 197 | + |
| 198 | + ;; CHECK: (func $SubObject.f (type $function) |
| 199 | + ;; CHECK-NEXT: ) |
| 200 | + (func $SubObject.f |
| 201 | + (type $function) |
| 202 | + ) |
| 203 | + |
| 204 | + ;; CHECK: (func $usages (type $7) |
| 205 | + ;; CHECK-NEXT: (local $o (ref null $SubObject)) |
| 206 | + ;; CHECK-NEXT: (local.set $o |
| 207 | + ;; CHECK-NEXT: (struct.new $SubObject |
| 208 | + ;; CHECK-NEXT: (global.get $SubObject.itable) |
| 209 | + ;; CHECK-NEXT: (global.get $SubObject.vtable) |
| 210 | + ;; CHECK-NEXT: ) |
| 211 | + ;; CHECK-NEXT: ) |
| 212 | + ;; CHECK-NEXT: (drop |
| 213 | + ;; CHECK-NEXT: (struct.get $SubObject.vtable 0 |
| 214 | + ;; CHECK-NEXT: (ref.get_desc $SubObject |
| 215 | + ;; CHECK-NEXT: (local.get $o) |
| 216 | + ;; CHECK-NEXT: ) |
| 217 | + ;; CHECK-NEXT: ) |
| 218 | + ;; CHECK-NEXT: ) |
| 219 | + ;; CHECK-NEXT: (drop |
| 220 | + ;; CHECK-NEXT: (struct.get $SubObject.vtable 2 |
| 221 | + ;; CHECK-NEXT: (ref.get_desc $SubObject |
| 222 | + ;; CHECK-NEXT: (local.get $o) |
| 223 | + ;; CHECK-NEXT: ) |
| 224 | + ;; CHECK-NEXT: ) |
| 225 | + ;; CHECK-NEXT: ) |
| 226 | + ;; CHECK-NEXT: (drop |
| 227 | + ;; CHECK-NEXT: (struct.get $SubObject.vtable 1 |
| 228 | + ;; CHECK-NEXT: (ref.get_desc $SubObject |
| 229 | + ;; CHECK-NEXT: (local.get $o) |
| 230 | + ;; CHECK-NEXT: ) |
| 231 | + ;; CHECK-NEXT: ) |
| 232 | + ;; CHECK-NEXT: ) |
| 233 | + ;; CHECK-NEXT: ) |
| 234 | + (func $usages |
| 235 | + (local $o (ref null $SubObject)) |
| 236 | + (local.set $o |
| 237 | + (struct.new $SubObject |
| 238 | + (global.get $SubObject.itable) |
| 239 | + (global.get $SubObject.vtable))) |
| 240 | + (drop |
| 241 | + ;; The access to vtable field 0 is NOT offset and will remain an |
| 242 | + ;; access to field 0. |
| 243 | + (struct.get $SubObject.vtable 0 |
| 244 | + (ref.get_desc $SubObject |
| 245 | + (local.get $o)))) |
| 246 | + (drop |
| 247 | + ;; The access to vtable field 1 is offset by the itable size and |
| 248 | + ;; will be an access to field 2. |
| 249 | + (struct.get $SubObject.vtable 1 |
| 250 | + (ref.get_desc $SubObject |
| 251 | + (local.get $o)))) |
| 252 | + (drop |
| 253 | + ;; The access to itable field 0 will be rerouted to be an access to |
| 254 | + ;; vtable field 1. |
| 255 | + (struct.get $Object.itable 0 |
| 256 | + (struct.get $SubObject $itable |
| 257 | + (local.get $o)))) |
| 258 | + ) |
| 259 | +) |
0 commit comments