|
607 | 607 | ) |
608 | 608 | ) |
609 | 609 |
|
| 610 | + ;; TNH: (func $cast-to-bottom (type $ref|any|_anyref_=>_none) (param $ref (ref any)) (param $nullable-ref anyref) |
| 611 | + ;; TNH-NEXT: (drop |
| 612 | + ;; TNH-NEXT: (block (result (ref none)) |
| 613 | + ;; TNH-NEXT: (drop |
| 614 | + ;; TNH-NEXT: (local.get $ref) |
| 615 | + ;; TNH-NEXT: ) |
| 616 | + ;; TNH-NEXT: (unreachable) |
| 617 | + ;; TNH-NEXT: ) |
| 618 | + ;; TNH-NEXT: ) |
| 619 | + ;; TNH-NEXT: (drop |
| 620 | + ;; TNH-NEXT: (block (result (ref none)) |
| 621 | + ;; TNH-NEXT: (drop |
| 622 | + ;; TNH-NEXT: (local.get $nullable-ref) |
| 623 | + ;; TNH-NEXT: ) |
| 624 | + ;; TNH-NEXT: (unreachable) |
| 625 | + ;; TNH-NEXT: ) |
| 626 | + ;; TNH-NEXT: ) |
| 627 | + ;; TNH-NEXT: (drop |
| 628 | + ;; TNH-NEXT: (block (result (ref none)) |
| 629 | + ;; TNH-NEXT: (drop |
| 630 | + ;; TNH-NEXT: (local.get $ref) |
| 631 | + ;; TNH-NEXT: ) |
| 632 | + ;; TNH-NEXT: (unreachable) |
| 633 | + ;; TNH-NEXT: ) |
| 634 | + ;; TNH-NEXT: ) |
| 635 | + ;; TNH-NEXT: (drop |
| 636 | + ;; TNH-NEXT: (block (result nullref) |
| 637 | + ;; TNH-NEXT: (drop |
| 638 | + ;; TNH-NEXT: (local.get $nullable-ref) |
| 639 | + ;; TNH-NEXT: ) |
| 640 | + ;; TNH-NEXT: (ref.null none) |
| 641 | + ;; TNH-NEXT: ) |
| 642 | + ;; TNH-NEXT: ) |
| 643 | + ;; TNH-NEXT: ) |
| 644 | + ;; NO_TNH: (func $cast-to-bottom (type $ref|any|_anyref_=>_none) (param $ref (ref any)) (param $nullable-ref anyref) |
| 645 | + ;; NO_TNH-NEXT: (drop |
| 646 | + ;; NO_TNH-NEXT: (block (result (ref none)) |
| 647 | + ;; NO_TNH-NEXT: (drop |
| 648 | + ;; NO_TNH-NEXT: (local.get $ref) |
| 649 | + ;; NO_TNH-NEXT: ) |
| 650 | + ;; NO_TNH-NEXT: (unreachable) |
| 651 | + ;; NO_TNH-NEXT: ) |
| 652 | + ;; NO_TNH-NEXT: ) |
| 653 | + ;; NO_TNH-NEXT: (drop |
| 654 | + ;; NO_TNH-NEXT: (block (result (ref none)) |
| 655 | + ;; NO_TNH-NEXT: (drop |
| 656 | + ;; NO_TNH-NEXT: (local.get $nullable-ref) |
| 657 | + ;; NO_TNH-NEXT: ) |
| 658 | + ;; NO_TNH-NEXT: (unreachable) |
| 659 | + ;; NO_TNH-NEXT: ) |
| 660 | + ;; NO_TNH-NEXT: ) |
| 661 | + ;; NO_TNH-NEXT: (drop |
| 662 | + ;; NO_TNH-NEXT: (block (result (ref none)) |
| 663 | + ;; NO_TNH-NEXT: (drop |
| 664 | + ;; NO_TNH-NEXT: (local.get $ref) |
| 665 | + ;; NO_TNH-NEXT: ) |
| 666 | + ;; NO_TNH-NEXT: (unreachable) |
| 667 | + ;; NO_TNH-NEXT: ) |
| 668 | + ;; NO_TNH-NEXT: ) |
| 669 | + ;; NO_TNH-NEXT: (drop |
| 670 | + ;; NO_TNH-NEXT: (ref.cast null none |
| 671 | + ;; NO_TNH-NEXT: (local.get $nullable-ref) |
| 672 | + ;; NO_TNH-NEXT: ) |
| 673 | + ;; NO_TNH-NEXT: ) |
| 674 | + ;; NO_TNH-NEXT: ) |
| 675 | + (func $cast-to-bottom (param $ref (ref any)) (param $nullable-ref anyref) |
| 676 | + ;; Non-nullable casts to none must trap (regardless of whether the input is |
| 677 | + ;; nullable or not, the output is an impossible type). |
| 678 | + (drop |
| 679 | + (ref.cast none |
| 680 | + (local.get $ref) |
| 681 | + ) |
| 682 | + ) |
| 683 | + (drop |
| 684 | + (ref.cast none |
| 685 | + (local.get $nullable-ref) |
| 686 | + ) |
| 687 | + ) |
| 688 | + ;; Nullable casts to null have more possibilities. First, if the input is |
| 689 | + ;; non-nullable then we trap. |
| 690 | + (drop |
| 691 | + (ref.cast null none |
| 692 | + (local.get $ref) |
| 693 | + ) |
| 694 | + ) |
| 695 | + ;; Second, if the value may be a null, then we either return a null or we |
| 696 | + ;; trap. In TNH mode we dismiss the possibility of a trap and so we can just |
| 697 | + ;; return a null here. (In non-TNH mode we could do a check for null etc., |
| 698 | + ;; but we'd be increasing code size.) |
| 699 | + (drop |
| 700 | + (ref.cast null none |
| 701 | + (local.get $nullable-ref) |
| 702 | + ) |
| 703 | + ) |
| 704 | + ) |
| 705 | + |
610 | 706 | ;; TNH: (func $null.cast-other.effects (type $ref?|$struct|_=>_none) (param $x (ref null $struct)) |
611 | 707 | ;; TNH-NEXT: (local $i i32) |
612 | 708 | ;; TNH-NEXT: (struct.set $struct 0 |
|
0 commit comments