| 1 |
;; RUN: wast --assert default --snapshot tests/snapshots % -f shared-everything-threads |
| 2 |
|
| 3 |
;; Check the `shared` attribute on tables. |
| 4 |
|
| 5 |
(module |
| 6 |
;; Imported. |
| 7 |
(table (import "spectest" "table_ref") shared 1 (ref null (shared func))) |
| 8 |
(table (import "spectest" "table_ref_with_max") shared 1 1 (ref null (shared func))) |
| 9 |
|
| 10 |
;; Normal. |
| 11 |
(table shared 1 (ref null (shared func))) |
| 12 |
(table shared 1 1 (ref null (shared func))) |
| 13 |
|
| 14 |
;; Inlined. |
| 15 |
(table shared (ref null (shared func)) (elem (ref.null (shared func)))) |
| 16 |
) |
| 17 |
|
| 18 |
;; Note that shared elements can live within an unshared table. |
| 19 |
(module |
| 20 |
(table (import "spectest" "table_ref") 1 (ref null (shared func))) |
| 21 |
) |
| 22 |
|
| 23 |
(assert_malformed |
| 24 |
(module quote "(table 1 shared funcref)") |
| 25 |
"unexpected token") |
| 26 |
|
| 27 |
(assert_malformed |
| 28 |
(module quote "(table 1 funcref shared)") |
| 29 |
"unexpected token") |
| 30 |
|
| 31 |
;; The proposal creates too much ambiguity to allow this syntax: the parser |
| 32 |
;; would need to lookahead multiple tokens. |
| 33 |
(assert_malformed |
| 34 |
(module quote "(table shared i64 (ref null (shared func)) (elem (ref.null (shared func))))") |
| 35 |
"expected a u64") |
| 36 |
|
| 37 |
(assert_invalid |
| 38 |
(module (table (import "spectest" "table_ref") shared 0 funcref)) |
| 39 |
"shared tables must have a shared element type") |
| 40 |
|
| 41 |
(assert_invalid |
| 42 |
(module |
| 43 |
(type $t (func)) |
| 44 |
(table shared 0 (ref $t))) |
| 45 |
"shared tables must have a shared element type") |
| 46 |
|
| 47 |
;; Check `table.atomic.*` instructions. |
| 48 |
(module (;eq;) |
| 49 |
(table $a (import "spectest" "table_eq") shared 1 (ref null (shared eq))) |
| 50 |
(table $b shared 1 (ref null (shared eq))) |
| 51 |
(func (export "table-atomic-get-eq-seq_cst-$a") (param $x i32) (result (ref null (shared eq))) |
| 52 |
local.get $x |
| 53 |
table.atomic.get seq_cst $a) |
| 54 |
(func (export "table-atomic-get-eq-seq_cst-$b") (param $x i32) (result (ref null (shared eq))) |
| 55 |
local.get $x |
| 56 |
table.atomic.get seq_cst $b) |
| 57 |
(func (export "table-atomic-get-eq-acq_rel-$a") (param $x i32) (result (ref null (shared eq))) |
| 58 |
local.get $x |
| 59 |
table.atomic.get acq_rel $a) |
| 60 |
(func (export "table-atomic-get-eq-acq_rel-$b") (param $x i32) (result (ref null (shared eq))) |
| 61 |
local.get $x |
| 62 |
table.atomic.get acq_rel $b) |
| 63 |
(func (export "table-atomic-set-eq-seq_cst-$a") (param $x i32) (param $y (ref null (shared eq))) |
| 64 |
local.get $x |
| 65 |
local.get $y |
| 66 |
table.atomic.set seq_cst $a) |
| 67 |
(func (export "table-atomic-set-eq-seq_cst-$b") (param $x i32) (param $y (ref null (shared eq))) |
| 68 |
local.get $x |
| 69 |
local.get $y |
| 70 |
table.atomic.set seq_cst $b) |
| 71 |
(func (export "table-atomic-set-eq-acq_rel-$a") (param $x i32) (param $y (ref null (shared eq))) |
| 72 |
local.get $x |
| 73 |
local.get $y |
| 74 |
table.atomic.set acq_rel $a) |
| 75 |
(func (export "table-atomic-set-eq-acq_rel-$b") (param $x i32) (param $y (ref null (shared eq))) |
| 76 |
local.get $x |
| 77 |
local.get $y |
| 78 |
table.atomic.set acq_rel $b) |
| 79 |
(func (export "table-atomic-rmw.xchg-eq-seq_cst-$a") (param $x i32) (param $y (ref null (shared eq))) (result (ref null (shared eq))) |
| 80 |
local.get $x |
| 81 |
local.get $y |
| 82 |
table.atomic.rmw.xchg seq_cst $a) |
| 83 |
(func (export "table-atomic-rmw.xchg-eq-seq_cst-$b") (param $x i32) (param $y (ref null (shared eq))) (result (ref null (shared eq))) |
| 84 |
local.get $x |
| 85 |
local.get $y |
| 86 |
table.atomic.rmw.xchg seq_cst $b) |
| 87 |
(func (export "table-atomic-rmw.xchg-eq-acq_rel-$a") (param $x i32) (param $y (ref null (shared eq))) (result (ref null (shared eq))) |
| 88 |
local.get $x |
| 89 |
local.get $y |
| 90 |
table.atomic.rmw.xchg acq_rel $a) |
| 91 |
(func (export "table-atomic-rmw.xchg-eq-acq_rel-$b") (param $x i32) (param $y (ref null (shared eq))) (result (ref null (shared eq))) |
| 92 |
local.get $x |
| 93 |
local.get $y |
| 94 |
table.atomic.rmw.xchg acq_rel $b) |
| 95 |
(func (export "table-atomic-rmw.cmpxchg-eq-seq_cst-$a") (param $x i32) (param $y (ref null (shared eq))) (param $z (ref null (shared eq))) (result (ref null (shared eq))) |
| 96 |
local.get $x |
| 97 |
local.get $y |
| 98 |
local.get $z |
| 99 |
table.atomic.rmw.cmpxchg seq_cst $a) |
| 100 |
(func (export "table-atomic-rmw.cmpxchg-eq-seq_cst-$b") (param $x i32) (param $y (ref null (shared eq))) (param $z (ref null (shared eq))) (result (ref null (shared eq))) |
| 101 |
local.get $x |
| 102 |
local.get $y |
| 103 |
local.get $z |
| 104 |
table.atomic.rmw.cmpxchg seq_cst $b) |
| 105 |
(func (export "table-atomic-rmw.cmpxchg-eq-acq_rel-$a") (param $x i32) (param $y (ref null (shared eq))) (param $z (ref null (shared eq))) (result (ref null (shared eq))) |
| 106 |
local.get $x |
| 107 |
local.get $y |
| 108 |
local.get $z |
| 109 |
table.atomic.rmw.cmpxchg acq_rel $a) |
| 110 |
(func (export "table-atomic-rmw.cmpxchg-eq-acq_rel-$b") (param $x i32) (param $y (ref null (shared eq))) (param $z (ref null (shared eq))) (result (ref null (shared eq))) |
| 111 |
local.get $x |
| 112 |
local.get $y |
| 113 |
local.get $z |
| 114 |
table.atomic.rmw.cmpxchg acq_rel $b) |
| 115 |
) |
| 116 |
|
| 117 |
(module (;any;) |
| 118 |
(table $a (import "spectest" "table_any") shared 1 (ref null (shared any))) |
| 119 |
(table $b shared 1 (ref null (shared any))) |
| 120 |
(func (export "table-atomic-get-any-seq_cst-$a") (param $x i32) (result (ref null (shared any))) |
| 121 |
local.get $x |
| 122 |
table.atomic.get seq_cst $a) |
| 123 |
(func (export "table-atomic-get-any-seq_cst-$b") (param $x i32) (result (ref null (shared any))) |
| 124 |
local.get $x |
| 125 |
table.atomic.get seq_cst $b) |
| 126 |
(func (export "table-atomic-get-any-acq_rel-$a") (param $x i32) (result (ref null (shared any))) |
| 127 |
local.get $x |
| 128 |
table.atomic.get acq_rel $a) |
| 129 |
(func (export "table-atomic-get-any-acq_rel-$b") (param $x i32) (result (ref null (shared any))) |
| 130 |
local.get $x |
| 131 |
table.atomic.get acq_rel $b) |
| 132 |
(func (export "table-atomic-set-any-seq_cst-$a") (param $x i32) (param $y (ref null (shared any))) |
| 133 |
local.get $x |
| 134 |
local.get $y |
| 135 |
table.atomic.set seq_cst $a) |
| 136 |
(func (export "table-atomic-set-any-seq_cst-$b") (param $x i32) (param $y (ref null (shared any))) |
| 137 |
local.get $x |
| 138 |
local.get $y |
| 139 |
table.atomic.set seq_cst $b) |
| 140 |
(func (export "table-atomic-set-any-acq_rel-$a") (param $x i32) (param $y (ref null (shared any))) |
| 141 |
local.get $x |
| 142 |
local.get $y |
| 143 |
table.atomic.set acq_rel $a) |
| 144 |
(func (export "table-atomic-set-any-acq_rel-$b") (param $x i32) (param $y (ref null (shared any))) |
| 145 |
local.get $x |
| 146 |
local.get $y |
| 147 |
table.atomic.set acq_rel $b) |
| 148 |
(func (export "table-atomic-rmw.xchg-any-seq_cst-$a") (param $x i32) (param $y (ref null (shared any))) (result (ref null (shared any))) |
| 149 |
local.get $x |
| 150 |
local.get $y |
| 151 |
table.atomic.rmw.xchg seq_cst $a) |
| 152 |
(func (export "table-atomic-rmw.xchg-any-seq_cst-$b") (param $x i32) (param $y (ref null (shared any))) (result (ref null (shared any))) |
| 153 |
local.get $x |
| 154 |
local.get $y |
| 155 |
table.atomic.rmw.xchg seq_cst $b) |
| 156 |
(func (export "table-atomic-rmw.xchg-any-acq_rel-$a") (param $x i32) (param $y (ref null (shared any))) (result (ref null (shared any))) |
| 157 |
local.get $x |
| 158 |
local.get $y |
| 159 |
table.atomic.rmw.xchg acq_rel $a) |
| 160 |
(func (export "table-atomic-rmw.xchg-any-acq_rel-$b") (param $x i32) (param $y (ref null (shared any))) (result (ref null (shared any))) |
| 161 |
local.get $x |
| 162 |
local.get $y |
| 163 |
table.atomic.rmw.xchg acq_rel $b) |
| 164 |
;; table.atomic.rmw.cmpxchg only works with subtypes of eqref. |
| 165 |
) |
| 166 |
|
| 167 |
;; Check that cmpxchg only works with eqref subtypes. |
| 168 |
(assert_invalid |
| 169 |
(module |
| 170 |
(table $a shared 0 (ref null (shared any))) |
| 171 |
(func (param $x i32) (param $y (ref null (shared any))) (param $z (ref null (shared any))) (result (ref null (shared any))) |
| 172 |
local.get $x |
| 173 |
local.get $y |
| 174 |
local.get $z |
| 175 |
table.atomic.rmw.cmpxchg seq_cst $a)) |
| 176 |
"invalid type") |
| 177 |
|
| 178 |
(assert_invalid |
| 179 |
(module |
| 180 |
(table 1 funcref) |
| 181 |
(func |
| 182 |
i32.const 0 |
| 183 |
table.atomic.get seq_cst 0 |
| 184 |
) |
| 185 |
) |
| 186 |
"invalid type: `table.atomic.get` only allows subtypes of `anyref`") |
| 187 |
|
| 188 |
(assert_invalid |
| 189 |
(module |
| 190 |
(table 1 funcref) |
| 191 |
(func |
| 192 |
i32.const 0 |
| 193 |
ref.null func |
| 194 |
table.atomic.set seq_cst 0 |
| 195 |
) |
| 196 |
) |
| 197 |
"invalid type: `table.atomic.set` only allows subtypes of `anyref`") |
| 198 |
|
| 199 |
(assert_invalid |
| 200 |
(module |
| 201 |
(table 1 funcref) |
| 202 |
(func |
| 203 |
i32.const 0 |
| 204 |
ref.null func |
| 205 |
table.atomic.rmw.xchg seq_cst 0 |
| 206 |
) |
| 207 |
) |
| 208 |
"invalid type: `table.atomic.rmw.xchg` only allows subtypes of `anyref`") |