Skip to content

Commit 787f633

Browse files
authored
disallow post-return functions for async lifts (#1976)
I can't find where in the spec this is disallowed, but Luke agreed that it _should_ be disallowed, so we'll update the spec to make that explicit. Indeed, we hope to deprecate post-return functions for both sync and async lifts in favor of `task.return`. Signed-off-by: Joel Dice <[email protected]>
1 parent 9c514f5 commit 787f633

File tree

4 files changed

+64
-10
lines changed

4 files changed

+64
-10
lines changed

crates/wasmparser/src/validator/component.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2045,6 +2045,13 @@ impl ComponentState {
20452045
bail!(offset, "cannot specify callback without lifting async")
20462046
}
20472047

2048+
if post_return.is_some() && async_ {
2049+
bail!(
2050+
offset,
2051+
"cannot specify post-return function when lifting async"
2052+
)
2053+
}
2054+
20482055
if info.requires_memory && memory.is_none() {
20492056
return Err(BinaryReaderError::new(
20502057
"canonical option `memory` is required",

tests/local/component-model-async/lift.wast

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,22 @@
1010
)
1111
)
1212

13+
;; async lift; no callback; with post-return
14+
(assert_invalid
15+
(component
16+
(core module $m
17+
(func (export "foo") (param i32) unreachable)
18+
(func (export "post-return-foo") unreachable)
19+
)
20+
(core instance $i (instantiate $m))
21+
22+
(func (export "foo") (param "p1" u32) (result u32)
23+
(canon lift (core func $i "foo") async (post-return (func $i "post-return-foo")))
24+
)
25+
)
26+
"cannot specify post-return function when lifting async"
27+
)
28+
1329
;; async lift; with callback
1430
(component
1531
(core module $m
@@ -39,6 +55,23 @@
3955
"canonical option `callback` uses a core function with an incorrect signature"
4056
)
4157

58+
;; async lift; with callback and post-return
59+
(assert_invalid
60+
(component
61+
(core module $m
62+
(func (export "callback") (param i32 i32 i32 i32) (result i32) unreachable)
63+
(func (export "foo") (param i32) (result i32) unreachable)
64+
(func (export "post-return-foo") (param i32) unreachable)
65+
)
66+
(core instance $i (instantiate $m))
67+
68+
(func (export "foo") (param "p1" u32) (result u32)
69+
(canon lift (core func $i "foo") async (callback (func $i "callback")) (post-return (func $i "post-return-foo")))
70+
)
71+
)
72+
"cannot specify post-return function when lifting async"
73+
)
74+
4275
;; async lift; with incorrectly-typed core function
4376
(assert_invalid
4477
(component

tests/snapshots/local/component-model-async/lift.wast.json

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,37 +8,51 @@
88
"module_type": "binary"
99
},
1010
{
11-
"type": "module",
12-
"line": 14,
11+
"type": "assert_invalid",
12+
"line": 15,
1313
"filename": "lift.1.wasm",
14-
"module_type": "binary"
14+
"module_type": "binary",
15+
"text": "cannot specify post-return function when lifting async"
1516
},
1617
{
17-
"type": "assert_invalid",
18-
"line": 28,
18+
"type": "module",
19+
"line": 30,
1920
"filename": "lift.2.wasm",
20-
"module_type": "binary",
21-
"text": "canonical option `callback` uses a core function with an incorrect signature"
21+
"module_type": "binary"
2222
},
2323
{
2424
"type": "assert_invalid",
2525
"line": 44,
2626
"filename": "lift.3.wasm",
2727
"module_type": "binary",
28-
"text": "lowered parameter types `[I32]` do not match parameter types `[I32, I32]` of core function 0"
28+
"text": "canonical option `callback` uses a core function with an incorrect signature"
2929
},
3030
{
3131
"type": "assert_invalid",
3232
"line": 60,
3333
"filename": "lift.4.wasm",
3434
"module_type": "binary",
35-
"text": "core instance 0 has no export named `callback`"
35+
"text": "cannot specify post-return function when lifting async"
3636
},
3737
{
3838
"type": "assert_invalid",
39-
"line": 75,
39+
"line": 77,
4040
"filename": "lift.5.wasm",
4141
"module_type": "binary",
42+
"text": "lowered parameter types `[I32]` do not match parameter types `[I32, I32]` of core function 0"
43+
},
44+
{
45+
"type": "assert_invalid",
46+
"line": 93,
47+
"filename": "lift.6.wasm",
48+
"module_type": "binary",
49+
"text": "core instance 0 has no export named `callback`"
50+
},
51+
{
52+
"type": "assert_invalid",
53+
"line": 108,
54+
"filename": "lift.7.wasm",
55+
"module_type": "binary",
4256
"text": "cannot specify callback without lifting async"
4357
}
4458
]
File renamed without changes.

0 commit comments

Comments
 (0)