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 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
11 changes: 10 additions & 1 deletion crates/cranelift/src/compiler/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1285,7 +1285,13 @@ impl<'a> TrampolineCompiler<'a> {
// realloc: *mut VMFuncRef
callee_args.push(self.load_realloc(vmctx, options.realloc));
// string_encoding: StringEncoding
callee_args.push(self.string_encoding(options.string_encoding))
callee_args.push(self.string_encoding(options.string_encoding));
// async: bool
callee_args.push(
self.builder
.ins()
.iconst(ir::types::I8, if options.async_ { 1 } else { 0 }),
);
}

for ty in tys {
Expand All @@ -1310,6 +1316,9 @@ impl<'a> TrampolineCompiler<'a> {
vmctx,
self.load_memory(vmctx, options.memory.unwrap()),
self.load_realloc(vmctx, options.realloc),
self.builder
.ins()
.iconst(ir::types::I8, if options.async_ { 1 } else { 0 }),
];
for ty in tys {
callee_args.push(self.builder.ins().iconst(ir::types::I32, i64::from(*ty)));
Expand Down
12 changes: 6 additions & 6 deletions crates/environ/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ macro_rules! foreach_builtin_component_function {
#[cfg(feature = "component-model-async")]
future_new(vmctx: vmctx, ty: u32) -> u64;
#[cfg(feature = "component-model-async")]
future_write(vmctx: vmctx, memory: ptr_u8, realloc: ptr_u8, string_encoding: u8, ty: u32, err_ctx_ty: u32, future: u32, address: u32) -> u64;
future_write(vmctx: vmctx, memory: ptr_u8, realloc: ptr_u8, string_encoding: u8, async_: u8, ty: u32, err_ctx_ty: u32, future: u32, address: u32) -> u64;
#[cfg(feature = "component-model-async")]
future_read(vmctx: vmctx, memory: ptr_u8, realloc: ptr_u8, string_encoding: u8, ty: u32, err_ctx_ty: u32, future: u32, address: u32) -> u64;
future_read(vmctx: vmctx, memory: ptr_u8, realloc: ptr_u8, string_encoding: u8, async_: u8, ty: u32, err_ctx_ty: u32, future: u32, address: u32) -> u64;
#[cfg(feature = "component-model-async")]
future_cancel_write(vmctx: vmctx, ty: u32, async_: u8, writer: u32) -> u64;
#[cfg(feature = "component-model-async")]
Expand All @@ -126,9 +126,9 @@ macro_rules! foreach_builtin_component_function {
#[cfg(feature = "component-model-async")]
stream_new(vmctx: vmctx, ty: u32) -> u64;
#[cfg(feature = "component-model-async")]
stream_write(vmctx: vmctx, memory: ptr_u8, realloc: ptr_u8, string_encoding: u8, ty: u32, err_ctx_ty: u32, stream: u32, address: u32, count: u32) -> u64;
stream_write(vmctx: vmctx, memory: ptr_u8, realloc: ptr_u8, string_encoding: u8, async_: u8, ty: u32, err_ctx_ty: u32, stream: u32, address: u32, count: u32) -> u64;
#[cfg(feature = "component-model-async")]
stream_read(vmctx: vmctx, memory: ptr_u8, realloc: ptr_u8, string_encoding: u8, ty: u32, err_ctx_ty: u32, stream: u32, address: u32, count: u32) -> u64;
stream_read(vmctx: vmctx, memory: ptr_u8, realloc: ptr_u8, string_encoding: u8, async_: u8, ty: u32, err_ctx_ty: u32, stream: u32, address: u32, count: u32) -> u64;
#[cfg(feature = "component-model-async")]
stream_cancel_write(vmctx: vmctx, ty: u32, async_: u8, writer: u32) -> u64;
#[cfg(feature = "component-model-async")]
Expand All @@ -138,9 +138,9 @@ macro_rules! foreach_builtin_component_function {
#[cfg(feature = "component-model-async")]
stream_close_readable(vmctx: vmctx, ty: u32, err_ctx_ty: u32, reader: u32, error: u32) -> bool;
#[cfg(feature = "component-model-async")]
flat_stream_write(vmctx: vmctx, memory: ptr_u8, realloc: ptr_u8, ty: u32, err_ctx_ty: u32, payload_size: u32, payload_align: u32, stream: u32, address: u32, count: u32) -> u64;
flat_stream_write(vmctx: vmctx, memory: ptr_u8, realloc: ptr_u8, async_: u8, ty: u32, err_ctx_ty: u32, payload_size: u32, payload_align: u32, stream: u32, address: u32, count: u32) -> u64;
#[cfg(feature = "component-model-async")]
flat_stream_read(vmctx: vmctx, memory: ptr_u8, realloc: ptr_u8, ty: u32, err_ctx_ty: u32, payload_size: u32, payload_align: u32, stream: u32, address: u32, count: u32) -> u64;
flat_stream_read(vmctx: vmctx, memory: ptr_u8, realloc: ptr_u8, async_: u8, ty: u32, err_ctx_ty: u32, payload_size: u32, payload_align: u32, stream: u32, address: u32, count: u32) -> u64;
#[cfg(feature = "component-model-async")]
error_context_new(vmctx: vmctx, memory: ptr_u8, realloc: ptr_u8, string_encoding: u8, ty: u32, debug_msg_address: u32, debug_msg_len: u32) -> u64;
#[cfg(feature = "component-model-async")]
Expand Down
18 changes: 18 additions & 0 deletions crates/wasmtime/src/runtime/component/concurrent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2427,6 +2427,7 @@ pub unsafe trait VMComponentAsyncStore {
memory: *mut VMMemoryDefinition,
realloc: *mut VMFuncRef,
string_encoding: u8,
async_: bool,
ty: TypeFutureTableIndex,
err_ctx_ty: TypeComponentLocalErrorContextTableIndex,
future: u32,
Expand All @@ -2440,6 +2441,7 @@ pub unsafe trait VMComponentAsyncStore {
memory: *mut VMMemoryDefinition,
realloc: *mut VMFuncRef,
string_encoding: u8,
async_: bool,
ty: TypeFutureTableIndex,
err_ctx_ty: TypeComponentLocalErrorContextTableIndex,
future: u32,
Expand All @@ -2453,6 +2455,7 @@ pub unsafe trait VMComponentAsyncStore {
memory: *mut VMMemoryDefinition,
realloc: *mut VMFuncRef,
string_encoding: u8,
async_: bool,
ty: TypeStreamTableIndex,
err_ctx_ty: TypeComponentLocalErrorContextTableIndex,
stream: u32,
Expand All @@ -2467,6 +2470,7 @@ pub unsafe trait VMComponentAsyncStore {
memory: *mut VMMemoryDefinition,
realloc: *mut VMFuncRef,
string_encoding: u8,
async_: bool,
ty: TypeStreamTableIndex,
err_ctx_ty: TypeComponentLocalErrorContextTableIndex,
stream: u32,
Expand All @@ -2481,6 +2485,7 @@ pub unsafe trait VMComponentAsyncStore {
instance: &mut ComponentInstance,
memory: *mut VMMemoryDefinition,
realloc: *mut VMFuncRef,
async_: bool,
ty: TypeStreamTableIndex,
err_ctx_ty: TypeComponentLocalErrorContextTableIndex,
payload_size: u32,
Expand All @@ -2497,6 +2502,7 @@ pub unsafe trait VMComponentAsyncStore {
instance: &mut ComponentInstance,
memory: *mut VMMemoryDefinition,
realloc: *mut VMFuncRef,
async_: bool,
ty: TypeStreamTableIndex,
err_ctx_ty: TypeComponentLocalErrorContextTableIndex,
payload_size: u32,
Expand Down Expand Up @@ -2629,6 +2635,7 @@ unsafe impl<T> VMComponentAsyncStore for StoreInner<T> {
memory: *mut VMMemoryDefinition,
realloc: *mut VMFuncRef,
string_encoding: u8,
async_: bool,
ty: TypeFutureTableIndex,
err_ctx_ty: TypeComponentLocalErrorContextTableIndex,
future: u32,
Expand All @@ -2639,6 +2646,7 @@ unsafe impl<T> VMComponentAsyncStore for StoreInner<T> {
memory,
realloc,
string_encoding,
async_,
TableIndex::Future(ty),
err_ctx_ty,
None,
Expand All @@ -2654,6 +2662,7 @@ unsafe impl<T> VMComponentAsyncStore for StoreInner<T> {
memory: *mut VMMemoryDefinition,
realloc: *mut VMFuncRef,
string_encoding: u8,
async_: bool,
ty: TypeFutureTableIndex,
err_ctx_ty: TypeComponentLocalErrorContextTableIndex,
future: u32,
Expand All @@ -2664,6 +2673,7 @@ unsafe impl<T> VMComponentAsyncStore for StoreInner<T> {
memory,
realloc,
string_encoding,
async_,
TableIndex::Future(ty),
err_ctx_ty,
None,
Expand All @@ -2679,6 +2689,7 @@ unsafe impl<T> VMComponentAsyncStore for StoreInner<T> {
memory: *mut VMMemoryDefinition,
realloc: *mut VMFuncRef,
string_encoding: u8,
async_: bool,
ty: TypeStreamTableIndex,
err_ctx_ty: TypeComponentLocalErrorContextTableIndex,
stream: u32,
Expand All @@ -2690,6 +2701,7 @@ unsafe impl<T> VMComponentAsyncStore for StoreInner<T> {
memory,
realloc,
string_encoding,
async_,
TableIndex::Stream(ty),
err_ctx_ty,
None,
Expand All @@ -2705,6 +2717,7 @@ unsafe impl<T> VMComponentAsyncStore for StoreInner<T> {
memory: *mut VMMemoryDefinition,
realloc: *mut VMFuncRef,
string_encoding: u8,
async_: bool,
ty: TypeStreamTableIndex,
err_ctx_ty: TypeComponentLocalErrorContextTableIndex,
stream: u32,
Expand All @@ -2716,6 +2729,7 @@ unsafe impl<T> VMComponentAsyncStore for StoreInner<T> {
memory,
realloc,
string_encoding,
async_,
TableIndex::Stream(ty),
err_ctx_ty,
None,
Expand All @@ -2730,6 +2744,7 @@ unsafe impl<T> VMComponentAsyncStore for StoreInner<T> {
instance: &mut ComponentInstance,
memory: *mut VMMemoryDefinition,
realloc: *mut VMFuncRef,
async_: bool,
ty: TypeStreamTableIndex,
err_ctx_ty: TypeComponentLocalErrorContextTableIndex,
payload_size: u32,
Expand All @@ -2743,6 +2758,7 @@ unsafe impl<T> VMComponentAsyncStore for StoreInner<T> {
memory,
realloc,
StringEncoding::Utf8 as u8,
async_,
TableIndex::Stream(ty),
err_ctx_ty,
Some(FlatAbi {
Expand All @@ -2760,6 +2776,7 @@ unsafe impl<T> VMComponentAsyncStore for StoreInner<T> {
instance: &mut ComponentInstance,
memory: *mut VMMemoryDefinition,
realloc: *mut VMFuncRef,
async_: bool,
ty: TypeStreamTableIndex,
err_ctx_ty: TypeComponentLocalErrorContextTableIndex,
payload_size: u32,
Expand All @@ -2773,6 +2790,7 @@ unsafe impl<T> VMComponentAsyncStore for StoreInner<T> {
memory,
realloc,
StringEncoding::Utf8 as u8,
async_,
TableIndex::Stream(ty),
err_ctx_ty,
Some(FlatAbi {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2185,13 +2185,18 @@ impl ComponentInstance {
memory: *mut VMMemoryDefinition,
realloc: *mut VMFuncRef,
string_encoding: u8,
async_: bool,
ty: TableIndex,
err_ctx_ty: TypeComponentLocalErrorContextTableIndex,
flat_abi: Option<FlatAbi>,
handle: u32,
address: u32,
count: u32,
) -> Result<u32> {
if !async_ {
bail!("synchronous stream and future writes not yet supported");
}

// TODO: handle errors sent via `{stream|future}.close-readable`:
_ = err_ctx_ty;

Expand Down Expand Up @@ -2324,13 +2329,18 @@ impl ComponentInstance {
memory: *mut VMMemoryDefinition,
realloc: *mut VMFuncRef,
string_encoding: u8,
async_: bool,
ty: TableIndex,
err_ctx_ty: TypeComponentLocalErrorContextTableIndex,
flat_abi: Option<FlatAbi>,
handle: u32,
address: u32,
count: u32,
) -> Result<u32> {
if !async_ {
bail!("synchronous stream and future reads not yet supported");
}

let address = usize::try_from(address).unwrap();
let count = usize::try_from(count).unwrap();
let options = unsafe {
Expand Down
12 changes: 12 additions & 0 deletions crates/wasmtime/src/runtime/vm/component/libcalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,7 @@ unsafe fn future_write(
memory: *mut u8,
realloc: *mut u8,
string_encoding: u8,
async_: u8,
ty: u32,
err_ctx_ty: u32,
future: u32,
Expand All @@ -896,6 +897,7 @@ unsafe fn future_write(
memory.cast::<crate::vm::VMMemoryDefinition>(),
realloc.cast::<crate::vm::VMFuncRef>(),
string_encoding,
async_ != 0,
wasmtime_environ::component::TypeFutureTableIndex::from_u32(ty),
wasmtime_environ::component::TypeComponentLocalErrorContextTableIndex::from_u32(
err_ctx_ty,
Expand All @@ -912,6 +914,7 @@ unsafe fn future_read(
memory: *mut u8,
realloc: *mut u8,
string_encoding: u8,
async_: u8,
ty: u32,
err_ctx_ty: u32,
future: u32,
Expand All @@ -923,6 +926,7 @@ unsafe fn future_read(
memory.cast::<crate::vm::VMMemoryDefinition>(),
realloc.cast::<crate::vm::VMFuncRef>(),
string_encoding,
async_ != 0,
wasmtime_environ::component::TypeFutureTableIndex::from_u32(ty),
wasmtime_environ::component::TypeComponentLocalErrorContextTableIndex::from_u32(
err_ctx_ty,
Expand Down Expand Up @@ -1020,6 +1024,7 @@ unsafe fn stream_write(
memory: *mut u8,
realloc: *mut u8,
string_encoding: u8,
async_: u8,
ty: u32,
err_ctx_ty: u32,
stream: u32,
Expand All @@ -1032,6 +1037,7 @@ unsafe fn stream_write(
memory.cast::<crate::vm::VMMemoryDefinition>(),
realloc.cast::<crate::vm::VMFuncRef>(),
string_encoding,
async_ != 0,
wasmtime_environ::component::TypeStreamTableIndex::from_u32(ty),
wasmtime_environ::component::TypeComponentLocalErrorContextTableIndex::from_u32(
err_ctx_ty,
Expand All @@ -1049,6 +1055,7 @@ unsafe fn stream_read(
memory: *mut u8,
realloc: *mut u8,
string_encoding: u8,
async_: u8,
ty: u32,
err_ctx_ty: u32,
stream: u32,
Expand All @@ -1061,6 +1068,7 @@ unsafe fn stream_read(
memory.cast::<crate::vm::VMMemoryDefinition>(),
realloc.cast::<crate::vm::VMFuncRef>(),
string_encoding,
async_ != 0,
wasmtime_environ::component::TypeStreamTableIndex::from_u32(ty),
wasmtime_environ::component::TypeComponentLocalErrorContextTableIndex::from_u32(
err_ctx_ty,
Expand Down Expand Up @@ -1149,6 +1157,7 @@ unsafe fn flat_stream_write(
vmctx: NonNull<VMComponentContext>,
memory: *mut u8,
realloc: *mut u8,
async_: u8,
ty: u32,
err_ctx_ty: u32,
payload_size: u32,
Expand All @@ -1164,6 +1173,7 @@ unsafe fn flat_stream_write(
instance,
memory.cast::<crate::vm::VMMemoryDefinition>(),
realloc.cast::<crate::vm::VMFuncRef>(),
async_ != 0,
wasmtime_environ::component::TypeStreamTableIndex::from_u32(ty),
wasmtime_environ::component::TypeComponentLocalErrorContextTableIndex::from_u32(
err_ctx_ty,
Expand All @@ -1182,6 +1192,7 @@ unsafe fn flat_stream_read(
vmctx: NonNull<VMComponentContext>,
memory: *mut u8,
realloc: *mut u8,
async_: u8,
ty: u32,
err_ctx_ty: u32,
payload_size: u32,
Expand All @@ -1197,6 +1208,7 @@ unsafe fn flat_stream_read(
instance,
memory.cast::<crate::vm::VMMemoryDefinition>(),
realloc.cast::<crate::vm::VMFuncRef>(),
async_ != 0,
wasmtime_environ::component::TypeStreamTableIndex::from_u32(ty),
wasmtime_environ::component::TypeComponentLocalErrorContextTableIndex::from_u32(
err_ctx_ty,
Expand Down
Loading