Skip to content

Commit 2dc1c57

Browse files
authored
Align cancellation with upstream specification (#2162)
* Align cancellation with upstream specification * Adjust binary opcodes for `task.cancel` and `subtask.cancel` * Adjust the core signature for the `yield` intrinsic. * Update another test
1 parent 974e0fd commit 2dc1c57

File tree

9 files changed

+12
-12
lines changed

9 files changed

+12
-12
lines changed

crates/wasm-encoder/src/component/canonicals.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ impl CanonicalFunctionSection {
212212

213213
/// Defines a function to acknowledge cancellation of the current task.
214214
pub fn task_cancel(&mut self) -> &mut Self {
215-
self.bytes.push(0x25);
215+
self.bytes.push(0x05);
216216
self.num_added += 1;
217217
self
218218
}
@@ -255,7 +255,7 @@ impl CanonicalFunctionSection {
255255

256256
/// Defines a function to cancel an in-progress task.
257257
pub fn subtask_cancel(&mut self, async_: bool) -> &mut Self {
258-
self.bytes.push(0x24);
258+
self.bytes.push(0x06);
259259
self.bytes.push(if async_ { 1 } else { 0 });
260260
self.num_added += 1;
261261
self

crates/wasmparser/src/readers/component/canonicals.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,10 +367,10 @@ impl<'a> FromReader<'a> for CanonicalFunction {
367367
},
368368
0x22 => CanonicalFunction::WaitableSetDrop,
369369
0x23 => CanonicalFunction::WaitableJoin,
370-
0x24 => CanonicalFunction::SubtaskCancel {
370+
0x06 => CanonicalFunction::SubtaskCancel {
371371
async_: reader.read()?,
372372
},
373-
0x25 => CanonicalFunction::TaskCancel,
373+
0x05 => CanonicalFunction::TaskCancel,
374374
0x40 => CanonicalFunction::ThreadSpawnRef {
375375
func_ty_index: reader.read()?,
376376
},

crates/wasmparser/src/validator/component.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1268,7 +1268,7 @@ impl ComponentState {
12681268
}
12691269

12701270
self.core_funcs
1271-
.push(types.intern_func_type(FuncType::new([], []), offset));
1271+
.push(types.intern_func_type(FuncType::new([], [ValType::I32]), offset));
12721272
Ok(())
12731273
}
12741274

crates/wit-component/src/dummy.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ fn push_root_async_intrinsics(dst: &mut String) {
379379
(import "$root" "[waitable-set-poll]" (func (param i32 i32) (result i32)))
380380
(import "$root" "[waitable-set-drop]" (func (param i32)))
381381
(import "$root" "[waitable-join]" (func (param i32 i32)))
382-
(import "$root" "[yield]" (func))
382+
(import "$root" "[yield]" (func (result i32)))
383383
(import "$root" "[subtask-drop]" (func (param i32)))
384384
(import "$root" "[subtask-cancel]" (func (param i32) (result i32)))
385385
(import "$root" "[error-context-new-utf8]" (func (param i32 i32) (result i32)))
@@ -395,7 +395,7 @@ fn push_root_async_intrinsics(dst: &mut String) {
395395
;; deferred behind 🚝 or 🚟 upstream
396396
;;(import "$root" "[async-lower][waitable-set-wait]" (func (param i32 i32) (result i32)))
397397
;;(import "$root" "[async-lower][waitable-set-poll]" (func (param i32 i32) (result i32)))
398-
;;(import "$root" "[async-lower][yield]" (func))
398+
;;(import "$root" "[async-lower][yield]" (func (result i32)))
399399
"#,
400400
);
401401
}

crates/wit-component/src/validation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ impl ImportMap {
607607
}
608608

609609
if Some(name) == names.yield_() {
610-
let expected = FuncType::new([], []);
610+
let expected = FuncType::new([], [ValType::I32]);
611611
validate_func_sig(name, &expected, ty)?;
612612
return Ok(Import::Yield { async_ });
613613
}

crates/wit-component/tests/components/async-builtins/component.wat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
(import "$root" "[waitable-set-poll]" (func (;6;) (type 4)))
1717
(import "$root" "[waitable-set-drop]" (func (;7;) (type 0)))
1818
(import "$root" "[waitable-join]" (func (;8;) (type 2)))
19-
(import "$root" "[yield]" (func (;9;) (type 1)))
19+
(import "$root" "[yield]" (func (;9;) (type 3)))
2020
(import "$root" "[subtask-drop]" (func (;10;) (type 0)))
2121
(import "$root" "[subtask-cancel]" (func (;11;) (type 5)))
2222
(import "$root" "[error-context-new-utf8]" (func (;12;) (type 4)))

crates/wit-component/tests/components/async-builtins/module.wat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
(import "$root" "[waitable-set-poll]" (func (param i32 i32) (result i32)))
99
(import "$root" "[waitable-set-drop]" (func (param i32)))
1010
(import "$root" "[waitable-join]" (func (param i32 i32)))
11-
(import "$root" "[yield]" (func))
11+
(import "$root" "[yield]" (func (result i32)))
1212
(import "$root" "[subtask-drop]" (func (param i32)))
1313
(import "$root" "[subtask-cancel]" (func (param i32) (result i32)))
1414
(import "$root" "[error-context-new-utf8]" (func (param i32 i32) (result i32)))

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@
182182
;; yield
183183
(component
184184
(core module $m
185-
(import "" "yield" (func $yield))
185+
(import "" "yield" (func $yield (result i32)))
186186
)
187187
(core func $yield (canon yield async))
188188
(core instance $i (instantiate $m (with "" (instance (export "yield" (func $yield))))))

tests/snapshots/cli/component-model-async/task-builtins.wast/19.print

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
(component
22
(core module $m (;0;)
3-
(type (;0;) (func))
3+
(type (;0;) (func (result i32)))
44
(import "" "yield" (func $yield (;0;) (type 0)))
55
)
66
(core func $yield (;0;) (canon yield async))

0 commit comments

Comments
 (0)