Skip to content

Commit e2d3556

Browse files
authored
Remove cancellable immediate from component model intrinsics (#2630)
This follows the spec update in WebAssembly/component-model#716 where the behavior here isn't quite working and it's not known to be used anywhere. This leaves the binary format encoding to avoid breaking that to avoid actually breaking anything in practice.
1 parent 2affea5 commit e2d3556

41 files changed

Lines changed: 350 additions & 1426 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

ci/generate-spec-tests.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ fn copy_test(src: &Path, dst: &Path, features: fn(&Path) -> &str) {
9191
// Temporary exception until WebAssembly/component-model#704 lands
9292
Some("kebab.wast") => "FAIL",
9393

94+
// Temporary until WebAssembly/component-model#716 lands
95+
Some("cancellable.wast") => "FAIL",
96+
Some("binary.wast") if dst.ends_with("components/binary/binary.wast") => "FAIL",
97+
9498
Some(_) | None => "RUN",
9599
};
96100

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

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -664,16 +664,14 @@ impl ComponentBuilder {
664664
}
665665

666666
/// Declares a new `waitable-set.wait` intrinsic.
667-
pub fn waitable_set_wait(&mut self, cancellable: bool, memory: u32) -> u32 {
668-
self.canonical_functions()
669-
.waitable_set_wait(cancellable, memory);
667+
pub fn waitable_set_wait(&mut self, memory: u32) -> u32 {
668+
self.canonical_functions().waitable_set_wait(memory);
670669
self.core_funcs.add(Some("waitable-set.wait"))
671670
}
672671

673672
/// Declares a new `waitable-set.poll` intrinsic.
674-
pub fn waitable_set_poll(&mut self, cancellable: bool, memory: u32) -> u32 {
675-
self.canonical_functions()
676-
.waitable_set_poll(cancellable, memory);
673+
pub fn waitable_set_poll(&mut self, memory: u32) -> u32 {
674+
self.canonical_functions().waitable_set_poll(memory);
677675
self.core_funcs.add(Some("waitable-set.poll"))
678676
}
679677

@@ -709,42 +707,38 @@ impl ComponentBuilder {
709707
}
710708

711709
/// Declares a new `thread.suspend` intrinsic.
712-
pub fn thread_suspend(&mut self, cancellable: bool) -> u32 {
713-
self.canonical_functions().thread_suspend(cancellable);
710+
pub fn thread_suspend(&mut self) -> u32 {
711+
self.canonical_functions().thread_suspend();
714712
self.core_funcs.add(Some("thread.suspend"))
715713
}
716714

717715
/// Declares a new `thread.yield` intrinsic.
718-
pub fn thread_yield(&mut self, cancellable: bool) -> u32 {
719-
self.canonical_functions().thread_yield(cancellable);
716+
pub fn thread_yield(&mut self) -> u32 {
717+
self.canonical_functions().thread_yield();
720718
self.core_funcs.add(Some("thread.yield"))
721719
}
722720

723721
/// Declares a new `thread.suspend-then-resume` intrinsic.
724-
pub fn thread_suspend_then_resume(&mut self, cancellable: bool) -> u32 {
725-
self.canonical_functions()
726-
.thread_suspend_then_resume(cancellable);
722+
pub fn thread_suspend_then_resume(&mut self) -> u32 {
723+
self.canonical_functions().thread_suspend_then_resume();
727724
self.core_funcs.add(Some("thread.suspend-then-resume"))
728725
}
729726

730727
/// Declares a new `thread.yield-then-resume` intrinsic.
731-
pub fn thread_yield_then_resume(&mut self, cancellable: bool) -> u32 {
732-
self.canonical_functions()
733-
.thread_yield_then_resume(cancellable);
728+
pub fn thread_yield_then_resume(&mut self) -> u32 {
729+
self.canonical_functions().thread_yield_then_resume();
734730
self.core_funcs.add(Some("thread.yield-then-resume"))
735731
}
736732

737733
/// Declares a new `thread.suspend-then-promote` intrinsic.
738-
pub fn thread_suspend_then_promote(&mut self, cancellable: bool) -> u32 {
739-
self.canonical_functions()
740-
.thread_suspend_then_promote(cancellable);
734+
pub fn thread_suspend_then_promote(&mut self) -> u32 {
735+
self.canonical_functions().thread_suspend_then_promote();
741736
self.core_funcs.add(Some("thread.suspend-then-promote"))
742737
}
743738

744739
/// Declares a new `thread.yield-then-promote` intrinsic.
745-
pub fn thread_yield_then_promote(&mut self, cancellable: bool) -> u32 {
746-
self.canonical_functions()
747-
.thread_yield_then_promote(cancellable);
740+
pub fn thread_yield_then_promote(&mut self) -> u32 {
741+
self.canonical_functions().thread_yield_then_promote();
748742
self.core_funcs.add(Some("thread.yield-then-resume"))
749743
}
750744

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -455,19 +455,19 @@ impl CanonicalFunctionSection {
455455

456456
/// Declare a new `waitable-set.wait` intrinsic, used to block on a
457457
/// `waitable-set`.
458-
pub fn waitable_set_wait(&mut self, async_: bool, memory: u32) -> &mut Self {
458+
pub fn waitable_set_wait(&mut self, memory: u32) -> &mut Self {
459459
self.bytes.push(0x20);
460-
self.bytes.push(if async_ { 1 } else { 0 });
460+
self.bytes.push(0);
461461
memory.encode(&mut self.bytes);
462462
self.num_added += 1;
463463
self
464464
}
465465

466466
/// Declare a new `waitable-set.wait` intrinsic, used to check, without
467467
/// blocking, if anything in a `waitable-set` is ready.
468-
pub fn waitable_set_poll(&mut self, async_: bool, memory: u32) -> &mut Self {
468+
pub fn waitable_set_poll(&mut self, memory: u32) -> &mut Self {
469469
self.bytes.push(0x21);
470-
self.bytes.push(if async_ { 1 } else { 0 });
470+
self.bytes.push(0);
471471
memory.encode(&mut self.bytes);
472472
self.num_added += 1;
473473
self
@@ -515,49 +515,49 @@ impl CanonicalFunctionSection {
515515
}
516516

517517
/// Declare a new `thread.suspend` intrinsic.
518-
pub fn thread_suspend(&mut self, cancellable: bool) -> &mut Self {
518+
pub fn thread_suspend(&mut self) -> &mut Self {
519519
self.bytes.push(0x29);
520-
self.bytes.push(if cancellable { 1 } else { 0 });
520+
self.bytes.push(0);
521521
self.num_added += 1;
522522
self
523523
}
524524

525525
/// Declare a new `thread.yield` intrinsic.
526-
pub fn thread_yield(&mut self, cancellable: bool) -> &mut Self {
526+
pub fn thread_yield(&mut self) -> &mut Self {
527527
self.bytes.push(0x0c);
528-
self.bytes.push(if cancellable { 1 } else { 0 });
528+
self.bytes.push(0);
529529
self.num_added += 1;
530530
self
531531
}
532532

533533
/// Declare a new `thread.suspend-then-resume` intrinsic.
534-
pub fn thread_suspend_then_resume(&mut self, cancellable: bool) -> &mut Self {
534+
pub fn thread_suspend_then_resume(&mut self) -> &mut Self {
535535
self.bytes.push(0x2a);
536-
self.bytes.push(if cancellable { 1 } else { 0 });
536+
self.bytes.push(0);
537537
self.num_added += 1;
538538
self
539539
}
540540

541541
/// Declare a new `thread.yield-then-resume` intrinsic.
542-
pub fn thread_yield_then_resume(&mut self, cancellable: bool) -> &mut Self {
542+
pub fn thread_yield_then_resume(&mut self) -> &mut Self {
543543
self.bytes.push(0x2b);
544-
self.bytes.push(if cancellable { 1 } else { 0 });
544+
self.bytes.push(0);
545545
self.num_added += 1;
546546
self
547547
}
548548

549549
/// Declare a new `thread.suspend-then-promote` intrinsic.
550-
pub fn thread_suspend_then_promote(&mut self, cancellable: bool) -> &mut Self {
550+
pub fn thread_suspend_then_promote(&mut self) -> &mut Self {
551551
self.bytes.push(0x2c);
552-
self.bytes.push(if cancellable { 1 } else { 0 });
552+
self.bytes.push(0);
553553
self.num_added += 1;
554554
self
555555
}
556556

557557
/// Declare a new `thread.yield-then-promote` intrinsic.
558-
pub fn thread_yield_then_promote(&mut self, cancellable: bool) -> &mut Self {
558+
pub fn thread_yield_then_promote(&mut self) -> &mut Self {
559559
self.bytes.push(0x2d);
560-
self.bytes.push(if cancellable { 1 } else { 0 });
560+
self.bytes.push(0);
561561
self.num_added += 1;
562562
self
563563
}

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

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,17 +1091,11 @@ pub mod component_utils {
10911091
wasmparser::CanonicalFunction::WaitableSetNew => {
10921092
section.waitable_set_new();
10931093
}
1094-
wasmparser::CanonicalFunction::WaitableSetWait {
1095-
cancellable,
1096-
memory,
1097-
} => {
1098-
section.waitable_set_wait(cancellable, reencoder.memory_index(memory)?);
1094+
wasmparser::CanonicalFunction::WaitableSetWait { memory } => {
1095+
section.waitable_set_wait(reencoder.memory_index(memory)?);
10991096
}
1100-
wasmparser::CanonicalFunction::WaitableSetPoll {
1101-
cancellable,
1102-
memory,
1103-
} => {
1104-
section.waitable_set_poll(cancellable, reencoder.memory_index(memory)?);
1097+
wasmparser::CanonicalFunction::WaitableSetPoll { memory } => {
1098+
section.waitable_set_poll(reencoder.memory_index(memory)?);
11051099
}
11061100
wasmparser::CanonicalFunction::WaitableSetDrop => {
11071101
section.waitable_set_drop();
@@ -1123,23 +1117,23 @@ pub mod component_utils {
11231117
wasmparser::CanonicalFunction::ThreadResumeLater => {
11241118
section.thread_resume_later();
11251119
}
1126-
wasmparser::CanonicalFunction::ThreadSuspend { cancellable } => {
1127-
section.thread_suspend(cancellable);
1120+
wasmparser::CanonicalFunction::ThreadSuspend => {
1121+
section.thread_suspend();
11281122
}
1129-
wasmparser::CanonicalFunction::ThreadYield { cancellable } => {
1130-
section.thread_yield(cancellable);
1123+
wasmparser::CanonicalFunction::ThreadYield => {
1124+
section.thread_yield();
11311125
}
1132-
wasmparser::CanonicalFunction::ThreadSuspendThenResume { cancellable } => {
1133-
section.thread_suspend_then_resume(cancellable);
1126+
wasmparser::CanonicalFunction::ThreadSuspendThenResume => {
1127+
section.thread_suspend_then_resume();
11341128
}
1135-
wasmparser::CanonicalFunction::ThreadYieldThenResume { cancellable } => {
1136-
section.thread_yield_then_resume(cancellable);
1129+
wasmparser::CanonicalFunction::ThreadYieldThenResume => {
1130+
section.thread_yield_then_resume();
11371131
}
1138-
wasmparser::CanonicalFunction::ThreadSuspendThenPromote { cancellable } => {
1139-
section.thread_suspend_then_promote(cancellable);
1132+
wasmparser::CanonicalFunction::ThreadSuspendThenPromote => {
1133+
section.thread_suspend_then_promote();
11401134
}
1141-
wasmparser::CanonicalFunction::ThreadYieldThenPromote { cancellable } => {
1142-
section.thread_yield_then_promote(cancellable);
1135+
wasmparser::CanonicalFunction::ThreadYieldThenPromote => {
1136+
section.thread_yield_then_promote();
11431137
}
11441138
}
11451139
Ok(())

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

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,7 @@ pub enum CanonicalFunction {
123123
},
124124
/// A function which yields control to the host so that other tasks are able
125125
/// to make progress, if any.
126-
ThreadYield {
127-
/// If `true`, indicates the caller instance maybe reentered.
128-
cancellable: bool,
129-
},
126+
ThreadYield,
130127
/// A function to drop a specified task which has completed.
131128
SubtaskDrop,
132129
/// A function to cancel an in-progress task.
@@ -257,17 +254,11 @@ pub enum CanonicalFunction {
257254
WaitableSetNew,
258255
/// A function to block on the next item within a `waitable-set`.
259256
WaitableSetWait {
260-
/// Whether or not the guest can be reentered while calling this
261-
/// function.
262-
cancellable: bool,
263257
/// Which memory the results of this operation are stored in.
264258
memory: u32,
265259
},
266260
/// A function to check if any items are ready within a `waitable-set`.
267261
WaitableSetPoll {
268-
/// Whether or not the guest can be reentered while calling this
269-
/// function.
270-
cancellable: bool,
271262
/// Which memory the results of this operation are stored in.
272263
memory: u32,
273264
},
@@ -287,30 +278,15 @@ pub enum CanonicalFunction {
287278
/// A function to schedule the given thread to be resumed later.
288279
ThreadResumeLater,
289280
/// A function to suspend the current thread, immediately yielding to any transitive async-lowered calling component.
290-
ThreadSuspend {
291-
/// Whether or not the thread can be cancelled while suspended.
292-
cancellable: bool,
293-
},
281+
ThreadSuspend,
294282
/// The `thread.suspend-then-resume` intrinsic
295-
ThreadSuspendThenResume {
296-
/// Whether or not the thread can be cancelled while awaiting resumption.
297-
cancellable: bool,
298-
},
283+
ThreadSuspendThenResume,
299284
/// The `thread.yield-then-resume` intrinsic
300-
ThreadYieldThenResume {
301-
/// Whether or not the thread can be cancelled while yielding.
302-
cancellable: bool,
303-
},
285+
ThreadYieldThenResume,
304286
/// The `thread.suspend-then-promote` intrinsic
305-
ThreadSuspendThenPromote {
306-
/// Whether or not the thread can be cancelled while suspended.
307-
cancellable: bool,
308-
},
287+
ThreadSuspendThenPromote,
309288
/// The `thread.yield-then-promote` intrinsic
310-
ThreadYieldThenPromote {
311-
/// Whether or not the thread can be cancelled while yielding.
312-
cancellable: bool,
313-
},
289+
ThreadYieldThenPromote,
314290
}
315291

316292
/// A reader for the canonical section of a WebAssembly component.
@@ -409,14 +385,18 @@ impl<'a> FromReader<'a> for CanonicalFunction {
409385
0x1e => CanonicalFunction::ErrorContextDrop,
410386

411387
0x1f => CanonicalFunction::WaitableSetNew,
412-
0x20 => CanonicalFunction::WaitableSetWait {
413-
cancellable: reader.read()?,
414-
memory: reader.read()?,
415-
},
416-
0x21 => CanonicalFunction::WaitableSetPoll {
417-
cancellable: reader.read()?,
418-
memory: reader.read()?,
419-
},
388+
0x20 => {
389+
read_legacy_cancellation_byte(reader)?;
390+
CanonicalFunction::WaitableSetWait {
391+
memory: reader.read()?,
392+
}
393+
}
394+
0x21 => {
395+
read_legacy_cancellation_byte(reader)?;
396+
CanonicalFunction::WaitableSetPoll {
397+
memory: reader.read()?,
398+
}
399+
}
420400
0x22 => CanonicalFunction::WaitableSetDrop,
421401
0x23 => CanonicalFunction::WaitableJoin,
422402
0x26 => CanonicalFunction::ThreadIndex,
@@ -425,24 +405,30 @@ impl<'a> FromReader<'a> for CanonicalFunction {
425405
table_index: reader.read()?,
426406
},
427407
0x28 => CanonicalFunction::ThreadResumeLater,
428-
0x29 => CanonicalFunction::ThreadSuspend {
429-
cancellable: reader.read()?,
430-
},
431-
0x0c => CanonicalFunction::ThreadYield {
432-
cancellable: reader.read()?,
433-
},
434-
0x2a => CanonicalFunction::ThreadSuspendThenResume {
435-
cancellable: reader.read()?,
436-
},
437-
0x2b => CanonicalFunction::ThreadYieldThenResume {
438-
cancellable: reader.read()?,
439-
},
440-
0x2c => CanonicalFunction::ThreadSuspendThenPromote {
441-
cancellable: reader.read()?,
442-
},
443-
0x2d => CanonicalFunction::ThreadYieldThenPromote {
444-
cancellable: reader.read()?,
445-
},
408+
0x29 => {
409+
read_legacy_cancellation_byte(reader)?;
410+
CanonicalFunction::ThreadSuspend
411+
}
412+
0x0c => {
413+
read_legacy_cancellation_byte(reader)?;
414+
CanonicalFunction::ThreadYield
415+
}
416+
0x2a => {
417+
read_legacy_cancellation_byte(reader)?;
418+
CanonicalFunction::ThreadSuspendThenResume
419+
}
420+
0x2b => {
421+
read_legacy_cancellation_byte(reader)?;
422+
CanonicalFunction::ThreadYieldThenResume
423+
}
424+
0x2c => {
425+
read_legacy_cancellation_byte(reader)?;
426+
CanonicalFunction::ThreadSuspendThenPromote
427+
}
428+
0x2d => {
429+
read_legacy_cancellation_byte(reader)?;
430+
CanonicalFunction::ThreadYieldThenPromote
431+
}
446432
0x40 => CanonicalFunction::ThreadSpawnRef {
447433
func_ty_index: reader.read()?,
448434
},
@@ -462,6 +448,20 @@ fn read_opts(reader: &mut BinaryReader<'_>) -> Result<Box<[CanonicalOption]>> {
462448
.collect::<Result<_>>()
463449
}
464450

451+
fn read_legacy_cancellation_byte(reader: &mut BinaryReader<'_>) -> Result<()> {
452+
Ok(match reader.read_u8()? {
453+
0x00 => {}
454+
0x01 => {
455+
return reader.invalid_leading_byte(
456+
0x01,
457+
"zero byte; this was historically accepted \
458+
as `cancellable` until WebAssembly/component-model#716",
459+
);
460+
}
461+
x => return reader.invalid_leading_byte(x, "zero byte"),
462+
})
463+
}
464+
465465
impl<'a> FromReader<'a> for CanonicalOption {
466466
fn from_reader(reader: &mut BinaryReader<'a>) -> Result<Self> {
467467
Ok(match reader.read_u8()? {

0 commit comments

Comments
 (0)