Skip to content
This repository was archived by the owner on Sep 8, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 3 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
51 changes: 17 additions & 34 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 15 additions & 15 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -589,21 +589,21 @@ lto = true

# TODO: remove this once we've switched to a wasm-tools/wit-bindgen release:
[patch.crates-io]
# wasmparser = { git = "https://github.com/bytecodealliance/wasm-tools" }
# wat = { git = "https://github.com/bytecodealliance/wasm-tools" }
# wast = { git = "https://github.com/bytecodealliance/wasm-tools" }
# wasmprinter = { git = "https://github.com/bytecodealliance/wasm-tools" }
# wasm-encoder = { git = "https://github.com/bytecodealliance/wasm-tools" }
# wasm-smith = { git = "https://github.com/bytecodealliance/wasm-tools" }
# wasm-mutate = { git = "https://github.com/bytecodealliance/wasm-tools" }
# wit-parser = { git = "https://github.com/bytecodealliance/wasm-tools" }
# wit-component = { git = "https://github.com/bytecodealliance/wasm-tools" }
# wasm-wave = { git = "https://github.com/bytecodealliance/wasm-tools" }
# wasm-compose = { git = "https://github.com/bytecodealliance/wasm-tools" }
# wasm-metadata = { git = "https://github.com/bytecodealliance/wasm-tools" }
# wit-bindgen = { git = "https://github.com/alexcrichton/wit-bindgen", branch = 'fix-a-tpyo' }
# wit-bindgen-rt = { git = "https://github.com/alexcrichton/wit-bindgen", branch = 'fix-a-tpyo' }
# wit-bindgen-rust-macro = { git = "https://github.com/alexcrichton/wit-bindgen", branch = 'fix-a-tpyo' }
wasmparser = { git = "https://github.com/alexcrichton/wasm-tools", branch = 'new-async-abi' }
wat = { git = "https://github.com/alexcrichton/wasm-tools", branch = 'new-async-abi' }
wast = { git = "https://github.com/alexcrichton/wasm-tools", branch = 'new-async-abi' }
wasmprinter = { git = "https://github.com/alexcrichton/wasm-tools", branch = 'new-async-abi' }
wasm-encoder = { git = "https://github.com/alexcrichton/wasm-tools", branch = 'new-async-abi' }
wasm-smith = { git = "https://github.com/alexcrichton/wasm-tools", branch = 'new-async-abi' }
wasm-mutate = { git = "https://github.com/alexcrichton/wasm-tools", branch = 'new-async-abi' }
wit-parser = { git = "https://github.com/alexcrichton/wasm-tools", branch = 'new-async-abi' }
wit-component = { git = "https://github.com/alexcrichton/wasm-tools", branch = 'new-async-abi' }
wasm-wave = { git = "https://github.com/alexcrichton/wasm-tools", branch = 'new-async-abi' }
wasm-compose = { git = "https://github.com/alexcrichton/wasm-tools", branch = 'new-async-abi' }
wasm-metadata = { git = "https://github.com/alexcrichton/wasm-tools", branch = 'new-async-abi' }
wit-bindgen = { git = "https://github.com/alexcrichton/wit-bindgen", branch = 'new-async-abi' }
wit-bindgen-rt = { git = "https://github.com/alexcrichton/wit-bindgen", branch = 'new-async-abi' }
wit-bindgen-rust-macro = { git = "https://github.com/alexcrichton/wit-bindgen", branch = 'new-async-abi' }

# wasmparser = { path = '../wasm-tools/crates/wasmparser' }
# wat = { path = '../wasm-tools/crates/wat' }
Expand Down
41 changes: 6 additions & 35 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_PREPARE_FIXED_PARAMS;
use wasmtime_environ::fact::PREPARE_CALL_FIXED_PARAMS;
use wasmtime_environ::{CompiledFunctionBody, component::*};
use wasmtime_environ::{
HostCall, ModuleInternedTypeIndex, PtrSize, TrapSentinel, Tunables, WasmFuncType, WasmValType,
Expand Down Expand Up @@ -255,9 +255,8 @@ impl<'a> TrampolineCompiler<'a> {
me.raise_if_host_trapped(rets.pop().unwrap());
})
}
Trampoline::SyncPrepareCall { memory } => self.translate_sync_prepare(*memory),
Trampoline::PrepareCall { memory } => self.translate_prepare(*memory),
Trampoline::SyncStartCall { callback } => self.translate_sync_start(*callback),
Trampoline::AsyncPrepareCall { memory } => self.translate_async_prepare(*memory),
Trampoline::AsyncStartCall {
callback,
post_return,
Expand Down Expand Up @@ -471,7 +470,7 @@ impl<'a> TrampolineCompiler<'a> {
);
}

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

