wasm-tools 1.248.0

CLI tools for interoperating with WebAssembly files
Documentation
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
;; RUN: wast --assert default --snapshot tests/snapshots % -f cm-async

;; backpressure.set -- removed from the spec
(assert_malformed
  (component quote
    "(core func (canon backpressure.set))"
  )
  "unexpected token")

;; backpressure.inc
(component
  (core module $m
    (import "" "backpressure.inc" (func $backpressure.inc))
  )
  (core func $backpressure.inc (canon backpressure.inc))
  (core instance $i (instantiate $m (with "" (instance (export "backpressure.inc" (func $backpressure.inc))))))
)

;; backpressure.inc; incorrect type
(assert_invalid
  (component
    (core module $m
      (import "" "backpressure.inc" (func $backpressure.inc (param i32)))
    )
    (core func $backpressure.inc (canon backpressure.inc))
    (core instance $i (instantiate $m (with "" (instance (export "backpressure.inc" (func $backpressure.inc))))))
  )
  "type mismatch for export `backpressure.inc` of module instantiation argument ``"
)

;; backpressure.dec
(component
  (core module $m
    (import "" "backpressure.dec" (func $backpressure.dec))
  )
  (core func $backpressure.dec (canon backpressure.dec))
  (core instance $i (instantiate $m (with "" (instance (export "backpressure.dec" (func $backpressure.dec))))))
)

;; backpressure.dec; decorrect type
(assert_invalid
  (component
    (core module $m
      (import "" "backpressure.dec" (func $backpressure.dec (param i32)))
    )
    (core func $backpressure.dec (canon backpressure.dec))
    (core instance $i (instantiate $m (with "" (instance (export "backpressure.dec" (func $backpressure.dec))))))
  )
  "type mismatch for export `backpressure.dec` of module instantiation argument ``"
)

;; task.return
(component
  (core module $m
    (import "" "task.return" (func $task-return (param i32)))
  )
  (core func $task-return (canon task.return (result u32)))
  (core instance $i (instantiate $m (with "" (instance (export "task.return" (func $task-return))))))
)

(assert_invalid
  (component (core func $task-return (canon task.return (result u32) async)))
  "cannot specify `async` option on `task.return`")

(assert_invalid
  (component
    (core func $f (canon backpressure.inc))
    (core func $task-return (canon task.return (result u32) (callback $f)))
  )
  "cannot specify callback without async")

(assert_invalid
  (component
    (core func $f (canon backpressure.inc))
    (core func $task-return (canon task.return (result u32) (post-return $f)))
  )
  "cannot specify `post-return` option on `task.return`")

(assert_invalid
  (component
    (core module $m
      (func (export "r") (param i32 i32 i32 i32) (result i32) unreachable)
      (memory (export "m") 0)
    )
    (core instance $m (instantiate $m))
    (core func $task-return (canon task.return (result u32) (realloc (func $m "r")) (memory $m "m")))
  )
  "cannot specify `realloc` option on `task.return`")

(component
  (core module $m
    (memory (export "m") 1)
  )
  (core instance $i (instantiate $m))
  (core func (canon task.return (result u32) string-encoding=utf8))
  (core func (canon task.return (result u32) string-encoding=utf16))
  (core func (canon task.return (result u32) string-encoding=latin1+utf16))
  (core func (canon task.return (result u32) (memory $i "m")))
)

;; task.cancel
(component
  (core module $m
    (import "" "task.cancel" (func $task-cancel))
  )
  (core func $task-cancel (canon task.cancel))
  (core instance $i (instantiate $m (with "" (instance (export "task.cancel" (func $task-cancel))))))
)

;; waitable-set.new
(component
  (core module $m (import "" "waitable-set.new" (func (result i32))))
  (core func $waitable-set-new (canon waitable-set.new))
  (core instance $i (instantiate $m (with "" (instance (export "waitable-set.new" (func $waitable-set-new))))))
)

