Skip to content
This repository was archived by the owner on Sep 8, 2025. It is now read-only.
37 changes: 19 additions & 18 deletions crates/cranelift/src/compiler/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use cranelift_codegen::ir::condcodes::IntCC;
use cranelift_codegen::ir::{self, InstBuilder, MemFlags, Value};
use cranelift_codegen::isa::{CallConv, TargetIsa};
use cranelift_frontend::FunctionBuilder;
use wasmtime_environ::fact::SYNC_ENTER_FIXED_PARAMS;
use wasmtime_environ::fact::SYNC_PREPARE_FIXED_PARAMS;
use wasmtime_environ::{component::*, CompiledFunctionBody};
use wasmtime_environ::{
HostCall, ModuleInternedTypeIndex, PtrSize, TrapSentinel, Tunables, WasmFuncType, WasmValType,
Expand Down Expand Up @@ -255,13 +255,13 @@ impl<'a> TrampolineCompiler<'a> {
me.raise_if_host_trapped(rets.pop().unwrap());
})
}
Trampoline::SyncEnterCall { memory } => self.translate_sync_enter(*memory),
Trampoline::SyncExitCall { callback } => self.translate_sync_exit(*callback),
Trampoline::AsyncEnterCall { memory } => self.translate_async_enter(*memory),
Trampoline::AsyncExitCall {
Trampoline::SyncPrepareCall { memory } => self.translate_sync_prepare(*memory),
Trampoline::SyncStartCall { callback } => self.translate_sync_start(*callback),
Trampoline::AsyncPrepareCall { memory } => self.translate_async_prepare(*memory),
Trampoline::AsyncStartCall {
callback,
post_return,
} => self.translate_async_exit(*callback, *post_return),
} => self.translate_async_start(*callback, *post_return),
Trampoline::FutureTransfer => {
self.translate_host_libcall(host::future_transfer, |me, rets| {
rets[0] = me.raise_if_negative_one_and_truncate(rets[0]);
Expand Down Expand Up @@ -349,9 +349,10 @@ impl<'a> TrampolineCompiler<'a> {
Abi::Array => {
// TODO: A guest could hypothetically export the same intrinsic
// it imported, allowing the host to call it directly. We need
// to support that here (except for `sync-enter`, `sync-exit`,
// `async-enter`, and `async-exit`, which are only ever called
// from FACT-generated Wasm code and never exported).
// to support that here (except for `sync-prepare`,
// `sync-start`, `async-prepare`, and `async-start`, which are
// only ever called from FACT-generated Wasm code and never
// exported).
//
// https://github.com/bytecodealliance/wasmtime/issues/10143
self.builder.ins().trap(TRAP_INTERNAL_ASSERT);
Expand Down Expand Up @@ -470,7 +471,7 @@ impl<'a> TrampolineCompiler<'a> {
);
}

fn translate_sync_enter(&mut self, memory: Option<RuntimeMemoryIndex>) {
fn translate_sync_prepare(&mut self, memory: Option<RuntimeMemoryIndex>) {
match self.abi {
Abi::Wasm => {}

Expand All @@ -488,7 +489,7 @@ impl<'a> TrampolineCompiler<'a> {
let pointer_type = self.isa.pointer_type();
let wasm_func_ty = &self.types[self.signature].unwrap_func();

let param_offset = SYNC_ENTER_FIXED_PARAMS.len();
let param_offset = SYNC_PREPARE_FIXED_PARAMS.len();
let spill_offset = param_offset + 2;

let (values_vec_ptr, len) = self.compiler.allocate_stack_array_and_spill_args(
Expand Down Expand Up @@ -516,13 +517,13 @@ impl<'a> TrampolineCompiler<'a> {

self.translate_intrinsic_libcall(
vmctx,
host::sync_enter,
host::sync_prepare,
&callee_args,
TrapSentinel::Falsy,
);
}

fn translate_sync_exit(&mut self, callback: Option<RuntimeCallbackIndex>) {
fn translate_sync_start(&mut self, callback: Option<RuntimeCallbackIndex>) {
match self.abi {
Abi::Wasm => {}

Expand Down Expand Up @@ -556,7 +557,7 @@ impl<'a> TrampolineCompiler<'a> {
callee_args.push(values_vec_ptr);
callee_args.push(values_vec_len);

let call = self.call_libcall(vmctx, host::sync_exit, &callee_args);
let call = self.call_libcall(vmctx, host::sync_start, &callee_args);

let succeeded = self.builder.func.dfg.inst_results(call)[0];
self.raise_if_host_trapped(succeeded);
Expand All @@ -571,7 +572,7 @@ impl<'a> TrampolineCompiler<'a> {
self.builder.ins().return_(&results);
}

fn translate_async_enter(&mut self, memory: Option<RuntimeMemoryIndex>) {
fn translate_async_prepare(&mut self, memory: Option<RuntimeMemoryIndex>) {
match self.abi {
Abi::Wasm => {}

Expand All @@ -593,13 +594,13 @@ impl<'a> TrampolineCompiler<'a> {

self.translate_intrinsic_libcall(
vmctx,
host::async_enter,
host::async_prepare,
&callee_args,
TrapSentinel::Falsy,
);
}

fn translate_async_exit(
fn translate_async_start(
&mut self,
callback: Option<RuntimeCallbackIndex>,
post_return: Option<RuntimePostReturnIndex>,
Expand Down Expand Up @@ -629,7 +630,7 @@ impl<'a> TrampolineCompiler<'a> {

self.translate_intrinsic_libcall(
vmctx,
host::async_exit,
host::async_start,
&callee_args,
TrapSentinel::NegativeOne,
);
Expand Down
8 changes: 4 additions & 4 deletions crates/environ/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,13 @@ macro_rules! foreach_builtin_component_function {
#[cfg(feature = "component-model-async")]
subtask_cancel(vmctx: vmctx, caller_instance: u32, async_: u8, task_id: u32) -> u64;
#[cfg(feature = "component-model-async")]
sync_enter(vmctx: vmctx, memory: ptr_u8, start: ptr_u8, return_: ptr_u8, caller_instance: u32, callee_instance: u32, task_return_type: u32, string_encoding: u32, result_count: u32, storage: ptr_u8, storage_len: size) -> bool;
sync_prepare(vmctx: vmctx, memory: ptr_u8, start: ptr_u8, return_: ptr_u8, caller_instance: u32, callee_instance: u32, task_return_type: u32, string_encoding: u32, result_count: u32, storage: ptr_u8, storage_len: size) -> bool;
#[cfg(feature = "component-model-async")]
sync_exit(vmctx: vmctx, callback: ptr_u8, callee: ptr_u8, param_count: u32, storage: ptr_u8, storage_len: size) -> bool;
sync_start(vmctx: vmctx, callback: ptr_u8, callee: ptr_u8, param_count: u32, storage: ptr_u8, storage_len: size) -> bool;
#[cfg(feature = "component-model-async")]
async_enter(vmctx: vmctx, memory: ptr_u8, start: ptr_u8, return_: ptr_u8, caller_instance: u32, callee_instance: u32, task_return_type: u32, string_encoding: u32, params: u32, results: u32) -> bool;
async_prepare(vmctx: vmctx, memory: ptr_u8, start: ptr_u8, return_: ptr_u8, caller_instance: u32, callee_instance: u32, task_return_type: u32, string_encoding: u32, params: u32, results: u32) -> bool;
#[cfg(feature = "component-model-async")]
async_exit(vmctx: vmctx, callback: ptr_u8, post_return: ptr_u8, callee: ptr_u8, param_count: u32, result_count: u32, flags: u32) -> u64;
async_start(vmctx: vmctx, callback: ptr_u8, post_return: ptr_u8, callee: ptr_u8, param_count: u32, result_count: u32, flags: u32) -> u64;
#[cfg(feature = "component-model-async")]
future_new(vmctx: vmctx, ty: u32) -> u64;
#[cfg(feature = "component-model-async")]
Expand Down
18 changes: 9 additions & 9 deletions crates/environ/src/component/dfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,16 +383,16 @@ pub enum Trampoline {
ResourceTransferBorrow,
ResourceEnterCall,
ResourceExitCall,
SyncEnterCall {
SyncPrepareCall {
memory: Option<MemoryId>,
},
SyncExitCall {
SyncStartCall {
callback: Option<CallbackId>,
},
AsyncEnterCall {
AsyncPrepareCall {
memory: Option<MemoryId>,
},
AsyncExitCall {
AsyncStartCall {
callback: Option<CallbackId>,
post_return: Option<PostReturnId>,
},
Expand Down Expand Up @@ -895,19 +895,19 @@ impl LinearizeDfg<'_> {
Trampoline::ResourceTransferBorrow => info::Trampoline::ResourceTransferBorrow,
Trampoline::ResourceEnterCall => info::Trampoline::ResourceEnterCall,
Trampoline::ResourceExitCall => info::Trampoline::ResourceExitCall,
Trampoline::SyncEnterCall { memory } => info::Trampoline::SyncEnterCall {
Trampoline::SyncPrepareCall { memory } => info::Trampoline::SyncPrepareCall {
memory: memory.map(|v| self.runtime_memory(v)),
},
Trampoline::SyncExitCall { callback } => info::Trampoline::SyncExitCall {
Trampoline::SyncStartCall { callback } => info::Trampoline::SyncStartCall {
callback: callback.map(|v| self.runtime_callback(v)),
},
Trampoline::AsyncEnterCall { memory } => info::Trampoline::AsyncEnterCall {
Trampoline::AsyncPrepareCall { memory } => info::Trampoline::AsyncPrepareCall {
memory: memory.map(|v| self.runtime_memory(v)),
},
Trampoline::AsyncExitCall {
Trampoline::AsyncStartCall {
callback,
post_return,
} => info::Trampoline::AsyncExitCall {
} => info::Trampoline::AsyncStartCall {
callback: callback.map(|v| self.runtime_callback(v)),
post_return: post_return.map(|v| self.runtime_post_return(v)),
},
Expand Down
32 changes: 16 additions & 16 deletions crates/environ/src/component/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -956,39 +956,39 @@ pub enum Trampoline {
/// Same as `ResourceEnterCall` except for when exiting a call.
ResourceExitCall,

/// An intrinsic used by FACT-generated modules to begin a call involving a
/// sync-lowered import and async-lifted export.
SyncEnterCall {
/// An intrinsic used by FACT-generated modules to prepare a call involving
/// a sync-lowered import and async-lifted export.
SyncPrepareCall {
/// The memory used to verify that the memory specified for the
/// `task.return` that is called at runtime matches the one specified in
/// the lifted export.
memory: Option<RuntimeMemoryIndex>,
},

/// An intrinsic used by FACT-generated modules to complete a call involving
/// a sync-lowered import and async-lifted export.
SyncExitCall {
/// An intrinsic used by FACT-generated modules to start a call involving a
/// sync-lowered import and async-lifted export.
SyncStartCall {
/// The callee's callback function, if any.
callback: Option<RuntimeCallbackIndex>,
},

/// An intrinsic used by FACT-generated modules to begin a call involving an
/// async-lowered import function.
AsyncEnterCall {
/// An intrinsic used by FACT-generated modules to prepare a call involving
/// an async-lowered import function.
AsyncPrepareCall {
/// The memory used to verify that the memory specified for the
/// `task.return` that is called at runtime (if any) matches the one
/// specified in the lifted export.
memory: Option<RuntimeMemoryIndex>,
},

/// An intrinsic used by FACT-generated modules to complete a call involving
/// An intrinsic used by FACT-generated modules to start a call involving
/// an async-lowered import function.
///
/// Note that `AsyncEnterCall` and `AsyncExitCall` could theoretically be
/// Note that `AsyncPrepareCall` and `AsyncStartCall` could theoretically be
/// combined into a single `AsyncCall` intrinsic, but we separate them to
/// allow the FACT-generated module to optionally call the callee directly
/// without an intermediate host stack frame.
AsyncExitCall {
AsyncStartCall {
/// The callee's callback, if any.
callback: Option<RuntimeCallbackIndex>,

Expand Down Expand Up @@ -1086,10 +1086,10 @@ impl Trampoline {
ResourceTransferBorrow => format!("component-resource-transfer-borrow"),
ResourceEnterCall => format!("component-resource-enter-call"),
ResourceExitCall => format!("component-resource-exit-call"),
SyncEnterCall { .. } => format!("component-sync-enter-call"),
SyncExitCall { .. } => format!("component-sync-exit-call"),
AsyncEnterCall { .. } => format!("component-async-enter-call"),
AsyncExitCall { .. } => format!("component-async-exit-call"),
SyncPrepareCall { .. } => format!("component-sync-prepare-call"),
SyncStartCall { .. } => format!("component-sync-start-call"),
AsyncPrepareCall { .. } => format!("component-async-prepare-call"),
AsyncStartCall { .. } => format!("component-async-start-call"),
FutureTransfer => format!("future-transfer"),
StreamTransfer => format!("stream-transfer"),
ErrorContextTransfer => format!("error-context-transfer"),
Expand Down
16 changes: 8 additions & 8 deletions crates/environ/src/component/translate/adapt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,25 +305,25 @@ fn fact_import_to_core_def(
}
fact::Import::ResourceEnterCall => simple_intrinsic(dfg::Trampoline::ResourceEnterCall),
fact::Import::ResourceExitCall => simple_intrinsic(dfg::Trampoline::ResourceExitCall),
fact::Import::SyncEnterCall { memory } => {
simple_intrinsic(dfg::Trampoline::SyncEnterCall {
fact::Import::SyncPrepareCall { memory } => {
simple_intrinsic(dfg::Trampoline::SyncPrepareCall {
memory: memory.as_ref().map(|v| dfg.memories.push(unwrap_memory(v))),
})
}
fact::Import::SyncExitCall { callback } => {
simple_intrinsic(dfg::Trampoline::SyncExitCall {
fact::Import::SyncStartCall { callback } => {
simple_intrinsic(dfg::Trampoline::SyncStartCall {
callback: callback.clone().map(|v| dfg.callbacks.push(v)),
})
}
fact::Import::AsyncEnterCall { memory } => {
simple_intrinsic(dfg::Trampoline::AsyncEnterCall {
fact::Import::AsyncPrepareCall { memory } => {
simple_intrinsic(dfg::Trampoline::AsyncPrepareCall {
memory: memory.as_ref().map(|v| dfg.memories.push(unwrap_memory(v))),
})
}
fact::Import::AsyncExitCall {
fact::Import::AsyncStartCall {
callback,
post_return,
} => simple_intrinsic(dfg::Trampoline::AsyncExitCall {
} => simple_intrinsic(dfg::Trampoline::AsyncStartCall {
callback: callback.clone().map(|v| dfg.callbacks.push(v)),
post_return: post_return.clone().map(|v| dfg.post_returns.push(v)),
}),
Expand Down
Loading