Skip to content

Commit 2b446bd

Browse files
authored
Ungate cancellable on some async intrinsics (#2436)
Accounting for WebAssembly/component-model#606
1 parent 66e106b commit 2b446bd

11 files changed

Lines changed: 161 additions & 131 deletions

File tree

crates/wasmparser/src/validator/component.rs

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,9 +1196,7 @@ impl ComponentState {
11961196
CanonicalFunction::TaskCancel => self.task_cancel(types, offset),
11971197
CanonicalFunction::ContextGet(i) => self.context_get(i, types, offset),
11981198
CanonicalFunction::ContextSet(i) => self.context_set(i, types, offset),
1199-
CanonicalFunction::ThreadYield { cancellable } => {
1200-
self.thread_yield(cancellable, types, offset)
1201-
}
1199+
CanonicalFunction::ThreadYield { cancellable: _ } => self.thread_yield(types, offset),
12021200
CanonicalFunction::SubtaskDrop => self.subtask_drop(types, offset),
12031201
CanonicalFunction::SubtaskCancel { async_ } => {
12041202
self.subtask_cancel(async_, types, offset)
@@ -1250,13 +1248,13 @@ impl ComponentState {
12501248
CanonicalFunction::ErrorContextDrop => self.error_context_drop(types, offset),
12511249
CanonicalFunction::WaitableSetNew => self.waitable_set_new(types, offset),
12521250
CanonicalFunction::WaitableSetWait {
1253-
cancellable,
1251+
cancellable: _,
12541252
memory,
1255-
} => self.waitable_set_wait(cancellable, memory, types, offset),
1253+
} => self.waitable_set_wait(memory, types, offset),
12561254
CanonicalFunction::WaitableSetPoll {
1257-
cancellable,
1255+
cancellable: _,
12581256
memory,
1259-
} => self.waitable_set_poll(cancellable, memory, types, offset),
1257+
} => self.waitable_set_poll(memory, types, offset),
12601258
CanonicalFunction::WaitableSetDrop => self.waitable_set_drop(types, offset),
12611259
CanonicalFunction::WaitableJoin => self.waitable_join(types, offset),
12621260
CanonicalFunction::ThreadIndex => self.thread_index(types, offset),
@@ -1535,24 +1533,13 @@ impl ComponentState {
15351533
Ok(())
15361534
}
15371535

1538-
fn thread_yield(
1539-
&mut self,
1540-
cancellable: bool,
1541-
types: &mut TypeAlloc,
1542-
offset: usize,
1543-
) -> Result<()> {
1536+
fn thread_yield(&mut self, types: &mut TypeAlloc, offset: usize) -> Result<()> {
15441537
if !self.features.cm_async() {
15451538
bail!(
15461539
offset,
15471540
"`thread.yield` requires the component model async feature"
15481541
)
15491542
}
1550-
if cancellable && !self.features.cm_async_stackful() {
1551-
bail!(
1552-
offset,
1553-
"cancellable `thread.yield` requires the component model async stackful feature"
1554-
)
1555-
}
15561543

15571544
self.core_funcs
15581545
.push(types.intern_func_type(FuncType::new([], [ValType::I32]), offset));
@@ -2053,7 +2040,6 @@ impl ComponentState {
20532040

20542041
fn waitable_set_wait(
20552042
&mut self,
2056-
cancellable: bool,
20572043
memory: u32,
20582044
types: &mut TypeAlloc,
20592045
offset: usize,
@@ -2064,12 +2050,6 @@ impl ComponentState {
20642050
"`waitable-set.wait` requires the component model async feature"
20652051
)
20662052
}
2067-
if cancellable && !self.features.cm_async_stackful() {
2068-
bail!(
2069-
offset,
2070-
"cancellable `waitable-set.wait` requires the component model async stackful feature"
2071-
)
2072-
}
20732053

20742054
self.cabi_memory_at(memory, offset)?;
20752055

@@ -2080,7 +2060,6 @@ impl ComponentState {
20802060

20812061
fn waitable_set_poll(
20822062
&mut self,
2083-
cancellable: bool,
20842063
memory: u32,
20852064
types: &mut TypeAlloc,
20862065
offset: usize,
@@ -2091,12 +2070,6 @@ impl ComponentState {
20912070
"`waitable-set.poll` requires the component model async feature"
20922071
)
20932072
}
2094-
if cancellable && !self.features.cm_async_stackful() {
2095-
bail!(
2096-
offset,
2097-
"cancellable `waitable-set.poll` requires the component model async stackful feature"
2098-
)
2099-
}
21002073

21012074
self.cabi_memory_at(memory, offset)?;
21022075

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

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -148,17 +148,15 @@
148148
"type mismatch for export `waitable-set.wait` of module instantiation argument ``"
149149
)
150150

151-
(assert_invalid
152-
(component
153-
(core module $libc (memory (export "memory") 1))
154-
(core instance $libc (instantiate $libc))
155-
(core module $m
156-
(import "" "waitable-set.wait" (func $waitable-set-wait (param i32 i32) (result i32)))
157-
)
158-
(core func $waitable-set-wait (canon waitable-set.wait cancellable (memory $libc "memory")))
159-
(core instance $i (instantiate $m (with "" (instance (export "waitable-set.wait" (func $waitable-set-wait))))))
151+
(component
152+
(core module $libc (memory (export "memory") 1))
153+
(core instance $libc (instantiate $libc))
154+
(core module $m
155+
(import "" "waitable-set.wait" (func $waitable-set-wait (param i32 i32) (result i32)))
160156
)
161-
"requires the component model async stackful feature")
157+
(core func $waitable-set-wait (canon waitable-set.wait cancellable (memory $libc "memory")))
158+
(core instance $i (instantiate $m (with "" (instance (export "waitable-set.wait" (func $waitable-set-wait))))))
159+
)
162160

163161
;; waitable-set.poll
164162
(component
@@ -170,17 +168,15 @@
170168
(core func $waitable-set-poll (canon waitable-set.poll (memory $libc "memory")))
171169
(core instance $i (instantiate $m (with "" (instance (export "waitable-set.poll" (func $waitable-set-poll))))))
172170
)
173-
(assert_invalid
174-
(component
175-
(core module $libc (memory (export "memory") 1))
176-
(core instance $libc (instantiate $libc))
177-
(core module $m
178-
(import "" "waitable-set.poll" (func $waitable-set-poll (param i32 i32) (result i32)))
179-
)
180-
(core func $waitable-set-poll (canon waitable-set.poll cancellable (memory $libc "memory")))
181-
(core instance $i (instantiate $m (with "" (instance (export "waitable-set.poll" (func $waitable-set-poll))))))
171+
(component
172+
(core module $libc (memory (export "memory") 1))
173+
(core instance $libc (instantiate $libc))
174+
(core module $m
175+
(import "" "waitable-set.poll" (func $waitable-set-poll (param i32 i32) (result i32)))
182176
)
183-
"requires the component model async stackful feature")
177+
(core func $waitable-set-poll (canon waitable-set.poll cancellable (memory $libc "memory")))
178+
(core instance $i (instantiate $m (with "" (instance (export "waitable-set.poll" (func $waitable-set-poll))))))
179+
)
184180

185181
;; waitable-set.poll; incorrect type
186182
(assert_invalid
@@ -298,15 +294,13 @@
298294
(core instance $i (instantiate $m (with "" (instance (export "thread.yield" (func $thread.yield))))))
299295
)
300296

301-
(assert_invalid
302-
(component
303-
(core module $m
304-
(import "" "thread.yield" (func $thread.yield (result i32)))
305-
)
306-
(core func $thread.yield (canon thread.yield cancellable))
307-
(core instance $i (instantiate $m (with "" (instance (export "thread.yield" (func $thread.yield))))))
297+
(component
298+
(core module $m
299+
(import "" "thread.yield" (func $thread.yield (result i32)))
308300
)
309-
"requires the component model async stackful feature")
301+
(core func $thread.yield (canon thread.yield cancellable))
302+
(core instance $i (instantiate $m (with "" (instance (export "thread.yield" (func $thread.yield))))))
303+
)
310304

311305
;; thread.yield; incorrect type
312306
(assert_invalid

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

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,11 @@
1313
"requires the component model async stackful feature")
1414

1515
;; waitable-set.wait cancellable
16-
(assert_invalid
17-
(component
18-
(core module $libc (memory (export "memory") 1))
19-
(core instance $libc (instantiate $libc))
20-
(core func (canon waitable-set.wait cancellable (memory $libc "memory")))
21-
)
22-
"requires the component model async stackful feature")
16+
(component
17+
(core module $libc (memory (export "memory") 1))
18+
(core instance $libc (instantiate $libc))
19+
(core func (canon waitable-set.wait cancellable (memory $libc "memory")))
20+
)
2321

2422
(component
2523
(core module $libc (memory (export "memory") 1))
@@ -28,13 +26,11 @@
2826
)
2927

3028
;; waitable-set.poll cancellable
31-
(assert_invalid
32-
(component
33-
(core module $libc (memory (export "memory") 1))
34-
(core instance $libc (instantiate $libc))
35-
(core func (canon waitable-set.poll cancellable (memory $libc "memory")))
36-
)
37-
"requires the component model async stackful feature")
29+
(component
30+
(core module $libc (memory (export "memory") 1))
31+
(core instance $libc (instantiate $libc))
32+
(core func (canon waitable-set.poll cancellable (memory $libc "memory")))
33+
)
3834

3935
(component
4036
(core module $libc (memory (export "memory") 1))
@@ -43,8 +39,6 @@
4339
)
4440

4541
;; thread.yield
46-
(assert_invalid
47-
(component (core func (canon thread.yield cancellable)))
48-
"requires the component model async stackful feature")
42+
(component (core func (canon thread.yield cancellable)))
4943

50-
(component (core func (canon thread.yield)))
44+
(component (core func (canon thread.yield)))

0 commit comments

Comments
 (0)