;; waitable-set.new; incorrect type
(assert_invalid
  (component
    (core module $m (import "" "waitable-set.new" (func (result i64))))
    (core func $waitable-set-new (canon waitable-set.new))
    (core instance $i (instantiate $m (with "" (instance (export "waitable-set.new" (func $waitable-set-new))))))
  )
  "type mismatch for export `waitable-set.new` of module instantiation argument ``"
)

;; waitable-set.wait
(component
  (core module $libc (memory (export "memory") 1))
  (core instance $libc (instantiate $libc))
  (core module $m
    (import "" "waitable-set.wait" (func $waitable-set-wait (param i32 i32) (result i32)))
  )
  (core func $waitable-set-wait (canon waitable-set.wait (memory $libc "memory")))
  (core instance $i (instantiate $m (with "" (instance (export "waitable-set.wait" (func $waitable-set-wait))))))
)

;; waitable-set.wait; incorrect type
(assert_invalid
  (component
    (core module $libc (memory (export "memory") 1))
    (core instance $libc (instantiate $libc))
    (core module $m
      (import "" "waitable-set.wait" (func $waitable-set-wait (param i32) (result i32)))
    )
    (core func $waitable-set-wait (canon waitable-set.wait (memory $libc "memory")))
    (core instance $i (instantiate $m (with "" (instance (export "waitable-set.wait" (func $waitable-set-wait))))))
  )
  "type mismatch for export `waitable-set.wait` of module instantiation argument ``"
)

(component
  (core module $libc (memory (export "memory") 1))
  (core instance $libc (instantiate $libc))
  (core module $m
    (import "" "waitable-set.wait" (func $waitable-set-wait (param i32 i32) (result i32)))
  )
  (core func $waitable-set-wait (canon waitable-set.wait cancellable (memory $libc "memory")))
  (core instance $i (instantiate $m (with "" (instance (export "waitable-set.wait" (func $waitable-set-wait))))))
)

;; waitable-set.poll
(component
  (core module $libc (memory (export "memory") 1))
  (core instance $libc (instantiate $libc))
  (core module $m
    (import "" "waitable-set.poll" (func $waitable-set-poll (param i32 i32) (result i32)))
  )
  (core func $waitable-set-poll (canon waitable-set.poll (memory $libc "memory")))
  (core instance $i (instantiate $m (with "" (instance (export "waitable-set.poll" (func $waitable-set-poll))))))
)
(component
  (core module $libc (memory (export "memory") 1))
  (core instance $libc (instantiate $libc))
  (core module $m
    (import "" "waitable-set.poll" (func $waitable-set-poll (param i32 i32) (result i32)))
  )
  (core func $waitable-set-poll (canon waitable-set.poll cancellable (memory $libc "memory")))
  (core instance $i (instantiate $m (with "" (instance (export "waitable-set.poll" (func $waitable-set-poll))))))
)

;; waitable-set.poll; incorrect type
(assert_invalid
  (component
    (core module $libc (memory (export "memory") 1))
    (core instance $libc (instantiate $libc))
    (core module $m
      (import "" "waitable-set.poll" (func $waitable-set-poll (param i32) (result i32)))
    )
    (core func $waitable-set-poll (canon waitable-set.poll (memory $libc "memory")))
    (core instance $i (instantiate $m (with "" (instance (export "waitable-set.poll" (func $waitable-set-poll))))))
  )
  "type mismatch for export `waitable-set.poll` of module instantiation argument ``"
)

;; waitable-set.drop
(component
  (core module $m (import "" "waitable-set.drop" (func (param i32))))
  (core func $waitable-set-drop (canon waitable-set.drop))
  (core instance $i (instantiate $m (with "" (instance (export "waitable-set.drop" (func $waitable-set-drop))))))
)

;; waitable-set.drop; incorrect type
(assert_invalid
  (component
    (core module $m (import "" "waitable-set.drop" (func (param i64))))
    (core func $waitable-set-drop (canon waitable-set.drop))
    (core instance $i (instantiate $m (with "" (instance (export "waitable-set.drop" (func $waitable-set-drop))))))
  )
  "type mismatch for export `waitable-set.drop` of module instantiation argument ``"
)

