Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions crates/cranelift/src/compiler/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -784,12 +784,30 @@ impl<'a> TrampolineCompiler<'a> {
},
);
}
Trampoline::ThreadSwitchTo {
Trampoline::ThreadSuspendToSuspended {
instance,
cancellable,
} => {
self.translate_libcall(
host::thread_switch_to,
host::thread_suspend_to_suspended,
TrapSentinel::NegativeOne,
WasmArgs::InRegisters,
|me, params| {
params.push(me.index_value(*instance));
params.push(
me.builder
.ins()
.iconst(ir::types::I8, i64::from(*cancellable)),
);
},
);
}
Trampoline::ThreadSuspendTo {
instance,
cancellable,
} => {
self.translate_libcall(
host::thread_suspend_to,
TrapSentinel::NegativeOne,
WasmArgs::InRegisters,
|me, params| {
Expand Down Expand Up @@ -820,22 +838,22 @@ impl<'a> TrampolineCompiler<'a> {
},
);
}
Trampoline::ThreadResumeLater { instance } => {
Trampoline::ThreadUnsuspend { instance } => {
self.translate_libcall(
host::thread_resume_later,
host::thread_unsuspend,
TrapSentinel::Falsy,
WasmArgs::InRegisters,
|me, params| {
params.push(me.index_value(*instance));
},
);
}
Trampoline::ThreadYieldTo {
Trampoline::ThreadYieldToSuspended {
instance,
cancellable,
} => {
self.translate_libcall(
host::thread_yield_to,
host::thread_yield_to_suspended,
TrapSentinel::NegativeOne,
WasmArgs::InRegisters,
|me, params| {
Expand Down
8 changes: 5 additions & 3 deletions crates/environ/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,15 @@ macro_rules! foreach_builtin_component_function {
#[cfg(feature = "component-model-async")]
thread_new_indirect(vmctx: vmctx, caller_instance: u32, func_ty_id: u32, func_table_idx: u32, func_idx: u32, context: u32) -> u64;
#[cfg(feature = "component-model-async")]
thread_switch_to(vmctx: vmctx, caller_instance: u32, cancellable: u8, thread_idx: u32) -> u32;
thread_suspend_to_suspended(vmctx: vmctx, caller_instance: u32, cancellable: u8, thread_idx: u32) -> u32;
#[cfg(feature = "component-model-async")]
thread_suspend_to(vmctx: vmctx, caller_instance: u32, cancellable: u8, thread_idx: u32) -> u32;
#[cfg(feature = "component-model-async")]
thread_suspend(vmctx: vmctx, caller_instance: u32, cancellable: u8) -> u32;
#[cfg(feature = "component-model-async")]
thread_resume_later(vmctx: vmctx, caller_instance: u32, thread_idx: u32) -> bool;
thread_unsuspend(vmctx: vmctx, caller_instance: u32, thread_idx: u32) -> bool;
#[cfg(feature = "component-model-async")]
thread_yield_to(vmctx: vmctx, caller_instance: u32, cancellable: u8, thread_idx: u32) -> u32;
thread_yield_to_suspended(vmctx: vmctx, caller_instance: u32, cancellable: u8, thread_idx: u32) -> u32;

trap(vmctx: vmctx, code: u32) -> bool;

Expand Down
27 changes: 19 additions & 8 deletions crates/environ/src/component/dfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,18 +492,22 @@ pub enum Trampoline {
start_func_ty_idx: ComponentTypeIndex,
start_func_table_id: TableId,
},
ThreadSwitchTo {
ThreadSuspendToSuspended {
instance: RuntimeComponentInstanceIndex,
cancellable: bool,
},
ThreadSuspend {
instance: RuntimeComponentInstanceIndex,
cancellable: bool,
},
ThreadResumeLater {
ThreadSuspendTo {
instance: RuntimeComponentInstanceIndex,
cancellable: bool,
},
ThreadUnsuspend {
instance: RuntimeComponentInstanceIndex,
},
ThreadYieldTo {
ThreadYieldToSuspended {
instance: RuntimeComponentInstanceIndex,
cancellable: bool,
},
Expand Down Expand Up @@ -1185,10 +1189,17 @@ impl LinearizeDfg<'_> {
start_func_ty_idx: *start_func_ty_idx,
start_func_table_idx: self.runtime_table(*start_func_table_id),
},
Trampoline::ThreadSwitchTo {
Trampoline::ThreadSuspendToSuspended {
instance,
cancellable,
} => info::Trampoline::ThreadSuspendToSuspended {
instance: *instance,
cancellable: *cancellable,
},
Trampoline::ThreadSuspendTo {
instance,
cancellable,
} => info::Trampoline::ThreadSwitchTo {
} => info::Trampoline::ThreadSuspendTo {
instance: *instance,
cancellable: *cancellable,
},
Expand All @@ -1199,13 +1210,13 @@ impl LinearizeDfg<'_> {
instance: *instance,
cancellable: *cancellable,
},
Trampoline::ThreadResumeLater { instance } => info::Trampoline::ThreadResumeLater {
Trampoline::ThreadUnsuspend { instance } => info::Trampoline::ThreadUnsuspend {
instance: *instance,
},
Trampoline::ThreadYieldTo {
Trampoline::ThreadYieldToSuspended {
instance,
cancellable,
} => info::Trampoline::ThreadYieldTo {
} => info::Trampoline::ThreadYieldToSuspended {
instance: *instance,
cancellable: *cancellable,
},
Expand Down
28 changes: 19 additions & 9 deletions crates/environ/src/component/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1154,8 +1154,17 @@ pub enum Trampoline {
start_func_table_idx: RuntimeTableIndex,
},

/// Intrinsic used to implement the `thread.switch-to` component model builtin.
ThreadSwitchTo {
/// Intrinsic used to implement the `thread.suspend-to-suspended` component model builtin.
ThreadSuspendToSuspended {
/// The specific component instance which is calling the intrinsic.
instance: RuntimeComponentInstanceIndex,
/// If `true`, indicates the caller instance may receive notification
/// of task cancellation.
cancellable: bool,
},

/// Intrinsic used to implement the `thread.suspend-to` component model builtin.
ThreadSuspendTo {
/// The specific component instance which is calling the intrinsic.
instance: RuntimeComponentInstanceIndex,
/// If `true`, indicates the caller instance may receive notification
Expand All @@ -1172,14 +1181,14 @@ pub enum Trampoline {
cancellable: bool,
},

/// Intrinsic used to implement the `thread.resume-later` component model builtin.
ThreadResumeLater {
/// Intrinsic used to implement the `thread.unsuspend` component model builtin.
ThreadUnsuspend {
/// The specific component instance which is calling the intrinsic.
instance: RuntimeComponentInstanceIndex,
},

/// Intrinsic used to implement the `thread.yield-to` component model builtin.
ThreadYieldTo {
/// Intrinsic used to implement the `thread.yield-to-suspended` component model builtin.
ThreadYieldToSuspended {
/// The specific component instance which is calling the intrinsic.
instance: RuntimeComponentInstanceIndex,
/// If `true`, indicates the caller instance may receive notification
Expand Down Expand Up @@ -1254,10 +1263,11 @@ impl Trampoline {
ContextSet { .. } => format!("context-set"),
ThreadIndex => format!("thread-index"),
ThreadNewIndirect { .. } => format!("thread-new-indirect"),
ThreadSwitchTo { .. } => format!("thread-switch-to"),
ThreadSuspendToSuspended { .. } => format!("thread-suspend-to-suspended"),
ThreadSuspendTo { .. } => format!("thread-suspend-to"),
ThreadSuspend { .. } => format!("thread-suspend"),
ThreadResumeLater { .. } => format!("thread-resume-later"),
ThreadYieldTo { .. } => format!("thread-yield-to"),
ThreadUnsuspend { .. } => format!("thread-unsuspend"),
ThreadYieldToSuspended { .. } => format!("thread-yield-to-suspended"),
}
}
}
27 changes: 18 additions & 9 deletions crates/environ/src/component/translate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,18 +319,22 @@ enum LocalInitializer<'data> {
start_func_ty: ComponentTypeIndex,
start_func_table_index: TableIndex,
},
ThreadSwitchTo {
ThreadSuspendToSuspended {
func: ModuleInternedTypeIndex,
cancellable: bool,
},
ThreadSuspend {
func: ModuleInternedTypeIndex,
cancellable: bool,
},
ThreadResumeLater {
ThreadSuspendTo {
func: ModuleInternedTypeIndex,
cancellable: bool,
},
ThreadUnsuspend {
func: ModuleInternedTypeIndex,
},
ThreadYieldTo {
ThreadYieldToSuspended {
func: ModuleInternedTypeIndex,
cancellable: bool,
},
Expand Down Expand Up @@ -1150,25 +1154,30 @@ impl<'a, 'data> Translator<'a, 'data> {
start_func_table_index: TableIndex::from_u32(table_index),
}
}
wasmparser::CanonicalFunction::ThreadSwitchTo { cancellable } => {
wasmparser::CanonicalFunction::ThreadSuspendToSuspended { cancellable } => {
let func = self.core_func_signature(core_func_index)?;
core_func_index += 1;
LocalInitializer::ThreadSwitchTo { func, cancellable }
LocalInitializer::ThreadSuspendToSuspended { func, cancellable }
}
wasmparser::CanonicalFunction::ThreadSuspend { cancellable } => {
let func = self.core_func_signature(core_func_index)?;
core_func_index += 1;
LocalInitializer::ThreadSuspend { func, cancellable }
}
wasmparser::CanonicalFunction::ThreadResumeLater => {
wasmparser::CanonicalFunction::ThreadSuspendTo { cancellable } => {
let func = self.core_func_signature(core_func_index)?;
core_func_index += 1;
LocalInitializer::ThreadSuspendTo { func, cancellable }
}
wasmparser::CanonicalFunction::ThreadUnsuspend => {
let func = self.core_func_signature(core_func_index)?;
core_func_index += 1;
LocalInitializer::ThreadResumeLater { func }
LocalInitializer::ThreadUnsuspend { func }
}
wasmparser::CanonicalFunction::ThreadYieldTo { cancellable } => {
wasmparser::CanonicalFunction::ThreadYieldToSuspended { cancellable } => {
let func = self.core_func_signature(core_func_index)?;
core_func_index += 1;
LocalInitializer::ThreadYieldTo { func, cancellable }
LocalInitializer::ThreadYieldToSuspended { func, cancellable }
}
};
self.result.initializers.push(init);
Expand Down
22 changes: 16 additions & 6 deletions crates/environ/src/component/translate/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1123,10 +1123,20 @@ impl<'a> Inliner<'a> {
));
frame.funcs.push((*func, dfg::CoreDef::Trampoline(index)));
}
ThreadSwitchTo { func, cancellable } => {
ThreadSuspendToSuspended { func, cancellable } => {
let index = self.result.trampolines.push((
*func,
dfg::Trampoline::ThreadSwitchTo {
dfg::Trampoline::ThreadSuspendToSuspended {
instance: frame.instance,
cancellable: *cancellable,
},
));
frame.funcs.push((*func, dfg::CoreDef::Trampoline(index)));
}
ThreadSuspendTo { func, cancellable } => {
let index = self.result.trampolines.push((
*func,
dfg::Trampoline::ThreadSuspendTo {
instance: frame.instance,
cancellable: *cancellable,
},
Expand All @@ -1143,19 +1153,19 @@ impl<'a> Inliner<'a> {
));
frame.funcs.push((*func, dfg::CoreDef::Trampoline(index)));
}
ThreadResumeLater { func } => {
ThreadUnsuspend { func } => {
let index = self.result.trampolines.push((
*func,
dfg::Trampoline::ThreadResumeLater {
dfg::Trampoline::ThreadUnsuspend {
instance: frame.instance,
},
));
frame.funcs.push((*func, dfg::CoreDef::Trampoline(index)));
}
ThreadYieldTo { func, cancellable } => {
ThreadYieldToSuspended { func, cancellable } => {
let index = self.result.trampolines.push((
*func,
dfg::Trampoline::ThreadYieldTo {
dfg::Trampoline::ThreadYieldToSuspended {
instance: frame.instance,
cancellable: *cancellable,
},
Expand Down
2 changes: 1 addition & 1 deletion crates/environ/src/component/types_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ impl ComponentTypesBuilder {
ComponentDefinedType::Stream(ty) => {
InterfaceType::Stream(self.stream_table_type(types, ty)?)
}
ComponentDefinedType::FixedSizeList(ty, size) => {
ComponentDefinedType::FixedLengthList(ty, size) => {
InterfaceType::FixedLengthList(self.fixed_length_list_type(types, ty, *size)?)
}
ComponentDefinedType::Map(..) => {
Expand Down
4 changes: 2 additions & 2 deletions crates/wasmtime/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1210,7 +1210,7 @@ impl Config {
/// incomplete.
#[cfg(feature = "component-model")]
pub fn wasm_component_model_fixed_length_lists(&mut self, enable: bool) -> &mut Self {
self.wasm_features(WasmFeatures::CM_FIXED_SIZE_LIST, enable);
self.wasm_features(WasmFeatures::CM_FIXED_LENGTH_LISTS, enable);
self
}

Expand Down Expand Up @@ -2183,7 +2183,7 @@ impl Config {
| WasmFeatures::CM_THREADING
| WasmFeatures::CM_ERROR_CONTEXT
| WasmFeatures::CM_GC
| WasmFeatures::CM_FIXED_SIZE_LIST;
| WasmFeatures::CM_FIXED_LENGTH_LISTS;

#[allow(unused_mut, reason = "easier to avoid #[cfg]")]
let mut unsupported = !features_known_to_wasmtime;
Expand Down
Loading
Loading