diff --git a/crates/wasm-encoder/src/component/builder.rs b/crates/wasm-encoder/src/component/builder.rs index 57cefe9e0b..236b9643a2 100644 --- a/crates/wasm-encoder/src/component/builder.rs +++ b/crates/wasm-encoder/src/component/builder.rs @@ -708,10 +708,17 @@ impl ComponentBuilder { self.core_funcs.add(Some("thread.new-indirect")) } - /// Declares a new `thread.switch-to` intrinsic. - pub fn thread_switch_to(&mut self, cancellable: bool) -> u32 { - self.canonical_functions().thread_switch_to(cancellable); - self.core_funcs.add(Some("thread.switch-to")) + /// Declares a new `thread.suspend-to-suspended` intrinsic. + pub fn thread_suspend_to_suspended(&mut self, cancellable: bool) -> u32 { + self.canonical_functions() + .thread_suspend_to_suspended(cancellable); + self.core_funcs.add(Some("thread.suspend-to-suspended")) + } + + /// Declares a new `thread.suspend-to` intrinsic. + pub fn thread_suspend_to(&mut self, cancellable: bool) -> u32 { + self.canonical_functions().thread_suspend_to(cancellable); + self.core_funcs.add(Some("thread.suspend-to")) } /// Declares a new `thread.suspend` intrinsic. @@ -720,16 +727,23 @@ impl ComponentBuilder { self.core_funcs.add(Some("thread.suspend")) } - /// Declares a new `thread.resume-later` intrinsic. - pub fn thread_resume_later(&mut self) -> u32 { - self.canonical_functions().thread_resume_later(); - self.core_funcs.add(Some("thread.resume-later")) + /// Declares a new `thread.unsuspend` intrinsic. + pub fn thread_unsuspend(&mut self) -> u32 { + self.canonical_functions().thread_unsuspend(); + self.core_funcs.add(Some("thread.unsuspend")) + } + + /// Declares a new `thread.yield-to-suspended` intrinsic. + pub fn thread_yield_to_suspended(&mut self, cancellable: bool) -> u32 { + self.canonical_functions() + .thread_yield_to_suspended(cancellable); + self.core_funcs.add(Some("thread.yield-to-suspended")) } - /// Declares a new `thread.yield-to` intrinsic. - pub fn thread_yield_to(&mut self, cancellable: bool) -> u32 { - self.canonical_functions().thread_yield_to(cancellable); - self.core_funcs.add(Some("thread.yield-to")) + /// Declares a new `thread.exit` intrinsic. + pub fn thread_exit(&mut self) -> u32 { + self.canonical_functions().thread_exit(); + self.core_funcs.add(Some("thread.exit")) } /// Adds a new custom section to this component. diff --git a/crates/wasm-encoder/src/component/canonicals.rs b/crates/wasm-encoder/src/component/canonicals.rs index 54d0ff45aa..ad08f5cde8 100644 --- a/crates/wasm-encoder/src/component/canonicals.rs +++ b/crates/wasm-encoder/src/component/canonicals.rs @@ -522,9 +522,9 @@ impl CanonicalFunctionSection { self } - /// Declare a new `thread.switch-to` intrinsic, used to switch execution to - /// another thread. - pub fn thread_switch_to(&mut self, cancellable: bool) -> &mut Self { + /// Declare a new `thread.suspend-to-suspended` intrinsic, used to switch execution to + /// another suspended thread. + pub fn thread_suspend_to_suspended(&mut self, cancellable: bool) -> &mut Self { self.bytes.push(0x28); self.bytes.push(if cancellable { 1 } else { 0 }); self.num_added += 1; @@ -540,23 +540,39 @@ impl CanonicalFunctionSection { self } - /// Declare a new `thread.resume-later` intrinsic, used to resume execution + /// Declare a new `thread.suspend-to` intrinsic, used to suspend the current + /// thread and switch to another thread that might not be suspended. + pub fn thread_suspend_to(&mut self, cancellable: bool) -> &mut Self { + self.bytes.push(0x2c); + self.bytes.push(if cancellable { 1 } else { 0 }); + self.num_added += 1; + self + } + + /// Declare a new `thread.unsuspend` intrinsic, used to resume execution /// of the given thread. - pub fn thread_resume_later(&mut self) -> &mut Self { + pub fn thread_unsuspend(&mut self) -> &mut Self { self.bytes.push(0x2a); self.num_added += 1; self } - /// Declare a new `thread.yield-to` intrinsic, used to yield execution to - /// a given thread. - pub fn thread_yield_to(&mut self, cancellable: bool) -> &mut Self { + /// Declare a new `thread.yield-to-suspended` intrinsic, used to yield execution to + /// a given suspended thread. + pub fn thread_yield_to_suspended(&mut self, cancellable: bool) -> &mut Self { self.bytes.push(0x2b); self.bytes.push(if cancellable { 1 } else { 0 }); self.num_added += 1; self } + /// Declare a new `thread.exit` intrinsic, used to terminate the current thread. + pub fn thread_exit(&mut self) -> &mut Self { + self.bytes.push(0x2d); + self.num_added += 1; + self + } + fn encode_options(&mut self, options: O) -> &mut Self where O: IntoIterator, diff --git a/crates/wasm-encoder/src/reencode/component.rs b/crates/wasm-encoder/src/reencode/component.rs index 33737f019d..47c5abf737 100644 --- a/crates/wasm-encoder/src/reencode/component.rs +++ b/crates/wasm-encoder/src/reencode/component.rs @@ -1121,17 +1121,23 @@ pub mod component_utils { let table_index = reencoder.table_index(table_index)?; section.thread_new_indirect(func_ty, table_index); } - wasmparser::CanonicalFunction::ThreadSwitchTo { cancellable } => { - section.thread_switch_to(cancellable); + wasmparser::CanonicalFunction::ThreadSuspendToSuspended { cancellable } => { + section.thread_suspend_to_suspended(cancellable); } wasmparser::CanonicalFunction::ThreadSuspend { cancellable } => { section.thread_suspend(cancellable); } - wasmparser::CanonicalFunction::ThreadResumeLater => { - section.thread_resume_later(); + wasmparser::CanonicalFunction::ThreadSuspendTo { cancellable } => { + section.thread_suspend_to(cancellable); } - wasmparser::CanonicalFunction::ThreadYieldTo { cancellable } => { - section.thread_yield_to(cancellable); + wasmparser::CanonicalFunction::ThreadUnsuspend => { + section.thread_unsuspend(); + } + wasmparser::CanonicalFunction::ThreadYieldToSuspended { cancellable } => { + section.thread_yield_to_suspended(cancellable); + } + wasmparser::CanonicalFunction::ThreadExit => { + section.thread_exit(); } } Ok(()) diff --git a/crates/wasmparser/src/readers/component/canonicals.rs b/crates/wasmparser/src/readers/component/canonicals.rs index 7d09a09197..42e2df71bb 100644 --- a/crates/wasmparser/src/readers/component/canonicals.rs +++ b/crates/wasmparser/src/readers/component/canonicals.rs @@ -274,8 +274,8 @@ pub enum CanonicalFunction { /// The index of the table to use. table_index: u32, }, - /// A function to suspend the current thread and switch to the given thread. - ThreadSwitchTo { + /// A function to suspend the current thread and switch to the given suspended thread. + ThreadSuspendToSuspended { /// Whether or not the thread can be cancelled while awaiting resumption. cancellable: bool, }, @@ -284,13 +284,20 @@ pub enum CanonicalFunction { /// Whether or not the thread can be cancelled while suspended. cancellable: bool, }, + /// A function to suspend the current thread and switch to another thread. + ThreadSuspendTo { + /// Whether or not the thread can be cancelled while suspended. + cancellable: bool, + }, /// A function to schedule the given thread to be resumed later. - ThreadResumeLater, - /// A function to suspend the current thread and switch to the given thread. - ThreadYieldTo { + ThreadUnsuspend, + /// A function to yield to the given suspended thread. + ThreadYieldToSuspended { /// Whether or not the thread can be cancelled while yielding. cancellable: bool, }, + /// A function to terminate the current thread. + ThreadExit, } /// A reader for the canonical section of a WebAssembly component. @@ -406,16 +413,20 @@ impl<'a> FromReader<'a> for CanonicalFunction { func_ty_index: reader.read()?, table_index: reader.read()?, }, - 0x28 => CanonicalFunction::ThreadSwitchTo { + 0x28 => CanonicalFunction::ThreadSuspendToSuspended { cancellable: reader.read()?, }, 0x29 => CanonicalFunction::ThreadSuspend { cancellable: reader.read()?, }, - 0x2a => CanonicalFunction::ThreadResumeLater, - 0x2b => CanonicalFunction::ThreadYieldTo { + 0x2a => CanonicalFunction::ThreadUnsuspend, + 0x2b => CanonicalFunction::ThreadYieldToSuspended { + cancellable: reader.read()?, + }, + 0x2c => CanonicalFunction::ThreadSuspendTo { cancellable: reader.read()?, }, + 0x2d => CanonicalFunction::ThreadExit, 0x06 => CanonicalFunction::SubtaskCancel { async_: reader.read()?, }, diff --git a/crates/wasmparser/src/validator/component.rs b/crates/wasmparser/src/validator/component.rs index c3ab9f4768..1e0ee6a0bc 100644 --- a/crates/wasmparser/src/validator/component.rs +++ b/crates/wasmparser/src/validator/component.rs @@ -1264,17 +1264,20 @@ impl ComponentState { func_ty_index, table_index, } => self.thread_new_indirect(func_ty_index, table_index, types, offset), - CanonicalFunction::ThreadSwitchTo { cancellable } => { - self.thread_switch_to(cancellable, types, offset) + CanonicalFunction::ThreadSuspendToSuspended { cancellable } => { + self.thread_suspend_to_suspended(cancellable, types, offset) } CanonicalFunction::ThreadSuspend { cancellable } => { self.thread_suspend(cancellable, types, offset) } - CanonicalFunction::ThreadResumeLater => self.thread_resume_later(types, offset), - - CanonicalFunction::ThreadYieldTo { cancellable } => { - self.thread_yield_to(cancellable, types, offset) + CanonicalFunction::ThreadSuspendTo { cancellable } => { + self.thread_suspend_to(cancellable, types, offset) + } + CanonicalFunction::ThreadUnsuspend => self.thread_unsuspend(types, offset), + CanonicalFunction::ThreadYieldToSuspended { cancellable } => { + self.thread_yield_to_suspended(cancellable, types, offset) } + CanonicalFunction::ThreadExit => self.thread_exit(types, offset), } } @@ -2203,7 +2206,7 @@ impl ComponentState { Ok(()) } - fn thread_switch_to( + fn thread_suspend_to_suspended( &mut self, _cancellable: bool, types: &mut TypeAlloc, @@ -2212,7 +2215,7 @@ impl ComponentState { if !self.features.cm_threading() { bail!( offset, - "`thread.switch_to` requires the component model threading feature" + "`thread.suspend_to_suspended` requires the component model threading feature" ) } @@ -2238,11 +2241,28 @@ impl ComponentState { Ok(()) } - fn thread_resume_later(&mut self, types: &mut TypeAlloc, offset: usize) -> Result<()> { + fn thread_suspend_to( + &mut self, + _cancellable: bool, + types: &mut TypeAlloc, + offset: usize, + ) -> Result<()> { if !self.features.cm_threading() { bail!( offset, - "`thread.resume_later` requires the component model threading feature" + "`thread.suspend_to` requires the component model threading feature" + ) + } + self.core_funcs + .push(types.intern_func_type(FuncType::new([ValType::I32], [ValType::I32]), offset)); + Ok(()) + } + + fn thread_unsuspend(&mut self, types: &mut TypeAlloc, offset: usize) -> Result<()> { + if !self.features.cm_threading() { + bail!( + offset, + "`thread.unsuspend` requires the component model threading feature" ) } self.core_funcs @@ -2250,7 +2270,7 @@ impl ComponentState { Ok(()) } - fn thread_yield_to( + fn thread_yield_to_suspended( &mut self, _cancellable: bool, types: &mut TypeAlloc, @@ -2259,7 +2279,7 @@ impl ComponentState { if !self.features.cm_threading() { bail!( offset, - "`thread.yield_to` requires the component model threading feature" + "`thread.yield_to_suspended` requires the component model threading feature" ) } self.core_funcs @@ -2267,6 +2287,18 @@ impl ComponentState { Ok(()) } + fn thread_exit(&mut self, types: &mut TypeAlloc, offset: usize) -> Result<()> { + if !self.features.cm_threading() { + bail!( + offset, + "`thread.exit` requires the component model threading feature" + ) + } + self.core_funcs + .push(types.intern_func_type(FuncType::new([], []), offset)); + Ok(()) + } + fn check_local_resource(&self, idx: u32, types: &TypeList, offset: usize) -> Result { let resource = self.resource_at(idx, types, offset)?; match self diff --git a/crates/wasmprinter/src/component.rs b/crates/wasmprinter/src/component.rs index f17262840f..0e1a3808c6 100644 --- a/crates/wasmprinter/src/component.rs +++ b/crates/wasmprinter/src/component.rs @@ -1169,8 +1169,8 @@ impl Printer<'_, '_> { me.end_group() })?; } - CanonicalFunction::ThreadSwitchTo { cancellable } => { - self.print_intrinsic(state, "canon thread.switch-to", &|me, _| { + CanonicalFunction::ThreadSuspendToSuspended { cancellable } => { + self.print_intrinsic(state, "canon thread.suspend-to-suspended", &|me, _| { if cancellable { me.result.write_str(" cancellable")?; } @@ -1185,17 +1185,28 @@ impl Printer<'_, '_> { Ok(()) })?; } - CanonicalFunction::ThreadResumeLater => { - self.print_intrinsic(state, "canon thread.resume-later", &|_, _| Ok(()))?; + CanonicalFunction::ThreadSuspendTo { cancellable } => { + self.print_intrinsic(state, "canon thread.suspend-to", &|me, _| { + if cancellable { + me.result.write_str(" cancellable")?; + } + Ok(()) + })?; + } + CanonicalFunction::ThreadUnsuspend => { + self.print_intrinsic(state, "canon thread.unsuspend", &|_, _| Ok(()))?; } - CanonicalFunction::ThreadYieldTo { cancellable } => { - self.print_intrinsic(state, "canon thread.yield-to", &|me, _| { + CanonicalFunction::ThreadYieldToSuspended { cancellable } => { + self.print_intrinsic(state, "canon thread.yield-to-suspended", &|me, _| { if cancellable { me.result.write_str(" cancellable")?; } Ok(()) })?; } + CanonicalFunction::ThreadExit => { + self.print_intrinsic(state, "canon thread.exit", &|_, _| Ok(()))?; + } } } diff --git a/crates/wast/src/component/binary.rs b/crates/wast/src/component/binary.rs index 90783505fd..6ee46b7716 100644 --- a/crates/wast/src/component/binary.rs +++ b/crates/wast/src/component/binary.rs @@ -519,21 +519,29 @@ impl<'a> Encoder<'a> { self.funcs .thread_new_indirect(info.ty.into(), info.table.idx.into()); } - CoreFuncKind::ThreadSwitchTo(info) => { + CoreFuncKind::ThreadSuspendToSuspended(info) => { self.core_func_names.push(name); - self.funcs.thread_switch_to(info.cancellable); + self.funcs.thread_suspend_to_suspended(info.cancellable); } CoreFuncKind::ThreadSuspend(info) => { self.core_func_names.push(name); self.funcs.thread_suspend(info.cancellable); } - CoreFuncKind::ThreadResumeLater => { + CoreFuncKind::ThreadSuspendTo(info) => { self.core_func_names.push(name); - self.funcs.thread_resume_later(); + self.funcs.thread_suspend_to(info.cancellable); } - CoreFuncKind::ThreadYieldTo(info) => { + CoreFuncKind::ThreadUnsuspend => { self.core_func_names.push(name); - self.funcs.thread_yield_to(info.cancellable); + self.funcs.thread_unsuspend(); + } + CoreFuncKind::ThreadYieldToSuspended(info) => { + self.core_func_names.push(name); + self.funcs.thread_yield_to_suspended(info.cancellable); + } + CoreFuncKind::ThreadExit => { + self.core_func_names.push(name); + self.funcs.thread_exit(); } }, } diff --git a/crates/wast/src/component/func.rs b/crates/wast/src/component/func.rs index 71644251b9..7745c7822c 100644 --- a/crates/wast/src/component/func.rs +++ b/crates/wast/src/component/func.rs @@ -87,10 +87,12 @@ pub enum CoreFuncKind<'a> { WaitableJoin, ThreadIndex, ThreadNewIndirect(CanonThreadNewIndirect<'a>), - ThreadSwitchTo(CanonThreadSwitchTo), + ThreadSuspendToSuspended(CanonThreadSuspendToSuspended), ThreadSuspend(CanonThreadSuspend), - ThreadResumeLater, - ThreadYieldTo(CanonThreadYieldTo), + ThreadSuspendTo(CanonThreadSuspendTo), + ThreadUnsuspend, + ThreadYieldToSuspended(CanonThreadYieldToSuspended), + ThreadExit, } impl<'a> Parse<'a> for CoreFuncKind<'a> { @@ -204,15 +206,20 @@ impl<'a> CoreFuncKind<'a> { Ok(CoreFuncKind::ThreadIndex) } else if l.peek::()? { Ok(CoreFuncKind::ThreadNewIndirect(parser.parse()?)) - } else if l.peek::()? { - Ok(CoreFuncKind::ThreadSwitchTo(parser.parse()?)) + } else if l.peek::()? { + Ok(CoreFuncKind::ThreadSuspendToSuspended(parser.parse()?)) } else if l.peek::()? { Ok(CoreFuncKind::ThreadSuspend(parser.parse()?)) - } else if l.peek::()? { - parser.parse::()?; - Ok(CoreFuncKind::ThreadResumeLater) - } else if l.peek::()? { - Ok(CoreFuncKind::ThreadYieldTo(parser.parse()?)) + } else if l.peek::()? { + Ok(CoreFuncKind::ThreadSuspendTo(parser.parse()?)) + } else if l.peek::()? { + parser.parse::()?; + Ok(CoreFuncKind::ThreadUnsuspend) + } else if l.peek::()? { + Ok(CoreFuncKind::ThreadYieldToSuspended(parser.parse()?)) + } else if l.peek::()? { + parser.parse::()?; + Ok(CoreFuncKind::ThreadExit) } else { Err(l.error()) } @@ -972,16 +979,16 @@ impl<'a> Parse<'a> for CanonThreadNewIndirect<'a> { } } -/// Information relating to the `thread.switch-to` intrinsic. +/// Information relating to the `thread.suspend-to-suspended` intrinsic. #[derive(Debug)] -pub struct CanonThreadSwitchTo { +pub struct CanonThreadSuspendToSuspended { /// Whether the thread can be cancelled while suspended at this point. pub cancellable: bool, } -impl<'a> Parse<'a> for CanonThreadSwitchTo { +impl<'a> Parse<'a> for CanonThreadSuspendToSuspended { fn parse(parser: Parser<'a>) -> Result { - parser.parse::()?; + parser.parse::()?; let cancellable = parser.parse::>()?.is_some(); Ok(Self { cancellable }) } @@ -1001,15 +1008,29 @@ impl<'a> Parse<'a> for CanonThreadSuspend { } } -/// Information relating to the `thread.yield-to` intrinsic. +/// Information relating to the `thread.suspend-to` intrinsic. #[derive(Debug)] -pub struct CanonThreadYieldTo { +pub struct CanonThreadSuspendTo { + /// Whether the thread can be cancelled while suspended at this point. + pub cancellable: bool, +} +impl<'a> Parse<'a> for CanonThreadSuspendTo { + fn parse(parser: Parser<'a>) -> Result { + parser.parse::()?; + let cancellable = parser.parse::>()?.is_some(); + Ok(Self { cancellable }) + } +} + +/// Information relating to the `thread.yield-to-suspended` intrinsic. +#[derive(Debug)] +pub struct CanonThreadYieldToSuspended { /// Whether the thread can be cancelled while yielding at this point. pub cancellable: bool, } -impl<'a> Parse<'a> for CanonThreadYieldTo { +impl<'a> Parse<'a> for CanonThreadYieldToSuspended { fn parse(parser: Parser<'a>) -> Result { - parser.parse::()?; + parser.parse::()?; let cancellable = parser.parse::>()?.is_some(); Ok(Self { cancellable }) } diff --git a/crates/wast/src/component/resolve.rs b/crates/wast/src/component/resolve.rs index e7d5316c1b..20751f72c9 100644 --- a/crates/wast/src/component/resolve.rs +++ b/crates/wast/src/component/resolve.rs @@ -475,10 +475,12 @@ impl<'a> Resolver<'a> { self.resolve_ns(&mut info.ty, Ns::CoreType)?; self.core_item_ref(&mut info.table)?; } - CoreFuncKind::ThreadSwitchTo(_) => {} + CoreFuncKind::ThreadSuspendToSuspended(_) => {} CoreFuncKind::ThreadSuspend(_) => {} - CoreFuncKind::ThreadResumeLater => {} - CoreFuncKind::ThreadYieldTo(_) => {} + CoreFuncKind::ThreadSuspendTo(_) => {} + CoreFuncKind::ThreadUnsuspend => {} + CoreFuncKind::ThreadYieldToSuspended(_) => {} + CoreFuncKind::ThreadExit => {} }, } diff --git a/crates/wast/src/lib.rs b/crates/wast/src/lib.rs index 4558b31b13..44ad340e32 100644 --- a/crates/wast/src/lib.rs +++ b/crates/wast/src/lib.rs @@ -604,10 +604,12 @@ pub mod kw { custom_keyword!(context_set = "context.set"); custom_keyword!(thread_index = "thread.index"); custom_keyword!(thread_new_indirect = "thread.new-indirect"); - custom_keyword!(thread_switch_to = "thread.switch-to"); + custom_keyword!(thread_suspend_to_suspended = "thread.suspend-to-suspended"); custom_keyword!(thread_suspend = "thread.suspend"); - custom_keyword!(thread_resume_later = "thread.resume-later"); - custom_keyword!(thread_yield_to = "thread.yield-to"); + custom_keyword!(thread_suspend_to = "thread.suspend-to"); + custom_keyword!(thread_unsuspend = "thread.unsuspend"); + custom_keyword!(thread_yield_to_suspended = "thread.yield-to-suspended"); + custom_keyword!(thread_exit = "thread.exit"); custom_keyword!(cancellable); } diff --git a/crates/wit-component/src/encoding.rs b/crates/wit-component/src/encoding.rs index cc5b084cba..2e2a44f59b 100644 --- a/crates/wit-component/src/encoding.rs +++ b/crates/wit-component/src/encoding.rs @@ -1997,20 +1997,28 @@ impl<'a> EncodingState<'a> { func_ty: FuncType::new([ValType::I32], []), }, )), - Import::ThreadSwitchTo { cancellable } => { - let index = self.component.thread_switch_to(*cancellable); + Import::ThreadSuspendToSuspended { cancellable } => { + let index = self.component.thread_suspend_to_suspended(*cancellable); Ok((ExportKind::Func, index)) } Import::ThreadSuspend { cancellable } => { let index = self.component.thread_suspend(*cancellable); Ok((ExportKind::Func, index)) } - Import::ThreadResumeLater => { - let index = self.component.thread_resume_later(); + Import::ThreadSuspendTo { cancellable } => { + let index = self.component.thread_suspend_to(*cancellable); Ok((ExportKind::Func, index)) } - Import::ThreadYieldTo { cancellable } => { - let index = self.component.thread_yield_to(*cancellable); + Import::ThreadUnsuspend => { + let index = self.component.thread_unsuspend(); + Ok((ExportKind::Func, index)) + } + Import::ThreadYieldToSuspended { cancellable } => { + let index = self.component.thread_yield_to_suspended(*cancellable); + Ok((ExportKind::Func, index)) + } + Import::ThreadExit => { + let index = self.component.thread_exit(); Ok((ExportKind::Func, index)) } } @@ -2625,10 +2633,12 @@ impl<'a> Shims<'a> { | Import::ContextGet(_) | Import::ContextSet(_) | Import::ThreadIndex - | Import::ThreadSwitchTo { .. } + | Import::ThreadSuspendToSuspended { .. } | Import::ThreadSuspend { .. } - | Import::ThreadResumeLater - | Import::ThreadYieldTo { .. } => {} + | Import::ThreadSuspendTo { .. } + | Import::ThreadUnsuspend + | Import::ThreadYieldToSuspended { .. } + | Import::ThreadExit => {} // If `task.return` needs to be indirect then generate a shim // for it, otherwise skip the shim and let it get materialized diff --git a/crates/wit-component/src/encoding/world.rs b/crates/wit-component/src/encoding/world.rs index 08313e81fb..fd2af939d9 100644 --- a/crates/wit-component/src/encoding/world.rs +++ b/crates/wit-component/src/encoding/world.rs @@ -433,10 +433,12 @@ impl<'a> ComponentWorld<'a> { | Import::ExportedTaskCancel | Import::ThreadIndex | Import::ThreadNewIndirect { .. } - | Import::ThreadSwitchTo { .. } + | Import::ThreadSuspendToSuspended { .. } | Import::ThreadSuspend { .. } - | Import::ThreadResumeLater - | Import::ThreadYieldTo { .. } => {} + | Import::ThreadSuspendTo { .. } + | Import::ThreadUnsuspend + | Import::ThreadYieldToSuspended { .. } + | Import::ThreadExit => {} } } } diff --git a/crates/wit-component/src/validation.rs b/crates/wit-component/src/validation.rs index 54ee808b99..c6852c3d29 100644 --- a/crates/wit-component/src/validation.rs +++ b/crates/wit-component/src/validation.rs @@ -431,10 +431,10 @@ pub enum Import { /// This allows the guest to create a new thread running a specified function. ThreadNewIndirect, - /// A `canon thread.switch-to` intrinsic. + /// A `canon thread.suspend-to-suspended` intrinsic. /// - /// This allows the guest to switch execution to another thread. - ThreadSwitchTo { cancellable: bool }, + /// This allows the guest to switch execution to another suspended thread. + ThreadSuspendToSuspended { cancellable: bool }, /// A `canon thread.suspend` intrinsic. /// @@ -442,15 +442,26 @@ pub enum Import { /// an unspecified thread. ThreadSuspend { cancellable: bool }, - /// A `canon thread.resume-later` intrinsic. + /// A `canon thread.suspend-to` intrinsic. + /// + /// This allows the guest to suspend the current thread and switch to another thread + /// that might not be suspended. + ThreadSuspendTo { cancellable: bool }, + + /// A `canon thread.unsuspend` intrinsic. /// /// This allows the guest to mark a suspended thread for later resumption. - ThreadResumeLater, + ThreadUnsuspend, - /// A `canon thread.yield-to` intrinsic. + /// A `canon thread.yield-to-suspended` intrinsic. /// - /// This allows the guest to suspend, yielding execution to a specified thread. - ThreadYieldTo { cancellable: bool }, + /// This allows the guest to suspend, yielding execution to a specified suspended thread. + ThreadYieldToSuspended { cancellable: bool }, + + /// A `canon thread.exit` intrinsic. + /// + /// This allows the guest to terminate the current thread. + ThreadExit, } impl ImportMap { @@ -700,10 +711,10 @@ impl ImportMap { validate_func_sig(name, &expected, ty)?; return Ok(Import::ThreadNewIndirect); } - if let Some(info) = names.thread_switch_to(name) { + if let Some(info) = names.thread_suspend_to_suspended(name) { let expected = FuncType::new([ValType::I32], [ValType::I32]); validate_func_sig(name, &expected, ty)?; - return Ok(Import::ThreadSwitchTo { + return Ok(Import::ThreadSuspendToSuspended { cancellable: info.cancellable, }); } @@ -714,18 +725,30 @@ impl ImportMap { cancellable: info.cancellable, }); } - if names.thread_resume_later(name) { + if let Some(info) = names.thread_suspend_to(name) { + let expected = FuncType::new([ValType::I32], [ValType::I32]); + validate_func_sig(name, &expected, ty)?; + return Ok(Import::ThreadSuspendTo { + cancellable: info.cancellable, + }); + } + if names.thread_unsuspend(name) { let expected = FuncType::new([ValType::I32], []); validate_func_sig(name, &expected, ty)?; - return Ok(Import::ThreadResumeLater); + return Ok(Import::ThreadUnsuspend); } - if let Some(info) = names.thread_yield_to(name) { + if let Some(info) = names.thread_yield_to_suspended(name) { let expected = FuncType::new([ValType::I32], [ValType::I32]); validate_func_sig(name, &expected, ty)?; - return Ok(Import::ThreadYieldTo { + return Ok(Import::ThreadYieldToSuspended { cancellable: info.cancellable, }); } + if names.thread_exit(name) { + let expected = FuncType::new([], []); + validate_func_sig(name, &expected, ty)?; + return Ok(Import::ThreadExit); + } let (key_name, abi) = names.world_key_name_and_abi(name); let key = WorldKey::Name(key_name.to_string()); @@ -1642,10 +1665,12 @@ trait NameMangling { ) -> Option; fn thread_index(&self, name: &str) -> bool; fn thread_new_indirect(&self, name: &str) -> bool; - fn thread_switch_to(&self, name: &str) -> Option>; + fn thread_suspend_to_suspended(&self, name: &str) -> Option>; fn thread_suspend(&self, name: &str) -> Option>; - fn thread_resume_later(&self, name: &str) -> bool; - fn thread_yield_to(&self, name: &str) -> Option>; + fn thread_suspend_to(&self, name: &str) -> Option>; + fn thread_unsuspend(&self, name: &str) -> bool; + fn thread_yield_to_suspended(&self, name: &str) -> Option>; + fn thread_exit(&self, name: &str) -> bool; fn module_to_interface( &self, module: &str, @@ -1780,18 +1805,24 @@ impl NameMangling for Standard { fn thread_new_indirect(&self, _name: &str) -> bool { false } - fn thread_switch_to(&self, _name: &str) -> Option> { + fn thread_suspend_to_suspended(&self, _name: &str) -> Option> { None } fn thread_suspend(&self, _name: &str) -> Option> { None } - fn thread_resume_later(&self, _name: &str) -> bool { + fn thread_suspend_to(&self, _name: &str) -> Option> { + None + } + fn thread_unsuspend(&self, _name: &str) -> bool { false } - fn thread_yield_to(&self, _name: &str) -> Option> { + fn thread_yield_to_suspended(&self, _name: &str) -> Option> { None } + fn thread_exit(&self, _name: &str) -> bool { + false + } fn future_new( &self, _lookup_context: &PayloadLookupContext, @@ -2239,17 +2270,23 @@ impl NameMangling for Legacy { // For now, we'll fix the type of the start function and the table to extract it from name == "[thread-new-indirect-v0]" } - fn thread_switch_to(&self, name: &str) -> Option> { - self.match_with_cancellable_prefix(name, "[thread-switch-to]") + fn thread_suspend_to_suspended(&self, name: &str) -> Option> { + self.match_with_cancellable_prefix(name, "[thread-suspend-to-suspended]") } fn thread_suspend(&self, name: &str) -> Option> { self.match_with_cancellable_prefix(name, "[thread-suspend]") } - fn thread_resume_later(&self, name: &str) -> bool { - name == "[thread-resume-later]" + fn thread_suspend_to(&self, name: &str) -> Option> { + self.match_with_cancellable_prefix(name, "[thread-suspend-to]") + } + fn thread_unsuspend(&self, name: &str) -> bool { + name == "[thread-unsuspend]" + } + fn thread_yield_to_suspended(&self, name: &str) -> Option> { + self.match_with_cancellable_prefix(name, "[thread-yield-to-suspended]") } - fn thread_yield_to(&self, name: &str) -> Option> { - self.match_with_cancellable_prefix(name, "[thread-yield-to]") + fn thread_exit(&self, name: &str) -> bool { + name == "[thread-exit]" } fn future_new(&self, lookup_context: &PayloadLookupContext, name: &str) -> Option { self.prefixed_payload(lookup_context, name, "[future-new-") diff --git a/crates/wit-component/tests/components/threading/component.wat b/crates/wit-component/tests/components/threading/component.wat index 8c41292e3d..00958aac21 100644 --- a/crates/wit-component/tests/components/threading/component.wat +++ b/crates/wit-component/tests/components/threading/component.wat @@ -14,29 +14,31 @@ (import "$root" "[context-set-1]" (func (;4;) (type $thread-start-func-ty))) (import "$root" "[thread-index]" (func (;5;) (type 3))) (import "$root" "[thread-new-indirect-v0]" (func (;6;) (type 4))) - (import "$root" "[thread-switch-to]" (func (;7;) (type 5))) + (import "$root" "[thread-suspend-to-suspended]" (func (;7;) (type 5))) (import "$root" "[thread-suspend]" (func (;8;) (type 3))) - (import "$root" "[thread-resume-later]" (func (;9;) (type $thread-start-func-ty))) - (import "$root" "[thread-yield-to]" (func (;10;) (type 5))) + (import "$root" "[thread-unsuspend]" (func (;9;) (type $thread-start-func-ty))) + (import "$root" "[thread-yield-to-suspended]" (func (;10;) (type 5))) + (import "$root" "[thread-suspend-to]" (func (;11;) (type 5))) + (import "$root" "[thread-exit]" (func (;12;) (type 1))) (table (;0;) 1 1 funcref) (memory (;0;) 1) - (export "thread_main" (func 11)) - (export "[async-lift-stackful]foo" (func 12)) - (export "[async-lift-stackful]foo:foo/bar#foo" (func 13)) + (export "thread_main" (func 12)) + (export "[async-lift-stackful]foo" (func 13)) + (export "[async-lift-stackful]foo:foo/bar#foo" (func 14)) (export "memory" (memory 0)) (export "__indirect_function_table" (table 0)) - (export "cabi_realloc" (func 14)) + (export "cabi_realloc" (func 15)) (elem (;0;) (i32.const 0) func 0) - (func (;11;) (type $thread-start-func-ty) (param i32) + (func (;12;) (type $thread-start-func-ty) (param i32) unreachable ) - (func (;12;) (type 2) (param i32 i32) + (func (;13;) (type 2) (param i32 i32) unreachable ) - (func (;13;) (type 2) (param i32 i32) + (func (;14;) (type 2) (param i32 i32) unreachable ) - (func (;14;) (type 6) (param i32 i32 i32 i32) (result i32) + (func (;15;) (type 6) (param i32 i32 i32 i32) (result i32) unreachable ) (@producers @@ -101,19 +103,21 @@ (core func $"context.set 1" (;4;) (canon context.set i32 1)) (core func $thread.index (;5;) (canon thread.index)) (alias core export $wit-component-shim-instance "2" (core func $thread.new-indirect (;6;))) - (core func $thread.switch-to (;7;) (canon thread.switch-to)) + (core func $thread.suspend-to-suspended (;7;) (canon thread.suspend-to-suspended)) (core func $thread.suspend (;8;) (canon thread.suspend)) - (core func $thread.resume-later (;9;) (canon thread.resume-later)) - (core func $thread.yield-to (;10;) (canon thread.yield-to)) + (core func $thread.unsuspend (;9;) (canon thread.unsuspend)) + (core func $thread.yield-to-suspended (;10;) (canon thread.yield-to-suspended)) + (core func $thread.suspend-to (;11;) (canon thread.suspend-to)) (core instance $$root (;3;) (export "[context-get-1]" (func $"context.get 1")) (export "[context-set-1]" (func $"context.set 1")) (export "[thread-index]" (func $thread.index)) (export "[thread-new-indirect-v0]" (func $thread.new-indirect)) - (export "[thread-switch-to]" (func $thread.switch-to)) + (export "[thread-suspend-to-suspended]" (func $thread.suspend-to-suspended)) (export "[thread-suspend]" (func $thread.suspend)) - (export "[thread-resume-later]" (func $thread.resume-later)) - (export "[thread-yield-to]" (func $thread.yield-to)) + (export "[thread-unsuspend]" (func $thread.unsuspend)) + (export "[thread-yield-to-suspended]" (func $thread.yield-to-suspended)) + (export "[thread-suspend-to]" (func $thread.suspend-to)) ) (core instance $main (;4;) (instantiate $main (with "[export]$root" (instance $"[export]$root")) @@ -123,28 +127,28 @@ ) (alias core export $main "memory" (core memory $memory (;0;))) (alias core export $wit-component-shim-instance "$imports" (core table $"shim table" (;0;))) - (alias core export $main "cabi_realloc" (core func $realloc (;11;))) - (core func $task.return (;12;) (canon task.return (result string) (memory $memory) string-encoding=utf8)) - (core func $"#core-func13 task.return" (@name "task.return") (;13;) (canon task.return (result string) (memory $memory) string-encoding=utf8)) + (alias core export $main "cabi_realloc" (core func $realloc (;12;))) + (core func $task.return (;13;) (canon task.return (result string) (memory $memory) string-encoding=utf8)) + (core func $"#core-func14 task.return" (@name "task.return") (;14;) (canon task.return (result string) (memory $memory) string-encoding=utf8)) (core type $thread-start (;0;) (func (param i32))) (alias core export $main "__indirect_function_table" (core table $indirect-function-table (;1;))) - (core func $"#core-func14 thread.new-indirect" (@name "thread.new-indirect") (;14;) (canon thread.new-indirect $thread-start (table $indirect-function-table))) + (core func $"#core-func15 thread.new-indirect" (@name "thread.new-indirect") (;15;) (canon thread.new-indirect $thread-start (table $indirect-function-table))) (core instance $fixup-args (;5;) (export "$imports" (table $"shim table")) (export "0" (func $task.return)) - (export "1" (func $"#core-func13 task.return")) - (export "2" (func $"#core-func14 thread.new-indirect")) + (export "1" (func $"#core-func14 task.return")) + (export "2" (func $"#core-func15 thread.new-indirect")) ) (core instance $fixup (;6;) (instantiate $wit-component-fixup (with "" (instance $fixup-args)) ) ) (type (;0;) (func (param "s" string) (result string))) - (alias core export $main "[async-lift-stackful]foo" (core func $"[async-lift-stackful]foo" (;15;))) + (alias core export $main "[async-lift-stackful]foo" (core func $"[async-lift-stackful]foo" (;16;))) (func $foo (;0;) (type 0) (canon lift (core func $"[async-lift-stackful]foo") (memory $memory) (realloc $realloc) string-encoding=utf8 async)) (export $"#func1 foo" (@name "foo") (;1;) "foo" (func $foo)) (type (;1;) (func (param "s" string) (result string))) - (alias core export $main "[async-lift-stackful]foo:foo/bar#foo" (core func $"[async-lift-stackful]foo:foo/bar#foo" (;16;))) + (alias core export $main "[async-lift-stackful]foo:foo/bar#foo" (core func $"[async-lift-stackful]foo:foo/bar#foo" (;17;))) (func $"#func2 foo" (@name "foo") (;2;) (type 1) (canon lift (core func $"[async-lift-stackful]foo:foo/bar#foo") (memory $memory) (realloc $realloc) string-encoding=utf8 async)) (component $foo:foo/bar-shim-component (;0;) (type (;0;) (func (param "s" string) (result string))) diff --git a/crates/wit-component/tests/components/threading/module.wat b/crates/wit-component/tests/components/threading/module.wat index 4b4099ed48..2c93e617b5 100644 --- a/crates/wit-component/tests/components/threading/module.wat +++ b/crates/wit-component/tests/components/threading/module.wat @@ -7,10 +7,12 @@ (import "$root" "[context-set-1]" (func (param i32))) (import "$root" "[thread-index]" (func (result i32))) (import "$root" "[thread-new-indirect-v0]" (func (param i32 i32) (result i32))) - (import "$root" "[thread-switch-to]" (func (param i32) (result i32))) + (import "$root" "[thread-suspend-to-suspended]" (func (param i32) (result i32))) (import "$root" "[thread-suspend]" (func (result i32))) - (import "$root" "[thread-resume-later]" (func (param i32))) - (import "$root" "[thread-yield-to]" (func (param i32) (result i32))) + (import "$root" "[thread-unsuspend]" (func (param i32))) + (import "$root" "[thread-yield-to-suspended]" (func (param i32) (result i32))) + (import "$root" "[thread-suspend-to]" (func (param i32) (result i32))) + (import "$root" "[thread-exit]" (func)) (func (export "thread_main") (param i32) unreachable) (func (export "[async-lift-stackful]foo") (param i32 i32) unreachable) (func (export "[async-lift-stackful]foo:foo/bar#foo") (param i32 i32) unreachable) diff --git a/src/bin/wasm-tools/dump.rs b/src/bin/wasm-tools/dump.rs index c0f0b7c2eb..47907d3ab3 100644 --- a/src/bin/wasm-tools/dump.rs +++ b/src/bin/wasm-tools/dump.rs @@ -499,12 +499,12 @@ impl<'a> Dump<'a> { | CanonicalFunction::ErrorContextDrop | CanonicalFunction::ThreadIndex | CanonicalFunction::ThreadNewIndirect { .. } - | CanonicalFunction::ThreadSwitchTo { .. } + | CanonicalFunction::ThreadSuspendToSuspended { .. } | CanonicalFunction::ThreadSuspend { .. } - | CanonicalFunction::ThreadResumeLater { .. } - | CanonicalFunction::ThreadYieldTo { .. } => { - ("core func", &mut i.core_funcs) - } + | CanonicalFunction::ThreadSuspendTo { .. } + | CanonicalFunction::ThreadUnsuspend { .. } + | CanonicalFunction::ThreadYieldToSuspended { .. } + | CanonicalFunction::ThreadExit => ("core func", &mut i.core_funcs), }; write!(me.state, "[{} {}] {:?}", name, inc(col), f)?; diff --git a/tests/cli/component-model/async/threading.wast b/tests/cli/component-model/async/threading.wast index 9cb6e2a606..0a78aeed6e 100644 --- a/tests/cli/component-model/async/threading.wast +++ b/tests/cli/component-model/async/threading.wast @@ -116,25 +116,46 @@ "type mismatch for export `thread.index` of module instantiation argument ``" ) -;; thread.switch-to +;; thread.suspend-to-suspended (component (core module $m - (import "" "thread.switch-to" (func $thread.switch-to (param i32) (result i32))) + (import "" "thread.suspend-to-suspended" (func $thread.suspend-to-suspended (param i32) (result i32))) ) - (core func $thread.switch-to (canon thread.switch-to cancellable)) - (core instance $i (instantiate $m (with "" (instance (export "thread.switch-to" (func $thread.switch-to)))))) + (core func $thread.suspend-to-suspended (canon thread.suspend-to-suspended cancellable)) + (core instance $i (instantiate $m (with "" (instance (export "thread.suspend-to-suspended" (func $thread.suspend-to-suspended)))))) ) -;; thread.switch-to; incorrect type +;; thread.suspend-to-suspended; incorrect type (assert_invalid (component (core module $m - (import "" "thread.switch-to" (func $thread.switch-to (param i32))) + (import "" "thread.suspend-to-suspended" (func $thread.suspend-to-suspended (param i32))) ) - (core func $thread.switch-to (canon thread.switch-to cancellable)) - (core instance $i (instantiate $m (with "" (instance (export "thread.switch-to" (func $thread.switch-to)))))) + (core func $thread.suspend-to-suspended (canon thread.suspend-to-suspended cancellable)) + (core instance $i (instantiate $m (with "" (instance (export "thread.suspend-to-suspended" (func $thread.suspend-to-suspended)))))) ) - "type mismatch for export `thread.switch-to` of module instantiation argument ``" + "type mismatch for export `thread.suspend-to-suspended` of module instantiation argument ``" +) + +;; thread.suspend-to +(component + (core module $m + (import "" "thread.suspend-to" (func $thread.suspend-to (param i32) (result i32))) + ) + (core func $thread.suspend-to (canon thread.suspend-to cancellable)) + (core instance $i (instantiate $m (with "" (instance (export "thread.suspend-to" (func $thread.suspend-to)))))) +) + +;; thread.suspend-to; incorrect type +(assert_invalid + (component + (core module $m + (import "" "thread.suspend-to" (func $thread.suspend-to (param i32))) + ) + (core func $thread.suspend-to (canon thread.suspend-to cancellable)) + (core instance $i (instantiate $m (with "" (instance (export "thread.suspend-to" (func $thread.suspend-to)))))) + ) + "type mismatch for export `thread.suspend-to` of module instantiation argument ``" ) ;; different forms of canonical intrinsics @@ -154,20 +175,47 @@ (core type $start (func (param i32))) (core func (canon thread.new-indirect $start (table $start-table))) (canon thread.new-indirect $start (table $start-table) (core func)) - (core func (canon thread.switch-to)) - (canon thread.switch-to (core func)) - (core func (canon thread.switch-to cancellable)) - (canon thread.switch-to cancellable (core func)) + (core func (canon thread.suspend-to-suspended)) + (canon thread.suspend-to-suspended (core func)) + (core func (canon thread.suspend-to-suspended cancellable)) + (canon thread.suspend-to-suspended cancellable (core func)) (core func (canon thread.suspend)) (canon thread.suspend (core func)) (core func (canon thread.suspend cancellable)) (canon thread.suspend cancellable (core func)) - (core func (canon thread.resume-later)) - (canon thread.resume-later (core func)) - (core func (canon thread.yield-to)) - (canon thread.yield-to (core func)) - (core func (canon thread.yield-to cancellable)) - (canon thread.yield-to cancellable (core func)) + (core func (canon thread.suspend-to)) + (canon thread.suspend-to (core func)) + (core func (canon thread.suspend-to cancellable)) + (canon thread.suspend-to cancellable (core func)) + (core func (canon thread.unsuspend)) + (canon thread.unsuspend (core func)) + (core func (canon thread.yield-to-suspended)) + (canon thread.yield-to-suspended (core func)) + (core func (canon thread.yield-to-suspended cancellable)) + (canon thread.yield-to-suspended cancellable (core func)) + (core func (canon thread.exit)) + (canon thread.exit (core func)) +) + +;; thread.exit +(component + (core module $m + (import "" "thread.exit" (func $thread.exit)) + ) + (core func $thread.exit (canon thread.exit)) + (core instance $i (instantiate $m (with "" (instance (export "thread.exit" (func $thread.exit)))))) +) + +;; thread.exit; incorrect type +(assert_invalid + (component + (core module $m + (import "" "thread.exit" (func $thread.exit (param i32))) + ) + (core func $thread.exit (canon thread.exit)) + (core instance $i (instantiate $m (with "" (instance (export "thread.exit" (func $thread.exit)))))) + ) + "type mismatch for export `thread.exit` of module instantiation argument ``" ) (component diff --git a/tests/cli/missing-features/component-model/threading.wast b/tests/cli/missing-features/component-model/threading.wast index 37f30b08cd..5a04f2b63a 100644 --- a/tests/cli/missing-features/component-model/threading.wast +++ b/tests/cli/missing-features/component-model/threading.wast @@ -6,8 +6,10 @@ (component (core func (canon thread.index)) (core func (canon thread.new-indirect 0 (table 0))) - (core func (canon thread.switch-to)) + (core func (canon thread.suspend-to-suspended)) (core func (canon thread.suspend)) - (core func (canon thread.resume-later)) - (core func (canon thread.yield-to))) + (core func (canon thread.suspend-to)) + (core func (canon thread.unsuspend)) + (core func (canon thread.yield-to-suspended)) + (core func (canon thread.exit))) "requires the component model threading feature") \ No newline at end of file diff --git a/tests/snapshots/cli/component-model/async/threading.wast.json b/tests/snapshots/cli/component-model/async/threading.wast.json index bd326cdbec..037cc3f444 100644 --- a/tests/snapshots/cli/component-model/async/threading.wast.json +++ b/tests/snapshots/cli/component-model/async/threading.wast.json @@ -99,18 +99,44 @@ "line": 130, "filename": "threading.14.wasm", "module_type": "binary", - "text": "type mismatch for export `thread.switch-to` of module instantiation argument ``" + "text": "type mismatch for export `thread.suspend-to-suspended` of module instantiation argument ``" }, { "type": "module", - "line": 142, + "line": 141, "filename": "threading.15.wasm", "module_type": "binary" }, { - "type": "module", - "line": 173, + "type": "assert_invalid", + "line": 151, "filename": "threading.16.wasm", + "module_type": "binary", + "text": "type mismatch for export `thread.suspend-to` of module instantiation argument ``" + }, + { + "type": "module", + "line": 163, + "filename": "threading.17.wasm", + "module_type": "binary" + }, + { + "type": "module", + "line": 201, + "filename": "threading.18.wasm", + "module_type": "binary" + }, + { + "type": "assert_invalid", + "line": 211, + "filename": "threading.19.wasm", + "module_type": "binary", + "text": "type mismatch for export `thread.exit` of module instantiation argument ``" + }, + { + "type": "module", + "line": 221, + "filename": "threading.20.wasm", "module_type": "binary" } ] diff --git a/tests/snapshots/cli/component-model/async/threading.wast/13.print b/tests/snapshots/cli/component-model/async/threading.wast/13.print index 6c92cb7183..c24fc5ac0d 100644 --- a/tests/snapshots/cli/component-model/async/threading.wast/13.print +++ b/tests/snapshots/cli/component-model/async/threading.wast/13.print @@ -1,11 +1,11 @@ (component (core module $m (;0;) (type (;0;) (func (param i32) (result i32))) - (import "" "thread.switch-to" (func $thread.switch-to (;0;) (type 0))) + (import "" "thread.suspend-to-suspended" (func $thread.suspend-to-suspended (;0;) (type 0))) ) - (core func $thread.switch-to (;0;) (canon thread.switch-to cancellable)) + (core func $thread.suspend-to-suspended (;0;) (canon thread.suspend-to-suspended cancellable)) (core instance (;0;) - (export "thread.switch-to" (func $thread.switch-to)) + (export "thread.suspend-to-suspended" (func $thread.suspend-to-suspended)) ) (core instance $i (;1;) (instantiate $m (with "" (instance 0)) diff --git a/tests/snapshots/cli/component-model/async/threading.wast/15.print b/tests/snapshots/cli/component-model/async/threading.wast/15.print index 1ba76b7c35..60d965ceba 100644 --- a/tests/snapshots/cli/component-model/async/threading.wast/15.print +++ b/tests/snapshots/cli/component-model/async/threading.wast/15.print @@ -1,29 +1,14 @@ (component (core module $m (;0;) - (table (;0;) 1 funcref) - (export "start-table" (table 0)) + (type (;0;) (func (param i32) (result i32))) + (import "" "thread.suspend-to" (func $thread.suspend-to (;0;) (type 0))) + ) + (core func $thread.suspend-to (;0;) (canon thread.suspend-to cancellable)) + (core instance (;0;) + (export "thread.suspend-to" (func $thread.suspend-to)) + ) + (core instance $i (;1;) (instantiate $m + (with "" (instance 0)) + ) ) - (core instance $i (;0;) (instantiate $m)) - (alias core export $i "start-table" (core table $start-table (;0;))) - (core func (;0;) (canon context.get i32 1)) - (core func (;1;) (canon context.get i32 1)) - (core func (;2;) (canon context.set i32 1)) - (core func (;3;) (canon context.set i32 1)) - (core type $start (;0;) (func (param i32))) - (core func (;4;) (canon thread.new-indirect $start (table $start-table))) - (core func (;5;) (canon thread.new-indirect $start (table $start-table))) - (core func (;6;) (canon thread.switch-to)) - (core func (;7;) (canon thread.switch-to)) - (core func (;8;) (canon thread.switch-to cancellable)) - (core func (;9;) (canon thread.switch-to cancellable)) - (core func (;10;) (canon thread.suspend)) - (core func (;11;) (canon thread.suspend)) - (core func (;12;) (canon thread.suspend cancellable)) - (core func (;13;) (canon thread.suspend cancellable)) - (core func (;14;) (canon thread.resume-later)) - (core func (;15;) (canon thread.resume-later)) - (core func (;16;) (canon thread.yield-to)) - (core func (;17;) (canon thread.yield-to)) - (core func (;18;) (canon thread.yield-to cancellable)) - (core func (;19;) (canon thread.yield-to cancellable)) ) diff --git a/tests/snapshots/cli/component-model/async/threading.wast/17.print b/tests/snapshots/cli/component-model/async/threading.wast/17.print new file mode 100644 index 0000000000..3c5bcde99c --- /dev/null +++ b/tests/snapshots/cli/component-model/async/threading.wast/17.print @@ -0,0 +1,35 @@ +(component + (core module $m (;0;) + (table (;0;) 1 funcref) + (export "start-table" (table 0)) + ) + (core instance $i (;0;) (instantiate $m)) + (alias core export $i "start-table" (core table $start-table (;0;))) + (core func (;0;) (canon context.get i32 1)) + (core func (;1;) (canon context.get i32 1)) + (core func (;2;) (canon context.set i32 1)) + (core func (;3;) (canon context.set i32 1)) + (core type $start (;0;) (func (param i32))) + (core func (;4;) (canon thread.new-indirect $start (table $start-table))) + (core func (;5;) (canon thread.new-indirect $start (table $start-table))) + (core func (;6;) (canon thread.suspend-to-suspended)) + (core func (;7;) (canon thread.suspend-to-suspended)) + (core func (;8;) (canon thread.suspend-to-suspended cancellable)) + (core func (;9;) (canon thread.suspend-to-suspended cancellable)) + (core func (;10;) (canon thread.suspend)) + (core func (;11;) (canon thread.suspend)) + (core func (;12;) (canon thread.suspend cancellable)) + (core func (;13;) (canon thread.suspend cancellable)) + (core func (;14;) (canon thread.suspend-to)) + (core func (;15;) (canon thread.suspend-to)) + (core func (;16;) (canon thread.suspend-to cancellable)) + (core func (;17;) (canon thread.suspend-to cancellable)) + (core func (;18;) (canon thread.unsuspend)) + (core func (;19;) (canon thread.unsuspend)) + (core func (;20;) (canon thread.yield-to-suspended)) + (core func (;21;) (canon thread.yield-to-suspended)) + (core func (;22;) (canon thread.yield-to-suspended cancellable)) + (core func (;23;) (canon thread.yield-to-suspended cancellable)) + (core func (;24;) (canon thread.exit)) + (core func (;25;) (canon thread.exit)) +) diff --git a/tests/snapshots/cli/component-model/async/threading.wast/18.print b/tests/snapshots/cli/component-model/async/threading.wast/18.print new file mode 100644 index 0000000000..3d215e7d18 --- /dev/null +++ b/tests/snapshots/cli/component-model/async/threading.wast/18.print @@ -0,0 +1,14 @@ +(component + (core module $m (;0;) + (type (;0;) (func)) + (import "" "thread.exit" (func $thread.exit (;0;) (type 0))) + ) + (core func $thread.exit (;0;) (canon thread.exit)) + (core instance (;0;) + (export "thread.exit" (func $thread.exit)) + ) + (core instance $i (;1;) (instantiate $m + (with "" (instance 0)) + ) + ) +) diff --git a/tests/snapshots/cli/component-model/async/threading.wast/16.print b/tests/snapshots/cli/component-model/async/threading.wast/20.print similarity index 100% rename from tests/snapshots/cli/component-model/async/threading.wast/16.print rename to tests/snapshots/cli/component-model/async/threading.wast/20.print