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