Skip to content

Commit b94f88d

Browse files
authored
Sync async gating with spec (#2097)
I meant to hold off merging #2095 until WebAssembly/component-model#468 was finished but I forgot and merged it anyway. This commit updates the implementation in wasmparser's validation with the result of some discussion on that upstream PR.
1 parent 7be33ae commit b94f88d

File tree

11 files changed

+127
-56
lines changed

11 files changed

+127
-56
lines changed

crates/wasmparser/src/validator/component.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -1256,10 +1256,10 @@ impl ComponentState {
12561256
if !features.cm_async() {
12571257
bail!(offset, "`yield` requires the component model async feature")
12581258
}
1259-
if async_ && !features.cm_async_builtins() {
1259+
if async_ && !features.cm_async_stackful() {
12601260
bail!(
12611261
offset,
1262-
"async `yield` requires the component model async builtins feature"
1262+
"async `yield` requires the component model async stackful feature"
12631263
)
12641264
}
12651265

@@ -1764,7 +1764,7 @@ impl ComponentState {
17641764

17651765
fn waitable_set_wait(
17661766
&mut self,
1767-
_async_: bool,
1767+
async_: bool,
17681768
memory: u32,
17691769
types: &mut TypeAlloc,
17701770
offset: usize,
@@ -1776,6 +1776,12 @@ impl ComponentState {
17761776
"`waitable-set.wait` requires the component model async feature"
17771777
)
17781778
}
1779+
if async_ && !features.cm_async_stackful() {
1780+
bail!(
1781+
offset,
1782+
"async `waitable-set.wait` requires the component model async stackful feature"
1783+
)
1784+
}
17791785

17801786
self.memory_at(memory, offset)?;
17811787

@@ -1798,10 +1804,10 @@ impl ComponentState {
17981804
"`waitable-set.poll` requires the component model async feature"
17991805
)
18001806
}
1801-
if async_ && !features.cm_async_builtins() {
1807+
if async_ && !features.cm_async_stackful() {
18021808
bail!(
18031809
offset,
1804-
"async `waitable-set.poll` requires the component model async builtins feature"
1810+
"async `waitable-set.poll` requires the component model async stackful feature"
18051811
)
18061812
}
18071813

crates/wit-component/src/dummy.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,6 @@ fn push_root_async_intrinsics(dst: &mut String) {
375375
(import "$root" "[backpressure-set]" (func (param i32)))
376376
(import "$root" "[waitable-set-new]" (func (result i32)))
377377
(import "$root" "[waitable-set-wait]" (func (param i32 i32) (result i32)))
378-
(import "$root" "[async-lower][waitable-set-wait]" (func (param i32 i32) (result i32)))
379378
(import "$root" "[waitable-set-poll]" (func (param i32 i32) (result i32)))
380379
(import "$root" "[waitable-set-drop]" (func (param i32)))
381380
(import "$root" "[waitable-join]" (func (param i32 i32)))
@@ -389,7 +388,8 @@ fn push_root_async_intrinsics(dst: &mut String) {
389388
(import "$root" "[error-context-debug-message-latin1+utf16]" (func (param i32 i32)))
390389
(import "$root" "[error-context-drop]" (func (param i32)))
391390
392-
;; deferred behind 🚝 upstream
391+
;; deferred behind 🚝 or 🚟 upstream
392+
;;(import "$root" "[async-lower][waitable-set-wait]" (func (param i32 i32) (result i32)))
393393
;;(import "$root" "[async-lower][waitable-set-poll]" (func (param i32 i32) (result i32)))
394394
;;(import "$root" "[async-lower][yield]" (func))
395395
"#,

tests/local/missing-features/component-model-async/async-builtins.wast

+10-22
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,3 @@
1-
;; waitable-set.poll async
2-
(assert_invalid
3-
(component
4-
(core module $libc (memory (export "memory") 1))
5-
(core instance $libc (instantiate $libc))
6-
(core func (canon waitable-set.poll async (memory $libc "memory")))
7-
)
8-
"requires the component model async builtins feature")
9-
10-
(component
11-
(core module $libc (memory (export "memory") 1))
12-
(core instance $libc (instantiate $libc))
13-
(core func (canon waitable-set.poll (memory $libc "memory")))
14-
)
15-
16-
;; yield
17-
(assert_invalid
18-
(component (core func (canon yield async)))
19-
"requires the component model async builtins feature")
20-
21-
(component (core func (canon yield)))
22-
231
;; {future,stream}.cancel-{read,write}
242
(assert_invalid
253
(component
@@ -50,3 +28,13 @@
5028
(core func (canon stream.cancel-read $s))
5129
(core func (canon stream.cancel-write $s))
5230
)
31+
32+
;; async resource.drop
33+
(assert_invalid
34+
(component
35+
(type $t (resource (rep i32)))
36+
(core func (canon resource.drop $t async)))
37+
"requires the component model async builtins feature")
38+
(component
39+
(type $t (resource (rep i32)))
40+
(core func (canon resource.drop $t)))

tests/local/missing-features/component-model-async/async-stackful.wast

+38
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,41 @@
88
)
99
)
1010
"requires the async stackful feature")
11+
12+
;; waitable-set.wait async
13+
(assert_invalid
14+
(component
15+
(core module $libc (memory (export "memory") 1))
16+
(core instance $libc (instantiate $libc))
17+
(core func (canon waitable-set.wait async (memory $libc "memory")))
18+
)
19+
"requires the component model async stackful feature")
20+
21+
(component
22+
(core module $libc (memory (export "memory") 1))
23+
(core instance $libc (instantiate $libc))
24+
(core func (canon waitable-set.wait (memory $libc "memory")))
25+
)
26+
27+
;; waitable-set.poll async
28+
(assert_invalid
29+
(component
30+
(core module $libc (memory (export "memory") 1))
31+
(core instance $libc (instantiate $libc))
32+
(core func (canon waitable-set.poll async (memory $libc "memory")))
33+
)
34+
"requires the component model async stackful feature")
35+
36+
(component
37+
(core module $libc (memory (export "memory") 1))
38+
(core instance $libc (instantiate $libc))
39+
(core func (canon waitable-set.poll (memory $libc "memory")))
40+
)
41+
42+
;; yield
43+
(assert_invalid
44+
(component (core func (canon yield async)))
45+
"requires the component model async stackful feature")
46+
47+
(component (core func (canon yield)))
48+

tests/snapshots/local/missing-features/component-model-async/async-builtins.wast.json

+14-27
Original file line numberDiff line numberDiff line change
@@ -8,57 +8,44 @@
88
"module_type": "binary",
99
"text": "requires the component model async builtins feature"
1010
},
11-
{
12-
"type": "module",
13-
"line": 10,
14-
"filename": "async-builtins.1.wasm",
15-
"module_type": "binary"
16-
},
1711
{
1812
"type": "assert_invalid",
19-
"line": 18,
20-
"filename": "async-builtins.2.wasm",
13+
"line": 8,
14+
"filename": "async-builtins.1.wasm",
2115
"module_type": "binary",
2216
"text": "requires the component model async builtins feature"
2317
},
24-
{
25-
"type": "module",
26-
"line": 21,
27-
"filename": "async-builtins.3.wasm",
28-
"module_type": "binary"
29-
},
3018
{
3119
"type": "assert_invalid",
32-
"line": 25,
33-
"filename": "async-builtins.4.wasm",
20+
"line": 13,
21+
"filename": "async-builtins.2.wasm",
3422
"module_type": "binary",
3523
"text": "requires the component model async builtins feature"
3624
},
3725
{
3826
"type": "assert_invalid",
39-
"line": 30,
40-
"filename": "async-builtins.5.wasm",
27+
"line": 18,
28+
"filename": "async-builtins.3.wasm",
4129
"module_type": "binary",
4230
"text": "requires the component model async builtins feature"
4331
},
4432
{
45-
"type": "assert_invalid",
46-
"line": 35,
47-
"filename": "async-builtins.6.wasm",
48-
"module_type": "binary",
49-
"text": "requires the component model async builtins feature"
33+
"type": "module",
34+
"line": 23,
35+
"filename": "async-builtins.4.wasm",
36+
"module_type": "binary"
5037
},
5138
{
5239
"type": "assert_invalid",
53-
"line": 40,
54-
"filename": "async-builtins.7.wasm",
40+
"line": 34,
41+
"filename": "async-builtins.5.wasm",
5542
"module_type": "binary",
5643
"text": "requires the component model async builtins feature"
5744
},
5845
{
5946
"type": "module",
60-
"line": 45,
61-
"filename": "async-builtins.8.wasm",
47+
"line": 38,
48+
"filename": "async-builtins.6.wasm",
6249
"module_type": "binary"
6350
}
6451
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
(component
2+
(type $t (;0;) (resource (rep i32)))
3+
(core func (;0;) (canon resource.drop $t))
4+
)

tests/snapshots/local/missing-features/component-model-async/async-stackful.wast.json

+39
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,45 @@
77
"filename": "async-stackful.0.wasm",
88
"module_type": "binary",
99
"text": "requires the async stackful feature"
10+
},
11+
{
12+
"type": "assert_invalid",
13+
"line": 14,
14+
"filename": "async-stackful.1.wasm",
15+
"module_type": "binary",
16+
"text": "requires the component model async stackful feature"
17+
},
18+
{
19+
"type": "module",
20+
"line": 21,
21+
"filename": "async-stackful.2.wasm",
22+
"module_type": "binary"
23+
},
24+
{
25+
"type": "assert_invalid",
26+
"line": 29,
27+
"filename": "async-stackful.3.wasm",
28+
"module_type": "binary",
29+
"text": "requires the component model async stackful feature"
30+
},
31+
{
32+
"type": "module",
33+
"line": 36,
34+
"filename": "async-stackful.4.wasm",
35+
"module_type": "binary"
36+
},
37+
{
38+
"type": "assert_invalid",
39+
"line": 44,
40+
"filename": "async-stackful.5.wasm",
41+
"module_type": "binary",
42+
"text": "requires the component model async stackful feature"
43+
},
44+
{
45+
"type": "module",
46+
"line": 47,
47+
"filename": "async-stackful.6.wasm",
48+
"module_type": "binary"
1049
}
1150
]
1251
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
(component
2+
(core module $libc (;0;)
3+
(memory (;0;) 1)
4+
(export "memory" (memory 0))
5+
)
6+
(core instance $libc (;0;) (instantiate $libc))
7+
(alias core export $libc "memory" (core memory (;0;)))
8+
(core func (;0;) (canon waitable-set.wait (memory 0)))
9+
)

0 commit comments

Comments
 (0)