;; waitable.join
(component
  (core module $m (import "" "waitable.join" (func (param i32 i32))))
  (core func $waitable.join (canon waitable.join))
  (core instance $i (instantiate $m (with "" (instance (export "waitable.join" (func $waitable.join))))))
)

;; waitable.join; incorrect type
(assert_invalid
  (component
    (core module $m (import "" "waitable.join" (func (param i64))))
    (core func $waitable.join (canon waitable.join))
    (core instance $i (instantiate $m (with "" (instance (export "waitable.join" (func $waitable.join))))))
  )
  "type mismatch for export `waitable.join` of module instantiation argument ``"
)

;; subtask.drop
(component
  (core module $m
    (import "" "subtask.drop" (func $subtask-drop (param i32)))
  )
  (core func $subtask-drop (canon subtask.drop))
  (core instance $i (instantiate $m (with "" (instance (export "subtask.drop" (func $subtask-drop))))))
)

;; subtask.drop; incorrect type
(assert_invalid
  (component
    (core module $m
      (import "" "subtask.drop" (func $subtask-drop (param i32) (result i32)))
    )
    (core func $subtask-drop (canon subtask.drop))
    (core instance $i (instantiate $m (with "" (instance (export "subtask.drop" (func $subtask-drop))))))
  )
  "type mismatch for export `subtask.drop` of module instantiation argument ``"
)

;; subtask.cancel
(component
  (core module $m
    (import "" "subtask.cancel" (func $subtask-cancel (param i32) (result i32)))
  )
  (core func $subtask-cancel (canon subtask.cancel))
  (core instance $i (instantiate $m (with "" (instance (export "subtask.cancel" (func $subtask-cancel))))))
)

;; subtask.cancel; incorrect type
(assert_invalid
  (component
    (core module $m
      (import "" "subtask.cancel" (func $subtask-cancel (param i32 i32) (result i32)))
    )
    (core func $subtask-cancel (canon subtask.cancel))
    (core instance $i (instantiate $m (with "" (instance (export "subtask.cancel" (func $subtask-cancel))))))
  )
  "type mismatch for export `subtask.cancel` of module instantiation argument ``"
)

;; context.{get,set}
(component
  (core func $get0 (canon context.get i32 0))
  (core func $set0 (canon context.set i32 0))

  (core module $m
    (import "" "get0" (func (result i32)))
    (import "" "set0" (func (param i32)))
  )
  (core instance (instantiate $m
    (with "" (instance
      (export "get0" (func $get0))
      (export "set0" (func $set0))
    ))
  ))
)

;; thread.yield
(component
  (core module $m
    (import "" "thread.yield" (func $thread.yield (result i32)))
  )
  (core func $thread.yield (canon thread.yield))
  (core instance $i (instantiate $m (with "" (instance (export "thread.yield" (func $thread.yield))))))
)

(component
  (core module $m
    (import "" "thread.yield" (func $thread.yield (result i32)))
  )
  (core func $thread.yield (canon thread.yield cancellable))
  (core instance $i (instantiate $m (with "" (instance (export "thread.yield" (func $thread.yield))))))
)

;; thread.yield; incorrect type
(assert_invalid
  (component
    (core module $m
      (import "" "thread.yield" (func $thread.yield (param i32) (result i32)))
    )
    (core func $thread.yield (canon thread.yield))
    (core instance $i (instantiate $m (with "" (instance (export "thread.yield" (func $thread.yield))))))
  )
  "type mismatch for export `thread.yield` of module instantiation argument ``"
)

(assert_invalid
  (component
    (core module $m (import "" "" (func (param i32) (result i32))))
    (core func $f (canon context.get i32 0))
    (core instance $i (instantiate $m (with "" (instance (export "" (func $f))))))
  )
  "found:    (func (result i32))")
(assert_invalid
  (component
    (core module $m (import "" "" (func (param i32) (result i32))))
    (core func $f (canon context.set i32 0))
    (core instance $i (instantiate $m (with "" (instance (export "" (func $f))))))
  )
  "found:    (func (param i32))")
