Debian Codegraph @

tests/cli/component-model-async/task-builtins.wast

raw
1 ;; RUN: wast --assert default --snapshot tests/snapshots % -f cm-async,cm-async-builtins,cm-async-stackful,cm-error-context
2
3 ;; backpressure.set
4 (component
5 (core module $m
6 (import "" "backpressure.set" (func $backpressure.set (param i32)))
7 )
8 (core func $backpressure.set (canon backpressure.set))
9 (core instance $i (instantiate $m (with "" (instance (export "backpressure.set" (func $backpressure.set))))))
10 )
11
12 ;; backpressure.set; incorrect type
13 (assert_invalid
14 (component
15 (core module $m
16 (import "" "backpressure.set" (func $backpressure.set (param i32 i32)))
17 )
18 (core func $backpressure.set (canon backpressure.set))
19 (core instance $i (instantiate $m (with "" (instance (export "backpressure.set" (func $backpressure.set))))))
20 )
21 "type mismatch for export `backpressure.set` of module instantiation argument ``"
22 )
23
24 ;; backpressure.inc
25 (component
26 (core module $m
27 (import "" "backpressure.inc" (func $backpressure.inc))
28 )
29 (core func $backpressure.inc (canon backpressure.inc))
30 (core instance $i (instantiate $m (with "" (instance (export "backpressure.inc" (func $backpressure.inc))))))
31 )
32
33 ;; backpressure.inc; incorrect type
34 (assert_invalid
35 (component
36 (core module $m
37 (import "" "backpressure.inc" (func $backpressure.inc (param i32)))
38 )
39 (core func $backpressure.inc (canon backpressure.inc))
40 (core instance $i (instantiate $m (with "" (instance (export "backpressure.inc" (func $backpressure.inc))))))
41 )
42 "type mismatch for export `backpressure.inc` of module instantiation argument ``"
43 )
44
45 ;; backpressure.dec
46 (component
47 (core module $m
48 (import "" "backpressure.dec" (func $backpressure.dec))
49 )
50 (core func $backpressure.dec (canon backpressure.dec))
51 (core instance $i (instantiate $m (with "" (instance (export "backpressure.dec" (func $backpressure.dec))))))
52 )
53
54 ;; backpressure.dec; decorrect type
55 (assert_invalid
56 (component
57 (core module $m
58 (import "" "backpressure.dec" (func $backpressure.dec (param i32)))
59 )
60 (core func $backpressure.dec (canon backpressure.dec))
61 (core instance $i (instantiate $m (with "" (instance (export "backpressure.dec" (func $backpressure.dec))))))
62 )
63 "type mismatch for export `backpressure.dec` of module instantiation argument ``"
64 )
65
66 ;; task.return
67 (component
68 (core module $m
69 (import "" "task.return" (func $task-return (param i32)))
70 )
71 (core func $task-return (canon task.return (result u32)))
72 (core instance $i (instantiate $m (with "" (instance (export "task.return" (func $task-return))))))
73 )
74
75 (assert_invalid
76 (component (core func $task-return (canon task.return (result u32) async)))
77 "cannot specify `async` option on `task.return`")
78
79 (assert_invalid
80 (component
81 (core func $f (canon backpressure.set))
82 (core func $task-return (canon task.return (result u32) (callback $f)))
83 )
84 "cannot specify callback without async")
85
86 (assert_invalid
87 (component
88 (core func $f (canon backpressure.set))
89 (core func $task-return (canon task.return (result u32) (post-return $f)))
90 )
91 "cannot specify `post-return` option on `task.return`")
92
93 (assert_invalid
94 (component
95 (core module $m
96 (func (export "r") (param i32 i32 i32 i32) (result i32) unreachable)
97 )
98 (core instance $m (instantiate $m))
99 (core func $task-return (canon task.return (result u32) (realloc (func $m "r"))))
100 )
101 "cannot specify `realloc` option on `task.return`")
102
103 (component
104 (core module $m
105 (memory (export "m") 1)
106 )
107 (core instance $i (instantiate $m))
108 (core func (canon task.return (result u32) string-encoding=utf8))
109 (core func (canon task.return (result u32) string-encoding=utf16))
110 (core func (canon task.return (result u32) string-encoding=latin1+utf16))
111 (core func (canon task.return (result u32) (memory $i "m")))
112 )
113
114 ;; task.cancel
115 (component
116 (core module $m
117 (import "" "task.cancel" (func $task-cancel))
118 )
119 (core func $task-cancel (canon task.cancel))
120 (core instance $i (instantiate $m (with "" (instance (export "task.cancel" (func $task-cancel))))))
121 )
122
123 ;; waitable-set.new
124 (component
125 (core module $m (import "" "waitable-set.new" (func (result i32))))
126 (core func $waitable-set-new (canon waitable-set.new))
127 (core instance $i (instantiate $m (with "" (instance (export "waitable-set.new" (func $waitable-set-new))))))
128 )
129
130 ;; waitable-set.new; incorrect type
131 (assert_invalid
132 (component
133 (core module $m (import "" "waitable-set.new" (func (result i64))))
134 (core func $waitable-set-new (canon waitable-set.new))
135 (core instance $i (instantiate $m (with "" (instance (export "waitable-set.new" (func $waitable-set-new))))))
136 )
137 "type mismatch for export `waitable-set.new` of module instantiation argument ``"
138 )
139
140 ;; waitable-set.wait
141 (component
142 (core module $libc (memory (export "memory") 1))
143 (core instance $libc (instantiate $libc))
144 (core module $m
145 (import "" "waitable-set.wait" (func $waitable-set-wait (param i32 i32) (result i32)))
146 )
147 (core func $waitable-set-wait (canon waitable-set.wait cancellable (memory $libc "memory")))
148 (core instance $i (instantiate $m (with "" (instance (export "waitable-set.wait" (func $waitable-set-wait))))))
149 )
150
151 ;; waitable-set.wait; incorrect type
152 (assert_invalid
153 (component
154 (core module $libc (memory (export "memory") 1))
155 (core instance $libc (instantiate $libc))
156 (core module $m
157 (import "" "waitable-set.wait" (func $waitable-set-wait (param i32) (result i32)))
158 )
159 (core func $waitable-set-wait (canon waitable-set.wait cancellable (memory $libc "memory")))
160 (core instance $i (instantiate $m (with "" (instance (export "waitable-set.wait" (func $waitable-set-wait))))))
161 )
162 "type mismatch for export `waitable-set.wait` of module instantiation argument ``"
163 )
164
165 ;; waitable-set.poll
166 (component
167 (core module $libc (memory (export "memory") 1))
168 (core instance $libc (instantiate $libc))
169 (core module $m
170 (import "" "waitable-set.poll" (func $waitable-set-poll (param i32 i32) (result i32)))
171 )
172 (core func $waitable-set-poll (canon waitable-set.poll cancellable (memory $libc "memory")))
173 (core instance $i (instantiate $m (with "" (instance (export "waitable-set.poll" (func $waitable-set-poll))))))
174 )
175
176 ;; waitable-set.poll; incorrect type
177 (assert_invalid
178 (component
179 (core module $libc (memory (export "memory") 1))
180 (core instance $libc (instantiate $libc))
181 (core module $m
182 (import "" "waitable-set.poll" (func $waitable-set-poll (param i32) (result i32)))
183 )
184 (core func $waitable-set-poll (canon waitable-set.poll cancellable (memory $libc "memory")))
185 (core instance $i (instantiate $m (with "" (instance (export "waitable-set.poll" (func $waitable-set-poll))))))
186 )
187 "type mismatch for export `waitable-set.poll` of module instantiation argument ``"
188 )
189
190 ;; waitable-set.drop
191 (component
192 (core module $m (import "" "waitable-set.drop" (func (param i32))))
193 (core func $waitable-set-drop (canon waitable-set.drop))
194 (core instance $i (instantiate $m (with "" (instance (export "waitable-set.drop" (func $waitable-set-drop))))))
195 )
196
197 ;; waitable-set.drop; incorrect type
198 (assert_invalid
199 (component
200 (core module $m (import "" "waitable-set.drop" (func (param i64))))
201 (core func $waitable-set-drop (canon waitable-set.drop))
202 (core instance $i (instantiate $m (with "" (instance (export "waitable-set.drop" (func $waitable-set-drop))))))
203 )
204 "type mismatch for export `waitable-set.drop` of module instantiation argument ``"
205 )
206
207 ;; waitable.join
208 (component
209 (core module $m (import "" "waitable.join" (func (param i32 i32))))
210 (core func $waitable.join (canon waitable.join))
211 (core instance $i (instantiate $m (with "" (instance (export "waitable.join" (func $waitable.join))))))
212 )
213
214 ;; waitable.join; incorrect type
215 (assert_invalid
216 (component
217 (core module $m (import "" "waitable.join" (func (param i64))))
218 (core func $waitable.join (canon waitable.join))
219 (core instance $i (instantiate $m (with "" (instance (export "waitable.join" (func $waitable.join))))))
220 )
221 "type mismatch for export `waitable.join` of module instantiation argument ``"
222 )
223
224 ;; thread.yield
225 (component
226 (core module $m
227 (import "" "thread.yield" (func $thread.yield (result i32)))
228 )
229 (core func $thread.yield (canon thread.yield cancellable))
230 (core instance $i (instantiate $m (with "" (instance (export "thread.yield" (func $thread.yield))))))
231 )
232
233 ;; thread.yield; incorrect type
234 (assert_invalid
235 (component
236 (core module $m
237 (import "" "thread.yield" (func $thread.yield (param i32) (result i32)))
238 )
239 (core func $thread.yield (canon thread.yield cancellable))
240 (core instance $i (instantiate $m (with "" (instance (export "thread.yield" (func $thread.yield))))))
241 )
242 "type mismatch for export `thread.yield` of module instantiation argument ``"
243 )
244
245 ;; subtask.drop
246 (component
247 (core module $m
248 (import "" "subtask.drop" (func $subtask-drop (param i32)))
249 )
250 (core func $subtask-drop (canon subtask.drop))
251 (core instance $i (instantiate $m (with "" (instance (export "subtask.drop" (func $subtask-drop))))))
252 )
253
254 ;; subtask.drop; incorrect type
255 (assert_invalid
256 (component
257 (core module $m
258 (import "" "subtask.drop" (func $subtask-drop (param i32) (result i32)))
259 )
260 (core func $subtask-drop (canon subtask.drop))
261 (core instance $i (instantiate $m (with "" (instance (export "subtask.drop" (func $subtask-drop))))))
262 )
263 "type mismatch for export `subtask.drop` of module instantiation argument ``"
264 )
265
266 ;; subtask.cancel
267 (component
268 (core module $m
269 (import "" "subtask.cancel" (func $subtask-cancel (param i32) (result i32)))
270 )
271 (core func $subtask-cancel (canon subtask.cancel))
272 (core instance $i (instantiate $m (with "" (instance (export "subtask.cancel" (func $subtask-cancel))))))
273 )
274
275 ;; subtask.cancel; incorrect type
276 (assert_invalid
277 (component
278 (core module $m
279 (import "" "subtask.cancel" (func $subtask-cancel (param i32 i32) (result i32)))
280 )
281 (core func $subtask-cancel (canon subtask.cancel))
282 (core instance $i (instantiate $m (with "" (instance (export "subtask.cancel" (func $subtask-cancel))))))
283 )
284 "type mismatch for export `subtask.cancel` of module instantiation argument ``"
285 )
286
287 ;; context.{get,set}
288 (component
289 (core func $get0 (canon context.get i32 0))
290 (core func $set0 (canon context.set i32 0))
291
292 (core module $m
293 (import "" "get0" (func (result i32)))
294 (import "" "set0" (func (param i32)))
295 )
296 (core instance (instantiate $m
297 (with "" (instance
298 (export "get0" (func $get0))
299 (export "set0" (func $set0))
300 ))
301 ))
302 )
303
304 (assert_invalid
305 (component
306 (core module $m (import "" "" (func (param i32) (result i32))))
307 (core func $f (canon context.get i32 0))
308 (core instance $i (instantiate $m (with "" (instance (export "" (func $f))))))
309 )
310 "found: (func (result i32))")
311 (assert_invalid
312 (component
313 (core module $m (import "" "" (func (param i32) (result i32))))
314 (core func $f (canon context.set i32 0))
315 (core instance $i (instantiate $m (with "" (instance (export "" (func $f))))))
316 )
317 "found: (func (param i32))")
318 (assert_invalid
319 (component
320 (core func (canon context.get i32 1)))
321 "immediate must be zero: 1")
322 (assert_invalid
323 (component
324 (core func (canon context.set i32 1)))
325 "immediate must be zero: 1")
326 (assert_invalid
327 (component
328 (core func (canon context.get i32 100)))
329 "immediate must be zero: 100")
330 (assert_invalid
331 (component
332 (core func (canon context.set i32 100)))
333 "immediate must be zero: 100")
334 (assert_malformed
335 (component quote
336 "(core func (canon context.get i64 100))")
337 "expected keyword `i32`")
338 (assert_malformed
339 (component quote
340 "(core func (canon context.set i64 100))")
341 "expected keyword `i32`")
342
343 (assert_malformed
344 (component binary
345 "\00asm" "\0d\00\01\00" ;; component header
346 "\08\04" ;; canonicals section, 4 bytes
347 "\01" ;; 1 count
348 "\0a\7e\00") ;; context.get i64 0
349 "invalid leading byte (0x7e) for context.get")
350 (assert_malformed
351 (component binary
352 "\00asm" "\0d\00\01\00" ;; component header
353 "\08\04" ;; canonicals section, 4 bytes
354 "\01" ;; 1 count
355 "\0b\7e\00") ;; context.set i64 0
356 "invalid leading byte (0x7e) for context.set")
357
358 ;; different forms of canonical intrinsics
359
360 (component
361 (core func (canon backpressure.set))
362 (canon backpressure.set (core func))
363 (core func (canon task.return))
364 (canon task.return (core func))
365 (core func (canon task.cancel))
366 (canon task.cancel (core func))
367 (core func (canon subtask.drop))
368 (canon subtask.drop (core func))
369 (core func (canon subtask.cancel))
370 (canon subtask.cancel (core func))
371 (core func (canon subtask.cancel async))
372 (canon subtask.cancel async (core func))
373
374 (core module $m
375 (memory (export "m") 1)
376 (func (export "r") (param i32 i32 i32 i32) (result i32) unreachable)
377 )
378 (core instance $i (instantiate $m))
379 (alias core export $i "m" (core memory $m))
380 (alias core export $i "r" (core func $r))
381
382 (type $r (resource (rep i32)))
383 (core func (canon resource.drop $r async))
384 (canon resource.drop $r async (core func))
385
386 (type $s (stream))
387 (type $f (future))
388 (core func (canon future.new $f))
389 (canon future.new $f (core func))
390 (core func (canon stream.new $s))
391 (canon stream.new $s (core func))
392 (core func (canon future.cancel-read $f))
393 (canon future.cancel-read $f (core func))
394 (core func (canon stream.cancel-read $s))
395 (canon stream.cancel-read $s (core func))
396 (core func (canon future.cancel-write $f))
397 (canon future.cancel-write $f (core func))
398 (core func (canon stream.cancel-write $s))
399 (canon stream.cancel-write $s (core func))
400 (core func (canon future.drop-readable $f))
401 (canon future.drop-readable $f (core func))
402 (core func (canon future.drop-writable $f))
403 (canon future.drop-writable $f (core func))
404 (core func (canon stream.drop-readable $s))
405 (canon stream.drop-readable $s (core func))
406 (core func (canon stream.drop-writable $s))
407 (canon stream.drop-writable $s (core func))
408 (core func (canon future.read $f (memory $m)))
409 (canon future.read $f (memory $m) (core func))
410 (core func (canon future.write $f (memory $m)))
411 (canon future.write $f (memory $m) (core func))
412 (core func (canon stream.read $s (memory $m)))
413 (canon stream.read $s (memory $m) (core func))
414 (core func (canon stream.write $s (memory $m)))
415 (canon stream.write $s (memory $m) (core func))
416
417 (core func (canon error-context.new (memory $m)))
418 (canon error-context.new (memory $m) (core func))
419 (core func (canon error-context.debug-message (memory $m) (realloc $r)))
420 (canon error-context.debug-message (memory $m) (realloc $r) (core func))
421 (core func (canon error-context.drop))
422 (canon error-context.drop (core func))
423
424 (core func (canon context.get i32 0))
425 (canon context.get i32 0 (core func))
426 (core func (canon context.set i32 0))
427 (canon context.set i32 0 (core func))
428
429 (core func (canon thread.yield))
430 (canon thread.yield (core func))
431 )
432
433 (component
434 (canon task.return (result (stream u8)) (core func))
435 )