| 1 |
;; RUN: wast --assert default --snapshot tests/snapshots % |
| 2 |
|
| 3 |
;; Cloned from tests/testsuite/proposals/function-references/type-equivalence.wast |
| 4 |
;; and modified for the GC proposal. |
| 5 |
|
| 6 |
;; Syntactic types (validation time) |
| 7 |
|
| 8 |
;; Simple types. |
| 9 |
|
| 10 |
(module |
| 11 |
(type $t1 (func (param f32 f32) (result f32))) |
| 12 |
(type $t2 (func (param $x f32) (param $y f32) (result f32))) |
| 13 |
|
| 14 |
(func $f1 (param $r (ref $t1)) (call $f2 (local.get $r))) |
| 15 |
(func $f2 (param $r (ref $t2)) (call $f1 (local.get $r))) |
| 16 |
) |
| 17 |
|
| 18 |
|
| 19 |
;; Indirect types. |
| 20 |
|
| 21 |
(module |
| 22 |
(type $s0 (func (param i32) (result f32))) |
| 23 |
(type $s1 (func (param i32 (ref $s0)) (result (ref $s0)))) |
| 24 |
(type $s2 (func (param i32 (ref $s0)) (result (ref $s0)))) |
| 25 |
(type $t1 (func (param (ref $s1)) (result (ref $s2)))) |
| 26 |
(type $t2 (func (param (ref $s2)) (result (ref $s1)))) |
| 27 |
|
| 28 |
(func $f1 (param $r (ref $t1)) (call $f2 (local.get $r))) |
| 29 |
(func $f2 (param $r (ref $t2)) (call $f1 (local.get $r))) |
| 30 |
) |
| 31 |
|
| 32 |
|
| 33 |
;; Recursive types. |
| 34 |
|
| 35 |
;; This case has been made valid by the GC proposal: |
| 36 |
;; every standalone type is now a recursive type group of size 1. |
| 37 |
(module |
| 38 |
(type $t (func (result (ref $t)))) |
| 39 |
) |
| 40 |
|
| 41 |
(assert_invalid |
| 42 |
(module |
| 43 |
(type $t1 (func (param (ref $t2)))) |
| 44 |
(type $t2 (func (param (ref $t1)))) |
| 45 |
) |
| 46 |
"unknown type" |
| 47 |
) |
| 48 |
|
| 49 |
|
| 50 |
;; Semantic types (run time) |
| 51 |
|
| 52 |
;; Simple types. |
| 53 |
|
| 54 |
(module |
| 55 |
(type $t1 (func (param f32 f32))) |
| 56 |
(type $t2 (func (param $x f32) (param $y f32))) |
| 57 |
|
| 58 |
(func $f1 (type $t1)) |
| 59 |
(func $f2 (type $t2)) |
| 60 |
(table funcref (elem $f1 $f2)) |
| 61 |
|
| 62 |
(func (export "run") |
| 63 |
(call_indirect (type $t1) (f32.const 1) (f32.const 2) (i32.const 1)) |
| 64 |
(call_indirect (type $t2) (f32.const 1) (f32.const 2) (i32.const 0)) |
| 65 |
) |
| 66 |
) |
| 67 |
(assert_return (invoke "run")) |
| 68 |
|
| 69 |
|
| 70 |
;; Indirect types. |
| 71 |
|
| 72 |
(module |
| 73 |
(type $s0 (func (param i32))) |
| 74 |
(type $s1 (func (param i32 (ref $s0)))) |
| 75 |
(type $s2 (func (param i32 (ref $s0)))) |
| 76 |
(type $t1 (func (param (ref $s1)))) |
| 77 |
(type $t2 (func (param (ref $s2)))) |
| 78 |
|
| 79 |
(func $s1 (type $s1)) |
| 80 |
(func $s2 (type $s2)) |
| 81 |
(func $f1 (type $t1)) |
| 82 |
(func $f2 (type $t2)) |
| 83 |
(table funcref (elem $f1 $f2 $s1 $s2)) |
| 84 |
|
| 85 |
(func (export "run") |
| 86 |
(call_indirect (type $t1) (ref.func $s1) (i32.const 0)) |
| 87 |
(call_indirect (type $t1) (ref.func $s1) (i32.const 1)) |
| 88 |
(call_indirect (type $t1) (ref.func $s2) (i32.const 0)) |
| 89 |
(call_indirect (type $t1) (ref.func $s2) (i32.const 1)) |
| 90 |
(call_indirect (type $t2) (ref.func $s1) (i32.const 0)) |
| 91 |
(call_indirect (type $t2) (ref.func $s1) (i32.const 1)) |
| 92 |
(call_indirect (type $t2) (ref.func $s2) (i32.const 0)) |
| 93 |
(call_indirect (type $t2) (ref.func $s2) (i32.const 1)) |
| 94 |
) |
| 95 |
) |
| 96 |
(assert_return (invoke "run")) |
| 97 |
|
| 98 |
|
| 99 |
;; Semantic types (link time) |
| 100 |
|
| 101 |
;; Simple types. |
| 102 |
|
| 103 |
(module |
| 104 |
(type $t1 (func (param f32 f32) (result f32))) |
| 105 |
(func (export "f") (param (ref $t1))) |
| 106 |
) |
| 107 |
(register "M") |
| 108 |
(module |
| 109 |
(type $t2 (func (param $x f32) (param $y f32) (result f32))) |
| 110 |
(func (import "M" "f") (param (ref $t2))) |
| 111 |
) |
| 112 |
|
| 113 |
|
| 114 |
;; Indirect types. |
| 115 |
|
| 116 |
(module |
| 117 |
(type $s0 (func (param i32) (result f32))) |
| 118 |
(type $s1 (func (param i32 (ref $s0)) (result (ref $s0)))) |
| 119 |
(type $s2 (func (param i32 (ref $s0)) (result (ref $s0)))) |
| 120 |
(type $t1 (func (param (ref $s1)) (result (ref $s2)))) |
| 121 |
(type $t2 (func (param (ref $s2)) (result (ref $s1)))) |
| 122 |
(func (export "f1") (param (ref $t1))) |
| 123 |
(func (export "f2") (param (ref $t1))) |
| 124 |
) |
| 125 |
(register "M") |
| 126 |
(module |
| 127 |
(type $s0 (func (param i32) (result f32))) |
| 128 |
(type $s1 (func (param i32 (ref $s0)) (result (ref $s0)))) |
| 129 |
(type $s2 (func (param i32 (ref $s0)) (result (ref $s0)))) |
| 130 |
(type $t1 (func (param (ref $s1)) (result (ref $s2)))) |
| 131 |
(type $t2 (func (param (ref $s2)) (result (ref $s1)))) |
| 132 |
(func (import "M" "f1") (param (ref $t1))) |
| 133 |
(func (import "M" "f1") (param (ref $t2))) |
| 134 |
(func (import "M" "f2") (param (ref $t1))) |
| 135 |
(func (import "M" "f2") (param (ref $t1))) |
| 136 |
) |