(assert_invalid
  (component
    (core func (canon context.get i32 1)))
  "immediate must be zero: 1")
(assert_invalid
  (component
    (core func (canon context.set i32 1)))
  "immediate must be zero: 1")
(assert_invalid
  (component
    (core func (canon context.get i32 100)))
  "immediate must be zero: 100")
(assert_invalid
  (component
    (core func (canon context.set i32 100)))
  "immediate must be zero: 100")
;; `i64` is accepted syntactically but requires the component model 64-bit
;; feature (`cm64`), which is not enabled by this test.
(assert_invalid
  (component
    (core func (canon context.get i64 0)))
  "64-bit `context.get` requires the component model 64-bit feature")
(assert_invalid
  (component
    (core func (canon context.set i64 0)))
  "64-bit `context.set` requires the component model 64-bit feature")

(assert_invalid
  (component binary
    "\00asm" "\0d\00\01\00" ;; component header
    "\08\04"                ;; canonicals section, 4 bytes
    "\01"                   ;; 1 count
    "\0a\7e\00")            ;; context.get i64 0
  "64-bit `context.get` requires the component model 64-bit feature")
(assert_invalid
  (component binary
    "\00asm" "\0d\00\01\00" ;; component header
    "\08\04"                ;; canonicals section, 4 bytes
    "\01"                   ;; 1 count
    "\0b\7e\00")            ;; context.set i64 0
  "64-bit `context.set` requires the component model 64-bit feature")

;; Other value types (e.g. `f32`) are rejected regardless of the `cm64` feature.
(assert_invalid
  (component
    (core func (canon context.get f32 0)))
  "`context.get` only supports `i32` or `i64`")
(assert_invalid
  (component
    (core func (canon context.set f32 0)))
  "`context.set` only supports `i32` or `i64`")

;; different forms of canonical intrinsics

(component
  (core func (canon backpressure.inc))
  (canon backpressure.inc (core func))
  (core func (canon backpressure.dec))
  (canon backpressure.dec (core func))
  (core func (canon task.return))
  (canon task.return (core func))
  (core func (canon task.cancel))
  (canon task.cancel (core func))
  (core func (canon subtask.drop))
  (canon subtask.drop (core func))
  (core func (canon subtask.cancel))
  (canon subtask.cancel (core func))

  (core module $m
    (memory (export "m") 1)
  )
  (core instance $i (instantiate $m))
  (alias core export $i "m" (core memory $m))

  (type $s (stream))
  (type $f (future))
  (core func (canon future.new $f))
  (canon future.new $f (core func))
  (core func (canon stream.new $s))
  (canon stream.new $s (core func))
  (core func (canon future.cancel-read $f))
  (canon future.cancel-read $f (core func))
  (core func (canon stream.cancel-read $s))
  (canon stream.cancel-read $s (core func))
  (core func (canon future.cancel-write $f))
  (canon future.cancel-write $f (core func))
  (core func (canon stream.cancel-write $s))
  (canon stream.cancel-write $s (core func))
  (core func (canon future.drop-readable $f))
  (canon future.drop-readable $f (core func))
  (core func (canon future.drop-writable $f))
  (canon future.drop-writable $f (core func))
  (core func (canon stream.drop-readable $s))
  (canon stream.drop-readable $s (core func))
  (core func (canon stream.drop-writable $s))
  (canon stream.drop-writable $s (core func))
  (core func (canon future.read $f (memory $m) async))
  (canon future.read $f (memory $m) async (core func))
  (core func (canon future.write $f (memory $m) async))
  (canon future.write $f (memory $m) async (core func))
  (core func (canon stream.read $s (memory $m) async))
  (canon stream.read $s (memory $m) async (core func))
  (core func (canon stream.write $s (memory $m) async))
  (canon stream.write $s (memory $m) async (core func))

  (core func (canon context.get i32 0))
  (canon context.get i32 0 (core func))
  (core func (canon context.set i32 0))
  (canon context.set i32 0 (core func))

  (core func (canon thread.yield))
  (canon thread.yield (core func))
)

(component
  (canon task.return (result (stream u8)) (core func))
)