Expand All @@ -489,8 +488,8 @@ 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_PREPARE_FIXED_PARAMS.len();
let spill_offset = param_offset + 2;
let param_offset = PREPARE_CALL_FIXED_PARAMS.len();
let spill_offset = param_offset + 2; // skip caller/callee vmctx

let (values_vec_ptr, len) = self.compiler.allocate_stack_array_and_spill_args(
&WasmFuncType::new(
Expand All @@ -517,7 +516,7 @@ impl<'a> TrampolineCompiler<'a> {

self.translate_intrinsic_libcall(
vmctx,
host::sync_prepare,
host::prepare_call,
&callee_args,
TrapSentinel::Falsy,
);
Expand Down Expand Up @@ -572,34 +571,6 @@ impl<'a> TrampolineCompiler<'a> {
self.builder.ins().return_(&results);
}

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

Abi::Array => {
// This code can only be called from (FACT-generated) Wasm, so
// we don't need to support the array ABI.
self.builder.ins().trap(TRAP_INTERNAL_ASSERT);
return;
}
}

let args = self.builder.func.dfg.block_params(self.block0).to_vec();
let vmctx = args[0];

let mut callee_args = vec![vmctx, self.load_optional_memory(vmctx, memory)];

// remaining parameters
callee_args.extend(args[2..].iter().copied());

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

fn translate_async_start(
&mut self,
callback: Option<RuntimeCallbackIndex>,
Expand Down
31 changes: 28 additions & 3 deletions crates/environ/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,26 @@
/// for transferring parameters.
pub const MAX_FLAT_PARAMS: usize = 16;

/// Similar to `MAX_FLAT_PARAMS`, but used for async-lowered imports instead of
/// sync ones.
pub const MAX_FLAT_ASYNC_PARAMS: usize = 4;

/// Canonical ABI-defined constant for the maximum number of "flat" results.
/// This number of results are returned directly from wasm and otherwise results
/// are transferred through memory.
pub const MAX_FLAT_RESULTS: usize = 1;

/// Sentinel value in `result_count_or_max_if_async` as part of the
/// `prepare_call` libcall which indicates that preparation is being done for an
/// async function that produces no result, aka there is no return pointer.
pub const PREPARE_ASYNC_NO_RESULT: u32 = u32::MAX;

/// Sentinel value in `result_count_or_max_if_async` as part of the
/// `prepare_call` libcall which indicates that preparation is being done for an
/// async function that produces at least one result, aka there is a return
/// pointer.
pub const PREPARE_ASYNC_WITH_RESULT: u32 = u32::MAX - 1;

mod artifacts;
mod info;
mod names;
Expand Down Expand Up @@ -106,12 +121,22 @@ 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_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;
prepare_call(
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_or_max_if_async: u32,
storage: ptr_u8,
torage_len: size
) -> bool;
#[cfg(feature = "component-model-async")]
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_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_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;
Expand Down
10 changes: 2 additions & 8 deletions crates/environ/src/component/dfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,15 +383,12 @@ pub enum Trampoline {
ResourceTransferBorrow,
ResourceEnterCall,
ResourceExitCall,
SyncPrepareCall {
PrepareCall {
memory: Option<MemoryId>,
},
SyncStartCall {
callback: Option<CallbackId>,
},
AsyncPrepareCall {
memory: Option<MemoryId>,
},
AsyncStartCall {
callback: Option<CallbackId>,
post_return: Option<PostReturnId>,
Expand Down Expand Up @@ -895,15 +892,12 @@ impl LinearizeDfg<'_> {
Trampoline::ResourceTransferBorrow => info::Trampoline::ResourceTransferBorrow,
Trampoline::ResourceEnterCall => info::Trampoline::ResourceEnterCall,
Trampoline::ResourceExitCall => info::Trampoline::ResourceExitCall,
Trampoline::SyncPrepareCall { memory } => info::Trampoline::SyncPrepareCall {
Trampoline::PrepareCall { memory } => info::Trampoline::PrepareCall {
memory: memory.map(|v| self.runtime_memory(v)),
},
Trampoline::SyncStartCall { callback } => info::Trampoline::SyncStartCall {
callback: callback.map(|v| self.runtime_callback(v)),
},
Trampoline::AsyncPrepareCall { memory } => info::Trampoline::AsyncPrepareCall {
memory: memory.map(|v| self.runtime_memory(v)),
},
Trampoline::AsyncStartCall {
callback,
post_return,
Expand Down
Loading