|
342 | 342 | )
|
343 | 343 | )
|
344 | 344 |
|
| 345 | +;; Zero descriptor instances in globals. |
| 346 | +(module |
| 347 | + (rec |
| 348 | + ;; CHECK: (rec |
| 349 | + ;; CHECK-NEXT: (type $A (sub (descriptor $A.desc (struct)))) |
| 350 | + (type $A (sub (descriptor $A.desc (struct)))) |
| 351 | + ;; CHECK: (type $A.desc (sub (describes $A (struct)))) |
| 352 | + (type $A.desc (sub (describes $A (struct)))) |
| 353 | + ) |
| 354 | + |
| 355 | + ;; CHECK: (type $2 (func (param anyref))) |
| 356 | + |
| 357 | + ;; CHECK: (func $test (type $2) (param $any anyref) |
| 358 | + ;; CHECK-NEXT: (drop |
| 359 | + ;; CHECK-NEXT: (ref.cast (ref $A) |
| 360 | + ;; CHECK-NEXT: (local.get $any) |
| 361 | + ;; CHECK-NEXT: ) |
| 362 | + ;; CHECK-NEXT: ) |
| 363 | + ;; CHECK-NEXT: ) |
| 364 | + (func $test (param $any anyref) |
| 365 | + ;; We do not optimize here. TODO: we could make this trap |
| 366 | + (drop |
| 367 | + (ref.cast (ref $A) |
| 368 | + (local.get $any) |
| 369 | + ) |
| 370 | + ) |
| 371 | + ) |
| 372 | +) |
| 373 | + |
345 | 374 | ;; Two descriptor instances in globals.
|
346 | 375 | (module
|
347 | 376 | (rec
|
|
414 | 443 | )
|
415 | 444 | )
|
416 | 445 |
|
| 446 | +;; Nullable cast. |
| 447 | +(module |
| 448 | + (rec |
| 449 | + ;; CHECK: (rec |
| 450 | + ;; CHECK-NEXT: (type $A (sub (descriptor $A.desc (struct)))) |
| 451 | + (type $A (sub (descriptor $A.desc (struct)))) |
| 452 | + ;; CHECK: (type $A.desc (sub (describes $A (struct)))) |
| 453 | + (type $A.desc (sub (describes $A (struct)))) |
| 454 | + ) |
| 455 | + |
| 456 | + ;; CHECK: (type $2 (func (param anyref))) |
| 457 | + |
| 458 | + ;; CHECK: (global $A.desc (ref $A.desc) (struct.new_default $A.desc)) |
| 459 | + (global $A.desc (ref $A.desc) (struct.new $A.desc)) |
| 460 | + |
| 461 | + ;; CHECK: (func $test (type $2) (param $any anyref) |
| 462 | + ;; CHECK-NEXT: (drop |
| 463 | + ;; CHECK-NEXT: (ref.cast_desc (ref null $A) |
| 464 | + ;; CHECK-NEXT: (local.get $any) |
| 465 | + ;; CHECK-NEXT: (global.get $A.desc) |
| 466 | + ;; CHECK-NEXT: ) |
| 467 | + ;; CHECK-NEXT: ) |
| 468 | + ;; CHECK-NEXT: ) |
| 469 | + (func $test (param $any anyref) |
| 470 | + ;; The cast is nullable, which we can still optimize: null will succeed as |
| 471 | + ;; expected. |
| 472 | + (drop |
| 473 | + (ref.cast (ref null $A) |
| 474 | + (local.get $any) |
| 475 | + ) |
| 476 | + ) |
| 477 | + ) |
| 478 | +) |
| 479 | + |
0 commit comments