From 8240bf4c558c2abb3732b22f7300dd99178c96cf Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 29 May 2026 11:43:12 -0700 Subject: [PATCH 1/3] Enable reflection on component async call stacks This commit adds a few new APIs to the surface area of the `wasmtime` crate as well as reorganizes some internals. Namely: * `StoreContextMut::async_call_stack` - yields an `Iterator` of the call stack of async tasks in the component model to understand the current call graph. * `{Typed,}Func::{start,finish}_call_concurrent` - these new APIs allow splitting apart the previous `call_concurrent` function into discrete steps to learn about the task being created, notably the `GuestTaskId`. The previous `call_concurrent` is reimplemented in terms of these functions. * Methods requiring the `component-model-async` Cargo feature are now under the `concurrent` module in `wasmtime` to cut down on `#[cfg]` required. This is all intended to address the concerns of WebAssembly/WASI#918, WebAssembly/WASI#919, and WebAssembly/WASI#920. This isn't plumbed into wasi-http yet, but that'll come as a --- .../src/runtime/component/concurrent.rs | 213 +++++--- .../src/runtime/component/concurrent/func.rs | 489 ++++++++++++++++++ crates/wasmtime/src/runtime/component/func.rs | 180 +------ .../src/runtime/component/func/typed.rs | 223 +------- crates/wasmtime/src/runtime/component/mod.rs | 7 +- tests/all/component_model/async.rs | 92 ++++ 6 files changed, 731 insertions(+), 473 deletions(-) create mode 100644 crates/wasmtime/src/runtime/component/concurrent/func.rs diff --git a/crates/wasmtime/src/runtime/component/concurrent.rs b/crates/wasmtime/src/runtime/component/concurrent.rs index 8061b242636c..b422691c3a64 100644 --- a/crates/wasmtime/src/runtime/component/concurrent.rs +++ b/crates/wasmtime/src/runtime/component/concurrent.rs @@ -51,7 +51,7 @@ //! in host functions. use crate::bail_bug; -use crate::component::func::{self, Func, call_post_return}; +use crate::component::func::{Func, call_post_return}; use crate::component::{ HasData, HasSelf, Instance, Resource, ResourceTable, ResourceTableError, RuntimeInstance, }; @@ -63,9 +63,9 @@ use crate::vm::{AlwaysMut, SendSyncPtr, VMFuncRef, VMMemoryDefinition, VMStore}; use crate::{ AsContext, AsContextMut, FuncType, Result, StoreContext, StoreContextMut, ValRaw, ValType, bail, }; +use core::marker; use error_contexts::GlobalErrorContextRefCount; use futures::channel::oneshot; -use futures::future::{self, FutureExt}; use futures::stream::{FuturesUnordered, StreamExt}; use futures_and_streams::{FlatAbi, ReturnCode, TransmitHandle, TransmitIndex}; use std::any::Any; @@ -74,6 +74,7 @@ use std::boxed::Box; use std::cell::UnsafeCell; use std::collections::{BTreeMap, BTreeSet, HashSet, VecDeque}; use std::fmt; +use std::future; use std::future::Future; use std::marker::PhantomData; use std::mem::{self, ManuallyDrop, MaybeUninit}; @@ -94,6 +95,7 @@ use wasmtime_environ::packed_option::ReservedValue; use wasmtime_environ::{NUM_COMPONENT_CONTEXT_SLOTS, Trap}; pub use abort::JoinHandle; +pub use func::{FuncCallConcurrent, TypedFuncCallConcurrent}; pub use future_stream_any::{FutureAny, StreamAny}; pub use futures_and_streams::{ Destination, DirectDestination, DirectSource, ErrorContext, FutureConsumer, FutureProducer, @@ -104,6 +106,7 @@ pub(crate) use futures_and_streams::{ResourcePair, lower_error_context_to_index} mod abort; mod error_contexts; +mod func; mod future_stream_any; mod futures_and_streams; pub(crate) mod table; @@ -1527,6 +1530,30 @@ impl StoreContextMut<'_, T> { closure(&mut accessor).await } } + + /// Returns an iterator over the current async call stack defined by the + /// component model. + /// + /// This can be used, for example to correlate a host import call with which + /// root export task originally called it. + /// + /// Tasks are yielded "youngest first" where the first item in the iterator + /// is the current task, and the last item in the iterator is the original + /// call. + pub fn async_call_stack(&mut self) -> impl Iterator { + let state = self.0.concurrent_state_mut(); + let mut cur = Some(state.current_thread); + core::iter::from_fn(move || { + while let Some(t) = cur { + cur = state.parent(t); + if let Some(thread) = t.guest() { + return Some(GuestTaskId(thread.task)); + } + } + + None + }) + } } impl StoreOpaque { @@ -1684,32 +1711,23 @@ impl StoreOpaque { return Ok(true); } let state = self.concurrent_state_mut(); - let mut cur = state.current_thread; - loop { - match cur { - CurrentThread::None => break Ok(true), - CurrentThread::Guest(thread) => { - let task = state.get_mut(thread.task)?; - - // Note that we only compare top-level instance IDs here. - // The idea is that the host is not allowed to recursively - // enter a top-level instance even if the specific leaf - // instance is not on the stack. This the behavior defined - // in the spec, and it allows us to elide runtime checks in - // guest-to-guest adapters. - if task.instance.instance == instance.instance { - break Ok(false); - } - cur = match task.caller { - Caller::Host { caller, .. } => caller, - Caller::Guest { thread } => thread.into(), - }; - } - CurrentThread::Host(id) => { - cur = state.get_mut(id)?.caller.into(); + let mut cur = Some(state.current_thread); + while let Some(t) = cur { + if let Some(thread) = t.guest() { + let task = state.get_mut(thread.task)?; + // Note that we only compare top-level instance IDs here. + // The idea is that the host is not allowed to recursively + // enter a top-level instance even if the specific leaf + // instance is not on the stack. This the behavior defined + // in the spec, and it allows us to elide runtime checks in + // guest-to-guest adapters. + if task.instance.instance == instance.instance { + return Ok(false); } } + cur = state.parent(t); } + Ok(true) } /// Helper function to retrieve the `InstanceState` for the @@ -3712,7 +3730,7 @@ impl Instance { } }; let memory = self.options_memory_mut(store, params.options); - let ptr = func::validate_inbounds_dynamic( + let ptr = crate::component::func::validate_inbounds_dynamic( &CanonicalAbiInfo::POINTER_PAIR, memory, &ValRaw::u32(params.payload), @@ -5351,6 +5369,21 @@ impl ConcurrentState { pub(crate) fn table(&mut self) -> &mut ResourceTable { self.table.get_mut() } + + /// Returns the parent thread, if any, of `cur`. + fn parent(&mut self, cur: CurrentThread) -> Option { + match cur { + CurrentThread::Guest(thread) => { + let task = self.get_mut(thread.task).ok()?; + Some(match task.caller { + Caller::Host { caller, .. } => caller, + Caller::Guest { thread } => thread.into(), + }) + } + CurrentThread::Host(id) => Some(self.get_mut(id).ok()?.caller.into()), + CurrentThread::None => None, + } + } } /// Provide a type hint to compiler about the shape of a parameter lower @@ -5372,37 +5405,23 @@ fn for_any_lift< fun } -/// Wrap the specified future in a `poll_fn` which asserts that the future is -/// only polled from the event loop of the specified `Store`. -/// -/// See `StoreContextMut::run_concurrent` for details. -fn checked( - id: StoreId, - fut: F, -) -> impl Future + Send + 'static { - async move { - let mut fut = pin!(fut); - future::poll_fn(move |cx| { - let message = "\ - `Future`s which depend on asynchronous component tasks, streams, or \ - futures to complete may only be polled from the event loop of the \ - store to which they belong. Please use \ - `StoreContextMut::{run_concurrent,spawn}` to poll or await them.\ - "; - tls::try_get(|store| { - let matched = match store { - tls::TryGet::Some(store) => store.id() == id, - tls::TryGet::Taken | tls::TryGet::None => false, - }; +fn check_ambient_store(id: StoreId) { + let message = "\ + `Future`s which depend on asynchronous component tasks, streams, or \ + futures to complete may only be polled from the event loop of the \ + store to which they belong. Please use \ + `StoreContextMut::{run_concurrent,spawn}` to poll or await them.\ + "; + tls::try_get(|store| { + let matched = match store { + tls::TryGet::Some(store) => store.id() == id, + tls::TryGet::Taken | tls::TryGet::None => false, + }; - if !matched { - panic!("{message}") - } - }); - fut.as_mut().poll(cx) - }) - .await - } + if !matched { + panic!("{message}") + } + }); } /// Assert that `StoreContextMut::run_concurrent` has not been called from @@ -5435,6 +5454,15 @@ enum WaitableCheck { Poll, } +/// An identifier representing a guest task within a component. +/// +/// This can be acquired by calling [`Func::start_call_concurrent`] or +/// [`TypedFunc::start_call_concurrent`] and then using the +/// [`FuncCallConcurrent::task`] accessor, for example. This can then be +/// reflected on with [`StoreContextMut::async_call_stack`]. +#[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)] +pub struct GuestTaskId(TableId); + /// Represents a guest task called from the host, prepared using `prepare_call`. pub(crate) struct PreparedCall { /// The guest export to be called @@ -5578,36 +5606,63 @@ pub(crate) fn prepare_call( }) } -/// Queue a call previously prepared using `prepare_call` to be run as part of -/// the associated `ComponentInstance`'s event loop. -/// -/// The returned future will resolve to the result once it is available, but -/// must only be polled via the instance's event loop. See -/// `StoreContextMut::run_concurrent` for details. -pub(crate) fn queue_call( - mut store: StoreContextMut, - prepared: PreparedCall, -) -> Result> + Send + 'static + use> { - let PreparedCall { - handle, - thread, - param_count, - rx, - .. - } = prepared; +pub(crate) struct QueuedCall { + store: StoreId, + task: TableId, + rx: oneshot::Receiver, + _marker: marker::PhantomData R>, +} + +impl QueuedCall { + /// Queue a call previously prepared using `prepare_call` to be run as part of + /// the associated `ComponentInstance`'s event loop. + /// + /// The returned future will resolve to the result once it is available, but + /// must only be polled via the instance's event loop. See + /// `StoreContextMut::run_concurrent` for details. + pub(crate) fn new( + mut store: StoreContextMut, + prepared: PreparedCall, + ) -> Result> { + let PreparedCall { + handle, + thread, + param_count, + rx, + .. + } = prepared; + + queue_call0(store.as_context_mut(), handle, thread, param_count)?; + + Ok(QueuedCall { + store: store.0.id(), + task: thread.task, + rx, + _marker: marker::PhantomData, + }) + } + + fn task(&self) -> GuestTaskId { + GuestTaskId(self.task) + } +} - queue_call0(store.as_context_mut(), handle, thread, param_count)?; +impl Future for QueuedCall +where + R: 'static, +{ + type Output = Result; - Ok(checked( - store.0.id(), - rx.map(move |result| match result { + fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { + check_ambient_store(self.store); + Pin::new(&mut self.rx).poll(cx).map(|result| match result { Ok(r) => match r.downcast() { Ok(r) => Ok(*r), Err(_) => bail_bug!("wrong type of value produced"), }, Err(e) => Err(e.into()), - }), - )) + }) + } } /// Queue a call previously prepared using `prepare_call` to be run as part of diff --git a/crates/wasmtime/src/runtime/component/concurrent/func.rs b/crates/wasmtime/src/runtime/component/concurrent/func.rs new file mode 100644 index 000000000000..57b5f05495d6 --- /dev/null +++ b/crates/wasmtime/src/runtime/component/concurrent/func.rs @@ -0,0 +1,489 @@ +use crate::component::concurrent::TaskId; +use crate::component::concurrent::{self, GuestTaskId, PreparedCall}; +use crate::component::func::LowerContext; +use crate::component::{AsAccessor, ComponentNamedList, Func, Lift, Lower, TypedFunc, Val}; +use crate::prelude::*; +use crate::runtime::vm::SendSyncPtr; +use crate::{AsContextMut, StoreContextMut, ValRaw}; +use core::marker; +use core::mem::MaybeUninit; +use core::ptr::NonNull; +use wasmtime_environ::component::{InterfaceType, MAX_FLAT_PARAMS, MAX_FLAT_RESULTS}; + +/// Returned from [`Func::start_call_concurrent`] to represent a +/// pending-but-not-yet-resolved call into wasm. +pub struct FuncCallConcurrent<'a, T> { + call: concurrent::QueuedCall>, + results: &'a mut [Val], + _marker: marker::PhantomData, +} + +impl Func { + /// Start a concurrent call to this function. + /// + /// Concurrency is achieved by relying on the [`Accessor`] argument, which + /// can be obtained by calling [`StoreContextMut::run_concurrent`]. + /// + /// Unlike [`Self::call`] and [`Self::call_async`] (both of which require + /// exclusive access to the store until the completion of the call), calls + /// made using this method may run concurrently with other calls to the same + /// instance. In addition, the runtime will call the `post-return` function + /// (if any) automatically when the guest task completes. + /// + /// # Progress + /// + /// For the wasm task being created in `call_concurrent` to make progress it + /// must be run within the scope of [`run_concurrent`]. If there are no + /// active calls to [`run_concurrent`] then the wasm task will appear as + /// stalled. This is typically not a concern as an [`Accessor`] is bound + /// by default to a scope of [`run_concurrent`]. + /// + /// One situation in which this can arise, for example, is that if a + /// [`run_concurrent`] computation finishes its async closure before all + /// wasm tasks have completed, then there will be no scope of + /// [`run_concurrent`] anywhere. In this situation the wasm tasks that have + /// not yet completed will not make progress until [`run_concurrent`] is + /// called again. + /// + /// Embedders will need to ensure that this future is `await`'d within the + /// scope of [`run_concurrent`] to ensure that the value can be produced + /// during the `await` call. + /// + /// # Cancellation + /// + /// Cancelling an async task created via `call_concurrent`, at this time, is + /// only possible by dropping the store that the computation runs within. + /// With [#11833] implemented then it will be possible to request + /// cancellation of a task, but that is not yet implemented. Hard-cancelling + /// a task will only ever be possible by dropping the entire store and it is + /// not possible to remove just one task from a store. + /// + /// This async function behaves more like a "spawn" than a normal Rust async + /// function. When this function is invoked then metadata for the function + /// call is recorded in the store connected to the `accessor` argument and + /// the wasm invocation is from then on connected to the store. If the + /// future created by this function is dropped it does not cancel the + /// in-progress execution of the wasm task. Dropping the future + /// relinquishes the host's ability to learn about the result of the task + /// but the task will still progress and invoke callbacks and such until + /// completion. + /// + /// This function will return an error if [`Config::concurrency_support`] is + /// disabled. + /// + /// [`Config::concurrency_support`]: crate::Config::concurrency_support + /// [`run_concurrent`]: crate::Store::run_concurrent + /// [#11833]: https://github.com/bytecodealliance/wasmtime/issues/11833 + /// [`Accessor`]: crate::component::Accessor + /// + /// # Panics + /// + /// Panics if the store that the [`Accessor`] is derived from does not own + /// this function. + /// + /// # Example + /// + /// Using [`StoreContextMut::run_concurrent`] to get an [`Accessor`]: + /// + /// ``` + /// # use { + /// # wasmtime::{ + /// # error::{Result}, + /// # component::{Component, Linker, ResourceTable}, + /// # Config, Engine, Store + /// # }, + /// # }; + /// # + /// # struct Ctx { table: ResourceTable } + /// # + /// # async fn foo() -> Result<()> { + /// # let mut config = Config::new(); + /// # let engine = Engine::new(&config)?; + /// # let mut store = Store::new(&engine, Ctx { table: ResourceTable::new() }); + /// # let mut linker = Linker::new(&engine); + /// # let component = Component::new(&engine, "")?; + /// # let instance = linker.instantiate_async(&mut store, &component).await?; + /// let my_func = instance.get_func(&mut store, "my_func").unwrap(); + /// store.run_concurrent(async |accessor| -> wasmtime::Result<_> { + /// my_func.call_concurrent(accessor, &[], &mut Vec::new()).await?; + /// Ok(()) + /// }).await??; + /// # Ok(()) + /// # } + /// ``` + pub async fn call_concurrent( + self, + accessor: impl AsAccessor, + params: &[Val], + results: &mut [Val], + ) -> Result<()> { + let accessor = accessor.as_accessor(); + let call = accessor.with(|store| self.start_call_concurrent(store, params, results))?; + self.finish_call_concurrent(accessor, call).await + } + + /// Performs preparatory work for invoking this function with `params`, + /// returning a [`FuncCallConcurrent`] + /// which can be passed to [`Func::finish_call_concurrent`] to resolve + /// the call. + /// + /// For more information see [`Func::call_concurrent`]. + pub fn start_call_concurrent<'a, T: Send + 'static>( + self, + mut store: impl AsContextMut, + params: &'a [Val], + results: &'a mut [Val], + ) -> Result> { + self.check_params_results(store.as_context_mut(), params, results)?; + let prepared = self.prepare_call_dynamic(store.as_context_mut(), params.to_vec())?; + let call = concurrent::QueuedCall::new(store.as_context_mut(), prepared)?; + Ok(FuncCallConcurrent { + call, + results, + _marker: marker::PhantomData, + }) + } + + /// Completes a call that was initiated via + /// [`Func::start_call_concurrent`]. + pub async fn finish_call_concurrent( + self, + accessor: impl AsAccessor, + call: FuncCallConcurrent<'_, T>, + ) -> Result<()> { + // Intentionally not used today, but left here for future API + // compatibility with using this. + let _ = accessor; + let FuncCallConcurrent { call, results, .. } = call; + let run_results = call.await?; + assert_eq!(run_results.len(), results.len()); + for (result, slot) in run_results.into_iter().zip(results) { + *slot = result; + } + Ok(()) + } + + /// Calls `concurrent::prepare_call` with monomorphized functions for + /// lowering the parameters and lifting the result. + fn prepare_call_dynamic<'a, T: Send + 'static>( + self, + mut store: StoreContextMut<'a, T>, + params: Vec, + ) -> Result>> { + let store = store.as_context_mut(); + + concurrent::prepare_call( + store, + self, + MAX_FLAT_PARAMS, + false, + move |func, store, params_out| { + func.with_lower_context(store, |cx, ty| { + Self::lower_args(cx, ¶ms, ty, params_out) + }) + }, + move |func, store, results| { + let max_flat = if func.abi_async(store) { + MAX_FLAT_PARAMS + } else { + MAX_FLAT_RESULTS + }; + let results = func.with_lift_context(store, |cx, ty| { + Self::lift_results(cx, ty, results, max_flat)?.collect::>>() + })?; + Ok(Box::new(results)) + }, + ) + } +} + +impl FuncCallConcurrent<'_, T> { + /// Returns the task that this invocation corresponds to. + /// + /// This can be later correlated with [`StoreContextMut::async_call_stack`] + /// for example. + pub fn task(&self) -> GuestTaskId { + self.call.task() + } +} + +/// Returned from [`TypedFunc::start_call_concurrent`] to represent a +/// pending-but-not-yet-resolved call into wasm. +pub struct TypedFuncCallConcurrent { + call: concurrent::QueuedCall, + _marker: marker::PhantomData, +} + +impl TypedFunc +where + Params: ComponentNamedList + Lower, + Return: ComponentNamedList + Lift, +{ + pub(crate) async fn call_async_concurrent( + &self, + mut store: impl AsContextMut, + params: Params, + ) -> Result + where + Return: 'static, + { + let mut store = store.as_context_mut(); + let ptr = SendSyncPtr::from(NonNull::from(¶ms).cast::()); + let prepared = self.prepare_call(store.as_context_mut(), true, move |cx, ty, dst| { + // SAFETY: The goal here is to get `Params`, a non-`'static` + // value, to live long enough to the lowering of the + // parameters. We're guaranteed that `Params` lives in the + // future of the outer function (we're in an `async fn`) so it'll + // stay alive as long as the future itself. That is distinct, + // for example, from the signature of `call_concurrent` below. + // + // Here a pointer to `Params` is smuggled to this location + // through a `SendSyncPtr` to thwart the `'static` check + // of rustc and the signature of `prepare_call`. + // + // Note the use of `SignalOnDrop` in the code that follows + // this closure, which ensures that the task will be removed + // from the concurrent state to which it belongs when the + // containing `Future` is dropped, so long as the parameters + // have not yet been lowered. Since this closure is removed from + // the task after the parameters are lowered, it will never be called + // after the containing `Future` is dropped. + let params = unsafe { ptr.cast::().as_ref() }; + Self::lower_args(cx, ty, dst, params) + })?; + + struct SignalOnDrop<'a, T: 'static> { + store: StoreContextMut<'a, T>, + task: TaskId, + } + + impl<'a, T> Drop for SignalOnDrop<'a, T> { + fn drop(&mut self) { + self.task.host_future_dropped(self.store.0).unwrap(); + } + } + + let mut wrapper = SignalOnDrop { + store, + task: prepared.task_id(), + }; + + let result = concurrent::QueuedCall::new(wrapper.store.as_context_mut(), prepared)?; + wrapper + .store + .as_context_mut() + .run_concurrent_trap_on_idle(async |_| Ok(result.await?)) + .await? + } + + /// Start a concurrent call to this function. + /// + /// Concurrency is achieved by relying on the [`Accessor`] argument, which + /// can be obtained by calling [`StoreContextMut::run_concurrent`]. + /// + /// Unlike [`Self::call`] and [`Self::call_async`] (both of which require + /// exclusive access to the store until the completion of the call), calls + /// made using this method may run concurrently with other calls to the same + /// instance. In addition, the runtime will call the `post-return` function + /// (if any) automatically when the guest task completes. + /// + /// This function will return an error if [`Config::concurrency_support`] is + /// disabled. + /// + /// [`Config::concurrency_support`]: crate::Config::concurrency_support + /// + /// # Progress and Cancellation + /// + /// For more information about how to make progress on the wasm task or how + /// to cancel the wasm task see the documentation for + /// [`Func::call_concurrent`]. + /// + /// [`Func::call_concurrent`]: crate::component::Func::call_concurrent + /// + /// # Panics + /// + /// Panics if the store that the [`Accessor`] is derived from does not own + /// this function. + /// + /// [`Accessor`]: crate::component::Accessor + /// + /// # Example + /// + /// Using [`StoreContextMut::run_concurrent`] to get an [`Accessor`]: + /// + /// ``` + /// # use { + /// # wasmtime::{ + /// # error::{Result}, + /// # component::{Component, Linker, ResourceTable}, + /// # Config, Engine, Store + /// # }, + /// # }; + /// # + /// # struct Ctx { table: ResourceTable } + /// # + /// # async fn foo() -> Result<()> { + /// # let mut config = Config::new(); + /// # let engine = Engine::new(&config)?; + /// # let mut store = Store::new(&engine, Ctx { table: ResourceTable::new() }); + /// # let mut linker = Linker::new(&engine); + /// # let component = Component::new(&engine, "")?; + /// # let instance = linker.instantiate_async(&mut store, &component).await?; + /// let my_typed_func = instance.get_typed_func::<(), ()>(&mut store, "my_typed_func")?; + /// store.run_concurrent(async |accessor| -> wasmtime::Result<_> { + /// my_typed_func.call_concurrent(accessor, ()).await?; + /// Ok(()) + /// }).await??; + /// # Ok(()) + /// # } + /// ``` + pub async fn call_concurrent( + self, + accessor: impl AsAccessor, + params: Params, + ) -> Result + where + Params: 'static, + Return: 'static, + { + let call = accessor + .as_accessor() + .with(|store| self.start_call_concurrent(store, params))?; + self.finish_call_concurrent(accessor, call).await + } + + /// Performs preparatory work for invoking this function with `params`, + /// returning a [`TypedFuncCallConcurrent`] + /// which can be passed to [`TypedFunc::finish_call_concurrent`] to resolve + /// the call. + /// + /// For more information see [`TypedFunc::call_concurrent`]. + pub fn start_call_concurrent( + self, + mut store: impl AsContextMut, + params: Params, + ) -> Result> + where + T: Send + 'static, + Params: 'static, + Return: 'static, + { + let mut store = store.as_context_mut(); + let mut store = store.as_context_mut(); + ensure!( + store.0.concurrency_support(), + "cannot use `call_concurrent` Config::concurrency_support disabled", + ); + + let prepared = self.prepare_call(store.as_context_mut(), false, move |cx, ty, dst| { + Self::lower_args(cx, ty, dst, ¶ms) + })?; + let call = concurrent::QueuedCall::new(store, prepared)?; + Ok(TypedFuncCallConcurrent { + call, + _marker: marker::PhantomData, + }) + } + + /// Completes a call that was initiated via + /// [`TypedFunc::start_call_concurrent`]. + pub async fn finish_call_concurrent( + self, + accessor: impl AsAccessor, + call: TypedFuncCallConcurrent, + ) -> Result + where + T: Send + 'static, + Params: 'static, + Return: 'static, + { + // This is intentionally part of the public API but not used yet. + // This'll likely want to be used in future refactorings. + let _ = accessor; + call.call.await + } + + /// Calls `concurrent::prepare_call` with monomorphized functions for + /// lowering the parameters and lifting the result according to the number + /// of core Wasm parameters and results in the signature of the function to + /// be called. + fn prepare_call( + self, + store: StoreContextMut<'_, T>, + host_future_present: bool, + lower: impl FnOnce( + &mut LowerContext, + InterfaceType, + &mut [MaybeUninit], + ) -> Result<()> + + Send + + Sync + + 'static, + ) -> Result> + where + Return: 'static, + { + use crate::component::storage::slice_to_storage; + debug_assert!(store.0.concurrency_support()); + + let param_count = if Params::flatten_count() <= MAX_FLAT_PARAMS { + Params::flatten_count() + } else { + 1 + }; + let max_results = if self.func().abi_async(store.0) { + MAX_FLAT_PARAMS + } else { + MAX_FLAT_RESULTS + }; + concurrent::prepare_call( + store, + *self.func(), + param_count, + host_future_present, + move |func, store, params_out| { + func.with_lower_context(store, |cx, ty| lower(cx, ty, params_out)) + }, + move |func, store, results| { + let result = if Return::flatten_count() <= max_results { + func.with_lift_context(store, |cx, ty| { + // SAFETY: Per the safety requiments documented for the + // `ComponentType` trait, `Return::Lower` must be + // compatible at the binary level with a `[ValRaw; N]`, + // where `N` is `mem::size_of::() / + // mem::size_of::()`. And since this function + // is only used when `Return::flatten_count() <= + // MAX_FLAT_RESULTS` and `MAX_FLAT_RESULTS == 1`, `N` + // can only either be 0 or 1. + // + // See `ComponentInstance::exit_call` for where we use + // the result count passed from + // `wasmtime_environ::fact::trampoline`-generated code + // to ensure the slice has the correct length, and also + // `concurrent::start_call` for where we conservatively + // use a slice length of 1 unconditionally. Also note + // that, as of this writing `slice_to_storage` + // double-checks the slice length is sufficient. + let results: &Return::Lower = unsafe { slice_to_storage(results) }; + Self::lift_stack_result(cx, ty, results) + })? + } else { + func.with_lift_context(store, |cx, ty| { + Self::lift_heap_result(cx, ty, &results[0]) + })? + }; + Ok(Box::new(result)) + }, + ) + } +} + +impl TypedFuncCallConcurrent { + /// Returns the task that this invocation corresponds to. + /// + /// This can be later correlated with [`StoreContextMut::async_call_stack`] + /// for example. + pub fn task(&self) -> GuestTaskId { + self.call.task() + } +} diff --git a/crates/wasmtime/src/runtime/component/func.rs b/crates/wasmtime/src/runtime/component/func.rs index ff7bfafc4056..423bb60ebb04 100644 --- a/crates/wasmtime/src/runtime/component/func.rs +++ b/crates/wasmtime/src/runtime/component/func.rs @@ -15,9 +15,6 @@ use wasmtime_environ::component::{ TypeFuncIndex, TypeTuple, }; -#[cfg(feature = "component-model-async")] -use crate::component::concurrent::{self, AsAccessor, PreparedCall}; - mod host; mod options; mod typed; @@ -263,26 +260,24 @@ impl Func { params: &[Val], results: &mut [Val], ) -> Result<()> { - let store = store.as_context_mut(); + let mut store = store.as_context_mut(); #[cfg(feature = "component-model-async")] if store.0.concurrency_support() { + let call = self.start_call_concurrent(&mut store, params, results)?; return store .run_concurrent_trap_on_idle(async |store| { - self.call_concurrent_dynamic(store, params, results) - .await - .map(drop) + self.finish_call_concurrent(store, call).await }) .await?; } - let mut store = store; store .on_fiber(|store| self.call_impl(store, params, results)) .await? } - fn check_params_results( + pub(crate) fn check_params_results( &self, store: StoreContextMut, params: &[Val], @@ -308,165 +303,6 @@ impl Func { Ok(()) } - /// Start a concurrent call to this function. - /// - /// Concurrency is achieved by relying on the [`Accessor`] argument, which - /// can be obtained by calling [`StoreContextMut::run_concurrent`]. - /// - /// Unlike [`Self::call`] and [`Self::call_async`] (both of which require - /// exclusive access to the store until the completion of the call), calls - /// made using this method may run concurrently with other calls to the same - /// instance. In addition, the runtime will call the `post-return` function - /// (if any) automatically when the guest task completes. - /// - /// # Progress - /// - /// For the wasm task being created in `call_concurrent` to make progress it - /// must be run within the scope of [`run_concurrent`]. If there are no - /// active calls to [`run_concurrent`] then the wasm task will appear as - /// stalled. This is typically not a concern as an [`Accessor`] is bound - /// by default to a scope of [`run_concurrent`]. - /// - /// One situation in which this can arise, for example, is that if a - /// [`run_concurrent`] computation finishes its async closure before all - /// wasm tasks have completed, then there will be no scope of - /// [`run_concurrent`] anywhere. In this situation the wasm tasks that have - /// not yet completed will not make progress until [`run_concurrent`] is - /// called again. - /// - /// Embedders will need to ensure that this future is `await`'d within the - /// scope of [`run_concurrent`] to ensure that the value can be produced - /// during the `await` call. - /// - /// # Cancellation - /// - /// Cancelling an async task created via `call_concurrent`, at this time, is - /// only possible by dropping the store that the computation runs within. - /// With [#11833] implemented then it will be possible to request - /// cancellation of a task, but that is not yet implemented. Hard-cancelling - /// a task will only ever be possible by dropping the entire store and it is - /// not possible to remove just one task from a store. - /// - /// This async function behaves more like a "spawn" than a normal Rust async - /// function. When this function is invoked then metadata for the function - /// call is recorded in the store connected to the `accessor` argument and - /// the wasm invocation is from then on connected to the store. If the - /// future created by this function is dropped it does not cancel the - /// in-progress execution of the wasm task. Dropping the future - /// relinquishes the host's ability to learn about the result of the task - /// but the task will still progress and invoke callbacks and such until - /// completion. - /// - /// This function will return an error if [`Config::concurrency_support`] is - /// disabled. - /// - /// [`Config::concurrency_support`]: crate::Config::concurrency_support - /// [`run_concurrent`]: crate::Store::run_concurrent - /// [#11833]: https://github.com/bytecodealliance/wasmtime/issues/11833 - /// [`Accessor`]: crate::component::Accessor - /// - /// # Panics - /// - /// Panics if the store that the [`Accessor`] is derived from does not own - /// this function. - /// - /// # Example - /// - /// Using [`StoreContextMut::run_concurrent`] to get an [`Accessor`]: - /// - /// ``` - /// # use { - /// # wasmtime::{ - /// # error::{Result}, - /// # component::{Component, Linker, ResourceTable}, - /// # Config, Engine, Store - /// # }, - /// # }; - /// # - /// # struct Ctx { table: ResourceTable } - /// # - /// # async fn foo() -> Result<()> { - /// # let mut config = Config::new(); - /// # let engine = Engine::new(&config)?; - /// # let mut store = Store::new(&engine, Ctx { table: ResourceTable::new() }); - /// # let mut linker = Linker::new(&engine); - /// # let component = Component::new(&engine, "")?; - /// # let instance = linker.instantiate_async(&mut store, &component).await?; - /// let my_func = instance.get_func(&mut store, "my_func").unwrap(); - /// store.run_concurrent(async |accessor| -> wasmtime::Result<_> { - /// my_func.call_concurrent(accessor, &[], &mut Vec::new()).await?; - /// Ok(()) - /// }).await??; - /// # Ok(()) - /// # } - /// ``` - #[cfg(feature = "component-model-async")] - pub async fn call_concurrent( - self, - accessor: impl AsAccessor, - params: &[Val], - results: &mut [Val], - ) -> Result<()> { - self.call_concurrent_dynamic(accessor, params, results) - .await - } - - /// Internal helper function for `call_async` and `call_concurrent`. - #[cfg(feature = "component-model-async")] - async fn call_concurrent_dynamic( - self, - accessor: impl AsAccessor, - params: &[Val], - results: &mut [Val], - ) -> Result<()> { - let result = accessor.as_accessor().with(|mut store| { - self.check_params_results(store.as_context_mut(), params, results)?; - let prepared = self.prepare_call_dynamic(store.as_context_mut(), params.to_vec())?; - concurrent::queue_call(store.as_context_mut(), prepared) - })?; - - let run_results = result.await?; - assert_eq!(run_results.len(), results.len()); - for (result, slot) in run_results.into_iter().zip(results) { - *slot = result; - } - Ok(()) - } - - /// Calls `concurrent::prepare_call` with monomorphized functions for - /// lowering the parameters and lifting the result. - #[cfg(feature = "component-model-async")] - fn prepare_call_dynamic<'a, T: Send + 'static>( - self, - mut store: StoreContextMut<'a, T>, - params: Vec, - ) -> Result>> { - let store = store.as_context_mut(); - - concurrent::prepare_call( - store, - self, - MAX_FLAT_PARAMS, - false, - move |func, store, params_out| { - func.with_lower_context(store, |cx, ty| { - Self::lower_args(cx, ¶ms, ty, params_out) - }) - }, - move |func, store, results| { - let max_flat = if func.abi_async(store) { - MAX_FLAT_PARAMS - } else { - MAX_FLAT_RESULTS - }; - let results = func.with_lift_context(store, |cx, ty| { - Self::lift_results(cx, ty, results, max_flat)?.collect::>>() - })?; - Ok(Box::new(results)) - }, - ) - } - fn call_impl( &self, mut store: impl AsContextMut, @@ -728,7 +564,7 @@ impl Func { Ok(()) } - fn lower_args( + pub(crate) fn lower_args( cx: &mut LowerContext<'_, T>, params: &[Val], params_ty: InterfaceType, @@ -769,7 +605,7 @@ impl Func { Ok(()) } - fn lift_results<'a, 'b>( + pub(crate) fn lift_results<'a, 'b>( cx: &'a mut LiftContext<'b>, results_ty: InterfaceType, src: &'a [ValRaw], @@ -829,7 +665,7 @@ impl Func { /// The `lower` closure provided should perform the actual lowering and /// return the result of the lowering operation which is then returned from /// this function as well. - fn with_lower_context( + pub(crate) fn with_lower_context( self, mut store: StoreContextMut, lower: impl FnOnce(&mut LowerContext, InterfaceType) -> Result<()>, @@ -854,7 +690,7 @@ impl Func { /// /// The closure `lift` provided should actually perform the lift itself and /// the result of that closure is returned from this function call as well. - fn with_lift_context( + pub(crate) fn with_lift_context( self, store: &mut StoreOpaque, lift: impl FnOnce(&mut LiftContext, InterfaceType) -> Result, diff --git a/crates/wasmtime/src/runtime/component/func/typed.rs b/crates/wasmtime/src/runtime/component/func/typed.rs index f176a299e334..e3655117ea00 100644 --- a/crates/wasmtime/src/runtime/component/func/typed.rs +++ b/crates/wasmtime/src/runtime/component/func/typed.rs @@ -17,9 +17,6 @@ use wasmtime_environ::component::{ OptionsIndex, StringEncoding, TypeMap, VariantInfo, }; -#[cfg(feature = "component-model-async")] -use crate::component::concurrent::{self, AsAccessor, PreparedCall}; - /// A statically-typed version of [`Func`] which takes `Params` as input and /// returns `Return`. /// @@ -178,57 +175,7 @@ where #[cfg(feature = "component-model-async")] if store.0.concurrency_support() { - use crate::component::concurrent::TaskId; - use crate::runtime::vm::SendSyncPtr; - use core::ptr::NonNull; - - let ptr = SendSyncPtr::from(NonNull::from(¶ms).cast::()); - let prepared = - self.prepare_call(store.as_context_mut(), true, move |cx, ty, dst| { - // SAFETY: The goal here is to get `Params`, a non-`'static` - // value, to live long enough to the lowering of the - // parameters. We're guaranteed that `Params` lives in the - // future of the outer function (we're in an `async fn`) so it'll - // stay alive as long as the future itself. That is distinct, - // for example, from the signature of `call_concurrent` below. - // - // Here a pointer to `Params` is smuggled to this location - // through a `SendSyncPtr` to thwart the `'static` check - // of rustc and the signature of `prepare_call`. - // - // Note the use of `SignalOnDrop` in the code that follows - // this closure, which ensures that the task will be removed - // from the concurrent state to which it belongs when the - // containing `Future` is dropped, so long as the parameters - // have not yet been lowered. Since this closure is removed from - // the task after the parameters are lowered, it will never be called - // after the containing `Future` is dropped. - let params = unsafe { ptr.cast::().as_ref() }; - Self::lower_args(cx, ty, dst, params) - })?; - - struct SignalOnDrop<'a, T: 'static> { - store: StoreContextMut<'a, T>, - task: TaskId, - } - - impl<'a, T> Drop for SignalOnDrop<'a, T> { - fn drop(&mut self) { - self.task.host_future_dropped(self.store.0).unwrap(); - } - } - - let mut wrapper = SignalOnDrop { - store, - task: prepared.task_id(), - }; - - let result = concurrent::queue_call(wrapper.store.as_context_mut(), prepared)?; - return wrapper - .store - .as_context_mut() - .run_concurrent_trap_on_idle(async |_| Ok(result.await?)) - .await?; + return self.call_async_concurrent(store, params).await; } store @@ -236,94 +183,7 @@ where .await? } - /// Start a concurrent call to this function. - /// - /// Concurrency is achieved by relying on the [`Accessor`] argument, which - /// can be obtained by calling [`StoreContextMut::run_concurrent`]. - /// - /// Unlike [`Self::call`] and [`Self::call_async`] (both of which require - /// exclusive access to the store until the completion of the call), calls - /// made using this method may run concurrently with other calls to the same - /// instance. In addition, the runtime will call the `post-return` function - /// (if any) automatically when the guest task completes. - /// - /// This function will return an error if [`Config::concurrency_support`] is - /// disabled. - /// - /// [`Config::concurrency_support`]: crate::Config::concurrency_support - /// - /// # Progress and Cancellation - /// - /// For more information about how to make progress on the wasm task or how - /// to cancel the wasm task see the documentation for - /// [`Func::call_concurrent`]. - /// - /// [`Func::call_concurrent`]: crate::component::Func::call_concurrent - /// - /// # Panics - /// - /// Panics if the store that the [`Accessor`] is derived from does not own - /// this function. - /// - /// [`Accessor`]: crate::component::Accessor - /// - /// # Example - /// - /// Using [`StoreContextMut::run_concurrent`] to get an [`Accessor`]: - /// - /// ``` - /// # use { - /// # wasmtime::{ - /// # error::{Result}, - /// # component::{Component, Linker, ResourceTable}, - /// # Config, Engine, Store - /// # }, - /// # }; - /// # - /// # struct Ctx { table: ResourceTable } - /// # - /// # async fn foo() -> Result<()> { - /// # let mut config = Config::new(); - /// # let engine = Engine::new(&config)?; - /// # let mut store = Store::new(&engine, Ctx { table: ResourceTable::new() }); - /// # let mut linker = Linker::new(&engine); - /// # let component = Component::new(&engine, "")?; - /// # let instance = linker.instantiate_async(&mut store, &component).await?; - /// let my_typed_func = instance.get_typed_func::<(), ()>(&mut store, "my_typed_func")?; - /// store.run_concurrent(async |accessor| -> wasmtime::Result<_> { - /// my_typed_func.call_concurrent(accessor, ()).await?; - /// Ok(()) - /// }).await??; - /// # Ok(()) - /// # } - /// ``` - #[cfg(feature = "component-model-async")] - pub async fn call_concurrent( - self, - accessor: impl AsAccessor, - params: Params, - ) -> Result - where - Params: 'static, - Return: 'static, - { - let result = accessor.as_accessor().with(|mut store| { - let mut store = store.as_context_mut(); - ensure!( - store.0.concurrency_support(), - "cannot use `call_concurrent` Config::concurrency_support disabled", - ); - - let prepared = - self.prepare_call(store.as_context_mut(), false, move |cx, ty, dst| { - Self::lower_args(cx, ty, dst, ¶ms) - })?; - concurrent::queue_call(store, prepared) - }); - Ok(result?.await?) - } - - fn lower_args( + pub(crate) fn lower_args( cx: &mut LowerContext, ty: InterfaceType, dst: &mut [MaybeUninit], @@ -343,81 +203,6 @@ where } } - /// Calls `concurrent::prepare_call` with monomorphized functions for - /// lowering the parameters and lifting the result according to the number - /// of core Wasm parameters and results in the signature of the function to - /// be called. - #[cfg(feature = "component-model-async")] - fn prepare_call( - self, - store: StoreContextMut<'_, T>, - host_future_present: bool, - lower: impl FnOnce( - &mut LowerContext, - InterfaceType, - &mut [MaybeUninit], - ) -> Result<()> - + Send - + Sync - + 'static, - ) -> Result> - where - Return: 'static, - { - use crate::component::storage::slice_to_storage; - debug_assert!(store.0.concurrency_support()); - - let param_count = if Params::flatten_count() <= MAX_FLAT_PARAMS { - Params::flatten_count() - } else { - 1 - }; - let max_results = if self.func.abi_async(store.0) { - MAX_FLAT_PARAMS - } else { - MAX_FLAT_RESULTS - }; - concurrent::prepare_call( - store, - self.func, - param_count, - host_future_present, - move |func, store, params_out| { - func.with_lower_context(store, |cx, ty| lower(cx, ty, params_out)) - }, - move |func, store, results| { - let result = if Return::flatten_count() <= max_results { - func.with_lift_context(store, |cx, ty| { - // SAFETY: Per the safety requiments documented for the - // `ComponentType` trait, `Return::Lower` must be - // compatible at the binary level with a `[ValRaw; N]`, - // where `N` is `mem::size_of::() / - // mem::size_of::()`. And since this function - // is only used when `Return::flatten_count() <= - // MAX_FLAT_RESULTS` and `MAX_FLAT_RESULTS == 1`, `N` - // can only either be 0 or 1. - // - // See `ComponentInstance::exit_call` for where we use - // the result count passed from - // `wasmtime_environ::fact::trampoline`-generated code - // to ensure the slice has the correct length, and also - // `concurrent::start_call` for where we conservatively - // use a slice length of 1 unconditionally. Also note - // that, as of this writing `slice_to_storage` - // double-checks the slice length is sufficient. - let results: &Return::Lower = unsafe { slice_to_storage(results) }; - Self::lift_stack_result(cx, ty, results) - })? - } else { - func.with_lift_context(store, |cx, ty| { - Self::lift_heap_result(cx, ty, &results[0]) - })? - }; - Ok(Box::new(result)) - }, - ) - } - fn call_impl(&self, mut store: impl AsContextMut, params: Params) -> Result { let mut store = store.as_context_mut(); @@ -539,7 +324,7 @@ where /// /// This is only used when the result fits in the maximum number of stack /// slots. - fn lift_stack_result( + pub(crate) fn lift_stack_result( cx: &mut LiftContext<'_>, ty: InterfaceType, dst: &Return::Lower, @@ -549,7 +334,7 @@ where /// Lift the result of a function where the result is stored indirectly on /// the heap. - fn lift_heap_result( + pub(crate) fn lift_heap_result( cx: &mut LiftContext<'_>, ty: InterfaceType, dst: &ValRaw, diff --git a/crates/wasmtime/src/runtime/component/mod.rs b/crates/wasmtime/src/runtime/component/mod.rs index 093ada9cddc5..7b82664408ac 100644 --- a/crates/wasmtime/src/runtime/component/mod.rs +++ b/crates/wasmtime/src/runtime/component/mod.rs @@ -120,9 +120,10 @@ pub use self::component::{Component, ComponentExportIndex, ExportLookup}; #[cfg(feature = "component-model-async")] pub use self::concurrent::{ Access, Accessor, AccessorTask, AsAccessor, Destination, DirectDestination, DirectSource, - ErrorContext, FutureAny, FutureConsumer, FutureProducer, FutureReader, GuardedFutureReader, - GuardedStreamReader, JoinHandle, ReadBuffer, Source, StreamAny, StreamConsumer, StreamProducer, - StreamReader, StreamResult, VMComponentAsyncStore, VecBuffer, WriteBuffer, + ErrorContext, FuncCallConcurrent, FutureAny, FutureConsumer, FutureProducer, FutureReader, + GuardedFutureReader, GuardedStreamReader, GuestTaskId, JoinHandle, ReadBuffer, Source, + StreamAny, StreamConsumer, StreamProducer, StreamReader, StreamResult, TypedFuncCallConcurrent, + VMComponentAsyncStore, VecBuffer, WriteBuffer, }; pub use self::func::{ ComponentNamedList, ComponentType, Func, Lift, Lower, TypedFunc, WasmList, WasmStr, diff --git a/tests/all/component_model/async.rs b/tests/all/component_model/async.rs index 2a91f1be206c..7df03ca8df8a 100644 --- a/tests/all/component_model/async.rs +++ b/tests/all/component_model/async.rs @@ -970,3 +970,95 @@ async fn bytes_stream_producer() -> Result<()> { Ok(()) } + +#[tokio::test] +#[cfg_attr(miri, ignore)] +async fn async_call_stack() -> Result<()> { + let mut config = Config::new(); + config.wasm_component_model_async(true); + let engine = Engine::new(&config)?; + + let component = Component::new( + &engine, + r#" + (component + (import "a" (func $a)) + (core func $a (canon lower (func $a))) + + (core module $a + (import "" "a" (func $a)) + (func (export "a") call $a) + ) + (core instance $a (instantiate $a + (with "" (instance (export "a" (func $a)))) + )) + (func (export "a") async (canon lift (core func $a "a"))) + ) + "#, + )?; + + let mut linker = Linker::new(&engine); + linker.root().func_wrap( + "a", + |mut store: StoreContextMut>, (): ()| { + let stack = store.async_call_stack().collect::>(); + assert_eq!(stack, [store.data().unwrap()]); + Ok(()) + }, + )?; + let mut store = Store::new(&engine, None); + let instance = linker.instantiate_async(&mut store, &component).await?; + let func = instance.get_typed_func::<(), ()>(&mut store, "a")?; + + let call = func.start_call_concurrent(&mut store, ())?; + *store.data_mut() = Some(call.task()); + store + .run_concurrent(async |store| func.finish_call_concurrent(store, call).await) + .await??; + + let component = Component::new( + &engine, + r#" + (component + (import "a" (func $a)) + (component $a + (import "a" (func $a)) + (core func $a (canon lower (func $a))) + + (core module $a + (import "" "a" (func $a)) + (func (export "a") call $a) + ) + (core instance $a (instantiate $a + (with "" (instance (export "a" (func $a)))) + )) + (func (export "a") (canon lift (core func $a "a"))) + ) + + (instance $a (instantiate $a (with "a" (func $a)))) + (instance $b (instantiate $a (with "a" (func $a "a")))) + (export "a" (func $b "a")) + ) + "#, + )?; + + let mut linker = Linker::new(&engine); + linker.root().func_wrap( + "a", + |mut store: StoreContextMut>, (): ()| { + let stack = store.async_call_stack().collect::>(); + assert_eq!(stack.len(), 2); + assert_eq!(stack.last(), store.data().as_ref()); + Ok(()) + }, + )?; + let instance = linker.instantiate_async(&mut store, &component).await?; + let func = instance.get_typed_func::<(), ()>(&mut store, "a")?; + + let call = func.start_call_concurrent(&mut store, ())?; + *store.data_mut() = Some(call.task()); + store + .run_concurrent(async |store| func.finish_call_concurrent(store, call).await) + .await??; + Ok(()) +} From c7b46290de5d649b5275723115800f5a92f4b4d7 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 29 May 2026 12:44:55 -0700 Subject: [PATCH 2/3] Thread request IDs through `wasi:http` handling This commit uses the previous commit to connect a generic, host-defined, request ID and provide a strong connection to the `GuestTaskId` that's being used to serve that request. This can be used by `wasi:http` handlers to provide a strong correlation between outgoing requests, for example, and incoming requests. --- crates/wasi-http/src/handler.rs | 456 +++++++++++++++++++------------- crates/wit-bindgen/src/lib.rs | 58 ++-- src/commands/serve.rs | 41 ++- 3 files changed, 329 insertions(+), 226 deletions(-) diff --git a/crates/wasi-http/src/handler.rs b/crates/wasi-http/src/handler.rs index 71f5a728caec..536ef772ac67 100644 --- a/crates/wasi-http/src/handler.rs +++ b/crates/wasi-http/src/handler.rs @@ -1,6 +1,8 @@ //! Provides utilities useful for dispatching incoming HTTP requests //! `wasi:http/handler` guest instances. +#[cfg(feature = "p2")] +use crate::p2; #[cfg(feature = "p2")] use crate::p2::bindings::http::types as p2_types; #[cfg(feature = "p3")] @@ -29,10 +31,10 @@ use std::sync::{ use std::task::{Context, Poll}; use std::time::Instant; use tokio::sync::Notify; -use wasmtime::component::Accessor; +use wasmtime::component::{Accessor, GuestTaskId, Resource, TypedFuncCallConcurrent}; #[cfg(feature = "p2")] use wasmtime::error::Context as _; -use wasmtime::{AsContextMut, Result, Store, format_err}; +use wasmtime::{AsContextMut, Result, Store, StoreContextMut, format_err}; /// Represents either a `wasi:http/types@0.2.x` or `wasi:http/types@0.3.x` `error-code`. pub enum ErrorCode { @@ -287,30 +289,6 @@ pub type Request = http::Request>; /// A Response returned by `ProxyHandler::handle`. pub type Response = http::Response>; -/// Alternative p2 bindings generated with `exports: { default: async | store }` -/// so we can use `TypedFunc::call_concurrent` with both p2 and p3 instances. -#[cfg(feature = "p2")] -pub mod p2 { - #[expect(missing_docs, reason = "bindgen-generated code")] - pub mod bindings { - wasmtime::component::bindgen!({ - path: "wit", - world: "wasi:http/proxy", - imports: { default: tracing }, - exports: { default: async | store }, - require_store_data_send: true, - with: { - // http is in this crate - "wasi:http": crate::p2::bindings::http, - // Upstream package dependencies - "wasi:io": wasmtime_wasi::p2::bindings::io, - } - }); - - pub use wasi::*; - } -} - /// Represents either a `wasi:http/incoming-handler@0.2.x` or /// `wasi:http/handler@0.3.x` pre-instance. pub enum ProxyPre { @@ -442,6 +420,11 @@ pub trait WorkerState: 'static + Send + Sync { /// The type of the associated data for [`Store`] belonging to this worker. type StoreData: Send; + /// An opaque unique identifier that hosts can assigned to requests which is + /// threaded from [`ProxyHandler::handle`] into + /// [`WorkerState::on_request_start`] + type RequestId: Send + Sync; + /// Indicate whether the worker should accept another request given the /// current number it is already handling concurrently and the total it has /// handled so far. @@ -449,6 +432,10 @@ pub trait WorkerState: 'static + Send + Sync { /// Notification that a request has been accepted by the worker. /// + /// This method can be used to record anything within `store`, if necessary. + /// The `task` corresponding to the component-model-level async task about + /// to be created is additionally passed here. + /// /// If the future returned by this function resolves before the guest has /// produced a response, the request will be considered "expired" and the /// original `ProxyHandler::handle` future will resolve to an @@ -477,7 +464,9 @@ pub trait WorkerState: 'static + Send + Sync { /// defence" will no longer be necessary. fn on_request_start( &self, - request: &Request, + store: StoreContextMut<'_, Self::StoreData>, + id: Self::RequestId, + task: GuestTaskId, ) -> Pin + 'static + Send + Sync>>; /// Dispose of the store belonging to the now-exited worker. @@ -542,7 +531,7 @@ pub trait HandlerState: 'static + Sync + Send + Sized { struct ProxyHandlerInner { state: S, - request_queue: Queue<(Request, oneshot::Sender>)>, + request_queue: Queue>, worker_count: AtomicUsize, } @@ -578,6 +567,12 @@ impl StartTimes { } } +type WorkerRequest = ( + <::WorkerState as WorkerState>::RequestId, + Request, + oneshot::Sender>, +); + struct Worker where S: HandlerState, @@ -615,10 +610,7 @@ where } } - async fn run( - self, - request: Option<(Request, oneshot::Sender>)>, - ) { + async fn run(self, request: Option>) { match self.handler.0.state.instantiate().await { Ok(Instance { store, @@ -633,8 +625,9 @@ where Err(error) => { let error = Arc::new(error); - if let Some((request, tx)) = request { + if let Some((request_id, request, tx)) = request { _ = tx.send(Err(InstantiationError { + request_id, request: Mutex::new(request), error, } @@ -643,7 +636,7 @@ where // In this case, the worker was spawned to handle any queued // requests. Since we can't handle those requests, we send // them all an instantiation error. - for (request, tx) in mem::take( + for (request_id, request, tx) in mem::take( self.handler .0 .request_queue @@ -653,6 +646,7 @@ where .deref_mut(), ) { _ = tx.send(Err(InstantiationError { + request_id, request: Mutex::new(request), error: error.clone(), } @@ -670,7 +664,7 @@ where view: ViewFn, expiration: S::WorkerExpiration, state: S::WorkerState, - request: Option<(Request, oneshot::Sender>)>, + request: Option>, ) { // NB: The code the follows is rather subtle in that it is structured // carefully to give the `HandlerState` implementation full control over @@ -733,8 +727,7 @@ where let mut futures = FuturesUnordered::new(); let mut start_times = StartTimes::default(); - let accept_request = |request: Request, - tx: oneshot::Sender>, + let accept_request = |(request_id, request, tx): WorkerRequest, futures: &mut FuturesUnordered<_>, start_times: &mut StartTimes, reuse_count: &mut usize| { @@ -750,34 +743,41 @@ where accept_concurrent.store(false, Relaxed); *reuse_count += 1; - // Notify the `HandlerState` that we're starting to handle a - // request and retrieve the deadline by which it must produce a - // response. - // - // If it fails to produce a response by the deadline, we'll stop - // accepting new requests and eventually exit the worker. - let expiration = dropper.state.on_request_start(&request); + let prepared = accessor.with(|mut store| { + let prepared = Prepared::new(store.as_context_mut(), proxy, request, view, tx); + match prepared { + Ok(prepared) => { + // Notify the `HandlerState` that we're starting to + // handle a request and retrieve the deadline by + // which it must produce a response. + // + // If it fails to produce a response by the + // deadline, we'll stop accepting new requests and + // eventually exit the worker. + let expiration = dropper.state.on_request_start( + store.as_context_mut(), + request_id, + prepared.task(), + ); + Ok((prepared, expiration)) + } + Err(e) => Err(e), + } + }); let start_time = Instant::now(); start_times.add(start_time); *status.try_lock().unwrap() = (WorkerStatus::Requests, start_time); futures.push(async move { - Ok::<_, wasmtime::Error>(( - handle(accessor, proxy, request, view, tx, expiration).await?, - start_time, - )) + let (prepared, expiration) = prepared?; + let sent = prepared.run(accessor, expiration).await?; + wasmtime::error::Ok((sent, start_time)) }); }; - if let Some((request, tx)) = request { - accept_request( - request, - tx, - &mut futures, - &mut start_times, - &mut reuse_count, - ); + if let Some(req) = request { + accept_request(req, &mut futures, &mut start_times, &mut reuse_count); } // This is the main driver loop for this worker. This is modeled as @@ -870,16 +870,9 @@ where // successful then push it into `futures` and turn this loop // again to see where we're at next time around. if self.available - && let Poll::Ready(Some((request, tx))) = - incoming_requests.as_mut().poll_next(cx) + && let Poll::Ready(Some(req)) = incoming_requests.as_mut().poll_next(cx) { - accept_request( - request, - tx, - &mut futures, - &mut start_times, - &mut reuse_count, - ); + accept_request(req, &mut futures, &mut start_times, &mut reuse_count); continue; } @@ -1018,7 +1011,9 @@ impl Clone for ProxyHandler { /// case, the caller may be able to recover and retry (e.g. after waiting for /// existing instances to be dropped and/or freeing memory used by caches, /// etc.). Otherwise, it will probably need to return an HTTP 500 error. -pub struct InstantiationError { +pub struct InstantiationError { + /// The ID of the request which was originally configured, + pub request_id: T, /// The original request passed to `ProxyHandler::handle`. /// /// This is wrapped in a `Mutex` to satisfy the `Send + Sync` bounds @@ -1031,19 +1026,19 @@ pub struct InstantiationError { pub error: Arc, } -impl fmt::Display for InstantiationError { +impl fmt::Display for InstantiationError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { write!(f, "instantiation error: {}", self.error) } } -impl fmt::Debug for InstantiationError { +impl fmt::Debug for InstantiationError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { write!(f, "instantiation error: {:?}", self.error) } } -impl error::Error for InstantiationError {} +impl error::Error for InstantiationError {} /// Returned when the guest failed to produce a response before the expiration /// returned by `HandlerState::on_request_start` elapsed. @@ -1114,18 +1109,22 @@ where /// In other failure cases (e.g. `wasi:http/types#error-code` return values /// and/or traps when executing synchronous WASIp2 handler functions), the /// original error returned by the handler will be returned. - pub async fn handle(&self, request: Request) -> Result { + pub async fn handle( + &self, + id: ::RequestId, + request: Request, + ) -> Result { let (tx, rx) = oneshot::channel(); - + let req = (id, request, tx); if self.0.worker_count.load(Relaxed) == 0 { // There are no available workers; skip the queue and pass // the request directly to the worker, which improves // performance as measured by `wasmtime-server-rps.sh` by // about 15%. - self.start_worker(Some((request, tx))); + self.start_worker(Some(req)); } else { let mut queue = self.0.request_queue.queue.lock().unwrap(); - queue.push_back((request, tx)); + queue.push_back(req); // Start a new worker to handle the request if the last worker just // went unavailable. See also `Worker::set_available` for what @@ -1146,9 +1145,9 @@ where // instantiation error, we'll give the request back to the caller in // an `Err(_)`, allowing the application to decide what to do next. if self.0.worker_count.load(Relaxed) == 0 { - let (request, tx) = queue.pop_back().unwrap(); + let req = queue.pop_back().unwrap(); drop(queue); - self.start_worker(Some((request, tx))); + self.start_worker(Some(req)); } else { drop(queue); self.0.request_queue.notify_push.notify_one(); @@ -1163,10 +1162,7 @@ where &self.0.state } - fn start_worker( - &self, - request: Option<(Request, oneshot::Sender>)>, - ) { + fn start_worker(&self, request: Option>) { tokio::spawn( Worker { handler: self.clone(), @@ -1177,133 +1173,213 @@ where } } -async fn handle( - accessor: &Accessor, - proxy: &Proxy, - request: Request, - view: ViewFn, - tx: oneshot::Sender>, - expiration: impl Future, -) -> Result { - let expiration = pin!(expiration); - - match (proxy, view) { - #[cfg(feature = "p3")] - (Proxy::P3(guest), ViewFn::P3(view)) => { - let (request, body) = request.into_parts(); - let body = body.map_err(p3_types::ErrorCode::from); - let request = http::Request::from_parts(request, body); - let (request, request_io_result) = p3::Request::from_http(request); - - let request = accessor.with(|mut store| { - Ok::<_, wasmtime::Error>(view(store.data_mut()).table.push(request)?) - })?; - - let handle = pin!(async move { - let response = guest - .wasi_http_handler() - .call_handle(accessor, request) - .await?; - - let response = accessor.with(|mut store| { - let response = view(store.get()).table.delete(response?)?; - Ok::<_, wasmtime::Error>(response.into_http_with_getter( - &mut store, - request_io_result, - view, - )?) - })?; +/// Representation of a "prepared" call for a guest, used to extract the +/// `GuestTaskId` before actually executing any handlers. +/// +/// Right now this is a bit gross since it has to type out a bunch of types by +/// hand. +enum Prepared<'a, T: 'static> { + #[cfg(feature = "p2")] + P2 { + guest: &'a p2::bindings::Proxy, + call: TypedFuncCallConcurrent< + T, + ( + Resource, + Resource, + ), + (), + >, + tx: Arc>>>>, + }, + #[cfg(feature = "p3")] + P3 { + guest: &'a p3::bindings::Service, + call: TypedFuncCallConcurrent< + T, + (Resource,), + (Result, p3_types::ErrorCode>,), + >, + tx: oneshot::Sender>, + request_io_result: Pin> + Send>>, + view: fn(&mut T) -> p3::WasiHttpCtxView, + }, +} - Ok(response.map(move |body| body.map_err(wasmtime::Error::from).boxed_unsync())) - }); - - // TODO: We should also use `oneshot::Sender::poll_close` to be - // notified when the receiver is dropped, in which case we should - // expire the request since the response is no longer of interest to - // the original `ProxyHandler::handle` caller. - let (result, sent) = match futures::future::select(handle, expiration).await { - Either::Left((result, _)) => (result, true), - // TODO: We should also send a cancel request to the expired - // task to give it a chance to shut down gracefully, but as of - // this writing Wasmtime does not yet provide an API for doing - // that. See issue #11833. Instead, we let it continue running - // as a background task until it either returns a response - // (which we'll ignore) or the instance itself has expired. - Either::Right(((), _)) => (Err(ExpirationError.into()), false), - }; +impl<'a, T: Send> Prepared<'a, T> { + fn new( + mut store: StoreContextMut<'_, T>, + proxy: &'a Proxy, + request: Request, + view: ViewFn, + tx: oneshot::Sender>, + ) -> Result> { + match (proxy, view) { + #[cfg(feature = "p3")] + (Proxy::P3(guest), ViewFn::P3(view)) => { + let (request, body) = request.into_parts(); + let body = body.map_err(p3_types::ErrorCode::from); + let request = http::Request::from_parts(request, body); + let (request, request_io_result) = p3::Request::from_http(request); + let request = view(store.data_mut()).table.push(request)?; + + Ok(Prepared::P3 { + tx, + request_io_result: Box::pin(request_io_result), + guest, + view, + call: guest + .wasi_http_handler() + .func_handle() + .start_call_concurrent(store, (request,))?, + }) + } + #[cfg(feature = "p2")] + (Proxy::P2(guest), ViewFn::P2(view)) => { + // Here we wrap the sender in an `Arc>>`, with one + // clone used in the `response-outparam` and the other used to send + // an error if the request expires or the handler returns without + // producing a response. + let tx = Arc::new(Mutex::new(Some(tx))); + + let request = + view(store.data_mut()).new_incoming_request(p2_types::Scheme::Http, request)?; + + let out = view(store.data_mut()).new_response_outparam_from_callback({ + let tx = tx.clone(); + move |value| { + if let Some(tx) = tx.lock().unwrap().take() { + _ = tx.send( + value + .map(|v| { + v.map(move |body| { + body.map_err(wasmtime::Error::from).boxed_unsync() + }) + }) + .map_err(wasmtime::Error::from), + ); + } + } + })?; - _ = tx.send(result); + Ok(Prepared::P2 { + guest, + tx, + call: guest + .wasi_http_incoming_handler() + .func_handle() + .start_call_concurrent(store, (request, out))?, + }) + } + #[cfg(all(feature = "p2", feature = "p3"))] + _ => unreachable!(), + } + } - Ok(sent) + fn task(&self) -> GuestTaskId { + match self { + #[cfg(feature = "p3")] + Prepared::P3 { call, .. } => call.task(), + #[cfg(feature = "p2")] + Prepared::P2 { call, .. } => call.task(), } - #[cfg(feature = "p2")] - (Proxy::P2(guest), ViewFn::P2(view)) => { - // Here we wrap the sender in an `Arc>>`, with one - // clone used in the `response-outparam` and the other used to send - // an error if the request expires or the handler returns without - // producing a response. - let tx = Arc::new(Mutex::new(Some(tx))); - - let (request, out) = accessor.with({ - let tx = tx.clone(); - move |mut access| { - let request = view(access.data_mut()) - .new_incoming_request(p2_types::Scheme::Http, request)?; - - let out = view(access.data_mut()).new_response_outparam_from_callback( - move |value| { - if let Some(tx) = tx.lock().unwrap().take() { - _ = tx.send( - value - .map(|v| { - v.map(move |body| { - body.map_err(wasmtime::Error::from).boxed_unsync() - }) - }) - .map_err(wasmtime::Error::from), - ); - } - }, - )?; + } - wasmtime::error::Ok((request, out)) - } - })?; + async fn run( + self, + accessor: &Accessor, + expiration: impl Future, + ) -> Result { + let expiration = pin!(expiration); - let handle = pin!( - guest - .wasi_http_incoming_handler() - .call_handle(accessor, request, out) - ); + match self { + #[cfg(feature = "p3")] + Prepared::P3 { + guest, + call, + tx, + request_io_result, + view, + } => { + let handle = + pin!(async move { + let response = guest + .wasi_http_handler() + .func_handle() + .finish_call_concurrent(accessor, call) + .await? + .0?; + + let response = accessor.with(|mut store| { + let response = view(store.get()).table.delete(response)?; + Ok::<_, wasmtime::Error>(response.into_http_with_getter( + &mut store, + request_io_result, + view, + )?) + })?; + + Ok(response + .map(move |body| body.map_err(wasmtime::Error::from).boxed_unsync())) + }); + + // TODO: We should also use `oneshot::Sender::poll_close` to be + // notified when the receiver is dropped, in which case we should + // expire the request since the response is no longer of interest to + // the original `ProxyHandler::handle` caller. + let (result, sent) = match futures::future::select(handle, expiration).await { + Either::Left((result, _)) => (result, true), + // TODO: We should also send a cancel request to the expired + // task to give it a chance to shut down gracefully, but as of + // this writing Wasmtime does not yet provide an API for doing + // that. See issue #11833. Instead, we let it continue running + // as a background task until it either returns a response + // (which we'll ignore) or the instance itself has expired. + Either::Right(((), _)) => (Err(ExpirationError.into()), false), + }; + + _ = tx.send(result); + + Ok(sent) + } + #[cfg(feature = "p2")] + Prepared::P2 { guest, call, tx } => { + let handle = pin!( + guest + .wasi_http_incoming_handler() + .func_handle() + .finish_call_concurrent(accessor, call) + ); - const MESSAGE: &str = "guest never invoked `response-outparam::set` method"; + const MESSAGE: &str = "guest never invoked `response-outparam::set` method"; - struct Dropper(Arc>>>>); + struct Dropper( + Arc>>>>, + ); - impl Drop for Dropper { - fn drop(&mut self) { - if let Some(tx) = self.0.lock().unwrap().take() { - _ = tx.send(Err(format_err!("{MESSAGE}"))); + impl Drop for Dropper { + fn drop(&mut self) { + if let Some(tx) = self.0.lock().unwrap().take() { + _ = tx.send(Err(format_err!("{MESSAGE}"))); + } } } - } - let tx = Dropper(tx); + let tx = Dropper(tx); - // See corresponding TODO comment for the p3 case above. - let (result, sent) = match futures::future::select(handle, expiration).await { - Either::Left((result, _)) => (result.context(MESSAGE), true), // See corresponding TODO comment for the p3 case above. - Either::Right(((), _)) => (Err(ExpirationError.into()), false), - }; + let (result, sent) = match futures::future::select(handle, expiration).await { + Either::Left((result, _)) => (result.context(MESSAGE), true), + // See corresponding TODO comment for the p3 case above. + Either::Right(((), _)) => (Err(ExpirationError.into()), false), + }; + + if let Some(tx) = tx.0.lock().unwrap().take() { + _ = tx.send(result.and_then(|()| Err(format_err!("{MESSAGE}")))); + } - if let Some(tx) = tx.0.lock().unwrap().take() { - _ = tx.send(result.and_then(|()| Err(format_err!("{MESSAGE}")))); + Ok(sent) } - - Ok(sent) } - #[cfg(all(feature = "p2", feature = "p3"))] - _ => unreachable!(), } } diff --git a/crates/wit-bindgen/src/lib.rs b/crates/wit-bindgen/src/lib.rs index b7add61260e8..1b2b399e5fd6 100644 --- a/crates/wit-bindgen/src/lib.rs +++ b/crates/wit-bindgen/src/lib.rs @@ -2797,10 +2797,42 @@ impl<'a> InterfaceGenerator<'a> { } else { ("", "", "") }; - - self.rustdoc(&func.docs); + let param_mode = if flags.contains(FunctionFlags::ASYNC | FunctionFlags::STORE) { + TypeMode::Owned + } else { + TypeMode::AllBorrowed("'_") + }; let wt = self.generator.wasmtime_path(); + // First generate an accessor to get the raw `TypedFunc` itself. + uwrite!( + self.src, + "pub fn func_{}(&self) -> {wt}::component::TypedFunc<{}> {{\n", + func.item_name().to_snake_case(), + self.typedfunc_sig(func, param_mode) + ); + + self.src.push_str("unsafe {\n"); + uwrite!( + self.src, + "{wt}::component::TypedFunc::<{}>", + self.typedfunc_sig(func, param_mode) + ); + let projection_to_func = if func.kind.resource().is_some() { + ".funcs" + } else { + "" + }; + uwriteln!( + self.src, + "::new_unchecked(self{projection_to_func}.{})", + func_field_name(self.resolve, func), + ); + self.src.push_str("}\n"); + self.src.push_str("}\n"); + + // Next generate the actual function itself. + self.rustdoc(&func.docs); uwrite!( self.src, "pub {async_} fn call_{}", @@ -2815,12 +2847,6 @@ impl<'a> InterfaceGenerator<'a> { uwrite!(self.src, "(&self, mut store: S, ",); } - let param_mode = if flags.contains(FunctionFlags::ASYNC | FunctionFlags::STORE) { - TypeMode::Owned - } else { - TypeMode::AllBorrowed("'_") - }; - for (i, param) in func.params.iter().enumerate() { uwrite!(self.src, "arg{}: ", i); self.print_ty(¶m.ty, param_mode); @@ -2868,23 +2894,11 @@ impl<'a> InterfaceGenerator<'a> { } } - self.src.push_str("let callee = unsafe {\n"); - uwrite!( - self.src, - "{wt}::component::TypedFunc::<{}>", - self.typedfunc_sig(func, param_mode) - ); - let projection_to_func = if func.kind.resource().is_some() { - ".funcs" - } else { - "" - }; uwriteln!( self.src, - "::new_unchecked(self{projection_to_func}.{})", - func_field_name(self.resolve, func), + "let callee = self.func_{}();", + func.item_name().to_snake_case(), ); - self.src.push_str("};\n"); self.src.push_str("let ("); if func.result.is_some() { diff --git a/src/commands/serve.rs b/src/commands/serve.rs index fd0c710f7804..6bd6f974fc6a 100644 --- a/src/commands/serve.rs +++ b/src/commands/serve.rs @@ -20,7 +20,7 @@ use std::{ }; use tokio::io::{self, AsyncWrite}; use tokio::sync::Notify; -use wasmtime::component::{Component, Linker}; +use wasmtime::component::{Component, GuestTaskId, Linker}; use wasmtime::error::Context as _; use wasmtime::{ AsContextMut as _, Engine, Result, Store, StoreContextMut, StoreLimits, UpdateDeadline, bail, @@ -28,8 +28,6 @@ use wasmtime::{ use wasmtime_cli_flags::opt::WasmtimeOptionValue; use wasmtime_wasi::p2::{StreamError, StreamResult}; use wasmtime_wasi::{WasiCtx, WasiCtxBuilder, WasiCtxView, WasiView}; -#[cfg(feature = "component-model-async")] -use wasmtime_wasi_http::handler::p2::bindings as p2; use wasmtime_wasi_http::handler::{ self, HandlerState, Instance, ProxyHandler, ProxyPre, ShouldAccept, ViewFn, WorkerExpiration, WorkerState, WorkerStatus, @@ -609,10 +607,10 @@ impl ServeCommand { #[cfg(feature = "component-model-async")] let instance = match wasmtime_wasi_http::p3::bindings::ServicePre::new(instance.clone()) { Ok(pre) => ProxyPre::P3(pre), - Err(_) => ProxyPre::P2(p2::ProxyPre::new(instance)?), + Err(_) => ProxyPre::P2(wasmtime_wasi_http::p2::bindings::ProxyPre::new(instance)?), }; #[cfg(not(feature = "component-model-async"))] - let instance = ProxyPre::P2(p2::ProxyPre::new(instance)?); + let instance = ProxyPre::P2(wasmtime_wasi_http::p2::bindings::ProxyPre::new(instance)?); // Spawn background task(s) waiting for graceful shutdown signals. This // always listens for ctrl-c but additionally can listen for a TCP @@ -691,6 +689,7 @@ impl ServeCommand { max_instance_concurrent_reuse_count, instance, next_instance_id: AtomicU64::default(), + next_request_id: AtomicU64::default(), // Give one shutdown guard to this handler which will track the // full lifetime of any instances spawned. _shutdown_guard: Box::new(shutdown.clone().increment()), @@ -835,6 +834,7 @@ struct HostWorkerState { impl WorkerState for HostWorkerState { type StoreData = Host; + type RequestId = u64; fn should_accept_request(&self, concurrent_count: usize, total_count: usize) -> ShouldAccept { if total_count >= self.max_instance_reuse_count { @@ -848,13 +848,13 @@ impl WorkerState for HostWorkerState { fn on_request_start( &self, - req: &handler::Request, + _store: StoreContextMut, + request_id: u64, + _task_id: GuestTaskId, ) -> Pin + 'static + Send + Sync>> { log::info!( - "Instance {} handling request {} {}", + "Instance {} handling request {request_id}", self.instance_id, - req.method(), - req.uri() ); Box::pin(tokio::time::sleep(self.request_timeout)) @@ -882,6 +882,7 @@ struct HostHandlerState { max_instance_concurrent_reuse_count: usize, instance: ProxyPre, next_instance_id: AtomicU64, + next_request_id: AtomicU64, _shutdown_guard: Box, } @@ -1257,12 +1258,24 @@ async fn handle_request( handler.state().request_headers.apply(req.headers_mut()); + let request_id = handler + .state() + .next_request_id + .fetch_add(1, Ordering::Relaxed); + log::info!( + "Received request {request_id}: {} {}", + req.method(), + req.uri() + ); handler - .handle(req.map(|body| { - body.map_err(ErrorCode::from_hyper_request_error) - .map_err(handler::ErrorCode::from) - .boxed_unsync() - })) + .handle( + request_id, + req.map(|body| { + body.map_err(ErrorCode::from_hyper_request_error) + .map_err(handler::ErrorCode::from) + .boxed_unsync() + }), + ) .await } From 960a49e9836d81f647c70083570df50d45b01bb8 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 29 May 2026 13:06:30 -0700 Subject: [PATCH 3/3] Update expansion tests --- crates/component-macro/tests/expanded/char.rs | 34 +- .../tests/expanded/char_async.rs | 34 +- .../tests/expanded/char_concurrent.rs | 34 +- .../tests/expanded/char_tracing_async.rs | 34 +- .../tests/expanded/conventions.rs | 176 +++-- .../tests/expanded/conventions_async.rs | 178 +++-- .../tests/expanded/conventions_concurrent.rs | 178 +++-- .../expanded/conventions_tracing_async.rs | 196 ++++-- .../component-macro/tests/expanded/flags.rs | 119 ++-- .../tests/expanded/flags_async.rs | 119 ++-- .../tests/expanded/flags_concurrent.rs | 119 ++-- .../tests/expanded/flags_tracing_async.rs | 119 ++-- .../component-macro/tests/expanded/floats.rs | 64 +- .../tests/expanded/floats_async.rs | 68 +- .../tests/expanded/floats_concurrent.rs | 68 +- .../tests/expanded/floats_tracing_async.rs | 68 +- .../tests/expanded/function-new.rs | 7 +- .../tests/expanded/function-new_async.rs | 7 +- .../tests/expanded/function-new_concurrent.rs | 7 +- .../expanded/function-new_tracing_async.rs | 7 +- .../tests/expanded/integers.rs | 275 +++++--- .../tests/expanded/integers_async.rs | 277 +++++--- .../tests/expanded/integers_concurrent.rs | 277 +++++--- .../tests/expanded/integers_tracing_async.rs | 277 +++++--- .../component-macro/tests/expanded/lists.rs | 550 ++++++++++----- .../tests/expanded/lists_async.rs | 582 ++++++++++------ .../tests/expanded/lists_concurrent.rs | 624 ++++++++++++------ .../tests/expanded/lists_tracing_async.rs | 586 ++++++++++------ .../tests/expanded/many-arguments.rs | 84 ++- .../tests/expanded/many-arguments_async.rs | 88 ++- .../expanded/many-arguments_concurrent.rs | 88 ++- .../expanded/many-arguments_tracing_async.rs | 88 ++- .../tests/expanded/multiversion.rs | 30 +- .../tests/expanded/multiversion_async.rs | 30 +- .../tests/expanded/multiversion_concurrent.rs | 30 +- .../expanded/multiversion_tracing_async.rs | 30 +- .../component-macro/tests/expanded/records.rs | 177 +++-- .../tests/expanded/records_async.rs | 187 ++++-- .../tests/expanded/records_concurrent.rs | 187 ++++-- .../tests/expanded/records_tracing_async.rs | 187 ++++-- .../tests/expanded/resources-export.rs | 154 +++-- .../tests/expanded/resources-export_async.rs | 166 +++-- .../expanded/resources-export_concurrent.rs | 166 +++-- .../resources-export_tracing_async.rs | 166 +++-- .../tests/expanded/resources-import.rs | 38 +- .../tests/expanded/resources-import_async.rs | 40 +- .../expanded/resources-import_concurrent.rs | 40 +- .../resources-import_tracing_async.rs | 40 +- .../tests/expanded/share-types.rs | 17 +- .../tests/expanded/share-types_async.rs | 17 +- .../tests/expanded/share-types_concurrent.rs | 17 +- .../expanded/share-types_tracing_async.rs | 17 +- .../tests/expanded/simple-functions.rs | 97 ++- .../tests/expanded/simple-functions_async.rs | 99 ++- .../expanded/simple-functions_concurrent.rs | 99 ++- .../simple-functions_tracing_async.rs | 99 ++- .../tests/expanded/simple-lists.rs | 94 ++- .../tests/expanded/simple-lists_async.rs | 104 ++- .../tests/expanded/simple-lists_concurrent.rs | 120 +++- .../expanded/simple-lists_tracing_async.rs | 104 ++- .../tests/expanded/small-anonymous.rs | 20 +- .../tests/expanded/small-anonymous_async.rs | 28 +- .../expanded/small-anonymous_concurrent.rs | 30 +- .../expanded/small-anonymous_tracing_async.rs | 30 +- .../tests/expanded/smoke-default.rs | 7 +- .../tests/expanded/smoke-default_async.rs | 7 +- .../expanded/smoke-default_concurrent.rs | 7 +- .../expanded/smoke-default_tracing_async.rs | 7 +- .../tests/expanded/smoke-export.rs | 9 +- .../tests/expanded/smoke-export_async.rs | 9 +- .../tests/expanded/smoke-export_concurrent.rs | 9 +- .../expanded/smoke-export_tracing_async.rs | 9 +- .../component-macro/tests/expanded/strings.rs | 53 +- .../tests/expanded/strings_async.rs | 55 +- .../tests/expanded/strings_concurrent.rs | 69 +- .../tests/expanded/strings_tracing_async.rs | 55 +- .../tests/expanded/variants.rs | 420 ++++++++---- .../tests/expanded/variants_async.rs | 466 ++++++++----- .../tests/expanded/variants_concurrent.rs | 475 ++++++++----- .../tests/expanded/variants_tracing_async.rs | 466 ++++++++----- .../tests/expanded/worlds-with-types.rs | 9 +- .../tests/expanded/worlds-with-types_async.rs | 9 +- .../expanded/worlds-with-types_concurrent.rs | 9 +- .../worlds-with-types_tracing_async.rs | 9 +- 84 files changed, 6805 insertions(+), 3446 deletions(-) diff --git a/crates/component-macro/tests/expanded/char.rs b/crates/component-macro/tests/expanded/char.rs index cb32d85fdd64..2d95a0df80a1 100644 --- a/crates/component-macro/tests/expanded/char.rs +++ b/crates/component-macro/tests/expanded/char.rs @@ -332,32 +332,42 @@ pub mod exports { } } impl Guest { + pub fn func_take_char( + &self, + ) -> wasmtime::component::TypedFunc<(char,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (char,), + (), + >::new_unchecked(self.take_char) + } + } /// A function that accepts a character pub fn call_take_char( &self, mut store: S, arg0: char, ) -> wasmtime::Result<()> { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (char,), - (), - >::new_unchecked(self.take_char) - }; + let callee = self.func_take_char(); let () = callee.call(store.as_context_mut(), (arg0,))?; Ok(()) } - /// A function that returns a character - pub fn call_return_char( + pub fn func_return_char( &self, - mut store: S, - ) -> wasmtime::Result { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc<(), (char,)> { + unsafe { wasmtime::component::TypedFunc::< (), (char,), >::new_unchecked(self.return_char) - }; + } + } + /// A function that returns a character + pub fn call_return_char( + &self, + mut store: S, + ) -> wasmtime::Result { + let callee = self.func_return_char(); let (ret0,) = callee.call(store.as_context_mut(), ())?; Ok(ret0) } diff --git a/crates/component-macro/tests/expanded/char_async.rs b/crates/component-macro/tests/expanded/char_async.rs index 15e3417ede8f..f0748488dc0b 100644 --- a/crates/component-macro/tests/expanded/char_async.rs +++ b/crates/component-macro/tests/expanded/char_async.rs @@ -346,6 +346,16 @@ pub mod exports { } } impl Guest { + pub fn func_take_char( + &self, + ) -> wasmtime::component::TypedFunc<(char,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (char,), + (), + >::new_unchecked(self.take_char) + } + } /// A function that accepts a character pub async fn call_take_char( &self, @@ -355,17 +365,22 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (char,), - (), - >::new_unchecked(self.take_char) - }; + let callee = self.func_take_char(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .await?; Ok(()) } + pub fn func_return_char( + &self, + ) -> wasmtime::component::TypedFunc<(), (char,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (char,), + >::new_unchecked(self.return_char) + } + } /// A function that returns a character pub async fn call_return_char( &self, @@ -374,12 +389,7 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (char,), - >::new_unchecked(self.return_char) - }; + let callee = self.func_return_char(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .await?; diff --git a/crates/component-macro/tests/expanded/char_concurrent.rs b/crates/component-macro/tests/expanded/char_concurrent.rs index 7edb4659984d..788ce315c42e 100644 --- a/crates/component-macro/tests/expanded/char_concurrent.rs +++ b/crates/component-macro/tests/expanded/char_concurrent.rs @@ -325,6 +325,16 @@ pub mod exports { } } impl Guest { + pub fn func_take_char( + &self, + ) -> wasmtime::component::TypedFunc<(char,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (char,), + (), + >::new_unchecked(self.take_char) + } + } /// A function that accepts a character pub async fn call_take_char<_T, _D>( &self, @@ -335,15 +345,20 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (char,), - (), - >::new_unchecked(self.take_char) - }; + let callee = self.func_take_char(); let () = callee.call_concurrent(accessor, (arg0,)).await?; Ok(()) } + pub fn func_return_char( + &self, + ) -> wasmtime::component::TypedFunc<(), (char,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (char,), + >::new_unchecked(self.return_char) + } + } /// A function that returns a character pub async fn call_return_char<_T, _D>( &self, @@ -353,12 +368,7 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (char,), - >::new_unchecked(self.return_char) - }; + let callee = self.func_return_char(); let (ret0,) = callee.call_concurrent(accessor, ()).await?; Ok(ret0) } diff --git a/crates/component-macro/tests/expanded/char_tracing_async.rs b/crates/component-macro/tests/expanded/char_tracing_async.rs index e8873b8c6217..ce5e12ef8eaf 100644 --- a/crates/component-macro/tests/expanded/char_tracing_async.rs +++ b/crates/component-macro/tests/expanded/char_tracing_async.rs @@ -375,6 +375,16 @@ pub mod exports { } } impl Guest { + pub fn func_take_char( + &self, + ) -> wasmtime::component::TypedFunc<(char,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (char,), + (), + >::new_unchecked(self.take_char) + } + } /// A function that accepts a character pub async fn call_take_char( &self, @@ -389,18 +399,23 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/chars", function = "take-char", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (char,), - (), - >::new_unchecked(self.take_char) - }; + let callee = self.func_take_char(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .instrument(span.clone()) .await?; Ok(()) } + pub fn func_return_char( + &self, + ) -> wasmtime::component::TypedFunc<(), (char,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (char,), + >::new_unchecked(self.return_char) + } + } /// A function that returns a character pub async fn call_return_char( &self, @@ -414,12 +429,7 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/chars", function = "return-char", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (char,), - >::new_unchecked(self.return_char) - }; + let callee = self.func_return_char(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) diff --git a/crates/component-macro/tests/expanded/conventions.rs b/crates/component-macro/tests/expanded/conventions.rs index a4dc34563244..c99bd6acbc23 100644 --- a/crates/component-macro/tests/expanded/conventions.rs +++ b/crates/component-macro/tests/expanded/conventions.rs @@ -626,109 +626,153 @@ pub mod exports { } } impl Guest { - pub fn call_kebab_case( + pub fn func_kebab_case( &self, - mut store: S, - ) -> wasmtime::Result<()> { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { wasmtime::component::TypedFunc::< (), (), >::new_unchecked(self.kebab_case) - }; - let () = callee.call(store.as_context_mut(), ())?; - Ok(()) + } } - pub fn call_foo( + pub fn call_kebab_case( &self, mut store: S, - arg0: LudicrousSpeed, ) -> wasmtime::Result<()> { - let callee = unsafe { + let callee = self.func_kebab_case(); + let () = callee.call(store.as_context_mut(), ())?; + Ok(()) + } + pub fn func_foo( + &self, + ) -> wasmtime::component::TypedFunc<(LudicrousSpeed,), ()> { + unsafe { wasmtime::component::TypedFunc::< (LudicrousSpeed,), (), >::new_unchecked(self.foo) - }; - let () = callee.call(store.as_context_mut(), (arg0,))?; - Ok(()) + } } - pub fn call_function_with_dashes( + pub fn call_foo( &self, mut store: S, + arg0: LudicrousSpeed, ) -> wasmtime::Result<()> { - let callee = unsafe { + let callee = self.func_foo(); + let () = callee.call(store.as_context_mut(), (arg0,))?; + Ok(()) + } + pub fn func_function_with_dashes( + &self, + ) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { wasmtime::component::TypedFunc::< (), (), >::new_unchecked(self.function_with_dashes) - }; + } + } + pub fn call_function_with_dashes( + &self, + mut store: S, + ) -> wasmtime::Result<()> { + let callee = self.func_function_with_dashes(); let () = callee.call(store.as_context_mut(), ())?; Ok(()) } - pub fn call_function_with_no_weird_characters< - S: wasmtime::AsContextMut, - >(&self, mut store: S) -> wasmtime::Result<()> { - let callee = unsafe { + pub fn func_function_with_no_weird_characters( + &self, + ) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { wasmtime::component::TypedFunc::< (), (), >::new_unchecked(self.function_with_no_weird_characters) - }; + } + } + pub fn call_function_with_no_weird_characters< + S: wasmtime::AsContextMut, + >(&self, mut store: S) -> wasmtime::Result<()> { + let callee = self.func_function_with_no_weird_characters(); let () = callee.call(store.as_context_mut(), ())?; Ok(()) } + pub fn func_apple(&self) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (), + >::new_unchecked(self.apple) + } + } pub fn call_apple( &self, mut store: S, ) -> wasmtime::Result<()> { - let callee = unsafe { + let callee = self.func_apple(); + let () = callee.call(store.as_context_mut(), ())?; + Ok(()) + } + pub fn func_apple_pear( + &self, + ) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { wasmtime::component::TypedFunc::< (), (), - >::new_unchecked(self.apple) - }; - let () = callee.call(store.as_context_mut(), ())?; - Ok(()) + >::new_unchecked(self.apple_pear) + } } pub fn call_apple_pear( &self, mut store: S, ) -> wasmtime::Result<()> { - let callee = unsafe { + let callee = self.func_apple_pear(); + let () = callee.call(store.as_context_mut(), ())?; + Ok(()) + } + pub fn func_apple_pear_grape( + &self, + ) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { wasmtime::component::TypedFunc::< (), (), - >::new_unchecked(self.apple_pear) - }; - let () = callee.call(store.as_context_mut(), ())?; - Ok(()) + >::new_unchecked(self.apple_pear_grape) + } } pub fn call_apple_pear_grape( &self, mut store: S, ) -> wasmtime::Result<()> { - let callee = unsafe { + let callee = self.func_apple_pear_grape(); + let () = callee.call(store.as_context_mut(), ())?; + Ok(()) + } + pub fn func_a0(&self) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { wasmtime::component::TypedFunc::< (), (), - >::new_unchecked(self.apple_pear_grape) - }; - let () = callee.call(store.as_context_mut(), ())?; - Ok(()) + >::new_unchecked(self.a0) + } } pub fn call_a0( &self, mut store: S, ) -> wasmtime::Result<()> { - let callee = unsafe { + let callee = self.func_a0(); + let () = callee.call(store.as_context_mut(), ())?; + Ok(()) + } + pub fn func_is_xml(&self) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { wasmtime::component::TypedFunc::< (), (), - >::new_unchecked(self.a0) - }; - let () = callee.call(store.as_context_mut(), ())?; - Ok(()) + >::new_unchecked(self.is_xml) + } } /// Comment out identifiers that collide when mapped to snake_case, for now; see /// https://github.com/WebAssembly/component-model/issues/118 @@ -739,52 +783,60 @@ pub mod exports { &self, mut store: S, ) -> wasmtime::Result<()> { - let callee = unsafe { + let callee = self.func_is_xml(); + let () = callee.call(store.as_context_mut(), ())?; + Ok(()) + } + pub fn func_explicit( + &self, + ) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { wasmtime::component::TypedFunc::< (), (), - >::new_unchecked(self.is_xml) - }; - let () = callee.call(store.as_context_mut(), ())?; - Ok(()) + >::new_unchecked(self.explicit) + } } pub fn call_explicit( &self, mut store: S, ) -> wasmtime::Result<()> { - let callee = unsafe { + let callee = self.func_explicit(); + let () = callee.call(store.as_context_mut(), ())?; + Ok(()) + } + pub fn func_explicit_kebab( + &self, + ) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { wasmtime::component::TypedFunc::< (), (), - >::new_unchecked(self.explicit) - }; - let () = callee.call(store.as_context_mut(), ())?; - Ok(()) + >::new_unchecked(self.explicit_kebab) + } } pub fn call_explicit_kebab( &self, mut store: S, ) -> wasmtime::Result<()> { - let callee = unsafe { + let callee = self.func_explicit_kebab(); + let () = callee.call(store.as_context_mut(), ())?; + Ok(()) + } + pub fn func_bool(&self) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { wasmtime::component::TypedFunc::< (), (), - >::new_unchecked(self.explicit_kebab) - }; - let () = callee.call(store.as_context_mut(), ())?; - Ok(()) + >::new_unchecked(self.bool) + } } /// Identifiers with the same name as keywords are quoted. pub fn call_bool( &self, mut store: S, ) -> wasmtime::Result<()> { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (), - >::new_unchecked(self.bool) - }; + let callee = self.func_bool(); let () = callee.call(store.as_context_mut(), ())?; Ok(()) } diff --git a/crates/component-macro/tests/expanded/conventions_async.rs b/crates/component-macro/tests/expanded/conventions_async.rs index eaffa3671798..f8f4ed843c83 100644 --- a/crates/component-macro/tests/expanded/conventions_async.rs +++ b/crates/component-macro/tests/expanded/conventions_async.rs @@ -684,6 +684,16 @@ pub mod exports { } } impl Guest { + pub fn func_kebab_case( + &self, + ) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (), + >::new_unchecked(self.kebab_case) + } + } pub async fn call_kebab_case( &self, mut store: S, @@ -691,15 +701,20 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (), - >::new_unchecked(self.kebab_case) - }; + let callee = self.func_kebab_case(); let () = callee.call_async(store.as_context_mut(), ()).await?; Ok(()) } + pub fn func_foo( + &self, + ) -> wasmtime::component::TypedFunc<(LudicrousSpeed,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (LudicrousSpeed,), + (), + >::new_unchecked(self.foo) + } + } pub async fn call_foo( &self, mut store: S, @@ -708,17 +723,22 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (LudicrousSpeed,), - (), - >::new_unchecked(self.foo) - }; + let callee = self.func_foo(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .await?; Ok(()) } + pub fn func_function_with_dashes( + &self, + ) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (), + >::new_unchecked(self.function_with_dashes) + } + } pub async fn call_function_with_dashes( &self, mut store: S, @@ -726,14 +746,19 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { + let callee = self.func_function_with_dashes(); + let () = callee.call_async(store.as_context_mut(), ()).await?; + Ok(()) + } + pub fn func_function_with_no_weird_characters( + &self, + ) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { wasmtime::component::TypedFunc::< (), (), - >::new_unchecked(self.function_with_dashes) - }; - let () = callee.call_async(store.as_context_mut(), ()).await?; - Ok(()) + >::new_unchecked(self.function_with_no_weird_characters) + } } pub async fn call_function_with_no_weird_characters< S: wasmtime::AsContextMut, @@ -741,14 +766,17 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { + let callee = self.func_function_with_no_weird_characters(); + let () = callee.call_async(store.as_context_mut(), ()).await?; + Ok(()) + } + pub fn func_apple(&self) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { wasmtime::component::TypedFunc::< (), (), - >::new_unchecked(self.function_with_no_weird_characters) - }; - let () = callee.call_async(store.as_context_mut(), ()).await?; - Ok(()) + >::new_unchecked(self.apple) + } } pub async fn call_apple( &self, @@ -757,14 +785,19 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { + let callee = self.func_apple(); + let () = callee.call_async(store.as_context_mut(), ()).await?; + Ok(()) + } + pub fn func_apple_pear( + &self, + ) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { wasmtime::component::TypedFunc::< (), (), - >::new_unchecked(self.apple) - }; - let () = callee.call_async(store.as_context_mut(), ()).await?; - Ok(()) + >::new_unchecked(self.apple_pear) + } } pub async fn call_apple_pear( &self, @@ -773,14 +806,19 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { + let callee = self.func_apple_pear(); + let () = callee.call_async(store.as_context_mut(), ()).await?; + Ok(()) + } + pub fn func_apple_pear_grape( + &self, + ) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { wasmtime::component::TypedFunc::< (), (), - >::new_unchecked(self.apple_pear) - }; - let () = callee.call_async(store.as_context_mut(), ()).await?; - Ok(()) + >::new_unchecked(self.apple_pear_grape) + } } pub async fn call_apple_pear_grape( &self, @@ -789,14 +827,17 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { + let callee = self.func_apple_pear_grape(); + let () = callee.call_async(store.as_context_mut(), ()).await?; + Ok(()) + } + pub fn func_a0(&self) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { wasmtime::component::TypedFunc::< (), (), - >::new_unchecked(self.apple_pear_grape) - }; - let () = callee.call_async(store.as_context_mut(), ()).await?; - Ok(()) + >::new_unchecked(self.a0) + } } pub async fn call_a0( &self, @@ -805,14 +846,17 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { + let callee = self.func_a0(); + let () = callee.call_async(store.as_context_mut(), ()).await?; + Ok(()) + } + pub fn func_is_xml(&self) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { wasmtime::component::TypedFunc::< (), (), - >::new_unchecked(self.a0) - }; - let () = callee.call_async(store.as_context_mut(), ()).await?; - Ok(()) + >::new_unchecked(self.is_xml) + } } /// Comment out identifiers that collide when mapped to snake_case, for now; see /// https://github.com/WebAssembly/component-model/issues/118 @@ -826,14 +870,19 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { + let callee = self.func_is_xml(); + let () = callee.call_async(store.as_context_mut(), ()).await?; + Ok(()) + } + pub fn func_explicit( + &self, + ) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { wasmtime::component::TypedFunc::< (), (), - >::new_unchecked(self.is_xml) - }; - let () = callee.call_async(store.as_context_mut(), ()).await?; - Ok(()) + >::new_unchecked(self.explicit) + } } pub async fn call_explicit( &self, @@ -842,14 +891,19 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { + let callee = self.func_explicit(); + let () = callee.call_async(store.as_context_mut(), ()).await?; + Ok(()) + } + pub fn func_explicit_kebab( + &self, + ) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { wasmtime::component::TypedFunc::< (), (), - >::new_unchecked(self.explicit) - }; - let () = callee.call_async(store.as_context_mut(), ()).await?; - Ok(()) + >::new_unchecked(self.explicit_kebab) + } } pub async fn call_explicit_kebab( &self, @@ -858,14 +912,17 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { + let callee = self.func_explicit_kebab(); + let () = callee.call_async(store.as_context_mut(), ()).await?; + Ok(()) + } + pub fn func_bool(&self) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { wasmtime::component::TypedFunc::< (), (), - >::new_unchecked(self.explicit_kebab) - }; - let () = callee.call_async(store.as_context_mut(), ()).await?; - Ok(()) + >::new_unchecked(self.bool) + } } /// Identifiers with the same name as keywords are quoted. pub async fn call_bool( @@ -875,12 +932,7 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (), - >::new_unchecked(self.bool) - }; + let callee = self.func_bool(); let () = callee.call_async(store.as_context_mut(), ()).await?; Ok(()) } diff --git a/crates/component-macro/tests/expanded/conventions_concurrent.rs b/crates/component-macro/tests/expanded/conventions_concurrent.rs index 679e9ec9a3b6..a3b65aedc6b4 100644 --- a/crates/component-macro/tests/expanded/conventions_concurrent.rs +++ b/crates/component-macro/tests/expanded/conventions_concurrent.rs @@ -632,6 +632,16 @@ pub mod exports { } } impl Guest { + pub fn func_kebab_case( + &self, + ) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (), + >::new_unchecked(self.kebab_case) + } + } pub async fn call_kebab_case<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -640,15 +650,20 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (), - >::new_unchecked(self.kebab_case) - }; + let callee = self.func_kebab_case(); let () = callee.call_concurrent(accessor, ()).await?; Ok(()) } + pub fn func_foo( + &self, + ) -> wasmtime::component::TypedFunc<(LudicrousSpeed,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (LudicrousSpeed,), + (), + >::new_unchecked(self.foo) + } + } pub async fn call_foo<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -658,15 +673,20 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (LudicrousSpeed,), - (), - >::new_unchecked(self.foo) - }; + let callee = self.func_foo(); let () = callee.call_concurrent(accessor, (arg0,)).await?; Ok(()) } + pub fn func_function_with_dashes( + &self, + ) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (), + >::new_unchecked(self.function_with_dashes) + } + } pub async fn call_function_with_dashes<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -675,14 +695,19 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { + let callee = self.func_function_with_dashes(); + let () = callee.call_concurrent(accessor, ()).await?; + Ok(()) + } + pub fn func_function_with_no_weird_characters( + &self, + ) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { wasmtime::component::TypedFunc::< (), (), - >::new_unchecked(self.function_with_dashes) - }; - let () = callee.call_concurrent(accessor, ()).await?; - Ok(()) + >::new_unchecked(self.function_with_no_weird_characters) + } } pub async fn call_function_with_no_weird_characters<_T, _D>( &self, @@ -692,14 +717,17 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { + let callee = self.func_function_with_no_weird_characters(); + let () = callee.call_concurrent(accessor, ()).await?; + Ok(()) + } + pub fn func_apple(&self) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { wasmtime::component::TypedFunc::< (), (), - >::new_unchecked(self.function_with_no_weird_characters) - }; - let () = callee.call_concurrent(accessor, ()).await?; - Ok(()) + >::new_unchecked(self.apple) + } } pub async fn call_apple<_T, _D>( &self, @@ -709,14 +737,19 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { + let callee = self.func_apple(); + let () = callee.call_concurrent(accessor, ()).await?; + Ok(()) + } + pub fn func_apple_pear( + &self, + ) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { wasmtime::component::TypedFunc::< (), (), - >::new_unchecked(self.apple) - }; - let () = callee.call_concurrent(accessor, ()).await?; - Ok(()) + >::new_unchecked(self.apple_pear) + } } pub async fn call_apple_pear<_T, _D>( &self, @@ -726,14 +759,19 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { + let callee = self.func_apple_pear(); + let () = callee.call_concurrent(accessor, ()).await?; + Ok(()) + } + pub fn func_apple_pear_grape( + &self, + ) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { wasmtime::component::TypedFunc::< (), (), - >::new_unchecked(self.apple_pear) - }; - let () = callee.call_concurrent(accessor, ()).await?; - Ok(()) + >::new_unchecked(self.apple_pear_grape) + } } pub async fn call_apple_pear_grape<_T, _D>( &self, @@ -743,14 +781,17 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { + let callee = self.func_apple_pear_grape(); + let () = callee.call_concurrent(accessor, ()).await?; + Ok(()) + } + pub fn func_a0(&self) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { wasmtime::component::TypedFunc::< (), (), - >::new_unchecked(self.apple_pear_grape) - }; - let () = callee.call_concurrent(accessor, ()).await?; - Ok(()) + >::new_unchecked(self.a0) + } } pub async fn call_a0<_T, _D>( &self, @@ -760,14 +801,17 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { + let callee = self.func_a0(); + let () = callee.call_concurrent(accessor, ()).await?; + Ok(()) + } + pub fn func_is_xml(&self) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { wasmtime::component::TypedFunc::< (), (), - >::new_unchecked(self.a0) - }; - let () = callee.call_concurrent(accessor, ()).await?; - Ok(()) + >::new_unchecked(self.is_xml) + } } /// Comment out identifiers that collide when mapped to snake_case, for now; see /// https://github.com/WebAssembly/component-model/issues/118 @@ -782,14 +826,19 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { + let callee = self.func_is_xml(); + let () = callee.call_concurrent(accessor, ()).await?; + Ok(()) + } + pub fn func_explicit( + &self, + ) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { wasmtime::component::TypedFunc::< (), (), - >::new_unchecked(self.is_xml) - }; - let () = callee.call_concurrent(accessor, ()).await?; - Ok(()) + >::new_unchecked(self.explicit) + } } pub async fn call_explicit<_T, _D>( &self, @@ -799,14 +848,19 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { + let callee = self.func_explicit(); + let () = callee.call_concurrent(accessor, ()).await?; + Ok(()) + } + pub fn func_explicit_kebab( + &self, + ) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { wasmtime::component::TypedFunc::< (), (), - >::new_unchecked(self.explicit) - }; - let () = callee.call_concurrent(accessor, ()).await?; - Ok(()) + >::new_unchecked(self.explicit_kebab) + } } pub async fn call_explicit_kebab<_T, _D>( &self, @@ -816,14 +870,17 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { + let callee = self.func_explicit_kebab(); + let () = callee.call_concurrent(accessor, ()).await?; + Ok(()) + } + pub fn func_bool(&self) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { wasmtime::component::TypedFunc::< (), (), - >::new_unchecked(self.explicit_kebab) - }; - let () = callee.call_concurrent(accessor, ()).await?; - Ok(()) + >::new_unchecked(self.bool) + } } /// Identifiers with the same name as keywords are quoted. pub async fn call_bool<_T, _D>( @@ -834,12 +891,7 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (), - >::new_unchecked(self.bool) - }; + let callee = self.func_bool(); let () = callee.call_concurrent(accessor, ()).await?; Ok(()) } diff --git a/crates/component-macro/tests/expanded/conventions_tracing_async.rs b/crates/component-macro/tests/expanded/conventions_tracing_async.rs index fa24b1da9bd0..25a494562d30 100644 --- a/crates/component-macro/tests/expanded/conventions_tracing_async.rs +++ b/crates/component-macro/tests/expanded/conventions_tracing_async.rs @@ -844,6 +844,16 @@ pub mod exports { } } impl Guest { + pub fn func_kebab_case( + &self, + ) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (), + >::new_unchecked(self.kebab_case) + } + } pub async fn call_kebab_case( &self, mut store: S, @@ -856,18 +866,23 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/conventions", function = "kebab-case", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (), - >::new_unchecked(self.kebab_case) - }; + let callee = self.func_kebab_case(); let () = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) .await?; Ok(()) } + pub fn func_foo( + &self, + ) -> wasmtime::component::TypedFunc<(LudicrousSpeed,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (LudicrousSpeed,), + (), + >::new_unchecked(self.foo) + } + } pub async fn call_foo( &self, mut store: S, @@ -881,18 +896,23 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/conventions", function = "foo", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (LudicrousSpeed,), - (), - >::new_unchecked(self.foo) - }; + let callee = self.func_foo(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .instrument(span.clone()) .await?; Ok(()) } + pub fn func_function_with_dashes( + &self, + ) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (), + >::new_unchecked(self.function_with_dashes) + } + } pub async fn call_function_with_dashes( &self, mut store: S, @@ -905,18 +925,23 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/conventions", function = "function-with-dashes", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (), - >::new_unchecked(self.function_with_dashes) - }; + let callee = self.func_function_with_dashes(); let () = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) .await?; Ok(()) } + pub fn func_function_with_no_weird_characters( + &self, + ) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (), + >::new_unchecked(self.function_with_no_weird_characters) + } + } pub async fn call_function_with_no_weird_characters< S: wasmtime::AsContextMut, >(&self, mut store: S) -> wasmtime::Result<()> @@ -929,18 +954,21 @@ pub mod exports { "foo:foo/conventions", function = "function-with-no-weird-characters", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (), - >::new_unchecked(self.function_with_no_weird_characters) - }; + let callee = self.func_function_with_no_weird_characters(); let () = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) .await?; Ok(()) } + pub fn func_apple(&self) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (), + >::new_unchecked(self.apple) + } + } pub async fn call_apple( &self, mut store: S, @@ -953,18 +981,23 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/conventions", function = "apple", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (), - >::new_unchecked(self.apple) - }; + let callee = self.func_apple(); let () = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) .await?; Ok(()) } + pub fn func_apple_pear( + &self, + ) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (), + >::new_unchecked(self.apple_pear) + } + } pub async fn call_apple_pear( &self, mut store: S, @@ -977,18 +1010,23 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/conventions", function = "apple-pear", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (), - >::new_unchecked(self.apple_pear) - }; + let callee = self.func_apple_pear(); let () = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) .await?; Ok(()) } + pub fn func_apple_pear_grape( + &self, + ) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (), + >::new_unchecked(self.apple_pear_grape) + } + } pub async fn call_apple_pear_grape( &self, mut store: S, @@ -1001,18 +1039,21 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/conventions", function = "apple-pear-grape", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (), - >::new_unchecked(self.apple_pear_grape) - }; + let callee = self.func_apple_pear_grape(); let () = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) .await?; Ok(()) } + pub fn func_a0(&self) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (), + >::new_unchecked(self.a0) + } + } pub async fn call_a0( &self, mut store: S, @@ -1025,18 +1066,21 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/conventions", function = "a0", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (), - >::new_unchecked(self.a0) - }; + let callee = self.func_a0(); let () = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) .await?; Ok(()) } + pub fn func_is_xml(&self) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (), + >::new_unchecked(self.is_xml) + } + } /// Comment out identifiers that collide when mapped to snake_case, for now; see /// https://github.com/WebAssembly/component-model/issues/118 /// APPLE: func() @@ -1054,18 +1098,23 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/conventions", function = "is-XML", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (), - >::new_unchecked(self.is_xml) - }; + let callee = self.func_is_xml(); let () = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) .await?; Ok(()) } + pub fn func_explicit( + &self, + ) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (), + >::new_unchecked(self.explicit) + } + } pub async fn call_explicit( &self, mut store: S, @@ -1078,18 +1127,23 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/conventions", function = "explicit", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (), - >::new_unchecked(self.explicit) - }; + let callee = self.func_explicit(); let () = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) .await?; Ok(()) } + pub fn func_explicit_kebab( + &self, + ) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (), + >::new_unchecked(self.explicit_kebab) + } + } pub async fn call_explicit_kebab( &self, mut store: S, @@ -1102,18 +1156,21 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/conventions", function = "explicit-kebab", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (), - >::new_unchecked(self.explicit_kebab) - }; + let callee = self.func_explicit_kebab(); let () = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) .await?; Ok(()) } + pub fn func_bool(&self) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (), + >::new_unchecked(self.bool) + } + } /// Identifiers with the same name as keywords are quoted. pub async fn call_bool( &self, @@ -1127,12 +1184,7 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/conventions", function = "bool", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (), - >::new_unchecked(self.bool) - }; + let callee = self.func_bool(); let () = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) diff --git a/crates/component-macro/tests/expanded/flags.rs b/crates/component-macro/tests/expanded/flags.rs index c23a04fe595d..cd8f8ca0e0f8 100644 --- a/crates/component-macro/tests/expanded/flags.rs +++ b/crates/component-macro/tests/expanded/flags.rs @@ -730,101 +730,136 @@ pub mod exports { } } impl Guest { - pub fn call_roundtrip_flag1( + pub fn func_roundtrip_flag1( &self, - mut store: S, - arg0: Flag1, - ) -> wasmtime::Result { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc<(Flag1,), (Flag1,)> { + unsafe { wasmtime::component::TypedFunc::< (Flag1,), (Flag1,), >::new_unchecked(self.roundtrip_flag1) - }; + } + } + pub fn call_roundtrip_flag1( + &self, + mut store: S, + arg0: Flag1, + ) -> wasmtime::Result { + let callee = self.func_roundtrip_flag1(); let (ret0,) = callee.call(store.as_context_mut(), (arg0,))?; Ok(ret0) } - pub fn call_roundtrip_flag2( + pub fn func_roundtrip_flag2( &self, - mut store: S, - arg0: Flag2, - ) -> wasmtime::Result { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc<(Flag2,), (Flag2,)> { + unsafe { wasmtime::component::TypedFunc::< (Flag2,), (Flag2,), >::new_unchecked(self.roundtrip_flag2) - }; + } + } + pub fn call_roundtrip_flag2( + &self, + mut store: S, + arg0: Flag2, + ) -> wasmtime::Result { + let callee = self.func_roundtrip_flag2(); let (ret0,) = callee.call(store.as_context_mut(), (arg0,))?; Ok(ret0) } - pub fn call_roundtrip_flag4( + pub fn func_roundtrip_flag4( &self, - mut store: S, - arg0: Flag4, - ) -> wasmtime::Result { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc<(Flag4,), (Flag4,)> { + unsafe { wasmtime::component::TypedFunc::< (Flag4,), (Flag4,), >::new_unchecked(self.roundtrip_flag4) - }; + } + } + pub fn call_roundtrip_flag4( + &self, + mut store: S, + arg0: Flag4, + ) -> wasmtime::Result { + let callee = self.func_roundtrip_flag4(); let (ret0,) = callee.call(store.as_context_mut(), (arg0,))?; Ok(ret0) } - pub fn call_roundtrip_flag8( + pub fn func_roundtrip_flag8( &self, - mut store: S, - arg0: Flag8, - ) -> wasmtime::Result { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc<(Flag8,), (Flag8,)> { + unsafe { wasmtime::component::TypedFunc::< (Flag8,), (Flag8,), >::new_unchecked(self.roundtrip_flag8) - }; + } + } + pub fn call_roundtrip_flag8( + &self, + mut store: S, + arg0: Flag8, + ) -> wasmtime::Result { + let callee = self.func_roundtrip_flag8(); let (ret0,) = callee.call(store.as_context_mut(), (arg0,))?; Ok(ret0) } - pub fn call_roundtrip_flag16( + pub fn func_roundtrip_flag16( &self, - mut store: S, - arg0: Flag16, - ) -> wasmtime::Result { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc<(Flag16,), (Flag16,)> { + unsafe { wasmtime::component::TypedFunc::< (Flag16,), (Flag16,), >::new_unchecked(self.roundtrip_flag16) - }; + } + } + pub fn call_roundtrip_flag16( + &self, + mut store: S, + arg0: Flag16, + ) -> wasmtime::Result { + let callee = self.func_roundtrip_flag16(); let (ret0,) = callee.call(store.as_context_mut(), (arg0,))?; Ok(ret0) } - pub fn call_roundtrip_flag32( + pub fn func_roundtrip_flag32( &self, - mut store: S, - arg0: Flag32, - ) -> wasmtime::Result { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc<(Flag32,), (Flag32,)> { + unsafe { wasmtime::component::TypedFunc::< (Flag32,), (Flag32,), >::new_unchecked(self.roundtrip_flag32) - }; + } + } + pub fn call_roundtrip_flag32( + &self, + mut store: S, + arg0: Flag32, + ) -> wasmtime::Result { + let callee = self.func_roundtrip_flag32(); let (ret0,) = callee.call(store.as_context_mut(), (arg0,))?; Ok(ret0) } - pub fn call_roundtrip_flag64( + pub fn func_roundtrip_flag64( &self, - mut store: S, - arg0: Flag64, - ) -> wasmtime::Result { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc<(Flag64,), (Flag64,)> { + unsafe { wasmtime::component::TypedFunc::< (Flag64,), (Flag64,), >::new_unchecked(self.roundtrip_flag64) - }; + } + } + pub fn call_roundtrip_flag64( + &self, + mut store: S, + arg0: Flag64, + ) -> wasmtime::Result { + let callee = self.func_roundtrip_flag64(); let (ret0,) = callee.call(store.as_context_mut(), (arg0,))?; Ok(ret0) } diff --git a/crates/component-macro/tests/expanded/flags_async.rs b/crates/component-macro/tests/expanded/flags_async.rs index 6ba9a2e0916d..251414ba5fea 100644 --- a/crates/component-macro/tests/expanded/flags_async.rs +++ b/crates/component-macro/tests/expanded/flags_async.rs @@ -786,6 +786,16 @@ pub mod exports { } } impl Guest { + pub fn func_roundtrip_flag1( + &self, + ) -> wasmtime::component::TypedFunc<(Flag1,), (Flag1,)> { + unsafe { + wasmtime::component::TypedFunc::< + (Flag1,), + (Flag1,), + >::new_unchecked(self.roundtrip_flag1) + } + } pub async fn call_roundtrip_flag1( &self, mut store: S, @@ -794,17 +804,22 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (Flag1,), - (Flag1,), - >::new_unchecked(self.roundtrip_flag1) - }; + let callee = self.func_roundtrip_flag1(); let (ret0,) = callee .call_async(store.as_context_mut(), (arg0,)) .await?; Ok(ret0) } + pub fn func_roundtrip_flag2( + &self, + ) -> wasmtime::component::TypedFunc<(Flag2,), (Flag2,)> { + unsafe { + wasmtime::component::TypedFunc::< + (Flag2,), + (Flag2,), + >::new_unchecked(self.roundtrip_flag2) + } + } pub async fn call_roundtrip_flag2( &self, mut store: S, @@ -813,17 +828,22 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (Flag2,), - (Flag2,), - >::new_unchecked(self.roundtrip_flag2) - }; + let callee = self.func_roundtrip_flag2(); let (ret0,) = callee .call_async(store.as_context_mut(), (arg0,)) .await?; Ok(ret0) } + pub fn func_roundtrip_flag4( + &self, + ) -> wasmtime::component::TypedFunc<(Flag4,), (Flag4,)> { + unsafe { + wasmtime::component::TypedFunc::< + (Flag4,), + (Flag4,), + >::new_unchecked(self.roundtrip_flag4) + } + } pub async fn call_roundtrip_flag4( &self, mut store: S, @@ -832,17 +852,22 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (Flag4,), - (Flag4,), - >::new_unchecked(self.roundtrip_flag4) - }; + let callee = self.func_roundtrip_flag4(); let (ret0,) = callee .call_async(store.as_context_mut(), (arg0,)) .await?; Ok(ret0) } + pub fn func_roundtrip_flag8( + &self, + ) -> wasmtime::component::TypedFunc<(Flag8,), (Flag8,)> { + unsafe { + wasmtime::component::TypedFunc::< + (Flag8,), + (Flag8,), + >::new_unchecked(self.roundtrip_flag8) + } + } pub async fn call_roundtrip_flag8( &self, mut store: S, @@ -851,17 +876,22 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (Flag8,), - (Flag8,), - >::new_unchecked(self.roundtrip_flag8) - }; + let callee = self.func_roundtrip_flag8(); let (ret0,) = callee .call_async(store.as_context_mut(), (arg0,)) .await?; Ok(ret0) } + pub fn func_roundtrip_flag16( + &self, + ) -> wasmtime::component::TypedFunc<(Flag16,), (Flag16,)> { + unsafe { + wasmtime::component::TypedFunc::< + (Flag16,), + (Flag16,), + >::new_unchecked(self.roundtrip_flag16) + } + } pub async fn call_roundtrip_flag16( &self, mut store: S, @@ -870,17 +900,22 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (Flag16,), - (Flag16,), - >::new_unchecked(self.roundtrip_flag16) - }; + let callee = self.func_roundtrip_flag16(); let (ret0,) = callee .call_async(store.as_context_mut(), (arg0,)) .await?; Ok(ret0) } + pub fn func_roundtrip_flag32( + &self, + ) -> wasmtime::component::TypedFunc<(Flag32,), (Flag32,)> { + unsafe { + wasmtime::component::TypedFunc::< + (Flag32,), + (Flag32,), + >::new_unchecked(self.roundtrip_flag32) + } + } pub async fn call_roundtrip_flag32( &self, mut store: S, @@ -889,17 +924,22 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (Flag32,), - (Flag32,), - >::new_unchecked(self.roundtrip_flag32) - }; + let callee = self.func_roundtrip_flag32(); let (ret0,) = callee .call_async(store.as_context_mut(), (arg0,)) .await?; Ok(ret0) } + pub fn func_roundtrip_flag64( + &self, + ) -> wasmtime::component::TypedFunc<(Flag64,), (Flag64,)> { + unsafe { + wasmtime::component::TypedFunc::< + (Flag64,), + (Flag64,), + >::new_unchecked(self.roundtrip_flag64) + } + } pub async fn call_roundtrip_flag64( &self, mut store: S, @@ -908,12 +948,7 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (Flag64,), - (Flag64,), - >::new_unchecked(self.roundtrip_flag64) - }; + let callee = self.func_roundtrip_flag64(); let (ret0,) = callee .call_async(store.as_context_mut(), (arg0,)) .await?; diff --git a/crates/component-macro/tests/expanded/flags_concurrent.rs b/crates/component-macro/tests/expanded/flags_concurrent.rs index f81f8886e79b..89d3e91d287c 100644 --- a/crates/component-macro/tests/expanded/flags_concurrent.rs +++ b/crates/component-macro/tests/expanded/flags_concurrent.rs @@ -725,6 +725,16 @@ pub mod exports { } } impl Guest { + pub fn func_roundtrip_flag1( + &self, + ) -> wasmtime::component::TypedFunc<(Flag1,), (Flag1,)> { + unsafe { + wasmtime::component::TypedFunc::< + (Flag1,), + (Flag1,), + >::new_unchecked(self.roundtrip_flag1) + } + } pub async fn call_roundtrip_flag1<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -734,15 +744,20 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (Flag1,), - (Flag1,), - >::new_unchecked(self.roundtrip_flag1) - }; + let callee = self.func_roundtrip_flag1(); let (ret0,) = callee.call_concurrent(accessor, (arg0,)).await?; Ok(ret0) } + pub fn func_roundtrip_flag2( + &self, + ) -> wasmtime::component::TypedFunc<(Flag2,), (Flag2,)> { + unsafe { + wasmtime::component::TypedFunc::< + (Flag2,), + (Flag2,), + >::new_unchecked(self.roundtrip_flag2) + } + } pub async fn call_roundtrip_flag2<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -752,15 +767,20 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (Flag2,), - (Flag2,), - >::new_unchecked(self.roundtrip_flag2) - }; + let callee = self.func_roundtrip_flag2(); let (ret0,) = callee.call_concurrent(accessor, (arg0,)).await?; Ok(ret0) } + pub fn func_roundtrip_flag4( + &self, + ) -> wasmtime::component::TypedFunc<(Flag4,), (Flag4,)> { + unsafe { + wasmtime::component::TypedFunc::< + (Flag4,), + (Flag4,), + >::new_unchecked(self.roundtrip_flag4) + } + } pub async fn call_roundtrip_flag4<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -770,15 +790,20 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (Flag4,), - (Flag4,), - >::new_unchecked(self.roundtrip_flag4) - }; + let callee = self.func_roundtrip_flag4(); let (ret0,) = callee.call_concurrent(accessor, (arg0,)).await?; Ok(ret0) } + pub fn func_roundtrip_flag8( + &self, + ) -> wasmtime::component::TypedFunc<(Flag8,), (Flag8,)> { + unsafe { + wasmtime::component::TypedFunc::< + (Flag8,), + (Flag8,), + >::new_unchecked(self.roundtrip_flag8) + } + } pub async fn call_roundtrip_flag8<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -788,15 +813,20 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (Flag8,), - (Flag8,), - >::new_unchecked(self.roundtrip_flag8) - }; + let callee = self.func_roundtrip_flag8(); let (ret0,) = callee.call_concurrent(accessor, (arg0,)).await?; Ok(ret0) } + pub fn func_roundtrip_flag16( + &self, + ) -> wasmtime::component::TypedFunc<(Flag16,), (Flag16,)> { + unsafe { + wasmtime::component::TypedFunc::< + (Flag16,), + (Flag16,), + >::new_unchecked(self.roundtrip_flag16) + } + } pub async fn call_roundtrip_flag16<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -806,15 +836,20 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (Flag16,), - (Flag16,), - >::new_unchecked(self.roundtrip_flag16) - }; + let callee = self.func_roundtrip_flag16(); let (ret0,) = callee.call_concurrent(accessor, (arg0,)).await?; Ok(ret0) } + pub fn func_roundtrip_flag32( + &self, + ) -> wasmtime::component::TypedFunc<(Flag32,), (Flag32,)> { + unsafe { + wasmtime::component::TypedFunc::< + (Flag32,), + (Flag32,), + >::new_unchecked(self.roundtrip_flag32) + } + } pub async fn call_roundtrip_flag32<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -824,15 +859,20 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (Flag32,), - (Flag32,), - >::new_unchecked(self.roundtrip_flag32) - }; + let callee = self.func_roundtrip_flag32(); let (ret0,) = callee.call_concurrent(accessor, (arg0,)).await?; Ok(ret0) } + pub fn func_roundtrip_flag64( + &self, + ) -> wasmtime::component::TypedFunc<(Flag64,), (Flag64,)> { + unsafe { + wasmtime::component::TypedFunc::< + (Flag64,), + (Flag64,), + >::new_unchecked(self.roundtrip_flag64) + } + } pub async fn call_roundtrip_flag64<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -842,12 +882,7 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (Flag64,), - (Flag64,), - >::new_unchecked(self.roundtrip_flag64) - }; + let callee = self.func_roundtrip_flag64(); let (ret0,) = callee.call_concurrent(accessor, (arg0,)).await?; Ok(ret0) } diff --git a/crates/component-macro/tests/expanded/flags_tracing_async.rs b/crates/component-macro/tests/expanded/flags_tracing_async.rs index 16f69506f1ce..0fe4e1485851 100644 --- a/crates/component-macro/tests/expanded/flags_tracing_async.rs +++ b/crates/component-macro/tests/expanded/flags_tracing_async.rs @@ -898,6 +898,16 @@ pub mod exports { } } impl Guest { + pub fn func_roundtrip_flag1( + &self, + ) -> wasmtime::component::TypedFunc<(Flag1,), (Flag1,)> { + unsafe { + wasmtime::component::TypedFunc::< + (Flag1,), + (Flag1,), + >::new_unchecked(self.roundtrip_flag1) + } + } pub async fn call_roundtrip_flag1( &self, mut store: S, @@ -911,18 +921,23 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/flegs", function = "roundtrip-flag1", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (Flag1,), - (Flag1,), - >::new_unchecked(self.roundtrip_flag1) - }; + let callee = self.func_roundtrip_flag1(); let (ret0,) = callee .call_async(store.as_context_mut(), (arg0,)) .instrument(span.clone()) .await?; Ok(ret0) } + pub fn func_roundtrip_flag2( + &self, + ) -> wasmtime::component::TypedFunc<(Flag2,), (Flag2,)> { + unsafe { + wasmtime::component::TypedFunc::< + (Flag2,), + (Flag2,), + >::new_unchecked(self.roundtrip_flag2) + } + } pub async fn call_roundtrip_flag2( &self, mut store: S, @@ -936,18 +951,23 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/flegs", function = "roundtrip-flag2", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (Flag2,), - (Flag2,), - >::new_unchecked(self.roundtrip_flag2) - }; + let callee = self.func_roundtrip_flag2(); let (ret0,) = callee .call_async(store.as_context_mut(), (arg0,)) .instrument(span.clone()) .await?; Ok(ret0) } + pub fn func_roundtrip_flag4( + &self, + ) -> wasmtime::component::TypedFunc<(Flag4,), (Flag4,)> { + unsafe { + wasmtime::component::TypedFunc::< + (Flag4,), + (Flag4,), + >::new_unchecked(self.roundtrip_flag4) + } + } pub async fn call_roundtrip_flag4( &self, mut store: S, @@ -961,18 +981,23 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/flegs", function = "roundtrip-flag4", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (Flag4,), - (Flag4,), - >::new_unchecked(self.roundtrip_flag4) - }; + let callee = self.func_roundtrip_flag4(); let (ret0,) = callee .call_async(store.as_context_mut(), (arg0,)) .instrument(span.clone()) .await?; Ok(ret0) } + pub fn func_roundtrip_flag8( + &self, + ) -> wasmtime::component::TypedFunc<(Flag8,), (Flag8,)> { + unsafe { + wasmtime::component::TypedFunc::< + (Flag8,), + (Flag8,), + >::new_unchecked(self.roundtrip_flag8) + } + } pub async fn call_roundtrip_flag8( &self, mut store: S, @@ -986,18 +1011,23 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/flegs", function = "roundtrip-flag8", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (Flag8,), - (Flag8,), - >::new_unchecked(self.roundtrip_flag8) - }; + let callee = self.func_roundtrip_flag8(); let (ret0,) = callee .call_async(store.as_context_mut(), (arg0,)) .instrument(span.clone()) .await?; Ok(ret0) } + pub fn func_roundtrip_flag16( + &self, + ) -> wasmtime::component::TypedFunc<(Flag16,), (Flag16,)> { + unsafe { + wasmtime::component::TypedFunc::< + (Flag16,), + (Flag16,), + >::new_unchecked(self.roundtrip_flag16) + } + } pub async fn call_roundtrip_flag16( &self, mut store: S, @@ -1011,18 +1041,23 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/flegs", function = "roundtrip-flag16", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (Flag16,), - (Flag16,), - >::new_unchecked(self.roundtrip_flag16) - }; + let callee = self.func_roundtrip_flag16(); let (ret0,) = callee .call_async(store.as_context_mut(), (arg0,)) .instrument(span.clone()) .await?; Ok(ret0) } + pub fn func_roundtrip_flag32( + &self, + ) -> wasmtime::component::TypedFunc<(Flag32,), (Flag32,)> { + unsafe { + wasmtime::component::TypedFunc::< + (Flag32,), + (Flag32,), + >::new_unchecked(self.roundtrip_flag32) + } + } pub async fn call_roundtrip_flag32( &self, mut store: S, @@ -1036,18 +1071,23 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/flegs", function = "roundtrip-flag32", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (Flag32,), - (Flag32,), - >::new_unchecked(self.roundtrip_flag32) - }; + let callee = self.func_roundtrip_flag32(); let (ret0,) = callee .call_async(store.as_context_mut(), (arg0,)) .instrument(span.clone()) .await?; Ok(ret0) } + pub fn func_roundtrip_flag64( + &self, + ) -> wasmtime::component::TypedFunc<(Flag64,), (Flag64,)> { + unsafe { + wasmtime::component::TypedFunc::< + (Flag64,), + (Flag64,), + >::new_unchecked(self.roundtrip_flag64) + } + } pub async fn call_roundtrip_flag64( &self, mut store: S, @@ -1061,12 +1101,7 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/flegs", function = "roundtrip-flag64", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (Flag64,), - (Flag64,), - >::new_unchecked(self.roundtrip_flag64) - }; + let callee = self.func_roundtrip_flag64(); let (ret0,) = callee .call_async(store.as_context_mut(), (arg0,)) .instrument(span.clone()) diff --git a/crates/component-macro/tests/expanded/floats.rs b/crates/component-macro/tests/expanded/floats.rs index a8537cf9184f..b29cb4fdb48e 100644 --- a/crates/component-macro/tests/expanded/floats.rs +++ b/crates/component-macro/tests/expanded/floats.rs @@ -367,57 +367,77 @@ pub mod exports { } } impl Guest { - pub fn call_f32_param( + pub fn func_f32_param( &self, - mut store: S, - arg0: f32, - ) -> wasmtime::Result<()> { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc<(f32,), ()> { + unsafe { wasmtime::component::TypedFunc::< (f32,), (), >::new_unchecked(self.f32_param) - }; - let () = callee.call(store.as_context_mut(), (arg0,))?; - Ok(()) + } } - pub fn call_f64_param( + pub fn call_f32_param( &self, mut store: S, - arg0: f64, + arg0: f32, ) -> wasmtime::Result<()> { - let callee = unsafe { + let callee = self.func_f32_param(); + let () = callee.call(store.as_context_mut(), (arg0,))?; + Ok(()) + } + pub fn func_f64_param( + &self, + ) -> wasmtime::component::TypedFunc<(f64,), ()> { + unsafe { wasmtime::component::TypedFunc::< (f64,), (), >::new_unchecked(self.f64_param) - }; + } + } + pub fn call_f64_param( + &self, + mut store: S, + arg0: f64, + ) -> wasmtime::Result<()> { + let callee = self.func_f64_param(); let () = callee.call(store.as_context_mut(), (arg0,))?; Ok(()) } - pub fn call_f32_result( + pub fn func_f32_result( &self, - mut store: S, - ) -> wasmtime::Result { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc<(), (f32,)> { + unsafe { wasmtime::component::TypedFunc::< (), (f32,), >::new_unchecked(self.f32_result) - }; + } + } + pub fn call_f32_result( + &self, + mut store: S, + ) -> wasmtime::Result { + let callee = self.func_f32_result(); let (ret0,) = callee.call(store.as_context_mut(), ())?; Ok(ret0) } - pub fn call_f64_result( + pub fn func_f64_result( &self, - mut store: S, - ) -> wasmtime::Result { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc<(), (f64,)> { + unsafe { wasmtime::component::TypedFunc::< (), (f64,), >::new_unchecked(self.f64_result) - }; + } + } + pub fn call_f64_result( + &self, + mut store: S, + ) -> wasmtime::Result { + let callee = self.func_f64_result(); let (ret0,) = callee.call(store.as_context_mut(), ())?; Ok(ret0) } diff --git a/crates/component-macro/tests/expanded/floats_async.rs b/crates/component-macro/tests/expanded/floats_async.rs index fd012d7c5fb2..48396e0c242d 100644 --- a/crates/component-macro/tests/expanded/floats_async.rs +++ b/crates/component-macro/tests/expanded/floats_async.rs @@ -395,6 +395,16 @@ pub mod exports { } } impl Guest { + pub fn func_f32_param( + &self, + ) -> wasmtime::component::TypedFunc<(f32,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (f32,), + (), + >::new_unchecked(self.f32_param) + } + } pub async fn call_f32_param( &self, mut store: S, @@ -403,17 +413,22 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (f32,), - (), - >::new_unchecked(self.f32_param) - }; + let callee = self.func_f32_param(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .await?; Ok(()) } + pub fn func_f64_param( + &self, + ) -> wasmtime::component::TypedFunc<(f64,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (f64,), + (), + >::new_unchecked(self.f64_param) + } + } pub async fn call_f64_param( &self, mut store: S, @@ -422,17 +437,22 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (f64,), - (), - >::new_unchecked(self.f64_param) - }; + let callee = self.func_f64_param(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .await?; Ok(()) } + pub fn func_f32_result( + &self, + ) -> wasmtime::component::TypedFunc<(), (f32,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (f32,), + >::new_unchecked(self.f32_result) + } + } pub async fn call_f32_result( &self, mut store: S, @@ -440,17 +460,22 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (f32,), - >::new_unchecked(self.f32_result) - }; + let callee = self.func_f32_result(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .await?; Ok(ret0) } + pub fn func_f64_result( + &self, + ) -> wasmtime::component::TypedFunc<(), (f64,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (f64,), + >::new_unchecked(self.f64_result) + } + } pub async fn call_f64_result( &self, mut store: S, @@ -458,12 +483,7 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (f64,), - >::new_unchecked(self.f64_result) - }; + let callee = self.func_f64_result(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .await?; diff --git a/crates/component-macro/tests/expanded/floats_concurrent.rs b/crates/component-macro/tests/expanded/floats_concurrent.rs index 875467d65ef7..71c9ba1f9d51 100644 --- a/crates/component-macro/tests/expanded/floats_concurrent.rs +++ b/crates/component-macro/tests/expanded/floats_concurrent.rs @@ -368,6 +368,16 @@ pub mod exports { } } impl Guest { + pub fn func_f32_param( + &self, + ) -> wasmtime::component::TypedFunc<(f32,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (f32,), + (), + >::new_unchecked(self.f32_param) + } + } pub async fn call_f32_param<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -377,15 +387,20 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (f32,), - (), - >::new_unchecked(self.f32_param) - }; + let callee = self.func_f32_param(); let () = callee.call_concurrent(accessor, (arg0,)).await?; Ok(()) } + pub fn func_f64_param( + &self, + ) -> wasmtime::component::TypedFunc<(f64,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (f64,), + (), + >::new_unchecked(self.f64_param) + } + } pub async fn call_f64_param<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -395,15 +410,20 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (f64,), - (), - >::new_unchecked(self.f64_param) - }; + let callee = self.func_f64_param(); let () = callee.call_concurrent(accessor, (arg0,)).await?; Ok(()) } + pub fn func_f32_result( + &self, + ) -> wasmtime::component::TypedFunc<(), (f32,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (f32,), + >::new_unchecked(self.f32_result) + } + } pub async fn call_f32_result<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -412,15 +432,20 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (f32,), - >::new_unchecked(self.f32_result) - }; + let callee = self.func_f32_result(); let (ret0,) = callee.call_concurrent(accessor, ()).await?; Ok(ret0) } + pub fn func_f64_result( + &self, + ) -> wasmtime::component::TypedFunc<(), (f64,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (f64,), + >::new_unchecked(self.f64_result) + } + } pub async fn call_f64_result<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -429,12 +454,7 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (f64,), - >::new_unchecked(self.f64_result) - }; + let callee = self.func_f64_result(); let (ret0,) = callee.call_concurrent(accessor, ()).await?; Ok(ret0) } diff --git a/crates/component-macro/tests/expanded/floats_tracing_async.rs b/crates/component-macro/tests/expanded/floats_tracing_async.rs index 394c6604a2e8..514922899766 100644 --- a/crates/component-macro/tests/expanded/floats_tracing_async.rs +++ b/crates/component-macro/tests/expanded/floats_tracing_async.rs @@ -453,6 +453,16 @@ pub mod exports { } } impl Guest { + pub fn func_f32_param( + &self, + ) -> wasmtime::component::TypedFunc<(f32,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (f32,), + (), + >::new_unchecked(self.f32_param) + } + } pub async fn call_f32_param( &self, mut store: S, @@ -466,18 +476,23 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/floats", function = "f32-param", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (f32,), - (), - >::new_unchecked(self.f32_param) - }; + let callee = self.func_f32_param(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .instrument(span.clone()) .await?; Ok(()) } + pub fn func_f64_param( + &self, + ) -> wasmtime::component::TypedFunc<(f64,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (f64,), + (), + >::new_unchecked(self.f64_param) + } + } pub async fn call_f64_param( &self, mut store: S, @@ -491,18 +506,23 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/floats", function = "f64-param", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (f64,), - (), - >::new_unchecked(self.f64_param) - }; + let callee = self.func_f64_param(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .instrument(span.clone()) .await?; Ok(()) } + pub fn func_f32_result( + &self, + ) -> wasmtime::component::TypedFunc<(), (f32,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (f32,), + >::new_unchecked(self.f32_result) + } + } pub async fn call_f32_result( &self, mut store: S, @@ -515,18 +535,23 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/floats", function = "f32-result", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (f32,), - >::new_unchecked(self.f32_result) - }; + let callee = self.func_f32_result(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) .await?; Ok(ret0) } + pub fn func_f64_result( + &self, + ) -> wasmtime::component::TypedFunc<(), (f64,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (f64,), + >::new_unchecked(self.f64_result) + } + } pub async fn call_f64_result( &self, mut store: S, @@ -539,12 +564,7 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/floats", function = "f64-result", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (f64,), - >::new_unchecked(self.f64_result) - }; + let callee = self.func_f64_result(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) diff --git a/crates/component-macro/tests/expanded/function-new.rs b/crates/component-macro/tests/expanded/function-new.rs index 0072bef34519..24bce75daf26 100644 --- a/crates/component-macro/tests/expanded/function-new.rs +++ b/crates/component-macro/tests/expanded/function-new.rs @@ -180,13 +180,14 @@ const _: () = { let pre = linker.instantiate_pre(component)?; FooPre::new(pre)?.instantiate_async(store).await } + pub fn func_new(&self) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { wasmtime::component::TypedFunc::<(), ()>::new_unchecked(self.new) } + } pub fn call_new( &self, mut store: S, ) -> wasmtime::Result<()> { - let callee = unsafe { - wasmtime::component::TypedFunc::<(), ()>::new_unchecked(self.new) - }; + let callee = self.func_new(); let () = callee.call(store.as_context_mut(), ())?; Ok(()) } diff --git a/crates/component-macro/tests/expanded/function-new_async.rs b/crates/component-macro/tests/expanded/function-new_async.rs index 44af5dc74479..229152889966 100644 --- a/crates/component-macro/tests/expanded/function-new_async.rs +++ b/crates/component-macro/tests/expanded/function-new_async.rs @@ -180,6 +180,9 @@ const _: () = { let pre = linker.instantiate_pre(component)?; FooPre::new(pre)?.instantiate_async(store).await } + pub fn func_new(&self) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { wasmtime::component::TypedFunc::<(), ()>::new_unchecked(self.new) } + } pub async fn call_new( &self, mut store: S, @@ -187,9 +190,7 @@ const _: () = { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::<(), ()>::new_unchecked(self.new) - }; + let callee = self.func_new(); let () = callee.call_async(store.as_context_mut(), ()).await?; Ok(()) } diff --git a/crates/component-macro/tests/expanded/function-new_concurrent.rs b/crates/component-macro/tests/expanded/function-new_concurrent.rs index d7a44b4eb24c..ce83a5118331 100644 --- a/crates/component-macro/tests/expanded/function-new_concurrent.rs +++ b/crates/component-macro/tests/expanded/function-new_concurrent.rs @@ -180,6 +180,9 @@ const _: () = { let pre = linker.instantiate_pre(component)?; FooPre::new(pre)?.instantiate_async(store).await } + pub fn func_new(&self) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { wasmtime::component::TypedFunc::<(), ()>::new_unchecked(self.new) } + } pub async fn call_new<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -188,9 +191,7 @@ const _: () = { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::<(), ()>::new_unchecked(self.new) - }; + let callee = self.func_new(); let () = callee.call_concurrent(accessor, ()).await?; Ok(()) } diff --git a/crates/component-macro/tests/expanded/function-new_tracing_async.rs b/crates/component-macro/tests/expanded/function-new_tracing_async.rs index 5e30aca2a0fe..5326732467de 100644 --- a/crates/component-macro/tests/expanded/function-new_tracing_async.rs +++ b/crates/component-macro/tests/expanded/function-new_tracing_async.rs @@ -180,6 +180,9 @@ const _: () = { let pre = linker.instantiate_pre(component)?; FooPre::new(pre)?.instantiate_async(store).await } + pub fn func_new(&self) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { wasmtime::component::TypedFunc::<(), ()>::new_unchecked(self.new) } + } pub async fn call_new( &self, mut store: S, @@ -192,9 +195,7 @@ const _: () = { tracing::Level::TRACE, "wit-bindgen export", module = "default", function = "new", ); - let callee = unsafe { - wasmtime::component::TypedFunc::<(), ()>::new_unchecked(self.new) - }; + let callee = self.func_new(); let () = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) diff --git a/crates/component-macro/tests/expanded/integers.rs b/crates/component-macro/tests/expanded/integers.rs index e2064dd7c744..0d7e703f1782 100644 --- a/crates/component-macro/tests/expanded/integers.rs +++ b/crates/component-macro/tests/expanded/integers.rs @@ -695,118 +695,155 @@ pub mod exports { } } impl Guest { + pub fn func_a1(&self) -> wasmtime::component::TypedFunc<(u8,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (u8,), + (), + >::new_unchecked(self.a1) + } + } pub fn call_a1( &self, mut store: S, arg0: u8, ) -> wasmtime::Result<()> { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (u8,), - (), - >::new_unchecked(self.a1) - }; + let callee = self.func_a1(); let () = callee.call(store.as_context_mut(), (arg0,))?; Ok(()) } + pub fn func_a2(&self) -> wasmtime::component::TypedFunc<(i8,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (i8,), + (), + >::new_unchecked(self.a2) + } + } pub fn call_a2( &self, mut store: S, arg0: i8, ) -> wasmtime::Result<()> { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (i8,), - (), - >::new_unchecked(self.a2) - }; + let callee = self.func_a2(); let () = callee.call(store.as_context_mut(), (arg0,))?; Ok(()) } + pub fn func_a3(&self) -> wasmtime::component::TypedFunc<(u16,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (u16,), + (), + >::new_unchecked(self.a3) + } + } pub fn call_a3( &self, mut store: S, arg0: u16, ) -> wasmtime::Result<()> { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (u16,), - (), - >::new_unchecked(self.a3) - }; + let callee = self.func_a3(); let () = callee.call(store.as_context_mut(), (arg0,))?; Ok(()) } + pub fn func_a4(&self) -> wasmtime::component::TypedFunc<(i16,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (i16,), + (), + >::new_unchecked(self.a4) + } + } pub fn call_a4( &self, mut store: S, arg0: i16, ) -> wasmtime::Result<()> { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (i16,), - (), - >::new_unchecked(self.a4) - }; + let callee = self.func_a4(); let () = callee.call(store.as_context_mut(), (arg0,))?; Ok(()) } + pub fn func_a5(&self) -> wasmtime::component::TypedFunc<(u32,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (u32,), + (), + >::new_unchecked(self.a5) + } + } pub fn call_a5( &self, mut store: S, arg0: u32, ) -> wasmtime::Result<()> { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (u32,), - (), - >::new_unchecked(self.a5) - }; + let callee = self.func_a5(); let () = callee.call(store.as_context_mut(), (arg0,))?; Ok(()) } + pub fn func_a6(&self) -> wasmtime::component::TypedFunc<(i32,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (i32,), + (), + >::new_unchecked(self.a6) + } + } pub fn call_a6( &self, mut store: S, arg0: i32, ) -> wasmtime::Result<()> { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (i32,), - (), - >::new_unchecked(self.a6) - }; + let callee = self.func_a6(); let () = callee.call(store.as_context_mut(), (arg0,))?; Ok(()) } + pub fn func_a7(&self) -> wasmtime::component::TypedFunc<(u64,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (u64,), + (), + >::new_unchecked(self.a7) + } + } pub fn call_a7( &self, mut store: S, arg0: u64, ) -> wasmtime::Result<()> { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (u64,), - (), - >::new_unchecked(self.a7) - }; + let callee = self.func_a7(); let () = callee.call(store.as_context_mut(), (arg0,))?; Ok(()) } + pub fn func_a8(&self) -> wasmtime::component::TypedFunc<(i64,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (i64,), + (), + >::new_unchecked(self.a8) + } + } pub fn call_a8( &self, mut store: S, arg0: i64, ) -> wasmtime::Result<()> { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (i64,), - (), - >::new_unchecked(self.a8) - }; + let callee = self.func_a8(); let () = callee.call(store.as_context_mut(), (arg0,))?; Ok(()) } + pub fn func_a9( + &self, + ) -> wasmtime::component::TypedFunc< + (u8, i8, u16, i16, u32, i32, u64, i64), + (), + > { + unsafe { + wasmtime::component::TypedFunc::< + (u8, i8, u16, i16, u32, i32, u64, i64), + (), + >::new_unchecked(self.a9) + } + } pub fn call_a9( &self, mut store: S, @@ -819,12 +856,7 @@ pub mod exports { arg6: u64, arg7: i64, ) -> wasmtime::Result<()> { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (u8, i8, u16, i16, u32, i32, u64, i64), - (), - >::new_unchecked(self.a9) - }; + let callee = self.func_a9(); let () = callee .call( store.as_context_mut(), @@ -832,120 +864,149 @@ pub mod exports { )?; Ok(()) } - pub fn call_r1( - &self, - mut store: S, - ) -> wasmtime::Result { - let callee = unsafe { + pub fn func_r1(&self) -> wasmtime::component::TypedFunc<(), (u8,)> { + unsafe { wasmtime::component::TypedFunc::< (), (u8,), >::new_unchecked(self.r1) - }; - let (ret0,) = callee.call(store.as_context_mut(), ())?; - Ok(ret0) + } } - pub fn call_r2( + pub fn call_r1( &self, mut store: S, - ) -> wasmtime::Result { - let callee = unsafe { + ) -> wasmtime::Result { + let callee = self.func_r1(); + let (ret0,) = callee.call(store.as_context_mut(), ())?; + Ok(ret0) + } + pub fn func_r2(&self) -> wasmtime::component::TypedFunc<(), (i8,)> { + unsafe { wasmtime::component::TypedFunc::< (), (i8,), >::new_unchecked(self.r2) - }; - let (ret0,) = callee.call(store.as_context_mut(), ())?; - Ok(ret0) + } } - pub fn call_r3( + pub fn call_r2( &self, mut store: S, - ) -> wasmtime::Result { - let callee = unsafe { + ) -> wasmtime::Result { + let callee = self.func_r2(); + let (ret0,) = callee.call(store.as_context_mut(), ())?; + Ok(ret0) + } + pub fn func_r3(&self) -> wasmtime::component::TypedFunc<(), (u16,)> { + unsafe { wasmtime::component::TypedFunc::< (), (u16,), >::new_unchecked(self.r3) - }; - let (ret0,) = callee.call(store.as_context_mut(), ())?; - Ok(ret0) + } } - pub fn call_r4( + pub fn call_r3( &self, mut store: S, - ) -> wasmtime::Result { - let callee = unsafe { + ) -> wasmtime::Result { + let callee = self.func_r3(); + let (ret0,) = callee.call(store.as_context_mut(), ())?; + Ok(ret0) + } + pub fn func_r4(&self) -> wasmtime::component::TypedFunc<(), (i16,)> { + unsafe { wasmtime::component::TypedFunc::< (), (i16,), >::new_unchecked(self.r4) - }; - let (ret0,) = callee.call(store.as_context_mut(), ())?; - Ok(ret0) + } } - pub fn call_r5( + pub fn call_r4( &self, mut store: S, - ) -> wasmtime::Result { - let callee = unsafe { + ) -> wasmtime::Result { + let callee = self.func_r4(); + let (ret0,) = callee.call(store.as_context_mut(), ())?; + Ok(ret0) + } + pub fn func_r5(&self) -> wasmtime::component::TypedFunc<(), (u32,)> { + unsafe { wasmtime::component::TypedFunc::< (), (u32,), >::new_unchecked(self.r5) - }; - let (ret0,) = callee.call(store.as_context_mut(), ())?; - Ok(ret0) + } } - pub fn call_r6( + pub fn call_r5( &self, mut store: S, - ) -> wasmtime::Result { - let callee = unsafe { + ) -> wasmtime::Result { + let callee = self.func_r5(); + let (ret0,) = callee.call(store.as_context_mut(), ())?; + Ok(ret0) + } + pub fn func_r6(&self) -> wasmtime::component::TypedFunc<(), (i32,)> { + unsafe { wasmtime::component::TypedFunc::< (), (i32,), >::new_unchecked(self.r6) - }; - let (ret0,) = callee.call(store.as_context_mut(), ())?; - Ok(ret0) + } } - pub fn call_r7( + pub fn call_r6( &self, mut store: S, - ) -> wasmtime::Result { - let callee = unsafe { + ) -> wasmtime::Result { + let callee = self.func_r6(); + let (ret0,) = callee.call(store.as_context_mut(), ())?; + Ok(ret0) + } + pub fn func_r7(&self) -> wasmtime::component::TypedFunc<(), (u64,)> { + unsafe { wasmtime::component::TypedFunc::< (), (u64,), >::new_unchecked(self.r7) - }; - let (ret0,) = callee.call(store.as_context_mut(), ())?; - Ok(ret0) + } } - pub fn call_r8( + pub fn call_r7( &self, mut store: S, - ) -> wasmtime::Result { - let callee = unsafe { + ) -> wasmtime::Result { + let callee = self.func_r7(); + let (ret0,) = callee.call(store.as_context_mut(), ())?; + Ok(ret0) + } + pub fn func_r8(&self) -> wasmtime::component::TypedFunc<(), (i64,)> { + unsafe { wasmtime::component::TypedFunc::< (), (i64,), >::new_unchecked(self.r8) - }; + } + } + pub fn call_r8( + &self, + mut store: S, + ) -> wasmtime::Result { + let callee = self.func_r8(); let (ret0,) = callee.call(store.as_context_mut(), ())?; Ok(ret0) } - pub fn call_pair_ret( + pub fn func_pair_ret( &self, - mut store: S, - ) -> wasmtime::Result<(i64, u8)> { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc<(), ((i64, u8),)> { + unsafe { wasmtime::component::TypedFunc::< (), ((i64, u8),), >::new_unchecked(self.pair_ret) - }; + } + } + pub fn call_pair_ret( + &self, + mut store: S, + ) -> wasmtime::Result<(i64, u8)> { + let callee = self.func_pair_ret(); let (ret0,) = callee.call(store.as_context_mut(), ())?; Ok(ret0) } diff --git a/crates/component-macro/tests/expanded/integers_async.rs b/crates/component-macro/tests/expanded/integers_async.rs index 65587932375e..943cab4e382a 100644 --- a/crates/component-macro/tests/expanded/integers_async.rs +++ b/crates/component-macro/tests/expanded/integers_async.rs @@ -784,6 +784,14 @@ pub mod exports { } } impl Guest { + pub fn func_a1(&self) -> wasmtime::component::TypedFunc<(u8,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (u8,), + (), + >::new_unchecked(self.a1) + } + } pub async fn call_a1( &self, mut store: S, @@ -792,17 +800,20 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (u8,), - (), - >::new_unchecked(self.a1) - }; + let callee = self.func_a1(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .await?; Ok(()) } + pub fn func_a2(&self) -> wasmtime::component::TypedFunc<(i8,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (i8,), + (), + >::new_unchecked(self.a2) + } + } pub async fn call_a2( &self, mut store: S, @@ -811,17 +822,20 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (i8,), - (), - >::new_unchecked(self.a2) - }; + let callee = self.func_a2(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .await?; Ok(()) } + pub fn func_a3(&self) -> wasmtime::component::TypedFunc<(u16,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (u16,), + (), + >::new_unchecked(self.a3) + } + } pub async fn call_a3( &self, mut store: S, @@ -830,17 +844,20 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (u16,), - (), - >::new_unchecked(self.a3) - }; + let callee = self.func_a3(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .await?; Ok(()) } + pub fn func_a4(&self) -> wasmtime::component::TypedFunc<(i16,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (i16,), + (), + >::new_unchecked(self.a4) + } + } pub async fn call_a4( &self, mut store: S, @@ -849,17 +866,20 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (i16,), - (), - >::new_unchecked(self.a4) - }; + let callee = self.func_a4(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .await?; Ok(()) } + pub fn func_a5(&self) -> wasmtime::component::TypedFunc<(u32,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (u32,), + (), + >::new_unchecked(self.a5) + } + } pub async fn call_a5( &self, mut store: S, @@ -868,17 +888,20 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (u32,), - (), - >::new_unchecked(self.a5) - }; + let callee = self.func_a5(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .await?; Ok(()) } + pub fn func_a6(&self) -> wasmtime::component::TypedFunc<(i32,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (i32,), + (), + >::new_unchecked(self.a6) + } + } pub async fn call_a6( &self, mut store: S, @@ -887,17 +910,20 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (i32,), - (), - >::new_unchecked(self.a6) - }; + let callee = self.func_a6(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .await?; Ok(()) } + pub fn func_a7(&self) -> wasmtime::component::TypedFunc<(u64,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (u64,), + (), + >::new_unchecked(self.a7) + } + } pub async fn call_a7( &self, mut store: S, @@ -906,17 +932,20 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (u64,), - (), - >::new_unchecked(self.a7) - }; + let callee = self.func_a7(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .await?; Ok(()) } + pub fn func_a8(&self) -> wasmtime::component::TypedFunc<(i64,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (i64,), + (), + >::new_unchecked(self.a8) + } + } pub async fn call_a8( &self, mut store: S, @@ -925,17 +954,25 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (i64,), - (), - >::new_unchecked(self.a8) - }; + let callee = self.func_a8(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .await?; Ok(()) } + pub fn func_a9( + &self, + ) -> wasmtime::component::TypedFunc< + (u8, i8, u16, i16, u32, i32, u64, i64), + (), + > { + unsafe { + wasmtime::component::TypedFunc::< + (u8, i8, u16, i16, u32, i32, u64, i64), + (), + >::new_unchecked(self.a9) + } + } pub async fn call_a9( &self, mut store: S, @@ -951,12 +988,7 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (u8, i8, u16, i16, u32, i32, u64, i64), - (), - >::new_unchecked(self.a9) - }; + let callee = self.func_a9(); let () = callee .call_async( store.as_context_mut(), @@ -965,6 +997,14 @@ pub mod exports { .await?; Ok(()) } + pub fn func_r1(&self) -> wasmtime::component::TypedFunc<(), (u8,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (u8,), + >::new_unchecked(self.r1) + } + } pub async fn call_r1( &self, mut store: S, @@ -972,17 +1012,20 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (u8,), - >::new_unchecked(self.r1) - }; + let callee = self.func_r1(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .await?; Ok(ret0) } + pub fn func_r2(&self) -> wasmtime::component::TypedFunc<(), (i8,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (i8,), + >::new_unchecked(self.r2) + } + } pub async fn call_r2( &self, mut store: S, @@ -990,17 +1033,20 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (i8,), - >::new_unchecked(self.r2) - }; + let callee = self.func_r2(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .await?; Ok(ret0) } + pub fn func_r3(&self) -> wasmtime::component::TypedFunc<(), (u16,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (u16,), + >::new_unchecked(self.r3) + } + } pub async fn call_r3( &self, mut store: S, @@ -1008,17 +1054,20 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (u16,), - >::new_unchecked(self.r3) - }; + let callee = self.func_r3(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .await?; Ok(ret0) } + pub fn func_r4(&self) -> wasmtime::component::TypedFunc<(), (i16,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (i16,), + >::new_unchecked(self.r4) + } + } pub async fn call_r4( &self, mut store: S, @@ -1026,17 +1075,20 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (i16,), - >::new_unchecked(self.r4) - }; + let callee = self.func_r4(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .await?; Ok(ret0) } + pub fn func_r5(&self) -> wasmtime::component::TypedFunc<(), (u32,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (u32,), + >::new_unchecked(self.r5) + } + } pub async fn call_r5( &self, mut store: S, @@ -1044,17 +1096,20 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (u32,), - >::new_unchecked(self.r5) - }; + let callee = self.func_r5(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .await?; Ok(ret0) } + pub fn func_r6(&self) -> wasmtime::component::TypedFunc<(), (i32,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (i32,), + >::new_unchecked(self.r6) + } + } pub async fn call_r6( &self, mut store: S, @@ -1062,17 +1117,20 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (i32,), - >::new_unchecked(self.r6) - }; + let callee = self.func_r6(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .await?; Ok(ret0) } + pub fn func_r7(&self) -> wasmtime::component::TypedFunc<(), (u64,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (u64,), + >::new_unchecked(self.r7) + } + } pub async fn call_r7( &self, mut store: S, @@ -1080,17 +1138,20 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (u64,), - >::new_unchecked(self.r7) - }; + let callee = self.func_r7(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .await?; Ok(ret0) } + pub fn func_r8(&self) -> wasmtime::component::TypedFunc<(), (i64,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (i64,), + >::new_unchecked(self.r8) + } + } pub async fn call_r8( &self, mut store: S, @@ -1098,17 +1159,22 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (i64,), - >::new_unchecked(self.r8) - }; + let callee = self.func_r8(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .await?; Ok(ret0) } + pub fn func_pair_ret( + &self, + ) -> wasmtime::component::TypedFunc<(), ((i64, u8),)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + ((i64, u8),), + >::new_unchecked(self.pair_ret) + } + } pub async fn call_pair_ret( &self, mut store: S, @@ -1116,12 +1182,7 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - ((i64, u8),), - >::new_unchecked(self.pair_ret) - }; + let callee = self.func_pair_ret(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .await?; diff --git a/crates/component-macro/tests/expanded/integers_concurrent.rs b/crates/component-macro/tests/expanded/integers_concurrent.rs index f7b5d3b60529..986a418bd3bb 100644 --- a/crates/component-macro/tests/expanded/integers_concurrent.rs +++ b/crates/component-macro/tests/expanded/integers_concurrent.rs @@ -705,6 +705,14 @@ pub mod exports { } } impl Guest { + pub fn func_a1(&self) -> wasmtime::component::TypedFunc<(u8,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (u8,), + (), + >::new_unchecked(self.a1) + } + } pub async fn call_a1<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -714,15 +722,18 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (u8,), - (), - >::new_unchecked(self.a1) - }; + let callee = self.func_a1(); let () = callee.call_concurrent(accessor, (arg0,)).await?; Ok(()) } + pub fn func_a2(&self) -> wasmtime::component::TypedFunc<(i8,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (i8,), + (), + >::new_unchecked(self.a2) + } + } pub async fn call_a2<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -732,15 +743,18 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (i8,), - (), - >::new_unchecked(self.a2) - }; + let callee = self.func_a2(); let () = callee.call_concurrent(accessor, (arg0,)).await?; Ok(()) } + pub fn func_a3(&self) -> wasmtime::component::TypedFunc<(u16,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (u16,), + (), + >::new_unchecked(self.a3) + } + } pub async fn call_a3<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -750,15 +764,18 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (u16,), - (), - >::new_unchecked(self.a3) - }; + let callee = self.func_a3(); let () = callee.call_concurrent(accessor, (arg0,)).await?; Ok(()) } + pub fn func_a4(&self) -> wasmtime::component::TypedFunc<(i16,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (i16,), + (), + >::new_unchecked(self.a4) + } + } pub async fn call_a4<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -768,15 +785,18 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (i16,), - (), - >::new_unchecked(self.a4) - }; + let callee = self.func_a4(); let () = callee.call_concurrent(accessor, (arg0,)).await?; Ok(()) } + pub fn func_a5(&self) -> wasmtime::component::TypedFunc<(u32,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (u32,), + (), + >::new_unchecked(self.a5) + } + } pub async fn call_a5<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -786,15 +806,18 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (u32,), - (), - >::new_unchecked(self.a5) - }; + let callee = self.func_a5(); let () = callee.call_concurrent(accessor, (arg0,)).await?; Ok(()) } + pub fn func_a6(&self) -> wasmtime::component::TypedFunc<(i32,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (i32,), + (), + >::new_unchecked(self.a6) + } + } pub async fn call_a6<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -804,15 +827,18 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (i32,), - (), - >::new_unchecked(self.a6) - }; + let callee = self.func_a6(); let () = callee.call_concurrent(accessor, (arg0,)).await?; Ok(()) } + pub fn func_a7(&self) -> wasmtime::component::TypedFunc<(u64,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (u64,), + (), + >::new_unchecked(self.a7) + } + } pub async fn call_a7<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -822,15 +848,18 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (u64,), - (), - >::new_unchecked(self.a7) - }; + let callee = self.func_a7(); let () = callee.call_concurrent(accessor, (arg0,)).await?; Ok(()) } + pub fn func_a8(&self) -> wasmtime::component::TypedFunc<(i64,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (i64,), + (), + >::new_unchecked(self.a8) + } + } pub async fn call_a8<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -840,15 +869,23 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (i64,), - (), - >::new_unchecked(self.a8) - }; + let callee = self.func_a8(); let () = callee.call_concurrent(accessor, (arg0,)).await?; Ok(()) } + pub fn func_a9( + &self, + ) -> wasmtime::component::TypedFunc< + (u8, i8, u16, i16, u32, i32, u64, i64), + (), + > { + unsafe { + wasmtime::component::TypedFunc::< + (u8, i8, u16, i16, u32, i32, u64, i64), + (), + >::new_unchecked(self.a9) + } + } pub async fn call_a9<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -865,12 +902,7 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (u8, i8, u16, i16, u32, i32, u64, i64), - (), - >::new_unchecked(self.a9) - }; + let callee = self.func_a9(); let () = callee .call_concurrent( accessor, @@ -879,6 +911,14 @@ pub mod exports { .await?; Ok(()) } + pub fn func_r1(&self) -> wasmtime::component::TypedFunc<(), (u8,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (u8,), + >::new_unchecked(self.r1) + } + } pub async fn call_r1<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -887,15 +927,18 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (u8,), - >::new_unchecked(self.r1) - }; + let callee = self.func_r1(); let (ret0,) = callee.call_concurrent(accessor, ()).await?; Ok(ret0) } + pub fn func_r2(&self) -> wasmtime::component::TypedFunc<(), (i8,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (i8,), + >::new_unchecked(self.r2) + } + } pub async fn call_r2<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -904,15 +947,18 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (i8,), - >::new_unchecked(self.r2) - }; + let callee = self.func_r2(); let (ret0,) = callee.call_concurrent(accessor, ()).await?; Ok(ret0) } + pub fn func_r3(&self) -> wasmtime::component::TypedFunc<(), (u16,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (u16,), + >::new_unchecked(self.r3) + } + } pub async fn call_r3<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -921,15 +967,18 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (u16,), - >::new_unchecked(self.r3) - }; + let callee = self.func_r3(); let (ret0,) = callee.call_concurrent(accessor, ()).await?; Ok(ret0) } + pub fn func_r4(&self) -> wasmtime::component::TypedFunc<(), (i16,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (i16,), + >::new_unchecked(self.r4) + } + } pub async fn call_r4<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -938,15 +987,18 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (i16,), - >::new_unchecked(self.r4) - }; + let callee = self.func_r4(); let (ret0,) = callee.call_concurrent(accessor, ()).await?; Ok(ret0) } + pub fn func_r5(&self) -> wasmtime::component::TypedFunc<(), (u32,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (u32,), + >::new_unchecked(self.r5) + } + } pub async fn call_r5<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -955,15 +1007,18 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (u32,), - >::new_unchecked(self.r5) - }; + let callee = self.func_r5(); let (ret0,) = callee.call_concurrent(accessor, ()).await?; Ok(ret0) } + pub fn func_r6(&self) -> wasmtime::component::TypedFunc<(), (i32,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (i32,), + >::new_unchecked(self.r6) + } + } pub async fn call_r6<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -972,15 +1027,18 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (i32,), - >::new_unchecked(self.r6) - }; + let callee = self.func_r6(); let (ret0,) = callee.call_concurrent(accessor, ()).await?; Ok(ret0) } + pub fn func_r7(&self) -> wasmtime::component::TypedFunc<(), (u64,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (u64,), + >::new_unchecked(self.r7) + } + } pub async fn call_r7<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -989,15 +1047,18 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (u64,), - >::new_unchecked(self.r7) - }; + let callee = self.func_r7(); let (ret0,) = callee.call_concurrent(accessor, ()).await?; Ok(ret0) } + pub fn func_r8(&self) -> wasmtime::component::TypedFunc<(), (i64,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (i64,), + >::new_unchecked(self.r8) + } + } pub async fn call_r8<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -1006,15 +1067,20 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (i64,), - >::new_unchecked(self.r8) - }; + let callee = self.func_r8(); let (ret0,) = callee.call_concurrent(accessor, ()).await?; Ok(ret0) } + pub fn func_pair_ret( + &self, + ) -> wasmtime::component::TypedFunc<(), ((i64, u8),)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + ((i64, u8),), + >::new_unchecked(self.pair_ret) + } + } pub async fn call_pair_ret<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -1023,12 +1089,7 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - ((i64, u8),), - >::new_unchecked(self.pair_ret) - }; + let callee = self.func_pair_ret(); let (ret0,) = callee.call_concurrent(accessor, ()).await?; Ok(ret0) } diff --git a/crates/component-macro/tests/expanded/integers_tracing_async.rs b/crates/component-macro/tests/expanded/integers_tracing_async.rs index 69512271c104..c44be832cdda 100644 --- a/crates/component-macro/tests/expanded/integers_tracing_async.rs +++ b/crates/component-macro/tests/expanded/integers_tracing_async.rs @@ -1049,6 +1049,14 @@ pub mod exports { } } impl Guest { + pub fn func_a1(&self) -> wasmtime::component::TypedFunc<(u8,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (u8,), + (), + >::new_unchecked(self.a1) + } + } pub async fn call_a1( &self, mut store: S, @@ -1062,18 +1070,21 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/integers", function = "a1", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (u8,), - (), - >::new_unchecked(self.a1) - }; + let callee = self.func_a1(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .instrument(span.clone()) .await?; Ok(()) } + pub fn func_a2(&self) -> wasmtime::component::TypedFunc<(i8,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (i8,), + (), + >::new_unchecked(self.a2) + } + } pub async fn call_a2( &self, mut store: S, @@ -1087,18 +1098,21 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/integers", function = "a2", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (i8,), - (), - >::new_unchecked(self.a2) - }; + let callee = self.func_a2(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .instrument(span.clone()) .await?; Ok(()) } + pub fn func_a3(&self) -> wasmtime::component::TypedFunc<(u16,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (u16,), + (), + >::new_unchecked(self.a3) + } + } pub async fn call_a3( &self, mut store: S, @@ -1112,18 +1126,21 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/integers", function = "a3", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (u16,), - (), - >::new_unchecked(self.a3) - }; + let callee = self.func_a3(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .instrument(span.clone()) .await?; Ok(()) } + pub fn func_a4(&self) -> wasmtime::component::TypedFunc<(i16,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (i16,), + (), + >::new_unchecked(self.a4) + } + } pub async fn call_a4( &self, mut store: S, @@ -1137,18 +1154,21 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/integers", function = "a4", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (i16,), - (), - >::new_unchecked(self.a4) - }; + let callee = self.func_a4(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .instrument(span.clone()) .await?; Ok(()) } + pub fn func_a5(&self) -> wasmtime::component::TypedFunc<(u32,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (u32,), + (), + >::new_unchecked(self.a5) + } + } pub async fn call_a5( &self, mut store: S, @@ -1162,18 +1182,21 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/integers", function = "a5", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (u32,), - (), - >::new_unchecked(self.a5) - }; + let callee = self.func_a5(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .instrument(span.clone()) .await?; Ok(()) } + pub fn func_a6(&self) -> wasmtime::component::TypedFunc<(i32,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (i32,), + (), + >::new_unchecked(self.a6) + } + } pub async fn call_a6( &self, mut store: S, @@ -1187,18 +1210,21 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/integers", function = "a6", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (i32,), - (), - >::new_unchecked(self.a6) - }; + let callee = self.func_a6(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .instrument(span.clone()) .await?; Ok(()) } + pub fn func_a7(&self) -> wasmtime::component::TypedFunc<(u64,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (u64,), + (), + >::new_unchecked(self.a7) + } + } pub async fn call_a7( &self, mut store: S, @@ -1212,18 +1238,21 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/integers", function = "a7", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (u64,), - (), - >::new_unchecked(self.a7) - }; + let callee = self.func_a7(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .instrument(span.clone()) .await?; Ok(()) } + pub fn func_a8(&self) -> wasmtime::component::TypedFunc<(i64,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (i64,), + (), + >::new_unchecked(self.a8) + } + } pub async fn call_a8( &self, mut store: S, @@ -1237,18 +1266,26 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/integers", function = "a8", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (i64,), - (), - >::new_unchecked(self.a8) - }; + let callee = self.func_a8(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .instrument(span.clone()) .await?; Ok(()) } + pub fn func_a9( + &self, + ) -> wasmtime::component::TypedFunc< + (u8, i8, u16, i16, u32, i32, u64, i64), + (), + > { + unsafe { + wasmtime::component::TypedFunc::< + (u8, i8, u16, i16, u32, i32, u64, i64), + (), + >::new_unchecked(self.a9) + } + } pub async fn call_a9( &self, mut store: S, @@ -1269,12 +1306,7 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/integers", function = "a9", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (u8, i8, u16, i16, u32, i32, u64, i64), - (), - >::new_unchecked(self.a9) - }; + let callee = self.func_a9(); let () = callee .call_async( store.as_context_mut(), @@ -1284,6 +1316,14 @@ pub mod exports { .await?; Ok(()) } + pub fn func_r1(&self) -> wasmtime::component::TypedFunc<(), (u8,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (u8,), + >::new_unchecked(self.r1) + } + } pub async fn call_r1( &self, mut store: S, @@ -1296,18 +1336,21 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/integers", function = "r1", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (u8,), - >::new_unchecked(self.r1) - }; + let callee = self.func_r1(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) .await?; Ok(ret0) } + pub fn func_r2(&self) -> wasmtime::component::TypedFunc<(), (i8,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (i8,), + >::new_unchecked(self.r2) + } + } pub async fn call_r2( &self, mut store: S, @@ -1320,18 +1363,21 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/integers", function = "r2", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (i8,), - >::new_unchecked(self.r2) - }; + let callee = self.func_r2(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) .await?; Ok(ret0) } + pub fn func_r3(&self) -> wasmtime::component::TypedFunc<(), (u16,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (u16,), + >::new_unchecked(self.r3) + } + } pub async fn call_r3( &self, mut store: S, @@ -1344,18 +1390,21 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/integers", function = "r3", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (u16,), - >::new_unchecked(self.r3) - }; + let callee = self.func_r3(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) .await?; Ok(ret0) } + pub fn func_r4(&self) -> wasmtime::component::TypedFunc<(), (i16,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (i16,), + >::new_unchecked(self.r4) + } + } pub async fn call_r4( &self, mut store: S, @@ -1368,18 +1417,21 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/integers", function = "r4", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (i16,), - >::new_unchecked(self.r4) - }; + let callee = self.func_r4(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) .await?; Ok(ret0) } + pub fn func_r5(&self) -> wasmtime::component::TypedFunc<(), (u32,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (u32,), + >::new_unchecked(self.r5) + } + } pub async fn call_r5( &self, mut store: S, @@ -1392,18 +1444,21 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/integers", function = "r5", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (u32,), - >::new_unchecked(self.r5) - }; + let callee = self.func_r5(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) .await?; Ok(ret0) } + pub fn func_r6(&self) -> wasmtime::component::TypedFunc<(), (i32,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (i32,), + >::new_unchecked(self.r6) + } + } pub async fn call_r6( &self, mut store: S, @@ -1416,18 +1471,21 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/integers", function = "r6", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (i32,), - >::new_unchecked(self.r6) - }; + let callee = self.func_r6(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) .await?; Ok(ret0) } + pub fn func_r7(&self) -> wasmtime::component::TypedFunc<(), (u64,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (u64,), + >::new_unchecked(self.r7) + } + } pub async fn call_r7( &self, mut store: S, @@ -1440,18 +1498,21 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/integers", function = "r7", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (u64,), - >::new_unchecked(self.r7) - }; + let callee = self.func_r7(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) .await?; Ok(ret0) } + pub fn func_r8(&self) -> wasmtime::component::TypedFunc<(), (i64,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (i64,), + >::new_unchecked(self.r8) + } + } pub async fn call_r8( &self, mut store: S, @@ -1464,18 +1525,23 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/integers", function = "r8", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (i64,), - >::new_unchecked(self.r8) - }; + let callee = self.func_r8(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) .await?; Ok(ret0) } + pub fn func_pair_ret( + &self, + ) -> wasmtime::component::TypedFunc<(), ((i64, u8),)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + ((i64, u8),), + >::new_unchecked(self.pair_ret) + } + } pub async fn call_pair_ret( &self, mut store: S, @@ -1488,12 +1554,7 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/integers", function = "pair-ret", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - ((i64, u8),), - >::new_unchecked(self.pair_ret) - }; + let callee = self.func_pair_ret(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) diff --git a/crates/component-macro/tests/expanded/lists.rs b/crates/component-macro/tests/expanded/lists.rs index e17e62e3a568..e000db2f5330 100644 --- a/crates/component-macro/tests/expanded/lists.rs +++ b/crates/component-macro/tests/expanded/lists.rs @@ -1552,276 +1552,419 @@ pub mod exports { } } impl Guest { - pub fn call_list_u8_param( + pub fn func_list_u8_param( &self, - mut store: S, - arg0: &[u8], - ) -> wasmtime::Result<()> { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc<(&[u8],), ()> { + unsafe { wasmtime::component::TypedFunc::< (&[u8],), (), >::new_unchecked(self.list_u8_param) - }; - let () = callee.call(store.as_context_mut(), (arg0,))?; - Ok(()) + } } - pub fn call_list_u16_param( + pub fn call_list_u8_param( &self, mut store: S, - arg0: &[u16], + arg0: &[u8], ) -> wasmtime::Result<()> { - let callee = unsafe { + let callee = self.func_list_u8_param(); + let () = callee.call(store.as_context_mut(), (arg0,))?; + Ok(()) + } + pub fn func_list_u16_param( + &self, + ) -> wasmtime::component::TypedFunc<(&[u16],), ()> { + unsafe { wasmtime::component::TypedFunc::< (&[u16],), (), >::new_unchecked(self.list_u16_param) - }; - let () = callee.call(store.as_context_mut(), (arg0,))?; - Ok(()) + } } - pub fn call_list_u32_param( + pub fn call_list_u16_param( &self, mut store: S, - arg0: &[u32], + arg0: &[u16], ) -> wasmtime::Result<()> { - let callee = unsafe { + let callee = self.func_list_u16_param(); + let () = callee.call(store.as_context_mut(), (arg0,))?; + Ok(()) + } + pub fn func_list_u32_param( + &self, + ) -> wasmtime::component::TypedFunc<(&[u32],), ()> { + unsafe { wasmtime::component::TypedFunc::< (&[u32],), (), >::new_unchecked(self.list_u32_param) - }; - let () = callee.call(store.as_context_mut(), (arg0,))?; - Ok(()) + } } - pub fn call_list_u64_param( + pub fn call_list_u32_param( &self, mut store: S, - arg0: &[u64], + arg0: &[u32], ) -> wasmtime::Result<()> { - let callee = unsafe { + let callee = self.func_list_u32_param(); + let () = callee.call(store.as_context_mut(), (arg0,))?; + Ok(()) + } + pub fn func_list_u64_param( + &self, + ) -> wasmtime::component::TypedFunc<(&[u64],), ()> { + unsafe { wasmtime::component::TypedFunc::< (&[u64],), (), >::new_unchecked(self.list_u64_param) - }; - let () = callee.call(store.as_context_mut(), (arg0,))?; - Ok(()) + } } - pub fn call_list_s8_param( + pub fn call_list_u64_param( &self, mut store: S, - arg0: &[i8], + arg0: &[u64], ) -> wasmtime::Result<()> { - let callee = unsafe { + let callee = self.func_list_u64_param(); + let () = callee.call(store.as_context_mut(), (arg0,))?; + Ok(()) + } + pub fn func_list_s8_param( + &self, + ) -> wasmtime::component::TypedFunc<(&[i8],), ()> { + unsafe { wasmtime::component::TypedFunc::< (&[i8],), (), >::new_unchecked(self.list_s8_param) - }; - let () = callee.call(store.as_context_mut(), (arg0,))?; - Ok(()) + } } - pub fn call_list_s16_param( + pub fn call_list_s8_param( &self, mut store: S, - arg0: &[i16], + arg0: &[i8], ) -> wasmtime::Result<()> { - let callee = unsafe { + let callee = self.func_list_s8_param(); + let () = callee.call(store.as_context_mut(), (arg0,))?; + Ok(()) + } + pub fn func_list_s16_param( + &self, + ) -> wasmtime::component::TypedFunc<(&[i16],), ()> { + unsafe { wasmtime::component::TypedFunc::< (&[i16],), (), >::new_unchecked(self.list_s16_param) - }; - let () = callee.call(store.as_context_mut(), (arg0,))?; - Ok(()) + } } - pub fn call_list_s32_param( + pub fn call_list_s16_param( &self, mut store: S, - arg0: &[i32], + arg0: &[i16], ) -> wasmtime::Result<()> { - let callee = unsafe { + let callee = self.func_list_s16_param(); + let () = callee.call(store.as_context_mut(), (arg0,))?; + Ok(()) + } + pub fn func_list_s32_param( + &self, + ) -> wasmtime::component::TypedFunc<(&[i32],), ()> { + unsafe { wasmtime::component::TypedFunc::< (&[i32],), (), >::new_unchecked(self.list_s32_param) - }; - let () = callee.call(store.as_context_mut(), (arg0,))?; - Ok(()) + } } - pub fn call_list_s64_param( + pub fn call_list_s32_param( &self, mut store: S, - arg0: &[i64], + arg0: &[i32], ) -> wasmtime::Result<()> { - let callee = unsafe { + let callee = self.func_list_s32_param(); + let () = callee.call(store.as_context_mut(), (arg0,))?; + Ok(()) + } + pub fn func_list_s64_param( + &self, + ) -> wasmtime::component::TypedFunc<(&[i64],), ()> { + unsafe { wasmtime::component::TypedFunc::< (&[i64],), (), >::new_unchecked(self.list_s64_param) - }; - let () = callee.call(store.as_context_mut(), (arg0,))?; - Ok(()) + } } - pub fn call_list_f32_param( + pub fn call_list_s64_param( &self, mut store: S, - arg0: &[f32], + arg0: &[i64], ) -> wasmtime::Result<()> { - let callee = unsafe { + let callee = self.func_list_s64_param(); + let () = callee.call(store.as_context_mut(), (arg0,))?; + Ok(()) + } + pub fn func_list_f32_param( + &self, + ) -> wasmtime::component::TypedFunc<(&[f32],), ()> { + unsafe { wasmtime::component::TypedFunc::< (&[f32],), (), >::new_unchecked(self.list_f32_param) - }; - let () = callee.call(store.as_context_mut(), (arg0,))?; - Ok(()) + } } - pub fn call_list_f64_param( + pub fn call_list_f32_param( &self, mut store: S, - arg0: &[f64], + arg0: &[f32], ) -> wasmtime::Result<()> { - let callee = unsafe { + let callee = self.func_list_f32_param(); + let () = callee.call(store.as_context_mut(), (arg0,))?; + Ok(()) + } + pub fn func_list_f64_param( + &self, + ) -> wasmtime::component::TypedFunc<(&[f64],), ()> { + unsafe { wasmtime::component::TypedFunc::< (&[f64],), (), >::new_unchecked(self.list_f64_param) - }; + } + } + pub fn call_list_f64_param( + &self, + mut store: S, + arg0: &[f64], + ) -> wasmtime::Result<()> { + let callee = self.func_list_f64_param(); let () = callee.call(store.as_context_mut(), (arg0,))?; Ok(()) } - pub fn call_list_u8_ret( + pub fn func_list_u8_ret( &self, - mut store: S, - ) -> wasmtime::Result> { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::__internal::Vec,), + > { + unsafe { wasmtime::component::TypedFunc::< (), (wasmtime::component::__internal::Vec,), >::new_unchecked(self.list_u8_ret) - }; + } + } + pub fn call_list_u8_ret( + &self, + mut store: S, + ) -> wasmtime::Result> { + let callee = self.func_list_u8_ret(); let (ret0,) = callee.call(store.as_context_mut(), ())?; Ok(ret0) } - pub fn call_list_u16_ret( + pub fn func_list_u16_ret( &self, - mut store: S, - ) -> wasmtime::Result> { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::__internal::Vec,), + > { + unsafe { wasmtime::component::TypedFunc::< (), (wasmtime::component::__internal::Vec,), >::new_unchecked(self.list_u16_ret) - }; + } + } + pub fn call_list_u16_ret( + &self, + mut store: S, + ) -> wasmtime::Result> { + let callee = self.func_list_u16_ret(); let (ret0,) = callee.call(store.as_context_mut(), ())?; Ok(ret0) } - pub fn call_list_u32_ret( + pub fn func_list_u32_ret( &self, - mut store: S, - ) -> wasmtime::Result> { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::__internal::Vec,), + > { + unsafe { wasmtime::component::TypedFunc::< (), (wasmtime::component::__internal::Vec,), >::new_unchecked(self.list_u32_ret) - }; + } + } + pub fn call_list_u32_ret( + &self, + mut store: S, + ) -> wasmtime::Result> { + let callee = self.func_list_u32_ret(); let (ret0,) = callee.call(store.as_context_mut(), ())?; Ok(ret0) } - pub fn call_list_u64_ret( + pub fn func_list_u64_ret( &self, - mut store: S, - ) -> wasmtime::Result> { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::__internal::Vec,), + > { + unsafe { wasmtime::component::TypedFunc::< (), (wasmtime::component::__internal::Vec,), >::new_unchecked(self.list_u64_ret) - }; + } + } + pub fn call_list_u64_ret( + &self, + mut store: S, + ) -> wasmtime::Result> { + let callee = self.func_list_u64_ret(); let (ret0,) = callee.call(store.as_context_mut(), ())?; Ok(ret0) } - pub fn call_list_s8_ret( + pub fn func_list_s8_ret( &self, - mut store: S, - ) -> wasmtime::Result> { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::__internal::Vec,), + > { + unsafe { wasmtime::component::TypedFunc::< (), (wasmtime::component::__internal::Vec,), >::new_unchecked(self.list_s8_ret) - }; + } + } + pub fn call_list_s8_ret( + &self, + mut store: S, + ) -> wasmtime::Result> { + let callee = self.func_list_s8_ret(); let (ret0,) = callee.call(store.as_context_mut(), ())?; Ok(ret0) } - pub fn call_list_s16_ret( + pub fn func_list_s16_ret( &self, - mut store: S, - ) -> wasmtime::Result> { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::__internal::Vec,), + > { + unsafe { wasmtime::component::TypedFunc::< (), (wasmtime::component::__internal::Vec,), >::new_unchecked(self.list_s16_ret) - }; + } + } + pub fn call_list_s16_ret( + &self, + mut store: S, + ) -> wasmtime::Result> { + let callee = self.func_list_s16_ret(); let (ret0,) = callee.call(store.as_context_mut(), ())?; Ok(ret0) } - pub fn call_list_s32_ret( + pub fn func_list_s32_ret( &self, - mut store: S, - ) -> wasmtime::Result> { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::__internal::Vec,), + > { + unsafe { wasmtime::component::TypedFunc::< (), (wasmtime::component::__internal::Vec,), >::new_unchecked(self.list_s32_ret) - }; + } + } + pub fn call_list_s32_ret( + &self, + mut store: S, + ) -> wasmtime::Result> { + let callee = self.func_list_s32_ret(); let (ret0,) = callee.call(store.as_context_mut(), ())?; Ok(ret0) } - pub fn call_list_s64_ret( + pub fn func_list_s64_ret( &self, - mut store: S, - ) -> wasmtime::Result> { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::__internal::Vec,), + > { + unsafe { wasmtime::component::TypedFunc::< (), (wasmtime::component::__internal::Vec,), >::new_unchecked(self.list_s64_ret) - }; + } + } + pub fn call_list_s64_ret( + &self, + mut store: S, + ) -> wasmtime::Result> { + let callee = self.func_list_s64_ret(); let (ret0,) = callee.call(store.as_context_mut(), ())?; Ok(ret0) } - pub fn call_list_f32_ret( + pub fn func_list_f32_ret( &self, - mut store: S, - ) -> wasmtime::Result> { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::__internal::Vec,), + > { + unsafe { wasmtime::component::TypedFunc::< (), (wasmtime::component::__internal::Vec,), >::new_unchecked(self.list_f32_ret) - }; + } + } + pub fn call_list_f32_ret( + &self, + mut store: S, + ) -> wasmtime::Result> { + let callee = self.func_list_f32_ret(); let (ret0,) = callee.call(store.as_context_mut(), ())?; Ok(ret0) } - pub fn call_list_f64_ret( + pub fn func_list_f64_ret( &self, - mut store: S, - ) -> wasmtime::Result> { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::__internal::Vec,), + > { + unsafe { wasmtime::component::TypedFunc::< (), (wasmtime::component::__internal::Vec,), >::new_unchecked(self.list_f64_ret) - }; + } + } + pub fn call_list_f64_ret( + &self, + mut store: S, + ) -> wasmtime::Result> { + let callee = self.func_list_f64_ret(); let (ret0,) = callee.call(store.as_context_mut(), ())?; Ok(ret0) } + pub fn func_tuple_list( + &self, + ) -> wasmtime::component::TypedFunc< + (&[(u8, i8)],), + (wasmtime::component::__internal::Vec<(i64, u32)>,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (&[(u8, i8)],), + (wasmtime::component::__internal::Vec<(i64, u32)>,), + >::new_unchecked(self.tuple_list) + } + } pub fn call_tuple_list( &self, mut store: S, @@ -1829,38 +1972,43 @@ pub mod exports { ) -> wasmtime::Result< wasmtime::component::__internal::Vec<(i64, u32)>, > { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (&[(u8, i8)],), - (wasmtime::component::__internal::Vec<(i64, u32)>,), - >::new_unchecked(self.tuple_list) - }; + let callee = self.func_tuple_list(); let (ret0,) = callee.call(store.as_context_mut(), (arg0,))?; Ok(ret0) } - pub fn call_string_list_arg( + pub fn func_string_list_arg( &self, - mut store: S, - arg0: &[wasmtime::component::__internal::String], - ) -> wasmtime::Result<()> { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc< + (&[wasmtime::component::__internal::String],), + (), + > { + unsafe { wasmtime::component::TypedFunc::< (&[wasmtime::component::__internal::String],), (), >::new_unchecked(self.string_list_arg) - }; + } + } + pub fn call_string_list_arg( + &self, + mut store: S, + arg0: &[wasmtime::component::__internal::String], + ) -> wasmtime::Result<()> { + let callee = self.func_string_list_arg(); let () = callee.call(store.as_context_mut(), (arg0,))?; Ok(()) } - pub fn call_string_list_ret( + pub fn func_string_list_ret( &self, - mut store: S, - ) -> wasmtime::Result< - wasmtime::component::__internal::Vec< - wasmtime::component::__internal::String, - >, + ) -> wasmtime::component::TypedFunc< + (), + ( + wasmtime::component::__internal::Vec< + wasmtime::component::__internal::String, + >, + ), > { - let callee = unsafe { + unsafe { wasmtime::component::TypedFunc::< (), ( @@ -1869,20 +2017,31 @@ pub mod exports { >, ), >::new_unchecked(self.string_list_ret) - }; - let (ret0,) = callee.call(store.as_context_mut(), ())?; - Ok(ret0) + } } - pub fn call_tuple_string_list( + pub fn call_string_list_ret( &self, mut store: S, - arg0: &[(u8, wasmtime::component::__internal::String)], ) -> wasmtime::Result< wasmtime::component::__internal::Vec< - (wasmtime::component::__internal::String, u8), + wasmtime::component::__internal::String, >, > { - let callee = unsafe { + let callee = self.func_string_list_ret(); + let (ret0,) = callee.call(store.as_context_mut(), ())?; + Ok(ret0) + } + pub fn func_tuple_string_list( + &self, + ) -> wasmtime::component::TypedFunc< + (&[(u8, wasmtime::component::__internal::String)],), + ( + wasmtime::component::__internal::Vec< + (wasmtime::component::__internal::String, u8), + >, + ), + > { + unsafe { wasmtime::component::TypedFunc::< (&[(u8, wasmtime::component::__internal::String)],), ( @@ -1891,20 +2050,32 @@ pub mod exports { >, ), >::new_unchecked(self.tuple_string_list) - }; - let (ret0,) = callee.call(store.as_context_mut(), (arg0,))?; - Ok(ret0) + } } - pub fn call_string_list( + pub fn call_tuple_string_list( &self, mut store: S, - arg0: &[wasmtime::component::__internal::String], + arg0: &[(u8, wasmtime::component::__internal::String)], ) -> wasmtime::Result< wasmtime::component::__internal::Vec< - wasmtime::component::__internal::String, + (wasmtime::component::__internal::String, u8), >, > { - let callee = unsafe { + let callee = self.func_tuple_string_list(); + let (ret0,) = callee.call(store.as_context_mut(), (arg0,))?; + Ok(ret0) + } + pub fn func_string_list( + &self, + ) -> wasmtime::component::TypedFunc< + (&[wasmtime::component::__internal::String],), + ( + wasmtime::component::__internal::Vec< + wasmtime::component::__internal::String, + >, + ), + > { + unsafe { wasmtime::component::TypedFunc::< (&[wasmtime::component::__internal::String],), ( @@ -1913,10 +2084,34 @@ pub mod exports { >, ), >::new_unchecked(self.string_list) - }; + } + } + pub fn call_string_list( + &self, + mut store: S, + arg0: &[wasmtime::component::__internal::String], + ) -> wasmtime::Result< + wasmtime::component::__internal::Vec< + wasmtime::component::__internal::String, + >, + > { + let callee = self.func_string_list(); let (ret0,) = callee.call(store.as_context_mut(), (arg0,))?; Ok(ret0) } + pub fn func_record_list( + &self, + ) -> wasmtime::component::TypedFunc< + (&[SomeRecord],), + (wasmtime::component::__internal::Vec,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (&[SomeRecord],), + (wasmtime::component::__internal::Vec,), + >::new_unchecked(self.record_list) + } + } pub fn call_record_list( &self, mut store: S, @@ -1924,15 +2119,23 @@ pub mod exports { ) -> wasmtime::Result< wasmtime::component::__internal::Vec, > { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (&[SomeRecord],), - (wasmtime::component::__internal::Vec,), - >::new_unchecked(self.record_list) - }; + let callee = self.func_record_list(); let (ret0,) = callee.call(store.as_context_mut(), (arg0,))?; Ok(ret0) } + pub fn func_record_list_reverse( + &self, + ) -> wasmtime::component::TypedFunc< + (&[OtherRecord],), + (wasmtime::component::__internal::Vec,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (&[OtherRecord],), + (wasmtime::component::__internal::Vec,), + >::new_unchecked(self.record_list_reverse) + } + } pub fn call_record_list_reverse( &self, mut store: S, @@ -1940,15 +2143,23 @@ pub mod exports { ) -> wasmtime::Result< wasmtime::component::__internal::Vec, > { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (&[OtherRecord],), - (wasmtime::component::__internal::Vec,), - >::new_unchecked(self.record_list_reverse) - }; + let callee = self.func_record_list_reverse(); let (ret0,) = callee.call(store.as_context_mut(), (arg0,))?; Ok(ret0) } + pub fn func_variant_list( + &self, + ) -> wasmtime::component::TypedFunc< + (&[SomeVariant],), + (wasmtime::component::__internal::Vec,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (&[SomeVariant],), + (wasmtime::component::__internal::Vec,), + >::new_unchecked(self.variant_list) + } + } pub fn call_variant_list( &self, mut store: S, @@ -1956,26 +2167,29 @@ pub mod exports { ) -> wasmtime::Result< wasmtime::component::__internal::Vec, > { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (&[SomeVariant],), - (wasmtime::component::__internal::Vec,), - >::new_unchecked(self.variant_list) - }; + let callee = self.func_variant_list(); let (ret0,) = callee.call(store.as_context_mut(), (arg0,))?; Ok(ret0) } - pub fn call_load_store_everything( + pub fn func_load_store_everything( &self, - mut store: S, - arg0: &LoadStoreAllSizes, - ) -> wasmtime::Result { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc< + (&LoadStoreAllSizes,), + (LoadStoreAllSizes,), + > { + unsafe { wasmtime::component::TypedFunc::< (&LoadStoreAllSizes,), (LoadStoreAllSizes,), >::new_unchecked(self.load_store_everything) - }; + } + } + pub fn call_load_store_everything( + &self, + mut store: S, + arg0: &LoadStoreAllSizes, + ) -> wasmtime::Result { + let callee = self.func_load_store_everything(); let (ret0,) = callee.call(store.as_context_mut(), (arg0,))?; Ok(ret0) } diff --git a/crates/component-macro/tests/expanded/lists_async.rs b/crates/component-macro/tests/expanded/lists_async.rs index b2ef873a2b99..214c5e37509d 100644 --- a/crates/component-macro/tests/expanded/lists_async.rs +++ b/crates/component-macro/tests/expanded/lists_async.rs @@ -1718,6 +1718,16 @@ pub mod exports { } } impl Guest { + pub fn func_list_u8_param( + &self, + ) -> wasmtime::component::TypedFunc<(&[u8],), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (&[u8],), + (), + >::new_unchecked(self.list_u8_param) + } + } pub async fn call_list_u8_param( &self, mut store: S, @@ -1726,17 +1736,22 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (&[u8],), - (), - >::new_unchecked(self.list_u8_param) - }; + let callee = self.func_list_u8_param(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .await?; Ok(()) } + pub fn func_list_u16_param( + &self, + ) -> wasmtime::component::TypedFunc<(&[u16],), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (&[u16],), + (), + >::new_unchecked(self.list_u16_param) + } + } pub async fn call_list_u16_param( &self, mut store: S, @@ -1745,17 +1760,22 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (&[u16],), - (), - >::new_unchecked(self.list_u16_param) - }; + let callee = self.func_list_u16_param(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .await?; Ok(()) } + pub fn func_list_u32_param( + &self, + ) -> wasmtime::component::TypedFunc<(&[u32],), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (&[u32],), + (), + >::new_unchecked(self.list_u32_param) + } + } pub async fn call_list_u32_param( &self, mut store: S, @@ -1764,17 +1784,22 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (&[u32],), - (), - >::new_unchecked(self.list_u32_param) - }; + let callee = self.func_list_u32_param(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .await?; Ok(()) } + pub fn func_list_u64_param( + &self, + ) -> wasmtime::component::TypedFunc<(&[u64],), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (&[u64],), + (), + >::new_unchecked(self.list_u64_param) + } + } pub async fn call_list_u64_param( &self, mut store: S, @@ -1783,17 +1808,22 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (&[u64],), - (), - >::new_unchecked(self.list_u64_param) - }; + let callee = self.func_list_u64_param(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .await?; Ok(()) } + pub fn func_list_s8_param( + &self, + ) -> wasmtime::component::TypedFunc<(&[i8],), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (&[i8],), + (), + >::new_unchecked(self.list_s8_param) + } + } pub async fn call_list_s8_param( &self, mut store: S, @@ -1802,17 +1832,22 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (&[i8],), - (), - >::new_unchecked(self.list_s8_param) - }; + let callee = self.func_list_s8_param(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .await?; Ok(()) } + pub fn func_list_s16_param( + &self, + ) -> wasmtime::component::TypedFunc<(&[i16],), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (&[i16],), + (), + >::new_unchecked(self.list_s16_param) + } + } pub async fn call_list_s16_param( &self, mut store: S, @@ -1821,17 +1856,22 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (&[i16],), - (), - >::new_unchecked(self.list_s16_param) - }; + let callee = self.func_list_s16_param(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .await?; Ok(()) } + pub fn func_list_s32_param( + &self, + ) -> wasmtime::component::TypedFunc<(&[i32],), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (&[i32],), + (), + >::new_unchecked(self.list_s32_param) + } + } pub async fn call_list_s32_param( &self, mut store: S, @@ -1840,17 +1880,22 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (&[i32],), - (), - >::new_unchecked(self.list_s32_param) - }; + let callee = self.func_list_s32_param(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .await?; Ok(()) } + pub fn func_list_s64_param( + &self, + ) -> wasmtime::component::TypedFunc<(&[i64],), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (&[i64],), + (), + >::new_unchecked(self.list_s64_param) + } + } pub async fn call_list_s64_param( &self, mut store: S, @@ -1859,17 +1904,22 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (&[i64],), - (), - >::new_unchecked(self.list_s64_param) - }; + let callee = self.func_list_s64_param(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .await?; Ok(()) } + pub fn func_list_f32_param( + &self, + ) -> wasmtime::component::TypedFunc<(&[f32],), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (&[f32],), + (), + >::new_unchecked(self.list_f32_param) + } + } pub async fn call_list_f32_param( &self, mut store: S, @@ -1878,17 +1928,22 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (&[f32],), - (), - >::new_unchecked(self.list_f32_param) - }; + let callee = self.func_list_f32_param(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .await?; Ok(()) } + pub fn func_list_f64_param( + &self, + ) -> wasmtime::component::TypedFunc<(&[f64],), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (&[f64],), + (), + >::new_unchecked(self.list_f64_param) + } + } pub async fn call_list_f64_param( &self, mut store: S, @@ -1897,17 +1952,25 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (&[f64],), - (), - >::new_unchecked(self.list_f64_param) - }; + let callee = self.func_list_f64_param(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .await?; Ok(()) } + pub fn func_list_u8_ret( + &self, + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::__internal::Vec,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (), + (wasmtime::component::__internal::Vec,), + >::new_unchecked(self.list_u8_ret) + } + } pub async fn call_list_u8_ret( &self, mut store: S, @@ -1915,17 +1978,25 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (wasmtime::component::__internal::Vec,), - >::new_unchecked(self.list_u8_ret) - }; + let callee = self.func_list_u8_ret(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .await?; Ok(ret0) } + pub fn func_list_u16_ret( + &self, + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::__internal::Vec,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (), + (wasmtime::component::__internal::Vec,), + >::new_unchecked(self.list_u16_ret) + } + } pub async fn call_list_u16_ret( &self, mut store: S, @@ -1933,17 +2004,25 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (wasmtime::component::__internal::Vec,), - >::new_unchecked(self.list_u16_ret) - }; + let callee = self.func_list_u16_ret(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .await?; Ok(ret0) } + pub fn func_list_u32_ret( + &self, + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::__internal::Vec,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (), + (wasmtime::component::__internal::Vec,), + >::new_unchecked(self.list_u32_ret) + } + } pub async fn call_list_u32_ret( &self, mut store: S, @@ -1951,17 +2030,25 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (wasmtime::component::__internal::Vec,), - >::new_unchecked(self.list_u32_ret) - }; + let callee = self.func_list_u32_ret(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .await?; Ok(ret0) } + pub fn func_list_u64_ret( + &self, + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::__internal::Vec,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (), + (wasmtime::component::__internal::Vec,), + >::new_unchecked(self.list_u64_ret) + } + } pub async fn call_list_u64_ret( &self, mut store: S, @@ -1969,17 +2056,25 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (wasmtime::component::__internal::Vec,), - >::new_unchecked(self.list_u64_ret) - }; + let callee = self.func_list_u64_ret(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .await?; Ok(ret0) } + pub fn func_list_s8_ret( + &self, + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::__internal::Vec,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (), + (wasmtime::component::__internal::Vec,), + >::new_unchecked(self.list_s8_ret) + } + } pub async fn call_list_s8_ret( &self, mut store: S, @@ -1987,17 +2082,25 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (wasmtime::component::__internal::Vec,), - >::new_unchecked(self.list_s8_ret) - }; + let callee = self.func_list_s8_ret(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .await?; Ok(ret0) } + pub fn func_list_s16_ret( + &self, + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::__internal::Vec,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (), + (wasmtime::component::__internal::Vec,), + >::new_unchecked(self.list_s16_ret) + } + } pub async fn call_list_s16_ret( &self, mut store: S, @@ -2005,17 +2108,25 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (wasmtime::component::__internal::Vec,), - >::new_unchecked(self.list_s16_ret) - }; + let callee = self.func_list_s16_ret(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .await?; Ok(ret0) } + pub fn func_list_s32_ret( + &self, + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::__internal::Vec,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (), + (wasmtime::component::__internal::Vec,), + >::new_unchecked(self.list_s32_ret) + } + } pub async fn call_list_s32_ret( &self, mut store: S, @@ -2023,17 +2134,25 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (wasmtime::component::__internal::Vec,), - >::new_unchecked(self.list_s32_ret) - }; + let callee = self.func_list_s32_ret(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .await?; Ok(ret0) } + pub fn func_list_s64_ret( + &self, + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::__internal::Vec,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (), + (wasmtime::component::__internal::Vec,), + >::new_unchecked(self.list_s64_ret) + } + } pub async fn call_list_s64_ret( &self, mut store: S, @@ -2041,17 +2160,25 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (wasmtime::component::__internal::Vec,), - >::new_unchecked(self.list_s64_ret) - }; + let callee = self.func_list_s64_ret(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .await?; Ok(ret0) } + pub fn func_list_f32_ret( + &self, + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::__internal::Vec,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (), + (wasmtime::component::__internal::Vec,), + >::new_unchecked(self.list_f32_ret) + } + } pub async fn call_list_f32_ret( &self, mut store: S, @@ -2059,17 +2186,25 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (wasmtime::component::__internal::Vec,), - >::new_unchecked(self.list_f32_ret) - }; + let callee = self.func_list_f32_ret(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .await?; Ok(ret0) } + pub fn func_list_f64_ret( + &self, + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::__internal::Vec,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (), + (wasmtime::component::__internal::Vec,), + >::new_unchecked(self.list_f64_ret) + } + } pub async fn call_list_f64_ret( &self, mut store: S, @@ -2077,17 +2212,25 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (wasmtime::component::__internal::Vec,), - >::new_unchecked(self.list_f64_ret) - }; + let callee = self.func_list_f64_ret(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .await?; Ok(ret0) } + pub fn func_tuple_list( + &self, + ) -> wasmtime::component::TypedFunc< + (&[(u8, i8)],), + (wasmtime::component::__internal::Vec<(i64, u32)>,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (&[(u8, i8)],), + (wasmtime::component::__internal::Vec<(i64, u32)>,), + >::new_unchecked(self.tuple_list) + } + } pub async fn call_tuple_list( &self, mut store: S, @@ -2098,17 +2241,25 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (&[(u8, i8)],), - (wasmtime::component::__internal::Vec<(i64, u32)>,), - >::new_unchecked(self.tuple_list) - }; + let callee = self.func_tuple_list(); let (ret0,) = callee .call_async(store.as_context_mut(), (arg0,)) .await?; Ok(ret0) } + pub fn func_string_list_arg( + &self, + ) -> wasmtime::component::TypedFunc< + (&[wasmtime::component::__internal::String],), + (), + > { + unsafe { + wasmtime::component::TypedFunc::< + (&[wasmtime::component::__internal::String],), + (), + >::new_unchecked(self.string_list_arg) + } + } pub async fn call_string_list_arg( &self, mut store: S, @@ -2117,17 +2268,33 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (&[wasmtime::component::__internal::String],), - (), - >::new_unchecked(self.string_list_arg) - }; + let callee = self.func_string_list_arg(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .await?; Ok(()) } + pub fn func_string_list_ret( + &self, + ) -> wasmtime::component::TypedFunc< + (), + ( + wasmtime::component::__internal::Vec< + wasmtime::component::__internal::String, + >, + ), + > { + unsafe { + wasmtime::component::TypedFunc::< + (), + ( + wasmtime::component::__internal::Vec< + wasmtime::component::__internal::String, + >, + ), + >::new_unchecked(self.string_list_ret) + } + } pub async fn call_string_list_ret( &self, mut store: S, @@ -2139,20 +2306,32 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { + let callee = self.func_string_list_ret(); + let (ret0,) = callee + .call_async(store.as_context_mut(), ()) + .await?; + Ok(ret0) + } + pub fn func_tuple_string_list( + &self, + ) -> wasmtime::component::TypedFunc< + (&[(u8, wasmtime::component::__internal::String)],), + ( + wasmtime::component::__internal::Vec< + (wasmtime::component::__internal::String, u8), + >, + ), + > { + unsafe { wasmtime::component::TypedFunc::< - (), + (&[(u8, wasmtime::component::__internal::String)],), ( wasmtime::component::__internal::Vec< - wasmtime::component::__internal::String, + (wasmtime::component::__internal::String, u8), >, ), - >::new_unchecked(self.string_list_ret) - }; - let (ret0,) = callee - .call_async(store.as_context_mut(), ()) - .await?; - Ok(ret0) + >::new_unchecked(self.tuple_string_list) + } } pub async fn call_tuple_string_list( &self, @@ -2166,20 +2345,32 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { + let callee = self.func_tuple_string_list(); + let (ret0,) = callee + .call_async(store.as_context_mut(), (arg0,)) + .await?; + Ok(ret0) + } + pub fn func_string_list( + &self, + ) -> wasmtime::component::TypedFunc< + (&[wasmtime::component::__internal::String],), + ( + wasmtime::component::__internal::Vec< + wasmtime::component::__internal::String, + >, + ), + > { + unsafe { wasmtime::component::TypedFunc::< - (&[(u8, wasmtime::component::__internal::String)],), + (&[wasmtime::component::__internal::String],), ( wasmtime::component::__internal::Vec< - (wasmtime::component::__internal::String, u8), + wasmtime::component::__internal::String, >, ), - >::new_unchecked(self.tuple_string_list) - }; - let (ret0,) = callee - .call_async(store.as_context_mut(), (arg0,)) - .await?; - Ok(ret0) + >::new_unchecked(self.string_list) + } } pub async fn call_string_list( &self, @@ -2193,21 +2384,25 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (&[wasmtime::component::__internal::String],), - ( - wasmtime::component::__internal::Vec< - wasmtime::component::__internal::String, - >, - ), - >::new_unchecked(self.string_list) - }; + let callee = self.func_string_list(); let (ret0,) = callee .call_async(store.as_context_mut(), (arg0,)) .await?; Ok(ret0) } + pub fn func_record_list( + &self, + ) -> wasmtime::component::TypedFunc< + (&[SomeRecord],), + (wasmtime::component::__internal::Vec,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (&[SomeRecord],), + (wasmtime::component::__internal::Vec,), + >::new_unchecked(self.record_list) + } + } pub async fn call_record_list( &self, mut store: S, @@ -2218,17 +2413,25 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (&[SomeRecord],), - (wasmtime::component::__internal::Vec,), - >::new_unchecked(self.record_list) - }; + let callee = self.func_record_list(); let (ret0,) = callee .call_async(store.as_context_mut(), (arg0,)) .await?; Ok(ret0) } + pub fn func_record_list_reverse( + &self, + ) -> wasmtime::component::TypedFunc< + (&[OtherRecord],), + (wasmtime::component::__internal::Vec,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (&[OtherRecord],), + (wasmtime::component::__internal::Vec,), + >::new_unchecked(self.record_list_reverse) + } + } pub async fn call_record_list_reverse( &self, mut store: S, @@ -2239,17 +2442,25 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (&[OtherRecord],), - (wasmtime::component::__internal::Vec,), - >::new_unchecked(self.record_list_reverse) - }; + let callee = self.func_record_list_reverse(); let (ret0,) = callee .call_async(store.as_context_mut(), (arg0,)) .await?; Ok(ret0) } + pub fn func_variant_list( + &self, + ) -> wasmtime::component::TypedFunc< + (&[SomeVariant],), + (wasmtime::component::__internal::Vec,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (&[SomeVariant],), + (wasmtime::component::__internal::Vec,), + >::new_unchecked(self.variant_list) + } + } pub async fn call_variant_list( &self, mut store: S, @@ -2260,17 +2471,25 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (&[SomeVariant],), - (wasmtime::component::__internal::Vec,), - >::new_unchecked(self.variant_list) - }; + let callee = self.func_variant_list(); let (ret0,) = callee .call_async(store.as_context_mut(), (arg0,)) .await?; Ok(ret0) } + pub fn func_load_store_everything( + &self, + ) -> wasmtime::component::TypedFunc< + (&LoadStoreAllSizes,), + (LoadStoreAllSizes,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (&LoadStoreAllSizes,), + (LoadStoreAllSizes,), + >::new_unchecked(self.load_store_everything) + } + } pub async fn call_load_store_everything( &self, mut store: S, @@ -2279,12 +2498,7 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (&LoadStoreAllSizes,), - (LoadStoreAllSizes,), - >::new_unchecked(self.load_store_everything) - }; + let callee = self.func_load_store_everything(); let (ret0,) = callee .call_async(store.as_context_mut(), (arg0,)) .await?; diff --git a/crates/component-macro/tests/expanded/lists_concurrent.rs b/crates/component-macro/tests/expanded/lists_concurrent.rs index d487bc4c6e0b..d74c6794dc4e 100644 --- a/crates/component-macro/tests/expanded/lists_concurrent.rs +++ b/crates/component-macro/tests/expanded/lists_concurrent.rs @@ -1521,6 +1521,19 @@ pub mod exports { } } impl Guest { + pub fn func_list_u8_param( + &self, + ) -> wasmtime::component::TypedFunc< + (wasmtime::component::__internal::Vec,), + (), + > { + unsafe { + wasmtime::component::TypedFunc::< + (wasmtime::component::__internal::Vec,), + (), + >::new_unchecked(self.list_u8_param) + } + } pub async fn call_list_u8_param<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -1530,15 +1543,23 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (wasmtime::component::__internal::Vec,), - (), - >::new_unchecked(self.list_u8_param) - }; + let callee = self.func_list_u8_param(); let () = callee.call_concurrent(accessor, (arg0,)).await?; Ok(()) } + pub fn func_list_u16_param( + &self, + ) -> wasmtime::component::TypedFunc< + (wasmtime::component::__internal::Vec,), + (), + > { + unsafe { + wasmtime::component::TypedFunc::< + (wasmtime::component::__internal::Vec,), + (), + >::new_unchecked(self.list_u16_param) + } + } pub async fn call_list_u16_param<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -1548,15 +1569,23 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (wasmtime::component::__internal::Vec,), - (), - >::new_unchecked(self.list_u16_param) - }; + let callee = self.func_list_u16_param(); let () = callee.call_concurrent(accessor, (arg0,)).await?; Ok(()) } + pub fn func_list_u32_param( + &self, + ) -> wasmtime::component::TypedFunc< + (wasmtime::component::__internal::Vec,), + (), + > { + unsafe { + wasmtime::component::TypedFunc::< + (wasmtime::component::__internal::Vec,), + (), + >::new_unchecked(self.list_u32_param) + } + } pub async fn call_list_u32_param<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -1566,15 +1595,23 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (wasmtime::component::__internal::Vec,), - (), - >::new_unchecked(self.list_u32_param) - }; + let callee = self.func_list_u32_param(); let () = callee.call_concurrent(accessor, (arg0,)).await?; Ok(()) } + pub fn func_list_u64_param( + &self, + ) -> wasmtime::component::TypedFunc< + (wasmtime::component::__internal::Vec,), + (), + > { + unsafe { + wasmtime::component::TypedFunc::< + (wasmtime::component::__internal::Vec,), + (), + >::new_unchecked(self.list_u64_param) + } + } pub async fn call_list_u64_param<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -1584,15 +1621,23 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (wasmtime::component::__internal::Vec,), - (), - >::new_unchecked(self.list_u64_param) - }; + let callee = self.func_list_u64_param(); let () = callee.call_concurrent(accessor, (arg0,)).await?; Ok(()) } + pub fn func_list_s8_param( + &self, + ) -> wasmtime::component::TypedFunc< + (wasmtime::component::__internal::Vec,), + (), + > { + unsafe { + wasmtime::component::TypedFunc::< + (wasmtime::component::__internal::Vec,), + (), + >::new_unchecked(self.list_s8_param) + } + } pub async fn call_list_s8_param<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -1602,15 +1647,23 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (wasmtime::component::__internal::Vec,), - (), - >::new_unchecked(self.list_s8_param) - }; + let callee = self.func_list_s8_param(); let () = callee.call_concurrent(accessor, (arg0,)).await?; Ok(()) } + pub fn func_list_s16_param( + &self, + ) -> wasmtime::component::TypedFunc< + (wasmtime::component::__internal::Vec,), + (), + > { + unsafe { + wasmtime::component::TypedFunc::< + (wasmtime::component::__internal::Vec,), + (), + >::new_unchecked(self.list_s16_param) + } + } pub async fn call_list_s16_param<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -1620,15 +1673,23 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (wasmtime::component::__internal::Vec,), - (), - >::new_unchecked(self.list_s16_param) - }; + let callee = self.func_list_s16_param(); let () = callee.call_concurrent(accessor, (arg0,)).await?; Ok(()) } + pub fn func_list_s32_param( + &self, + ) -> wasmtime::component::TypedFunc< + (wasmtime::component::__internal::Vec,), + (), + > { + unsafe { + wasmtime::component::TypedFunc::< + (wasmtime::component::__internal::Vec,), + (), + >::new_unchecked(self.list_s32_param) + } + } pub async fn call_list_s32_param<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -1638,15 +1699,23 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (wasmtime::component::__internal::Vec,), - (), - >::new_unchecked(self.list_s32_param) - }; + let callee = self.func_list_s32_param(); let () = callee.call_concurrent(accessor, (arg0,)).await?; Ok(()) } + pub fn func_list_s64_param( + &self, + ) -> wasmtime::component::TypedFunc< + (wasmtime::component::__internal::Vec,), + (), + > { + unsafe { + wasmtime::component::TypedFunc::< + (wasmtime::component::__internal::Vec,), + (), + >::new_unchecked(self.list_s64_param) + } + } pub async fn call_list_s64_param<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -1656,15 +1725,23 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (wasmtime::component::__internal::Vec,), - (), - >::new_unchecked(self.list_s64_param) - }; + let callee = self.func_list_s64_param(); let () = callee.call_concurrent(accessor, (arg0,)).await?; Ok(()) } + pub fn func_list_f32_param( + &self, + ) -> wasmtime::component::TypedFunc< + (wasmtime::component::__internal::Vec,), + (), + > { + unsafe { + wasmtime::component::TypedFunc::< + (wasmtime::component::__internal::Vec,), + (), + >::new_unchecked(self.list_f32_param) + } + } pub async fn call_list_f32_param<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -1674,15 +1751,23 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (wasmtime::component::__internal::Vec,), - (), - >::new_unchecked(self.list_f32_param) - }; + let callee = self.func_list_f32_param(); let () = callee.call_concurrent(accessor, (arg0,)).await?; Ok(()) } + pub fn func_list_f64_param( + &self, + ) -> wasmtime::component::TypedFunc< + (wasmtime::component::__internal::Vec,), + (), + > { + unsafe { + wasmtime::component::TypedFunc::< + (wasmtime::component::__internal::Vec,), + (), + >::new_unchecked(self.list_f64_param) + } + } pub async fn call_list_f64_param<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -1692,15 +1777,23 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (wasmtime::component::__internal::Vec,), - (), - >::new_unchecked(self.list_f64_param) - }; + let callee = self.func_list_f64_param(); let () = callee.call_concurrent(accessor, (arg0,)).await?; Ok(()) } + pub fn func_list_u8_ret( + &self, + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::__internal::Vec,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (), + (wasmtime::component::__internal::Vec,), + >::new_unchecked(self.list_u8_ret) + } + } pub async fn call_list_u8_ret<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -1709,15 +1802,23 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (wasmtime::component::__internal::Vec,), - >::new_unchecked(self.list_u8_ret) - }; + let callee = self.func_list_u8_ret(); let (ret0,) = callee.call_concurrent(accessor, ()).await?; Ok(ret0) } + pub fn func_list_u16_ret( + &self, + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::__internal::Vec,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (), + (wasmtime::component::__internal::Vec,), + >::new_unchecked(self.list_u16_ret) + } + } pub async fn call_list_u16_ret<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -1726,15 +1827,23 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (wasmtime::component::__internal::Vec,), - >::new_unchecked(self.list_u16_ret) - }; + let callee = self.func_list_u16_ret(); let (ret0,) = callee.call_concurrent(accessor, ()).await?; Ok(ret0) } + pub fn func_list_u32_ret( + &self, + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::__internal::Vec,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (), + (wasmtime::component::__internal::Vec,), + >::new_unchecked(self.list_u32_ret) + } + } pub async fn call_list_u32_ret<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -1743,15 +1852,23 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (wasmtime::component::__internal::Vec,), - >::new_unchecked(self.list_u32_ret) - }; + let callee = self.func_list_u32_ret(); let (ret0,) = callee.call_concurrent(accessor, ()).await?; Ok(ret0) } + pub fn func_list_u64_ret( + &self, + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::__internal::Vec,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (), + (wasmtime::component::__internal::Vec,), + >::new_unchecked(self.list_u64_ret) + } + } pub async fn call_list_u64_ret<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -1760,15 +1877,23 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (wasmtime::component::__internal::Vec,), - >::new_unchecked(self.list_u64_ret) - }; + let callee = self.func_list_u64_ret(); let (ret0,) = callee.call_concurrent(accessor, ()).await?; Ok(ret0) } + pub fn func_list_s8_ret( + &self, + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::__internal::Vec,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (), + (wasmtime::component::__internal::Vec,), + >::new_unchecked(self.list_s8_ret) + } + } pub async fn call_list_s8_ret<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -1777,15 +1902,23 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (wasmtime::component::__internal::Vec,), - >::new_unchecked(self.list_s8_ret) - }; + let callee = self.func_list_s8_ret(); let (ret0,) = callee.call_concurrent(accessor, ()).await?; Ok(ret0) } + pub fn func_list_s16_ret( + &self, + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::__internal::Vec,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (), + (wasmtime::component::__internal::Vec,), + >::new_unchecked(self.list_s16_ret) + } + } pub async fn call_list_s16_ret<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -1794,15 +1927,23 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (wasmtime::component::__internal::Vec,), - >::new_unchecked(self.list_s16_ret) - }; + let callee = self.func_list_s16_ret(); let (ret0,) = callee.call_concurrent(accessor, ()).await?; Ok(ret0) } + pub fn func_list_s32_ret( + &self, + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::__internal::Vec,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (), + (wasmtime::component::__internal::Vec,), + >::new_unchecked(self.list_s32_ret) + } + } pub async fn call_list_s32_ret<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -1811,15 +1952,23 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (wasmtime::component::__internal::Vec,), - >::new_unchecked(self.list_s32_ret) - }; + let callee = self.func_list_s32_ret(); let (ret0,) = callee.call_concurrent(accessor, ()).await?; Ok(ret0) } + pub fn func_list_s64_ret( + &self, + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::__internal::Vec,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (), + (wasmtime::component::__internal::Vec,), + >::new_unchecked(self.list_s64_ret) + } + } pub async fn call_list_s64_ret<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -1828,15 +1977,23 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (wasmtime::component::__internal::Vec,), - >::new_unchecked(self.list_s64_ret) - }; + let callee = self.func_list_s64_ret(); let (ret0,) = callee.call_concurrent(accessor, ()).await?; Ok(ret0) } + pub fn func_list_f32_ret( + &self, + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::__internal::Vec,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (), + (wasmtime::component::__internal::Vec,), + >::new_unchecked(self.list_f32_ret) + } + } pub async fn call_list_f32_ret<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -1845,15 +2002,23 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (wasmtime::component::__internal::Vec,), - >::new_unchecked(self.list_f32_ret) - }; + let callee = self.func_list_f32_ret(); let (ret0,) = callee.call_concurrent(accessor, ()).await?; Ok(ret0) } + pub fn func_list_f64_ret( + &self, + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::__internal::Vec,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (), + (wasmtime::component::__internal::Vec,), + >::new_unchecked(self.list_f64_ret) + } + } pub async fn call_list_f64_ret<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -1862,15 +2027,23 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (wasmtime::component::__internal::Vec,), - >::new_unchecked(self.list_f64_ret) - }; + let callee = self.func_list_f64_ret(); let (ret0,) = callee.call_concurrent(accessor, ()).await?; Ok(ret0) } + pub fn func_tuple_list( + &self, + ) -> wasmtime::component::TypedFunc< + (wasmtime::component::__internal::Vec<(u8, i8)>,), + (wasmtime::component::__internal::Vec<(i64, u32)>,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (wasmtime::component::__internal::Vec<(u8, i8)>,), + (wasmtime::component::__internal::Vec<(i64, u32)>,), + >::new_unchecked(self.tuple_list) + } + } pub async fn call_tuple_list<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -1882,15 +2055,31 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (wasmtime::component::__internal::Vec<(u8, i8)>,), - (wasmtime::component::__internal::Vec<(i64, u32)>,), - >::new_unchecked(self.tuple_list) - }; + let callee = self.func_tuple_list(); let (ret0,) = callee.call_concurrent(accessor, (arg0,)).await?; Ok(ret0) } + pub fn func_string_list_arg( + &self, + ) -> wasmtime::component::TypedFunc< + ( + wasmtime::component::__internal::Vec< + wasmtime::component::__internal::String, + >, + ), + (), + > { + unsafe { + wasmtime::component::TypedFunc::< + ( + wasmtime::component::__internal::Vec< + wasmtime::component::__internal::String, + >, + ), + (), + >::new_unchecked(self.string_list_arg) + } + } pub async fn call_string_list_arg<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -1902,18 +2091,30 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { + let callee = self.func_string_list_arg(); + let () = callee.call_concurrent(accessor, (arg0,)).await?; + Ok(()) + } + pub fn func_string_list_ret( + &self, + ) -> wasmtime::component::TypedFunc< + (), + ( + wasmtime::component::__internal::Vec< + wasmtime::component::__internal::String, + >, + ), + > { + unsafe { wasmtime::component::TypedFunc::< + (), ( wasmtime::component::__internal::Vec< wasmtime::component::__internal::String, >, ), - (), - >::new_unchecked(self.string_list_arg) - }; - let () = callee.call_concurrent(accessor, (arg0,)).await?; - Ok(()) + >::new_unchecked(self.string_list_ret) + } } pub async fn call_string_list_ret<_T, _D>( &self, @@ -1927,18 +2128,38 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { + let callee = self.func_string_list_ret(); + let (ret0,) = callee.call_concurrent(accessor, ()).await?; + Ok(ret0) + } + pub fn func_tuple_string_list( + &self, + ) -> wasmtime::component::TypedFunc< + ( + wasmtime::component::__internal::Vec< + (u8, wasmtime::component::__internal::String), + >, + ), + ( + wasmtime::component::__internal::Vec< + (wasmtime::component::__internal::String, u8), + >, + ), + > { + unsafe { wasmtime::component::TypedFunc::< - (), ( wasmtime::component::__internal::Vec< - wasmtime::component::__internal::String, + (u8, wasmtime::component::__internal::String), >, ), - >::new_unchecked(self.string_list_ret) - }; - let (ret0,) = callee.call_concurrent(accessor, ()).await?; - Ok(ret0) + ( + wasmtime::component::__internal::Vec< + (wasmtime::component::__internal::String, u8), + >, + ), + >::new_unchecked(self.tuple_string_list) + } } pub async fn call_tuple_string_list<_T, _D>( &self, @@ -1955,22 +2176,38 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { + let callee = self.func_tuple_string_list(); + let (ret0,) = callee.call_concurrent(accessor, (arg0,)).await?; + Ok(ret0) + } + pub fn func_string_list( + &self, + ) -> wasmtime::component::TypedFunc< + ( + wasmtime::component::__internal::Vec< + wasmtime::component::__internal::String, + >, + ), + ( + wasmtime::component::__internal::Vec< + wasmtime::component::__internal::String, + >, + ), + > { + unsafe { wasmtime::component::TypedFunc::< ( wasmtime::component::__internal::Vec< - (u8, wasmtime::component::__internal::String), + wasmtime::component::__internal::String, >, ), ( wasmtime::component::__internal::Vec< - (wasmtime::component::__internal::String, u8), + wasmtime::component::__internal::String, >, ), - >::new_unchecked(self.tuple_string_list) - }; - let (ret0,) = callee.call_concurrent(accessor, (arg0,)).await?; - Ok(ret0) + >::new_unchecked(self.string_list) + } } pub async fn call_string_list<_T, _D>( &self, @@ -1987,23 +2224,23 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - ( - wasmtime::component::__internal::Vec< - wasmtime::component::__internal::String, - >, - ), - ( - wasmtime::component::__internal::Vec< - wasmtime::component::__internal::String, - >, - ), - >::new_unchecked(self.string_list) - }; + let callee = self.func_string_list(); let (ret0,) = callee.call_concurrent(accessor, (arg0,)).await?; Ok(ret0) } + pub fn func_record_list( + &self, + ) -> wasmtime::component::TypedFunc< + (wasmtime::component::__internal::Vec,), + (wasmtime::component::__internal::Vec,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (wasmtime::component::__internal::Vec,), + (wasmtime::component::__internal::Vec,), + >::new_unchecked(self.record_list) + } + } pub async fn call_record_list<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -2015,15 +2252,23 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (wasmtime::component::__internal::Vec,), - (wasmtime::component::__internal::Vec,), - >::new_unchecked(self.record_list) - }; + let callee = self.func_record_list(); let (ret0,) = callee.call_concurrent(accessor, (arg0,)).await?; Ok(ret0) } + pub fn func_record_list_reverse( + &self, + ) -> wasmtime::component::TypedFunc< + (wasmtime::component::__internal::Vec,), + (wasmtime::component::__internal::Vec,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (wasmtime::component::__internal::Vec,), + (wasmtime::component::__internal::Vec,), + >::new_unchecked(self.record_list_reverse) + } + } pub async fn call_record_list_reverse<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -2035,15 +2280,23 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (wasmtime::component::__internal::Vec,), - (wasmtime::component::__internal::Vec,), - >::new_unchecked(self.record_list_reverse) - }; + let callee = self.func_record_list_reverse(); let (ret0,) = callee.call_concurrent(accessor, (arg0,)).await?; Ok(ret0) } + pub fn func_variant_list( + &self, + ) -> wasmtime::component::TypedFunc< + (wasmtime::component::__internal::Vec,), + (wasmtime::component::__internal::Vec,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (wasmtime::component::__internal::Vec,), + (wasmtime::component::__internal::Vec,), + >::new_unchecked(self.variant_list) + } + } pub async fn call_variant_list<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -2055,15 +2308,23 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (wasmtime::component::__internal::Vec,), - (wasmtime::component::__internal::Vec,), - >::new_unchecked(self.variant_list) - }; + let callee = self.func_variant_list(); let (ret0,) = callee.call_concurrent(accessor, (arg0,)).await?; Ok(ret0) } + pub fn func_load_store_everything( + &self, + ) -> wasmtime::component::TypedFunc< + (LoadStoreAllSizes,), + (LoadStoreAllSizes,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (LoadStoreAllSizes,), + (LoadStoreAllSizes,), + >::new_unchecked(self.load_store_everything) + } + } pub async fn call_load_store_everything<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -2073,12 +2334,7 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (LoadStoreAllSizes,), - (LoadStoreAllSizes,), - >::new_unchecked(self.load_store_everything) - }; + let callee = self.func_load_store_everything(); let (ret0,) = callee.call_concurrent(accessor, (arg0,)).await?; Ok(ret0) } diff --git a/crates/component-macro/tests/expanded/lists_tracing_async.rs b/crates/component-macro/tests/expanded/lists_tracing_async.rs index 493824cbca5b..9fb5d880e29a 100644 --- a/crates/component-macro/tests/expanded/lists_tracing_async.rs +++ b/crates/component-macro/tests/expanded/lists_tracing_async.rs @@ -2149,6 +2149,16 @@ pub mod exports { } } impl Guest { + pub fn func_list_u8_param( + &self, + ) -> wasmtime::component::TypedFunc<(&[u8],), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (&[u8],), + (), + >::new_unchecked(self.list_u8_param) + } + } pub async fn call_list_u8_param( &self, mut store: S, @@ -2162,18 +2172,23 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/lists", function = "list-u8-param", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (&[u8],), - (), - >::new_unchecked(self.list_u8_param) - }; + let callee = self.func_list_u8_param(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .instrument(span.clone()) .await?; Ok(()) } + pub fn func_list_u16_param( + &self, + ) -> wasmtime::component::TypedFunc<(&[u16],), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (&[u16],), + (), + >::new_unchecked(self.list_u16_param) + } + } pub async fn call_list_u16_param( &self, mut store: S, @@ -2187,18 +2202,23 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/lists", function = "list-u16-param", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (&[u16],), - (), - >::new_unchecked(self.list_u16_param) - }; + let callee = self.func_list_u16_param(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .instrument(span.clone()) .await?; Ok(()) } + pub fn func_list_u32_param( + &self, + ) -> wasmtime::component::TypedFunc<(&[u32],), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (&[u32],), + (), + >::new_unchecked(self.list_u32_param) + } + } pub async fn call_list_u32_param( &self, mut store: S, @@ -2212,18 +2232,23 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/lists", function = "list-u32-param", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (&[u32],), - (), - >::new_unchecked(self.list_u32_param) - }; + let callee = self.func_list_u32_param(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .instrument(span.clone()) .await?; Ok(()) } + pub fn func_list_u64_param( + &self, + ) -> wasmtime::component::TypedFunc<(&[u64],), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (&[u64],), + (), + >::new_unchecked(self.list_u64_param) + } + } pub async fn call_list_u64_param( &self, mut store: S, @@ -2237,18 +2262,23 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/lists", function = "list-u64-param", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (&[u64],), - (), - >::new_unchecked(self.list_u64_param) - }; + let callee = self.func_list_u64_param(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .instrument(span.clone()) .await?; Ok(()) } + pub fn func_list_s8_param( + &self, + ) -> wasmtime::component::TypedFunc<(&[i8],), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (&[i8],), + (), + >::new_unchecked(self.list_s8_param) + } + } pub async fn call_list_s8_param( &self, mut store: S, @@ -2262,18 +2292,23 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/lists", function = "list-s8-param", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (&[i8],), - (), - >::new_unchecked(self.list_s8_param) - }; + let callee = self.func_list_s8_param(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .instrument(span.clone()) .await?; Ok(()) } + pub fn func_list_s16_param( + &self, + ) -> wasmtime::component::TypedFunc<(&[i16],), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (&[i16],), + (), + >::new_unchecked(self.list_s16_param) + } + } pub async fn call_list_s16_param( &self, mut store: S, @@ -2287,18 +2322,23 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/lists", function = "list-s16-param", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (&[i16],), - (), - >::new_unchecked(self.list_s16_param) - }; + let callee = self.func_list_s16_param(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .instrument(span.clone()) .await?; Ok(()) } + pub fn func_list_s32_param( + &self, + ) -> wasmtime::component::TypedFunc<(&[i32],), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (&[i32],), + (), + >::new_unchecked(self.list_s32_param) + } + } pub async fn call_list_s32_param( &self, mut store: S, @@ -2312,18 +2352,23 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/lists", function = "list-s32-param", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (&[i32],), - (), - >::new_unchecked(self.list_s32_param) - }; + let callee = self.func_list_s32_param(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .instrument(span.clone()) .await?; Ok(()) } + pub fn func_list_s64_param( + &self, + ) -> wasmtime::component::TypedFunc<(&[i64],), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (&[i64],), + (), + >::new_unchecked(self.list_s64_param) + } + } pub async fn call_list_s64_param( &self, mut store: S, @@ -2337,18 +2382,23 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/lists", function = "list-s64-param", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (&[i64],), - (), - >::new_unchecked(self.list_s64_param) - }; + let callee = self.func_list_s64_param(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .instrument(span.clone()) .await?; Ok(()) } + pub fn func_list_f32_param( + &self, + ) -> wasmtime::component::TypedFunc<(&[f32],), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (&[f32],), + (), + >::new_unchecked(self.list_f32_param) + } + } pub async fn call_list_f32_param( &self, mut store: S, @@ -2362,18 +2412,23 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/lists", function = "list-f32-param", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (&[f32],), - (), - >::new_unchecked(self.list_f32_param) - }; + let callee = self.func_list_f32_param(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .instrument(span.clone()) .await?; Ok(()) } + pub fn func_list_f64_param( + &self, + ) -> wasmtime::component::TypedFunc<(&[f64],), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (&[f64],), + (), + >::new_unchecked(self.list_f64_param) + } + } pub async fn call_list_f64_param( &self, mut store: S, @@ -2387,18 +2442,26 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/lists", function = "list-f64-param", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (&[f64],), - (), - >::new_unchecked(self.list_f64_param) - }; + let callee = self.func_list_f64_param(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .instrument(span.clone()) .await?; Ok(()) } + pub fn func_list_u8_ret( + &self, + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::__internal::Vec,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (), + (wasmtime::component::__internal::Vec,), + >::new_unchecked(self.list_u8_ret) + } + } pub async fn call_list_u8_ret( &self, mut store: S, @@ -2411,18 +2474,26 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/lists", function = "list-u8-ret", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (wasmtime::component::__internal::Vec,), - >::new_unchecked(self.list_u8_ret) - }; + let callee = self.func_list_u8_ret(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) .await?; Ok(ret0) } + pub fn func_list_u16_ret( + &self, + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::__internal::Vec,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (), + (wasmtime::component::__internal::Vec,), + >::new_unchecked(self.list_u16_ret) + } + } pub async fn call_list_u16_ret( &self, mut store: S, @@ -2435,18 +2506,26 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/lists", function = "list-u16-ret", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (wasmtime::component::__internal::Vec,), - >::new_unchecked(self.list_u16_ret) - }; + let callee = self.func_list_u16_ret(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) .await?; Ok(ret0) } + pub fn func_list_u32_ret( + &self, + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::__internal::Vec,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (), + (wasmtime::component::__internal::Vec,), + >::new_unchecked(self.list_u32_ret) + } + } pub async fn call_list_u32_ret( &self, mut store: S, @@ -2459,18 +2538,26 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/lists", function = "list-u32-ret", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (wasmtime::component::__internal::Vec,), - >::new_unchecked(self.list_u32_ret) - }; + let callee = self.func_list_u32_ret(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) .await?; Ok(ret0) } + pub fn func_list_u64_ret( + &self, + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::__internal::Vec,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (), + (wasmtime::component::__internal::Vec,), + >::new_unchecked(self.list_u64_ret) + } + } pub async fn call_list_u64_ret( &self, mut store: S, @@ -2483,18 +2570,26 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/lists", function = "list-u64-ret", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (wasmtime::component::__internal::Vec,), - >::new_unchecked(self.list_u64_ret) - }; + let callee = self.func_list_u64_ret(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) .await?; Ok(ret0) } + pub fn func_list_s8_ret( + &self, + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::__internal::Vec,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (), + (wasmtime::component::__internal::Vec,), + >::new_unchecked(self.list_s8_ret) + } + } pub async fn call_list_s8_ret( &self, mut store: S, @@ -2507,18 +2602,26 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/lists", function = "list-s8-ret", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (wasmtime::component::__internal::Vec,), - >::new_unchecked(self.list_s8_ret) - }; + let callee = self.func_list_s8_ret(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) .await?; Ok(ret0) } + pub fn func_list_s16_ret( + &self, + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::__internal::Vec,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (), + (wasmtime::component::__internal::Vec,), + >::new_unchecked(self.list_s16_ret) + } + } pub async fn call_list_s16_ret( &self, mut store: S, @@ -2531,18 +2634,26 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/lists", function = "list-s16-ret", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (wasmtime::component::__internal::Vec,), - >::new_unchecked(self.list_s16_ret) - }; + let callee = self.func_list_s16_ret(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) .await?; Ok(ret0) } + pub fn func_list_s32_ret( + &self, + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::__internal::Vec,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (), + (wasmtime::component::__internal::Vec,), + >::new_unchecked(self.list_s32_ret) + } + } pub async fn call_list_s32_ret( &self, mut store: S, @@ -2555,18 +2666,26 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/lists", function = "list-s32-ret", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (wasmtime::component::__internal::Vec,), - >::new_unchecked(self.list_s32_ret) - }; + let callee = self.func_list_s32_ret(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) .await?; Ok(ret0) } + pub fn func_list_s64_ret( + &self, + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::__internal::Vec,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (), + (wasmtime::component::__internal::Vec,), + >::new_unchecked(self.list_s64_ret) + } + } pub async fn call_list_s64_ret( &self, mut store: S, @@ -2579,18 +2698,26 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/lists", function = "list-s64-ret", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (wasmtime::component::__internal::Vec,), - >::new_unchecked(self.list_s64_ret) - }; + let callee = self.func_list_s64_ret(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) .await?; Ok(ret0) } + pub fn func_list_f32_ret( + &self, + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::__internal::Vec,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (), + (wasmtime::component::__internal::Vec,), + >::new_unchecked(self.list_f32_ret) + } + } pub async fn call_list_f32_ret( &self, mut store: S, @@ -2603,18 +2730,26 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/lists", function = "list-f32-ret", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (wasmtime::component::__internal::Vec,), - >::new_unchecked(self.list_f32_ret) - }; + let callee = self.func_list_f32_ret(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) .await?; Ok(ret0) } + pub fn func_list_f64_ret( + &self, + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::__internal::Vec,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (), + (wasmtime::component::__internal::Vec,), + >::new_unchecked(self.list_f64_ret) + } + } pub async fn call_list_f64_ret( &self, mut store: S, @@ -2627,18 +2762,26 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/lists", function = "list-f64-ret", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (wasmtime::component::__internal::Vec,), - >::new_unchecked(self.list_f64_ret) - }; + let callee = self.func_list_f64_ret(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) .await?; Ok(ret0) } + pub fn func_tuple_list( + &self, + ) -> wasmtime::component::TypedFunc< + (&[(u8, i8)],), + (wasmtime::component::__internal::Vec<(i64, u32)>,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (&[(u8, i8)],), + (wasmtime::component::__internal::Vec<(i64, u32)>,), + >::new_unchecked(self.tuple_list) + } + } pub async fn call_tuple_list( &self, mut store: S, @@ -2654,18 +2797,26 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/lists", function = "tuple-list", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (&[(u8, i8)],), - (wasmtime::component::__internal::Vec<(i64, u32)>,), - >::new_unchecked(self.tuple_list) - }; + let callee = self.func_tuple_list(); let (ret0,) = callee .call_async(store.as_context_mut(), (arg0,)) .instrument(span.clone()) .await?; Ok(ret0) } + pub fn func_string_list_arg( + &self, + ) -> wasmtime::component::TypedFunc< + (&[wasmtime::component::__internal::String],), + (), + > { + unsafe { + wasmtime::component::TypedFunc::< + (&[wasmtime::component::__internal::String],), + (), + >::new_unchecked(self.string_list_arg) + } + } pub async fn call_string_list_arg( &self, mut store: S, @@ -2679,18 +2830,34 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/lists", function = "string-list-arg", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (&[wasmtime::component::__internal::String],), - (), - >::new_unchecked(self.string_list_arg) - }; + let callee = self.func_string_list_arg(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .instrument(span.clone()) .await?; Ok(()) } + pub fn func_string_list_ret( + &self, + ) -> wasmtime::component::TypedFunc< + (), + ( + wasmtime::component::__internal::Vec< + wasmtime::component::__internal::String, + >, + ), + > { + unsafe { + wasmtime::component::TypedFunc::< + (), + ( + wasmtime::component::__internal::Vec< + wasmtime::component::__internal::String, + >, + ), + >::new_unchecked(self.string_list_ret) + } + } pub async fn call_string_list_ret( &self, mut store: S, @@ -2707,22 +2874,34 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/lists", function = "string-list-ret", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - ( - wasmtime::component::__internal::Vec< - wasmtime::component::__internal::String, - >, - ), - >::new_unchecked(self.string_list_ret) - }; + let callee = self.func_string_list_ret(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) .await?; Ok(ret0) } + pub fn func_tuple_string_list( + &self, + ) -> wasmtime::component::TypedFunc< + (&[(u8, wasmtime::component::__internal::String)],), + ( + wasmtime::component::__internal::Vec< + (wasmtime::component::__internal::String, u8), + >, + ), + > { + unsafe { + wasmtime::component::TypedFunc::< + (&[(u8, wasmtime::component::__internal::String)],), + ( + wasmtime::component::__internal::Vec< + (wasmtime::component::__internal::String, u8), + >, + ), + >::new_unchecked(self.tuple_string_list) + } + } pub async fn call_tuple_string_list( &self, mut store: S, @@ -2740,22 +2919,34 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/lists", function = "tuple-string-list", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (&[(u8, wasmtime::component::__internal::String)],), - ( - wasmtime::component::__internal::Vec< - (wasmtime::component::__internal::String, u8), - >, - ), - >::new_unchecked(self.tuple_string_list) - }; + let callee = self.func_tuple_string_list(); let (ret0,) = callee .call_async(store.as_context_mut(), (arg0,)) .instrument(span.clone()) .await?; Ok(ret0) } + pub fn func_string_list( + &self, + ) -> wasmtime::component::TypedFunc< + (&[wasmtime::component::__internal::String],), + ( + wasmtime::component::__internal::Vec< + wasmtime::component::__internal::String, + >, + ), + > { + unsafe { + wasmtime::component::TypedFunc::< + (&[wasmtime::component::__internal::String],), + ( + wasmtime::component::__internal::Vec< + wasmtime::component::__internal::String, + >, + ), + >::new_unchecked(self.string_list) + } + } pub async fn call_string_list( &self, mut store: S, @@ -2773,22 +2964,26 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/lists", function = "string-list", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (&[wasmtime::component::__internal::String],), - ( - wasmtime::component::__internal::Vec< - wasmtime::component::__internal::String, - >, - ), - >::new_unchecked(self.string_list) - }; + let callee = self.func_string_list(); let (ret0,) = callee .call_async(store.as_context_mut(), (arg0,)) .instrument(span.clone()) .await?; Ok(ret0) } + pub fn func_record_list( + &self, + ) -> wasmtime::component::TypedFunc< + (&[SomeRecord],), + (wasmtime::component::__internal::Vec,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (&[SomeRecord],), + (wasmtime::component::__internal::Vec,), + >::new_unchecked(self.record_list) + } + } pub async fn call_record_list( &self, mut store: S, @@ -2804,18 +2999,26 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/lists", function = "record-list", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (&[SomeRecord],), - (wasmtime::component::__internal::Vec,), - >::new_unchecked(self.record_list) - }; + let callee = self.func_record_list(); let (ret0,) = callee .call_async(store.as_context_mut(), (arg0,)) .instrument(span.clone()) .await?; Ok(ret0) } + pub fn func_record_list_reverse( + &self, + ) -> wasmtime::component::TypedFunc< + (&[OtherRecord],), + (wasmtime::component::__internal::Vec,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (&[OtherRecord],), + (wasmtime::component::__internal::Vec,), + >::new_unchecked(self.record_list_reverse) + } + } pub async fn call_record_list_reverse( &self, mut store: S, @@ -2831,18 +3034,26 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/lists", function = "record-list-reverse", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (&[OtherRecord],), - (wasmtime::component::__internal::Vec,), - >::new_unchecked(self.record_list_reverse) - }; + let callee = self.func_record_list_reverse(); let (ret0,) = callee .call_async(store.as_context_mut(), (arg0,)) .instrument(span.clone()) .await?; Ok(ret0) } + pub fn func_variant_list( + &self, + ) -> wasmtime::component::TypedFunc< + (&[SomeVariant],), + (wasmtime::component::__internal::Vec,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (&[SomeVariant],), + (wasmtime::component::__internal::Vec,), + >::new_unchecked(self.variant_list) + } + } pub async fn call_variant_list( &self, mut store: S, @@ -2858,18 +3069,26 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/lists", function = "variant-list", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (&[SomeVariant],), - (wasmtime::component::__internal::Vec,), - >::new_unchecked(self.variant_list) - }; + let callee = self.func_variant_list(); let (ret0,) = callee .call_async(store.as_context_mut(), (arg0,)) .instrument(span.clone()) .await?; Ok(ret0) } + pub fn func_load_store_everything( + &self, + ) -> wasmtime::component::TypedFunc< + (&LoadStoreAllSizes,), + (LoadStoreAllSizes,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (&LoadStoreAllSizes,), + (LoadStoreAllSizes,), + >::new_unchecked(self.load_store_everything) + } + } pub async fn call_load_store_everything( &self, mut store: S, @@ -2883,12 +3102,7 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/lists", function = "load-store-everything", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (&LoadStoreAllSizes,), - (LoadStoreAllSizes,), - >::new_unchecked(self.load_store_everything) - }; + let callee = self.func_load_store_everything(); let (ret0,) = callee .call_async(store.as_context_mut(), (arg0,)) .instrument(span.clone()) diff --git a/crates/component-macro/tests/expanded/many-arguments.rs b/crates/component-macro/tests/expanded/many-arguments.rs index 9af3a5756718..f4d42c0cc993 100644 --- a/crates/component-macro/tests/expanded/many-arguments.rs +++ b/crates/component-macro/tests/expanded/many-arguments.rs @@ -625,27 +625,30 @@ pub mod exports { } } impl Guest { - pub fn call_many_args( + pub fn func_many_args( &self, - mut store: S, - arg0: u64, - arg1: u64, - arg2: u64, - arg3: u64, - arg4: u64, - arg5: u64, - arg6: u64, - arg7: u64, - arg8: u64, - arg9: u64, - arg10: u64, - arg11: u64, - arg12: u64, - arg13: u64, - arg14: u64, - arg15: u64, - ) -> wasmtime::Result<()> { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc< + ( + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + ), + (), + > { + unsafe { wasmtime::component::TypedFunc::< ( u64, @@ -667,7 +670,29 @@ pub mod exports { ), (), >::new_unchecked(self.many_args) - }; + } + } + pub fn call_many_args( + &self, + mut store: S, + arg0: u64, + arg1: u64, + arg2: u64, + arg3: u64, + arg4: u64, + arg5: u64, + arg6: u64, + arg7: u64, + arg8: u64, + arg9: u64, + arg10: u64, + arg11: u64, + arg12: u64, + arg13: u64, + arg14: u64, + arg15: u64, + ) -> wasmtime::Result<()> { + let callee = self.func_many_args(); let () = callee .call( store.as_context_mut(), @@ -692,17 +717,22 @@ pub mod exports { )?; Ok(()) } - pub fn call_big_argument( + pub fn func_big_argument( &self, - mut store: S, - arg0: &BigStruct, - ) -> wasmtime::Result<()> { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc<(&BigStruct,), ()> { + unsafe { wasmtime::component::TypedFunc::< (&BigStruct,), (), >::new_unchecked(self.big_argument) - }; + } + } + pub fn call_big_argument( + &self, + mut store: S, + arg0: &BigStruct, + ) -> wasmtime::Result<()> { + let callee = self.func_big_argument(); let () = callee.call(store.as_context_mut(), (arg0,))?; Ok(()) } diff --git a/crates/component-macro/tests/expanded/many-arguments_async.rs b/crates/component-macro/tests/expanded/many-arguments_async.rs index 8737073991be..d9cb396ba654 100644 --- a/crates/component-macro/tests/expanded/many-arguments_async.rs +++ b/crates/component-macro/tests/expanded/many-arguments_async.rs @@ -639,6 +639,53 @@ pub mod exports { } } impl Guest { + pub fn func_many_args( + &self, + ) -> wasmtime::component::TypedFunc< + ( + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + ), + (), + > { + unsafe { + wasmtime::component::TypedFunc::< + ( + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + ), + (), + >::new_unchecked(self.many_args) + } + } pub async fn call_many_args( &self, mut store: S, @@ -662,29 +709,7 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - ( - u64, - u64, - u64, - u64, - u64, - u64, - u64, - u64, - u64, - u64, - u64, - u64, - u64, - u64, - u64, - u64, - ), - (), - >::new_unchecked(self.many_args) - }; + let callee = self.func_many_args(); let () = callee .call_async( store.as_context_mut(), @@ -710,6 +735,16 @@ pub mod exports { .await?; Ok(()) } + pub fn func_big_argument( + &self, + ) -> wasmtime::component::TypedFunc<(&BigStruct,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (&BigStruct,), + (), + >::new_unchecked(self.big_argument) + } + } pub async fn call_big_argument( &self, mut store: S, @@ -718,12 +753,7 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (&BigStruct,), - (), - >::new_unchecked(self.big_argument) - }; + let callee = self.func_big_argument(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .await?; diff --git a/crates/component-macro/tests/expanded/many-arguments_concurrent.rs b/crates/component-macro/tests/expanded/many-arguments_concurrent.rs index d1cf1d6993a5..1fcddc04edc2 100644 --- a/crates/component-macro/tests/expanded/many-arguments_concurrent.rs +++ b/crates/component-macro/tests/expanded/many-arguments_concurrent.rs @@ -586,6 +586,53 @@ pub mod exports { } } impl Guest { + pub fn func_many_args( + &self, + ) -> wasmtime::component::TypedFunc< + ( + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + ), + (), + > { + unsafe { + wasmtime::component::TypedFunc::< + ( + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + ), + (), + >::new_unchecked(self.many_args) + } + } pub async fn call_many_args<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -610,29 +657,7 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - ( - u64, - u64, - u64, - u64, - u64, - u64, - u64, - u64, - u64, - u64, - u64, - u64, - u64, - u64, - u64, - u64, - ), - (), - >::new_unchecked(self.many_args) - }; + let callee = self.func_many_args(); let () = callee .call_concurrent( accessor, @@ -658,6 +683,16 @@ pub mod exports { .await?; Ok(()) } + pub fn func_big_argument( + &self, + ) -> wasmtime::component::TypedFunc<(BigStruct,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (BigStruct,), + (), + >::new_unchecked(self.big_argument) + } + } pub async fn call_big_argument<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -667,12 +702,7 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (BigStruct,), - (), - >::new_unchecked(self.big_argument) - }; + let callee = self.func_big_argument(); let () = callee.call_concurrent(accessor, (arg0,)).await?; Ok(()) } diff --git a/crates/component-macro/tests/expanded/many-arguments_tracing_async.rs b/crates/component-macro/tests/expanded/many-arguments_tracing_async.rs index db617b7d3ec2..a7709a3838dd 100644 --- a/crates/component-macro/tests/expanded/many-arguments_tracing_async.rs +++ b/crates/component-macro/tests/expanded/many-arguments_tracing_async.rs @@ -682,6 +682,53 @@ pub mod exports { } } impl Guest { + pub fn func_many_args( + &self, + ) -> wasmtime::component::TypedFunc< + ( + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + ), + (), + > { + unsafe { + wasmtime::component::TypedFunc::< + ( + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + ), + (), + >::new_unchecked(self.many_args) + } + } pub async fn call_many_args( &self, mut store: S, @@ -710,29 +757,7 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/manyarg", function = "many-args", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - ( - u64, - u64, - u64, - u64, - u64, - u64, - u64, - u64, - u64, - u64, - u64, - u64, - u64, - u64, - u64, - u64, - ), - (), - >::new_unchecked(self.many_args) - }; + let callee = self.func_many_args(); let () = callee .call_async( store.as_context_mut(), @@ -759,6 +784,16 @@ pub mod exports { .await?; Ok(()) } + pub fn func_big_argument( + &self, + ) -> wasmtime::component::TypedFunc<(&BigStruct,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (&BigStruct,), + (), + >::new_unchecked(self.big_argument) + } + } pub async fn call_big_argument( &self, mut store: S, @@ -772,12 +807,7 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/manyarg", function = "big-argument", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (&BigStruct,), - (), - >::new_unchecked(self.big_argument) - }; + let callee = self.func_big_argument(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .instrument(span.clone()) diff --git a/crates/component-macro/tests/expanded/multiversion.rs b/crates/component-macro/tests/expanded/multiversion.rs index 61f37ca8860a..361ce4c69402 100644 --- a/crates/component-macro/tests/expanded/multiversion.rs +++ b/crates/component-macro/tests/expanded/multiversion.rs @@ -363,16 +363,19 @@ pub mod exports { } } impl Guest { - pub fn call_x( - &self, - mut store: S, - ) -> wasmtime::Result<()> { - let callee = unsafe { + pub fn func_x(&self) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { wasmtime::component::TypedFunc::< (), (), >::new_unchecked(self.x) - }; + } + } + pub fn call_x( + &self, + mut store: S, + ) -> wasmtime::Result<()> { + let callee = self.func_x(); let () = callee.call(store.as_context_mut(), ())?; Ok(()) } @@ -442,16 +445,19 @@ pub mod exports { } } impl Guest { - pub fn call_x( - &self, - mut store: S, - ) -> wasmtime::Result<()> { - let callee = unsafe { + pub fn func_x(&self) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { wasmtime::component::TypedFunc::< (), (), >::new_unchecked(self.x) - }; + } + } + pub fn call_x( + &self, + mut store: S, + ) -> wasmtime::Result<()> { + let callee = self.func_x(); let () = callee.call(store.as_context_mut(), ())?; Ok(()) } diff --git a/crates/component-macro/tests/expanded/multiversion_async.rs b/crates/component-macro/tests/expanded/multiversion_async.rs index 4cd200af19dd..430039648504 100644 --- a/crates/component-macro/tests/expanded/multiversion_async.rs +++ b/crates/component-macro/tests/expanded/multiversion_async.rs @@ -367,6 +367,14 @@ pub mod exports { } } impl Guest { + pub fn func_x(&self) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (), + >::new_unchecked(self.x) + } + } pub async fn call_x( &self, mut store: S, @@ -374,12 +382,7 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (), - >::new_unchecked(self.x) - }; + let callee = self.func_x(); let () = callee.call_async(store.as_context_mut(), ()).await?; Ok(()) } @@ -449,6 +452,14 @@ pub mod exports { } } impl Guest { + pub fn func_x(&self) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (), + >::new_unchecked(self.x) + } + } pub async fn call_x( &self, mut store: S, @@ -456,12 +467,7 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (), - >::new_unchecked(self.x) - }; + let callee = self.func_x(); let () = callee.call_async(store.as_context_mut(), ()).await?; Ok(()) } diff --git a/crates/component-macro/tests/expanded/multiversion_concurrent.rs b/crates/component-macro/tests/expanded/multiversion_concurrent.rs index b32c6c4ce81a..030bff4cd046 100644 --- a/crates/component-macro/tests/expanded/multiversion_concurrent.rs +++ b/crates/component-macro/tests/expanded/multiversion_concurrent.rs @@ -355,6 +355,14 @@ pub mod exports { } } impl Guest { + pub fn func_x(&self) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (), + >::new_unchecked(self.x) + } + } pub async fn call_x<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -363,12 +371,7 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (), - >::new_unchecked(self.x) - }; + let callee = self.func_x(); let () = callee.call_concurrent(accessor, ()).await?; Ok(()) } @@ -438,6 +441,14 @@ pub mod exports { } } impl Guest { + pub fn func_x(&self) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (), + >::new_unchecked(self.x) + } + } pub async fn call_x<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -446,12 +457,7 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (), - >::new_unchecked(self.x) - }; + let callee = self.func_x(); let () = callee.call_concurrent(accessor, ()).await?; Ok(()) } diff --git a/crates/component-macro/tests/expanded/multiversion_tracing_async.rs b/crates/component-macro/tests/expanded/multiversion_tracing_async.rs index b4ee5cea7a4b..94c4fb4d88aa 100644 --- a/crates/component-macro/tests/expanded/multiversion_tracing_async.rs +++ b/crates/component-macro/tests/expanded/multiversion_tracing_async.rs @@ -393,6 +393,14 @@ pub mod exports { } } impl Guest { + pub fn func_x(&self) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (), + >::new_unchecked(self.x) + } + } pub async fn call_x( &self, mut store: S, @@ -405,12 +413,7 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "my:dep/a@0.1.0", function = "x", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (), - >::new_unchecked(self.x) - }; + let callee = self.func_x(); let () = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) @@ -483,6 +486,14 @@ pub mod exports { } } impl Guest { + pub fn func_x(&self) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (), + >::new_unchecked(self.x) + } + } pub async fn call_x( &self, mut store: S, @@ -495,12 +506,7 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "my:dep/a@0.2.0", function = "x", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (), - >::new_unchecked(self.x) - }; + let callee = self.func_x(); let () = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) diff --git a/crates/component-macro/tests/expanded/records.rs b/crates/component-macro/tests/expanded/records.rs index 01980b5c07e2..46d1a79d7189 100644 --- a/crates/component-macro/tests/expanded/records.rs +++ b/crates/component-macro/tests/expanded/records.rs @@ -981,152 +981,207 @@ pub mod exports { } } impl Guest { - pub fn call_tuple_arg( + pub fn func_tuple_arg( &self, - mut store: S, - arg0: (char, u32), - ) -> wasmtime::Result<()> { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc<((char, u32),), ()> { + unsafe { wasmtime::component::TypedFunc::< ((char, u32),), (), >::new_unchecked(self.tuple_arg) - }; + } + } + pub fn call_tuple_arg( + &self, + mut store: S, + arg0: (char, u32), + ) -> wasmtime::Result<()> { + let callee = self.func_tuple_arg(); let () = callee.call(store.as_context_mut(), (arg0,))?; Ok(()) } - pub fn call_tuple_result( + pub fn func_tuple_result( &self, - mut store: S, - ) -> wasmtime::Result<(char, u32)> { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc<(), ((char, u32),)> { + unsafe { wasmtime::component::TypedFunc::< (), ((char, u32),), >::new_unchecked(self.tuple_result) - }; + } + } + pub fn call_tuple_result( + &self, + mut store: S, + ) -> wasmtime::Result<(char, u32)> { + let callee = self.func_tuple_result(); let (ret0,) = callee.call(store.as_context_mut(), ())?; Ok(ret0) } - pub fn call_empty_arg( + pub fn func_empty_arg( &self, - mut store: S, - arg0: Empty, - ) -> wasmtime::Result<()> { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc<(Empty,), ()> { + unsafe { wasmtime::component::TypedFunc::< (Empty,), (), >::new_unchecked(self.empty_arg) - }; + } + } + pub fn call_empty_arg( + &self, + mut store: S, + arg0: Empty, + ) -> wasmtime::Result<()> { + let callee = self.func_empty_arg(); let () = callee.call(store.as_context_mut(), (arg0,))?; Ok(()) } - pub fn call_empty_result( + pub fn func_empty_result( &self, - mut store: S, - ) -> wasmtime::Result { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc<(), (Empty,)> { + unsafe { wasmtime::component::TypedFunc::< (), (Empty,), >::new_unchecked(self.empty_result) - }; + } + } + pub fn call_empty_result( + &self, + mut store: S, + ) -> wasmtime::Result { + let callee = self.func_empty_result(); let (ret0,) = callee.call(store.as_context_mut(), ())?; Ok(ret0) } - pub fn call_scalar_arg( + pub fn func_scalar_arg( &self, - mut store: S, - arg0: Scalars, - ) -> wasmtime::Result<()> { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc<(Scalars,), ()> { + unsafe { wasmtime::component::TypedFunc::< (Scalars,), (), >::new_unchecked(self.scalar_arg) - }; + } + } + pub fn call_scalar_arg( + &self, + mut store: S, + arg0: Scalars, + ) -> wasmtime::Result<()> { + let callee = self.func_scalar_arg(); let () = callee.call(store.as_context_mut(), (arg0,))?; Ok(()) } - pub fn call_scalar_result( + pub fn func_scalar_result( &self, - mut store: S, - ) -> wasmtime::Result { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc<(), (Scalars,)> { + unsafe { wasmtime::component::TypedFunc::< (), (Scalars,), >::new_unchecked(self.scalar_result) - }; + } + } + pub fn call_scalar_result( + &self, + mut store: S, + ) -> wasmtime::Result { + let callee = self.func_scalar_result(); let (ret0,) = callee.call(store.as_context_mut(), ())?; Ok(ret0) } - pub fn call_flags_arg( + pub fn func_flags_arg( &self, - mut store: S, - arg0: ReallyFlags, - ) -> wasmtime::Result<()> { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc<(ReallyFlags,), ()> { + unsafe { wasmtime::component::TypedFunc::< (ReallyFlags,), (), >::new_unchecked(self.flags_arg) - }; + } + } + pub fn call_flags_arg( + &self, + mut store: S, + arg0: ReallyFlags, + ) -> wasmtime::Result<()> { + let callee = self.func_flags_arg(); let () = callee.call(store.as_context_mut(), (arg0,))?; Ok(()) } - pub fn call_flags_result( + pub fn func_flags_result( &self, - mut store: S, - ) -> wasmtime::Result { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc<(), (ReallyFlags,)> { + unsafe { wasmtime::component::TypedFunc::< (), (ReallyFlags,), >::new_unchecked(self.flags_result) - }; + } + } + pub fn call_flags_result( + &self, + mut store: S, + ) -> wasmtime::Result { + let callee = self.func_flags_result(); let (ret0,) = callee.call(store.as_context_mut(), ())?; Ok(ret0) } - pub fn call_aggregate_arg( + pub fn func_aggregate_arg( &self, - mut store: S, - arg0: &Aggregates, - ) -> wasmtime::Result<()> { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc<(&Aggregates,), ()> { + unsafe { wasmtime::component::TypedFunc::< (&Aggregates,), (), >::new_unchecked(self.aggregate_arg) - }; + } + } + pub fn call_aggregate_arg( + &self, + mut store: S, + arg0: &Aggregates, + ) -> wasmtime::Result<()> { + let callee = self.func_aggregate_arg(); let () = callee.call(store.as_context_mut(), (arg0,))?; Ok(()) } - pub fn call_aggregate_result( + pub fn func_aggregate_result( &self, - mut store: S, - ) -> wasmtime::Result { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc<(), (Aggregates,)> { + unsafe { wasmtime::component::TypedFunc::< (), (Aggregates,), >::new_unchecked(self.aggregate_result) - }; + } + } + pub fn call_aggregate_result( + &self, + mut store: S, + ) -> wasmtime::Result { + let callee = self.func_aggregate_result(); let (ret0,) = callee.call(store.as_context_mut(), ())?; Ok(ret0) } - pub fn call_typedef_inout( + pub fn func_typedef_inout( &self, - mut store: S, - arg0: TupleTypedef2, - ) -> wasmtime::Result { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc<(TupleTypedef2,), (i32,)> { + unsafe { wasmtime::component::TypedFunc::< (TupleTypedef2,), (i32,), >::new_unchecked(self.typedef_inout) - }; + } + } + pub fn call_typedef_inout( + &self, + mut store: S, + arg0: TupleTypedef2, + ) -> wasmtime::Result { + let callee = self.func_typedef_inout(); let (ret0,) = callee.call(store.as_context_mut(), (arg0,))?; Ok(ret0) } diff --git a/crates/component-macro/tests/expanded/records_async.rs b/crates/component-macro/tests/expanded/records_async.rs index 71e7a225cf6e..a954717aa263 100644 --- a/crates/component-macro/tests/expanded/records_async.rs +++ b/crates/component-macro/tests/expanded/records_async.rs @@ -1059,6 +1059,16 @@ pub mod exports { } } impl Guest { + pub fn func_tuple_arg( + &self, + ) -> wasmtime::component::TypedFunc<((char, u32),), ()> { + unsafe { + wasmtime::component::TypedFunc::< + ((char, u32),), + (), + >::new_unchecked(self.tuple_arg) + } + } pub async fn call_tuple_arg( &self, mut store: S, @@ -1067,17 +1077,22 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - ((char, u32),), - (), - >::new_unchecked(self.tuple_arg) - }; + let callee = self.func_tuple_arg(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .await?; Ok(()) } + pub fn func_tuple_result( + &self, + ) -> wasmtime::component::TypedFunc<(), ((char, u32),)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + ((char, u32),), + >::new_unchecked(self.tuple_result) + } + } pub async fn call_tuple_result( &self, mut store: S, @@ -1085,17 +1100,22 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - ((char, u32),), - >::new_unchecked(self.tuple_result) - }; + let callee = self.func_tuple_result(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .await?; Ok(ret0) } + pub fn func_empty_arg( + &self, + ) -> wasmtime::component::TypedFunc<(Empty,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (Empty,), + (), + >::new_unchecked(self.empty_arg) + } + } pub async fn call_empty_arg( &self, mut store: S, @@ -1104,17 +1124,22 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (Empty,), - (), - >::new_unchecked(self.empty_arg) - }; + let callee = self.func_empty_arg(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .await?; Ok(()) } + pub fn func_empty_result( + &self, + ) -> wasmtime::component::TypedFunc<(), (Empty,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (Empty,), + >::new_unchecked(self.empty_result) + } + } pub async fn call_empty_result( &self, mut store: S, @@ -1122,17 +1147,22 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (Empty,), - >::new_unchecked(self.empty_result) - }; + let callee = self.func_empty_result(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .await?; Ok(ret0) } + pub fn func_scalar_arg( + &self, + ) -> wasmtime::component::TypedFunc<(Scalars,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (Scalars,), + (), + >::new_unchecked(self.scalar_arg) + } + } pub async fn call_scalar_arg( &self, mut store: S, @@ -1141,17 +1171,22 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (Scalars,), - (), - >::new_unchecked(self.scalar_arg) - }; + let callee = self.func_scalar_arg(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .await?; Ok(()) } + pub fn func_scalar_result( + &self, + ) -> wasmtime::component::TypedFunc<(), (Scalars,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (Scalars,), + >::new_unchecked(self.scalar_result) + } + } pub async fn call_scalar_result( &self, mut store: S, @@ -1159,17 +1194,22 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (Scalars,), - >::new_unchecked(self.scalar_result) - }; + let callee = self.func_scalar_result(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .await?; Ok(ret0) } + pub fn func_flags_arg( + &self, + ) -> wasmtime::component::TypedFunc<(ReallyFlags,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (ReallyFlags,), + (), + >::new_unchecked(self.flags_arg) + } + } pub async fn call_flags_arg( &self, mut store: S, @@ -1178,17 +1218,22 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (ReallyFlags,), - (), - >::new_unchecked(self.flags_arg) - }; + let callee = self.func_flags_arg(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .await?; Ok(()) } + pub fn func_flags_result( + &self, + ) -> wasmtime::component::TypedFunc<(), (ReallyFlags,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (ReallyFlags,), + >::new_unchecked(self.flags_result) + } + } pub async fn call_flags_result( &self, mut store: S, @@ -1196,17 +1241,22 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (ReallyFlags,), - >::new_unchecked(self.flags_result) - }; + let callee = self.func_flags_result(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .await?; Ok(ret0) } + pub fn func_aggregate_arg( + &self, + ) -> wasmtime::component::TypedFunc<(&Aggregates,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (&Aggregates,), + (), + >::new_unchecked(self.aggregate_arg) + } + } pub async fn call_aggregate_arg( &self, mut store: S, @@ -1215,17 +1265,22 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (&Aggregates,), - (), - >::new_unchecked(self.aggregate_arg) - }; + let callee = self.func_aggregate_arg(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .await?; Ok(()) } + pub fn func_aggregate_result( + &self, + ) -> wasmtime::component::TypedFunc<(), (Aggregates,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (Aggregates,), + >::new_unchecked(self.aggregate_result) + } + } pub async fn call_aggregate_result( &self, mut store: S, @@ -1233,17 +1288,22 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (Aggregates,), - >::new_unchecked(self.aggregate_result) - }; + let callee = self.func_aggregate_result(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .await?; Ok(ret0) } + pub fn func_typedef_inout( + &self, + ) -> wasmtime::component::TypedFunc<(TupleTypedef2,), (i32,)> { + unsafe { + wasmtime::component::TypedFunc::< + (TupleTypedef2,), + (i32,), + >::new_unchecked(self.typedef_inout) + } + } pub async fn call_typedef_inout( &self, mut store: S, @@ -1252,12 +1312,7 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (TupleTypedef2,), - (i32,), - >::new_unchecked(self.typedef_inout) - }; + let callee = self.func_typedef_inout(); let (ret0,) = callee .call_async(store.as_context_mut(), (arg0,)) .await?; diff --git a/crates/component-macro/tests/expanded/records_concurrent.rs b/crates/component-macro/tests/expanded/records_concurrent.rs index 2a2f793f7f20..3620f72fa63c 100644 --- a/crates/component-macro/tests/expanded/records_concurrent.rs +++ b/crates/component-macro/tests/expanded/records_concurrent.rs @@ -992,6 +992,16 @@ pub mod exports { } } impl Guest { + pub fn func_tuple_arg( + &self, + ) -> wasmtime::component::TypedFunc<((char, u32),), ()> { + unsafe { + wasmtime::component::TypedFunc::< + ((char, u32),), + (), + >::new_unchecked(self.tuple_arg) + } + } pub async fn call_tuple_arg<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -1001,15 +1011,20 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - ((char, u32),), - (), - >::new_unchecked(self.tuple_arg) - }; + let callee = self.func_tuple_arg(); let () = callee.call_concurrent(accessor, (arg0,)).await?; Ok(()) } + pub fn func_tuple_result( + &self, + ) -> wasmtime::component::TypedFunc<(), ((char, u32),)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + ((char, u32),), + >::new_unchecked(self.tuple_result) + } + } pub async fn call_tuple_result<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -1018,15 +1033,20 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - ((char, u32),), - >::new_unchecked(self.tuple_result) - }; + let callee = self.func_tuple_result(); let (ret0,) = callee.call_concurrent(accessor, ()).await?; Ok(ret0) } + pub fn func_empty_arg( + &self, + ) -> wasmtime::component::TypedFunc<(Empty,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (Empty,), + (), + >::new_unchecked(self.empty_arg) + } + } pub async fn call_empty_arg<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -1036,15 +1056,20 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (Empty,), - (), - >::new_unchecked(self.empty_arg) - }; + let callee = self.func_empty_arg(); let () = callee.call_concurrent(accessor, (arg0,)).await?; Ok(()) } + pub fn func_empty_result( + &self, + ) -> wasmtime::component::TypedFunc<(), (Empty,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (Empty,), + >::new_unchecked(self.empty_result) + } + } pub async fn call_empty_result<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -1053,15 +1078,20 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (Empty,), - >::new_unchecked(self.empty_result) - }; + let callee = self.func_empty_result(); let (ret0,) = callee.call_concurrent(accessor, ()).await?; Ok(ret0) } + pub fn func_scalar_arg( + &self, + ) -> wasmtime::component::TypedFunc<(Scalars,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (Scalars,), + (), + >::new_unchecked(self.scalar_arg) + } + } pub async fn call_scalar_arg<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -1071,15 +1101,20 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (Scalars,), - (), - >::new_unchecked(self.scalar_arg) - }; + let callee = self.func_scalar_arg(); let () = callee.call_concurrent(accessor, (arg0,)).await?; Ok(()) } + pub fn func_scalar_result( + &self, + ) -> wasmtime::component::TypedFunc<(), (Scalars,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (Scalars,), + >::new_unchecked(self.scalar_result) + } + } pub async fn call_scalar_result<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -1088,15 +1123,20 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (Scalars,), - >::new_unchecked(self.scalar_result) - }; + let callee = self.func_scalar_result(); let (ret0,) = callee.call_concurrent(accessor, ()).await?; Ok(ret0) } + pub fn func_flags_arg( + &self, + ) -> wasmtime::component::TypedFunc<(ReallyFlags,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (ReallyFlags,), + (), + >::new_unchecked(self.flags_arg) + } + } pub async fn call_flags_arg<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -1106,15 +1146,20 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (ReallyFlags,), - (), - >::new_unchecked(self.flags_arg) - }; + let callee = self.func_flags_arg(); let () = callee.call_concurrent(accessor, (arg0,)).await?; Ok(()) } + pub fn func_flags_result( + &self, + ) -> wasmtime::component::TypedFunc<(), (ReallyFlags,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (ReallyFlags,), + >::new_unchecked(self.flags_result) + } + } pub async fn call_flags_result<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -1123,15 +1168,20 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (ReallyFlags,), - >::new_unchecked(self.flags_result) - }; + let callee = self.func_flags_result(); let (ret0,) = callee.call_concurrent(accessor, ()).await?; Ok(ret0) } + pub fn func_aggregate_arg( + &self, + ) -> wasmtime::component::TypedFunc<(Aggregates,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (Aggregates,), + (), + >::new_unchecked(self.aggregate_arg) + } + } pub async fn call_aggregate_arg<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -1141,15 +1191,20 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (Aggregates,), - (), - >::new_unchecked(self.aggregate_arg) - }; + let callee = self.func_aggregate_arg(); let () = callee.call_concurrent(accessor, (arg0,)).await?; Ok(()) } + pub fn func_aggregate_result( + &self, + ) -> wasmtime::component::TypedFunc<(), (Aggregates,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (Aggregates,), + >::new_unchecked(self.aggregate_result) + } + } pub async fn call_aggregate_result<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -1158,15 +1213,20 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (Aggregates,), - >::new_unchecked(self.aggregate_result) - }; + let callee = self.func_aggregate_result(); let (ret0,) = callee.call_concurrent(accessor, ()).await?; Ok(ret0) } + pub fn func_typedef_inout( + &self, + ) -> wasmtime::component::TypedFunc<(TupleTypedef2,), (i32,)> { + unsafe { + wasmtime::component::TypedFunc::< + (TupleTypedef2,), + (i32,), + >::new_unchecked(self.typedef_inout) + } + } pub async fn call_typedef_inout<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -1176,12 +1236,7 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (TupleTypedef2,), - (i32,), - >::new_unchecked(self.typedef_inout) - }; + let callee = self.func_typedef_inout(); let (ret0,) = callee.call_concurrent(accessor, (arg0,)).await?; Ok(ret0) } diff --git a/crates/component-macro/tests/expanded/records_tracing_async.rs b/crates/component-macro/tests/expanded/records_tracing_async.rs index 499fa9a11873..8ae2ad42eed7 100644 --- a/crates/component-macro/tests/expanded/records_tracing_async.rs +++ b/crates/component-macro/tests/expanded/records_tracing_async.rs @@ -1220,6 +1220,16 @@ pub mod exports { } } impl Guest { + pub fn func_tuple_arg( + &self, + ) -> wasmtime::component::TypedFunc<((char, u32),), ()> { + unsafe { + wasmtime::component::TypedFunc::< + ((char, u32),), + (), + >::new_unchecked(self.tuple_arg) + } + } pub async fn call_tuple_arg( &self, mut store: S, @@ -1233,18 +1243,23 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/records", function = "tuple-arg", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - ((char, u32),), - (), - >::new_unchecked(self.tuple_arg) - }; + let callee = self.func_tuple_arg(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .instrument(span.clone()) .await?; Ok(()) } + pub fn func_tuple_result( + &self, + ) -> wasmtime::component::TypedFunc<(), ((char, u32),)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + ((char, u32),), + >::new_unchecked(self.tuple_result) + } + } pub async fn call_tuple_result( &self, mut store: S, @@ -1257,18 +1272,23 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/records", function = "tuple-result", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - ((char, u32),), - >::new_unchecked(self.tuple_result) - }; + let callee = self.func_tuple_result(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) .await?; Ok(ret0) } + pub fn func_empty_arg( + &self, + ) -> wasmtime::component::TypedFunc<(Empty,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (Empty,), + (), + >::new_unchecked(self.empty_arg) + } + } pub async fn call_empty_arg( &self, mut store: S, @@ -1282,18 +1302,23 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/records", function = "empty-arg", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (Empty,), - (), - >::new_unchecked(self.empty_arg) - }; + let callee = self.func_empty_arg(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .instrument(span.clone()) .await?; Ok(()) } + pub fn func_empty_result( + &self, + ) -> wasmtime::component::TypedFunc<(), (Empty,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (Empty,), + >::new_unchecked(self.empty_result) + } + } pub async fn call_empty_result( &self, mut store: S, @@ -1306,18 +1331,23 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/records", function = "empty-result", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (Empty,), - >::new_unchecked(self.empty_result) - }; + let callee = self.func_empty_result(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) .await?; Ok(ret0) } + pub fn func_scalar_arg( + &self, + ) -> wasmtime::component::TypedFunc<(Scalars,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (Scalars,), + (), + >::new_unchecked(self.scalar_arg) + } + } pub async fn call_scalar_arg( &self, mut store: S, @@ -1331,18 +1361,23 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/records", function = "scalar-arg", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (Scalars,), - (), - >::new_unchecked(self.scalar_arg) - }; + let callee = self.func_scalar_arg(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .instrument(span.clone()) .await?; Ok(()) } + pub fn func_scalar_result( + &self, + ) -> wasmtime::component::TypedFunc<(), (Scalars,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (Scalars,), + >::new_unchecked(self.scalar_result) + } + } pub async fn call_scalar_result( &self, mut store: S, @@ -1355,18 +1390,23 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/records", function = "scalar-result", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (Scalars,), - >::new_unchecked(self.scalar_result) - }; + let callee = self.func_scalar_result(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) .await?; Ok(ret0) } + pub fn func_flags_arg( + &self, + ) -> wasmtime::component::TypedFunc<(ReallyFlags,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (ReallyFlags,), + (), + >::new_unchecked(self.flags_arg) + } + } pub async fn call_flags_arg( &self, mut store: S, @@ -1380,18 +1420,23 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/records", function = "flags-arg", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (ReallyFlags,), - (), - >::new_unchecked(self.flags_arg) - }; + let callee = self.func_flags_arg(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .instrument(span.clone()) .await?; Ok(()) } + pub fn func_flags_result( + &self, + ) -> wasmtime::component::TypedFunc<(), (ReallyFlags,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (ReallyFlags,), + >::new_unchecked(self.flags_result) + } + } pub async fn call_flags_result( &self, mut store: S, @@ -1404,18 +1449,23 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/records", function = "flags-result", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (ReallyFlags,), - >::new_unchecked(self.flags_result) - }; + let callee = self.func_flags_result(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) .await?; Ok(ret0) } + pub fn func_aggregate_arg( + &self, + ) -> wasmtime::component::TypedFunc<(&Aggregates,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (&Aggregates,), + (), + >::new_unchecked(self.aggregate_arg) + } + } pub async fn call_aggregate_arg( &self, mut store: S, @@ -1429,18 +1479,23 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/records", function = "aggregate-arg", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (&Aggregates,), - (), - >::new_unchecked(self.aggregate_arg) - }; + let callee = self.func_aggregate_arg(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .instrument(span.clone()) .await?; Ok(()) } + pub fn func_aggregate_result( + &self, + ) -> wasmtime::component::TypedFunc<(), (Aggregates,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (Aggregates,), + >::new_unchecked(self.aggregate_result) + } + } pub async fn call_aggregate_result( &self, mut store: S, @@ -1453,18 +1508,23 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/records", function = "aggregate-result", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (Aggregates,), - >::new_unchecked(self.aggregate_result) - }; + let callee = self.func_aggregate_result(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) .await?; Ok(ret0) } + pub fn func_typedef_inout( + &self, + ) -> wasmtime::component::TypedFunc<(TupleTypedef2,), (i32,)> { + unsafe { + wasmtime::component::TypedFunc::< + (TupleTypedef2,), + (i32,), + >::new_unchecked(self.typedef_inout) + } + } pub async fn call_typedef_inout( &self, mut store: S, @@ -1478,12 +1538,7 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/records", function = "typedef-inout", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (TupleTypedef2,), - (i32,), - >::new_unchecked(self.typedef_inout) - }; + let callee = self.func_typedef_inout(); let (ret0,) = callee .call_async(store.as_context_mut(), (arg0,)) .instrument(span.clone()) diff --git a/crates/component-macro/tests/expanded/resources-export.rs b/crates/component-macro/tests/expanded/resources-export.rs index 2ac0d09fe866..7bd7a26b3cc8 100644 --- a/crates/component-macro/tests/expanded/resources-export.rs +++ b/crates/component-macro/tests/expanded/resources-export.rs @@ -400,43 +400,64 @@ pub mod exports { } } impl GuestA<'_> { - pub fn call_constructor( + pub fn func_constructor( &self, - mut store: S, - ) -> wasmtime::Result { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::ResourceAny,), + > { + unsafe { wasmtime::component::TypedFunc::< (), (wasmtime::component::ResourceAny,), >::new_unchecked(self.funcs.constructor_a_constructor) - }; + } + } + pub fn call_constructor( + &self, + mut store: S, + ) -> wasmtime::Result { + let callee = self.func_constructor(); let (ret0,) = callee.call(store.as_context_mut(), ())?; Ok(ret0) } - pub fn call_static_a( + pub fn func_static_a( &self, - mut store: S, - ) -> wasmtime::Result { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc<(), (u32,)> { + unsafe { wasmtime::component::TypedFunc::< (), (u32,), >::new_unchecked(self.funcs.static_a_static_a) - }; - let (ret0,) = callee.call(store.as_context_mut(), ())?; - Ok(ret0) + } } - pub fn call_method_a( + pub fn call_static_a( &self, mut store: S, - arg0: wasmtime::component::ResourceAny, ) -> wasmtime::Result { - let callee = unsafe { + let callee = self.func_static_a(); + let (ret0,) = callee.call(store.as_context_mut(), ())?; + Ok(ret0) + } + pub fn func_method_a( + &self, + ) -> wasmtime::component::TypedFunc< + (wasmtime::component::ResourceAny,), + (u32,), + > { + unsafe { wasmtime::component::TypedFunc::< (wasmtime::component::ResourceAny,), (u32,), >::new_unchecked(self.funcs.method_a_method_a) - }; + } + } + pub fn call_method_a( + &self, + mut store: S, + arg0: wasmtime::component::ResourceAny, + ) -> wasmtime::Result { + let callee = self.func_method_a(); let (ret0,) = callee.call(store.as_context_mut(), (arg0,))?; Ok(ret0) } @@ -546,40 +567,59 @@ pub mod exports { } } impl GuestA<'_> { - pub fn call_constructor( + pub fn func_constructor( &self, - mut store: S, - arg0: wasmtime::component::Resource, - ) -> wasmtime::Result { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc< + (wasmtime::component::Resource,), + (wasmtime::component::ResourceAny,), + > { + unsafe { wasmtime::component::TypedFunc::< (wasmtime::component::Resource,), (wasmtime::component::ResourceAny,), >::new_unchecked(self.funcs.constructor_a_constructor) - }; + } + } + pub fn call_constructor( + &self, + mut store: S, + arg0: wasmtime::component::Resource, + ) -> wasmtime::Result { + let callee = self.func_constructor(); let (ret0,) = callee.call(store.as_context_mut(), (arg0,))?; Ok(ret0) } - pub fn call_static_a( + pub fn func_static_a( &self, - mut store: S, - ) -> wasmtime::Result> { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::Resource,), + > { + unsafe { wasmtime::component::TypedFunc::< (), (wasmtime::component::Resource,), >::new_unchecked(self.funcs.static_a_static_a) - }; - let (ret0,) = callee.call(store.as_context_mut(), ())?; - Ok(ret0) + } } - pub fn call_method_a( + pub fn call_static_a( &self, mut store: S, - arg0: wasmtime::component::ResourceAny, - arg1: wasmtime::component::Resource, ) -> wasmtime::Result> { - let callee = unsafe { + let callee = self.func_static_a(); + let (ret0,) = callee.call(store.as_context_mut(), ())?; + Ok(ret0) + } + pub fn func_method_a( + &self, + ) -> wasmtime::component::TypedFunc< + ( + wasmtime::component::ResourceAny, + wasmtime::component::Resource, + ), + (wasmtime::component::Resource,), + > { + unsafe { wasmtime::component::TypedFunc::< ( wasmtime::component::ResourceAny, @@ -587,7 +627,15 @@ pub mod exports { ), (wasmtime::component::Resource,), >::new_unchecked(self.funcs.method_a_method_a) - }; + } + } + pub fn call_method_a( + &self, + mut store: S, + arg0: wasmtime::component::ResourceAny, + arg1: wasmtime::component::Resource, + ) -> wasmtime::Result> { + let callee = self.func_method_a(); let (ret0,) = callee.call(store.as_context_mut(), (arg0, arg1))?; Ok(ret0) } @@ -669,16 +717,24 @@ pub mod exports { } } impl GuestA<'_> { - pub fn call_constructor( + pub fn func_constructor( &self, - mut store: S, - ) -> wasmtime::Result { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::ResourceAny,), + > { + unsafe { wasmtime::component::TypedFunc::< (), (wasmtime::component::ResourceAny,), >::new_unchecked(self.funcs.constructor_a_constructor) - }; + } + } + pub fn call_constructor( + &self, + mut store: S, + ) -> wasmtime::Result { + let callee = self.func_constructor(); let (ret0,) = callee.call(store.as_context_mut(), ())?; Ok(ret0) } @@ -761,17 +817,25 @@ pub mod exports { } } impl GuestB<'_> { - pub fn call_constructor( + pub fn func_constructor( &self, - mut store: S, - arg0: wasmtime::component::ResourceAny, - ) -> wasmtime::Result { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc< + (wasmtime::component::ResourceAny,), + (wasmtime::component::ResourceAny,), + > { + unsafe { wasmtime::component::TypedFunc::< (wasmtime::component::ResourceAny,), (wasmtime::component::ResourceAny,), >::new_unchecked(self.funcs.constructor_b_constructor) - }; + } + } + pub fn call_constructor( + &self, + mut store: S, + arg0: wasmtime::component::ResourceAny, + ) -> wasmtime::Result { + let callee = self.func_constructor(); let (ret0,) = callee.call(store.as_context_mut(), (arg0,))?; Ok(ret0) } diff --git a/crates/component-macro/tests/expanded/resources-export_async.rs b/crates/component-macro/tests/expanded/resources-export_async.rs index 29eeda6d5e6b..ed6827f8bfb7 100644 --- a/crates/component-macro/tests/expanded/resources-export_async.rs +++ b/crates/component-macro/tests/expanded/resources-export_async.rs @@ -405,6 +405,19 @@ pub mod exports { } } impl GuestA<'_> { + pub fn func_constructor( + &self, + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::ResourceAny,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (), + (wasmtime::component::ResourceAny,), + >::new_unchecked(self.funcs.constructor_a_constructor) + } + } pub async fn call_constructor( &self, mut store: S, @@ -412,17 +425,22 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (wasmtime::component::ResourceAny,), - >::new_unchecked(self.funcs.constructor_a_constructor) - }; + let callee = self.func_constructor(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .await?; Ok(ret0) } + pub fn func_static_a( + &self, + ) -> wasmtime::component::TypedFunc<(), (u32,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (u32,), + >::new_unchecked(self.funcs.static_a_static_a) + } + } pub async fn call_static_a( &self, mut store: S, @@ -430,17 +448,25 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (u32,), - >::new_unchecked(self.funcs.static_a_static_a) - }; + let callee = self.func_static_a(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .await?; Ok(ret0) } + pub fn func_method_a( + &self, + ) -> wasmtime::component::TypedFunc< + (wasmtime::component::ResourceAny,), + (u32,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (wasmtime::component::ResourceAny,), + (u32,), + >::new_unchecked(self.funcs.method_a_method_a) + } + } pub async fn call_method_a( &self, mut store: S, @@ -449,12 +475,7 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (wasmtime::component::ResourceAny,), - (u32,), - >::new_unchecked(self.funcs.method_a_method_a) - }; + let callee = self.func_method_a(); let (ret0,) = callee .call_async(store.as_context_mut(), (arg0,)) .await?; @@ -566,6 +587,19 @@ pub mod exports { } } impl GuestA<'_> { + pub fn func_constructor( + &self, + ) -> wasmtime::component::TypedFunc< + (wasmtime::component::Resource,), + (wasmtime::component::ResourceAny,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (wasmtime::component::Resource,), + (wasmtime::component::ResourceAny,), + >::new_unchecked(self.funcs.constructor_a_constructor) + } + } pub async fn call_constructor( &self, mut store: S, @@ -574,17 +608,25 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (wasmtime::component::Resource,), - (wasmtime::component::ResourceAny,), - >::new_unchecked(self.funcs.constructor_a_constructor) - }; + let callee = self.func_constructor(); let (ret0,) = callee .call_async(store.as_context_mut(), (arg0,)) .await?; Ok(ret0) } + pub fn func_static_a( + &self, + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::Resource,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (), + (wasmtime::component::Resource,), + >::new_unchecked(self.funcs.static_a_static_a) + } + } pub async fn call_static_a( &self, mut store: S, @@ -592,17 +634,31 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (wasmtime::component::Resource,), - >::new_unchecked(self.funcs.static_a_static_a) - }; + let callee = self.func_static_a(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .await?; Ok(ret0) } + pub fn func_method_a( + &self, + ) -> wasmtime::component::TypedFunc< + ( + wasmtime::component::ResourceAny, + wasmtime::component::Resource, + ), + (wasmtime::component::Resource,), + > { + unsafe { + wasmtime::component::TypedFunc::< + ( + wasmtime::component::ResourceAny, + wasmtime::component::Resource, + ), + (wasmtime::component::Resource,), + >::new_unchecked(self.funcs.method_a_method_a) + } + } pub async fn call_method_a( &self, mut store: S, @@ -612,15 +668,7 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - ( - wasmtime::component::ResourceAny, - wasmtime::component::Resource, - ), - (wasmtime::component::Resource,), - >::new_unchecked(self.funcs.method_a_method_a) - }; + let callee = self.func_method_a(); let (ret0,) = callee .call_async(store.as_context_mut(), (arg0, arg1)) .await?; @@ -704,6 +752,19 @@ pub mod exports { } } impl GuestA<'_> { + pub fn func_constructor( + &self, + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::ResourceAny,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (), + (wasmtime::component::ResourceAny,), + >::new_unchecked(self.funcs.constructor_a_constructor) + } + } pub async fn call_constructor( &self, mut store: S, @@ -711,12 +772,7 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (wasmtime::component::ResourceAny,), - >::new_unchecked(self.funcs.constructor_a_constructor) - }; + let callee = self.func_constructor(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .await?; @@ -801,6 +857,19 @@ pub mod exports { } } impl GuestB<'_> { + pub fn func_constructor( + &self, + ) -> wasmtime::component::TypedFunc< + (wasmtime::component::ResourceAny,), + (wasmtime::component::ResourceAny,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (wasmtime::component::ResourceAny,), + (wasmtime::component::ResourceAny,), + >::new_unchecked(self.funcs.constructor_b_constructor) + } + } pub async fn call_constructor( &self, mut store: S, @@ -809,12 +878,7 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (wasmtime::component::ResourceAny,), - (wasmtime::component::ResourceAny,), - >::new_unchecked(self.funcs.constructor_b_constructor) - }; + let callee = self.func_constructor(); let (ret0,) = callee .call_async(store.as_context_mut(), (arg0,)) .await?; diff --git a/crates/component-macro/tests/expanded/resources-export_concurrent.rs b/crates/component-macro/tests/expanded/resources-export_concurrent.rs index 1be725a1c592..5cd1422d0981 100644 --- a/crates/component-macro/tests/expanded/resources-export_concurrent.rs +++ b/crates/component-macro/tests/expanded/resources-export_concurrent.rs @@ -397,6 +397,19 @@ pub mod exports { } } impl GuestA<'_> { + pub fn func_constructor( + &self, + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::ResourceAny,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (), + (wasmtime::component::ResourceAny,), + >::new_unchecked(self.funcs.constructor_a_constructor) + } + } pub async fn call_constructor<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -405,15 +418,20 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (wasmtime::component::ResourceAny,), - >::new_unchecked(self.funcs.constructor_a_constructor) - }; + let callee = self.func_constructor(); let (ret0,) = callee.call_concurrent(accessor, ()).await?; Ok(ret0) } + pub fn func_static_a( + &self, + ) -> wasmtime::component::TypedFunc<(), (u32,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (u32,), + >::new_unchecked(self.funcs.static_a_static_a) + } + } pub async fn call_static_a<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -422,15 +440,23 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (u32,), - >::new_unchecked(self.funcs.static_a_static_a) - }; + let callee = self.func_static_a(); let (ret0,) = callee.call_concurrent(accessor, ()).await?; Ok(ret0) } + pub fn func_method_a( + &self, + ) -> wasmtime::component::TypedFunc< + (wasmtime::component::ResourceAny,), + (u32,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (wasmtime::component::ResourceAny,), + (u32,), + >::new_unchecked(self.funcs.method_a_method_a) + } + } pub async fn call_method_a<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -440,12 +466,7 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (wasmtime::component::ResourceAny,), - (u32,), - >::new_unchecked(self.funcs.method_a_method_a) - }; + let callee = self.func_method_a(); let (ret0,) = callee.call_concurrent(accessor, (arg0,)).await?; Ok(ret0) } @@ -555,6 +576,19 @@ pub mod exports { } } impl GuestA<'_> { + pub fn func_constructor( + &self, + ) -> wasmtime::component::TypedFunc< + (wasmtime::component::Resource,), + (wasmtime::component::ResourceAny,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (wasmtime::component::Resource,), + (wasmtime::component::ResourceAny,), + >::new_unchecked(self.funcs.constructor_a_constructor) + } + } pub async fn call_constructor<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -564,15 +598,23 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (wasmtime::component::Resource,), - (wasmtime::component::ResourceAny,), - >::new_unchecked(self.funcs.constructor_a_constructor) - }; + let callee = self.func_constructor(); let (ret0,) = callee.call_concurrent(accessor, (arg0,)).await?; Ok(ret0) } + pub fn func_static_a( + &self, + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::Resource,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (), + (wasmtime::component::Resource,), + >::new_unchecked(self.funcs.static_a_static_a) + } + } pub async fn call_static_a<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -581,15 +623,29 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (wasmtime::component::Resource,), - >::new_unchecked(self.funcs.static_a_static_a) - }; + let callee = self.func_static_a(); let (ret0,) = callee.call_concurrent(accessor, ()).await?; Ok(ret0) } + pub fn func_method_a( + &self, + ) -> wasmtime::component::TypedFunc< + ( + wasmtime::component::ResourceAny, + wasmtime::component::Resource, + ), + (wasmtime::component::Resource,), + > { + unsafe { + wasmtime::component::TypedFunc::< + ( + wasmtime::component::ResourceAny, + wasmtime::component::Resource, + ), + (wasmtime::component::Resource,), + >::new_unchecked(self.funcs.method_a_method_a) + } + } pub async fn call_method_a<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -600,15 +656,7 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - ( - wasmtime::component::ResourceAny, - wasmtime::component::Resource, - ), - (wasmtime::component::Resource,), - >::new_unchecked(self.funcs.method_a_method_a) - }; + let callee = self.func_method_a(); let (ret0,) = callee .call_concurrent(accessor, (arg0, arg1)) .await?; @@ -692,6 +740,19 @@ pub mod exports { } } impl GuestA<'_> { + pub fn func_constructor( + &self, + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::ResourceAny,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (), + (wasmtime::component::ResourceAny,), + >::new_unchecked(self.funcs.constructor_a_constructor) + } + } pub async fn call_constructor<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -700,12 +761,7 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (wasmtime::component::ResourceAny,), - >::new_unchecked(self.funcs.constructor_a_constructor) - }; + let callee = self.func_constructor(); let (ret0,) = callee.call_concurrent(accessor, ()).await?; Ok(ret0) } @@ -788,6 +844,19 @@ pub mod exports { } } impl GuestB<'_> { + pub fn func_constructor( + &self, + ) -> wasmtime::component::TypedFunc< + (wasmtime::component::ResourceAny,), + (wasmtime::component::ResourceAny,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (wasmtime::component::ResourceAny,), + (wasmtime::component::ResourceAny,), + >::new_unchecked(self.funcs.constructor_b_constructor) + } + } pub async fn call_constructor<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -797,12 +866,7 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (wasmtime::component::ResourceAny,), - (wasmtime::component::ResourceAny,), - >::new_unchecked(self.funcs.constructor_b_constructor) - }; + let callee = self.func_constructor(); let (ret0,) = callee.call_concurrent(accessor, (arg0,)).await?; Ok(ret0) } diff --git a/crates/component-macro/tests/expanded/resources-export_tracing_async.rs b/crates/component-macro/tests/expanded/resources-export_tracing_async.rs index 7b69542c17af..0cd9123ad67c 100644 --- a/crates/component-macro/tests/expanded/resources-export_tracing_async.rs +++ b/crates/component-macro/tests/expanded/resources-export_tracing_async.rs @@ -405,6 +405,19 @@ pub mod exports { } } impl GuestA<'_> { + pub fn func_constructor( + &self, + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::ResourceAny,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (), + (wasmtime::component::ResourceAny,), + >::new_unchecked(self.funcs.constructor_a_constructor) + } + } pub async fn call_constructor( &self, mut store: S, @@ -417,18 +430,23 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/simple-export", function = "[constructor]a", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (wasmtime::component::ResourceAny,), - >::new_unchecked(self.funcs.constructor_a_constructor) - }; + let callee = self.func_constructor(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) .await?; Ok(ret0) } + pub fn func_static_a( + &self, + ) -> wasmtime::component::TypedFunc<(), (u32,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (u32,), + >::new_unchecked(self.funcs.static_a_static_a) + } + } pub async fn call_static_a( &self, mut store: S, @@ -441,18 +459,26 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/simple-export", function = "[static]a.static-a", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (u32,), - >::new_unchecked(self.funcs.static_a_static_a) - }; + let callee = self.func_static_a(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) .await?; Ok(ret0) } + pub fn func_method_a( + &self, + ) -> wasmtime::component::TypedFunc< + (wasmtime::component::ResourceAny,), + (u32,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (wasmtime::component::ResourceAny,), + (u32,), + >::new_unchecked(self.funcs.method_a_method_a) + } + } pub async fn call_method_a( &self, mut store: S, @@ -466,12 +492,7 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/simple-export", function = "[method]a.method-a", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (wasmtime::component::ResourceAny,), - (u32,), - >::new_unchecked(self.funcs.method_a_method_a) - }; + let callee = self.func_method_a(); let (ret0,) = callee .call_async(store.as_context_mut(), (arg0,)) .instrument(span.clone()) @@ -584,6 +605,19 @@ pub mod exports { } } impl GuestA<'_> { + pub fn func_constructor( + &self, + ) -> wasmtime::component::TypedFunc< + (wasmtime::component::Resource,), + (wasmtime::component::ResourceAny,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (wasmtime::component::Resource,), + (wasmtime::component::ResourceAny,), + >::new_unchecked(self.funcs.constructor_a_constructor) + } + } pub async fn call_constructor( &self, mut store: S, @@ -597,18 +631,26 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/export-using-import", function = "[constructor]a", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (wasmtime::component::Resource,), - (wasmtime::component::ResourceAny,), - >::new_unchecked(self.funcs.constructor_a_constructor) - }; + let callee = self.func_constructor(); let (ret0,) = callee .call_async(store.as_context_mut(), (arg0,)) .instrument(span.clone()) .await?; Ok(ret0) } + pub fn func_static_a( + &self, + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::Resource,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (), + (wasmtime::component::Resource,), + >::new_unchecked(self.funcs.static_a_static_a) + } + } pub async fn call_static_a( &self, mut store: S, @@ -622,18 +664,32 @@ pub mod exports { "foo:foo/export-using-import", function = "[static]a.static-a", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (wasmtime::component::Resource,), - >::new_unchecked(self.funcs.static_a_static_a) - }; + let callee = self.func_static_a(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) .await?; Ok(ret0) } + pub fn func_method_a( + &self, + ) -> wasmtime::component::TypedFunc< + ( + wasmtime::component::ResourceAny, + wasmtime::component::Resource, + ), + (wasmtime::component::Resource,), + > { + unsafe { + wasmtime::component::TypedFunc::< + ( + wasmtime::component::ResourceAny, + wasmtime::component::Resource, + ), + (wasmtime::component::Resource,), + >::new_unchecked(self.funcs.method_a_method_a) + } + } pub async fn call_method_a( &self, mut store: S, @@ -649,15 +705,7 @@ pub mod exports { "foo:foo/export-using-import", function = "[method]a.method-a", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - ( - wasmtime::component::ResourceAny, - wasmtime::component::Resource, - ), - (wasmtime::component::Resource,), - >::new_unchecked(self.funcs.method_a_method_a) - }; + let callee = self.func_method_a(); let (ret0,) = callee .call_async(store.as_context_mut(), (arg0, arg1)) .instrument(span.clone()) @@ -742,6 +790,19 @@ pub mod exports { } } impl GuestA<'_> { + pub fn func_constructor( + &self, + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::ResourceAny,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (), + (wasmtime::component::ResourceAny,), + >::new_unchecked(self.funcs.constructor_a_constructor) + } + } pub async fn call_constructor( &self, mut store: S, @@ -754,12 +815,7 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/export-using-export1", function = "[constructor]a", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (wasmtime::component::ResourceAny,), - >::new_unchecked(self.funcs.constructor_a_constructor) - }; + let callee = self.func_constructor(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) @@ -845,6 +901,19 @@ pub mod exports { } } impl GuestB<'_> { + pub fn func_constructor( + &self, + ) -> wasmtime::component::TypedFunc< + (wasmtime::component::ResourceAny,), + (wasmtime::component::ResourceAny,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (wasmtime::component::ResourceAny,), + (wasmtime::component::ResourceAny,), + >::new_unchecked(self.funcs.constructor_b_constructor) + } + } pub async fn call_constructor( &self, mut store: S, @@ -858,12 +927,7 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/export-using-export2", function = "[constructor]b", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (wasmtime::component::ResourceAny,), - (wasmtime::component::ResourceAny,), - >::new_unchecked(self.funcs.constructor_b_constructor) - }; + let callee = self.func_constructor(); let (ret0,) = callee .call_async(store.as_context_mut(), (arg0,)) .instrument(span.clone()) diff --git a/crates/component-macro/tests/expanded/resources-import.rs b/crates/component-macro/tests/expanded/resources-import.rs index 58429f002311..bb1da2e2f227 100644 --- a/crates/component-macro/tests/expanded/resources-import.rs +++ b/crates/component-macro/tests/expanded/resources-import.rs @@ -351,16 +351,24 @@ const _: () = { >(linker, host_getter)?; Ok(()) } - pub fn call_some_world_func2( + pub fn func_some_world_func2( &self, - mut store: S, - ) -> wasmtime::Result> { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::Resource,), + > { + unsafe { wasmtime::component::TypedFunc::< (), (wasmtime::component::Resource,), >::new_unchecked(self.some_world_func2) - }; + } + } + pub fn call_some_world_func2( + &self, + mut store: S, + ) -> wasmtime::Result> { + let callee = self.func_some_world_func2(); let (ret0,) = callee.call(store.as_context_mut(), ())?; Ok(ret0) } @@ -1274,17 +1282,25 @@ pub mod exports { } } impl Guest { - pub fn call_handle( + pub fn func_handle( &self, - mut store: S, - arg0: wasmtime::component::Resource, - ) -> wasmtime::Result<()> { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc< + (wasmtime::component::Resource,), + (), + > { + unsafe { wasmtime::component::TypedFunc::< (wasmtime::component::Resource,), (), >::new_unchecked(self.handle) - }; + } + } + pub fn call_handle( + &self, + mut store: S, + arg0: wasmtime::component::Resource, + ) -> wasmtime::Result<()> { + let callee = self.func_handle(); let () = callee.call(store.as_context_mut(), (arg0,))?; Ok(()) } diff --git a/crates/component-macro/tests/expanded/resources-import_async.rs b/crates/component-macro/tests/expanded/resources-import_async.rs index ac93b576f0e5..bb40ecf54304 100644 --- a/crates/component-macro/tests/expanded/resources-import_async.rs +++ b/crates/component-macro/tests/expanded/resources-import_async.rs @@ -384,6 +384,19 @@ const _: () = { >(linker, host_getter)?; Ok(()) } + pub fn func_some_world_func2( + &self, + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::Resource,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (), + (wasmtime::component::Resource,), + >::new_unchecked(self.some_world_func2) + } + } pub async fn call_some_world_func2( &self, mut store: S, @@ -391,12 +404,7 @@ const _: () = { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (wasmtime::component::Resource,), - >::new_unchecked(self.some_world_func2) - }; + let callee = self.func_some_world_func2(); let (ret0,) = callee.call_async(store.as_context_mut(), ()).await?; Ok(ret0) } @@ -1458,6 +1466,19 @@ pub mod exports { } } impl Guest { + pub fn func_handle( + &self, + ) -> wasmtime::component::TypedFunc< + (wasmtime::component::Resource,), + (), + > { + unsafe { + wasmtime::component::TypedFunc::< + (wasmtime::component::Resource,), + (), + >::new_unchecked(self.handle) + } + } pub async fn call_handle( &self, mut store: S, @@ -1466,12 +1487,7 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (wasmtime::component::Resource,), - (), - >::new_unchecked(self.handle) - }; + let callee = self.func_handle(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .await?; diff --git a/crates/component-macro/tests/expanded/resources-import_concurrent.rs b/crates/component-macro/tests/expanded/resources-import_concurrent.rs index ec1cc84935d8..5f716494af15 100644 --- a/crates/component-macro/tests/expanded/resources-import_concurrent.rs +++ b/crates/component-macro/tests/expanded/resources-import_concurrent.rs @@ -355,6 +355,19 @@ const _: () = { >(linker, host_getter)?; Ok(()) } + pub fn func_some_world_func2( + &self, + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::Resource,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (), + (wasmtime::component::Resource,), + >::new_unchecked(self.some_world_func2) + } + } pub async fn call_some_world_func2<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -363,12 +376,7 @@ const _: () = { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (wasmtime::component::Resource,), - >::new_unchecked(self.some_world_func2) - }; + let callee = self.func_some_world_func2(); let (ret0,) = callee.call_concurrent(accessor, ()).await?; Ok(ret0) } @@ -1242,6 +1250,19 @@ pub mod exports { } } impl Guest { + pub fn func_handle( + &self, + ) -> wasmtime::component::TypedFunc< + (wasmtime::component::Resource,), + (), + > { + unsafe { + wasmtime::component::TypedFunc::< + (wasmtime::component::Resource,), + (), + >::new_unchecked(self.handle) + } + } pub async fn call_handle<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -1251,12 +1272,7 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (wasmtime::component::Resource,), - (), - >::new_unchecked(self.handle) - }; + let callee = self.func_handle(); let () = callee.call_concurrent(accessor, (arg0,)).await?; Ok(()) } diff --git a/crates/component-macro/tests/expanded/resources-import_tracing_async.rs b/crates/component-macro/tests/expanded/resources-import_tracing_async.rs index 86b570e95995..c02b68aef16c 100644 --- a/crates/component-macro/tests/expanded/resources-import_tracing_async.rs +++ b/crates/component-macro/tests/expanded/resources-import_tracing_async.rs @@ -439,6 +439,19 @@ const _: () = { >(linker, host_getter)?; Ok(()) } + pub fn func_some_world_func2( + &self, + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::Resource,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (), + (wasmtime::component::Resource,), + >::new_unchecked(self.some_world_func2) + } + } pub async fn call_some_world_func2( &self, mut store: S, @@ -451,12 +464,7 @@ const _: () = { tracing::Level::TRACE, "wit-bindgen export", module = "default", function = "some-world-func2", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (wasmtime::component::Resource,), - >::new_unchecked(self.some_world_func2) - }; + let callee = self.func_some_world_func2(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) @@ -1875,6 +1883,19 @@ pub mod exports { } } impl Guest { + pub fn func_handle( + &self, + ) -> wasmtime::component::TypedFunc< + (wasmtime::component::Resource,), + (), + > { + unsafe { + wasmtime::component::TypedFunc::< + (wasmtime::component::Resource,), + (), + >::new_unchecked(self.handle) + } + } pub async fn call_handle( &self, mut store: S, @@ -1888,12 +1909,7 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/uses-resource-transitively", function = "handle", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (wasmtime::component::Resource,), - (), - >::new_unchecked(self.handle) - }; + let callee = self.func_handle(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .instrument(span.clone()) diff --git a/crates/component-macro/tests/expanded/share-types.rs b/crates/component-macro/tests/expanded/share-types.rs index 803eaf827860..266e28a08098 100644 --- a/crates/component-macro/tests/expanded/share-types.rs +++ b/crates/component-macro/tests/expanded/share-types.rs @@ -396,17 +396,22 @@ pub mod exports { } } impl Guest { - pub fn call_handle_request( + pub fn func_handle_request( &self, - mut store: S, - arg0: &Request, - ) -> wasmtime::Result { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc<(&Request,), (Response,)> { + unsafe { wasmtime::component::TypedFunc::< (&Request,), (Response,), >::new_unchecked(self.handle_request) - }; + } + } + pub fn call_handle_request( + &self, + mut store: S, + arg0: &Request, + ) -> wasmtime::Result { + let callee = self.func_handle_request(); let (ret0,) = callee.call(store.as_context_mut(), (arg0,))?; Ok(ret0) } diff --git a/crates/component-macro/tests/expanded/share-types_async.rs b/crates/component-macro/tests/expanded/share-types_async.rs index 5e7a390156cb..5cda6052819c 100644 --- a/crates/component-macro/tests/expanded/share-types_async.rs +++ b/crates/component-macro/tests/expanded/share-types_async.rs @@ -404,6 +404,16 @@ pub mod exports { } } impl Guest { + pub fn func_handle_request( + &self, + ) -> wasmtime::component::TypedFunc<(&Request,), (Response,)> { + unsafe { + wasmtime::component::TypedFunc::< + (&Request,), + (Response,), + >::new_unchecked(self.handle_request) + } + } pub async fn call_handle_request( &self, mut store: S, @@ -412,12 +422,7 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (&Request,), - (Response,), - >::new_unchecked(self.handle_request) - }; + let callee = self.func_handle_request(); let (ret0,) = callee.call_async(store.as_context_mut(), (arg0,)).await?; Ok(ret0) } diff --git a/crates/component-macro/tests/expanded/share-types_concurrent.rs b/crates/component-macro/tests/expanded/share-types_concurrent.rs index 47e208013a13..6b963ba07df7 100644 --- a/crates/component-macro/tests/expanded/share-types_concurrent.rs +++ b/crates/component-macro/tests/expanded/share-types_concurrent.rs @@ -393,6 +393,16 @@ pub mod exports { } } impl Guest { + pub fn func_handle_request( + &self, + ) -> wasmtime::component::TypedFunc<(Request,), (Response,)> { + unsafe { + wasmtime::component::TypedFunc::< + (Request,), + (Response,), + >::new_unchecked(self.handle_request) + } + } pub async fn call_handle_request<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -402,12 +412,7 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (Request,), - (Response,), - >::new_unchecked(self.handle_request) - }; + let callee = self.func_handle_request(); let (ret0,) = callee.call_concurrent(accessor, (arg0,)).await?; Ok(ret0) } diff --git a/crates/component-macro/tests/expanded/share-types_tracing_async.rs b/crates/component-macro/tests/expanded/share-types_tracing_async.rs index f3921821c303..2aa73e0b3344 100644 --- a/crates/component-macro/tests/expanded/share-types_tracing_async.rs +++ b/crates/component-macro/tests/expanded/share-types_tracing_async.rs @@ -420,6 +420,16 @@ pub mod exports { } } impl Guest { + pub fn func_handle_request( + &self, + ) -> wasmtime::component::TypedFunc<(&Request,), (Response,)> { + unsafe { + wasmtime::component::TypedFunc::< + (&Request,), + (Response,), + >::new_unchecked(self.handle_request) + } + } pub async fn call_handle_request( &self, mut store: S, @@ -433,12 +443,7 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "http-handler", function = "handle-request", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (&Request,), - (Response,), - >::new_unchecked(self.handle_request) - }; + let callee = self.func_handle_request(); let (ret0,) = callee .call_async(store.as_context_mut(), (arg0,)) .instrument(span.clone()) diff --git a/crates/component-macro/tests/expanded/simple-functions.rs b/crates/component-macro/tests/expanded/simple-functions.rs index e40991e4fee2..9d8443373d9f 100644 --- a/crates/component-macro/tests/expanded/simple-functions.rs +++ b/crates/component-macro/tests/expanded/simple-functions.rs @@ -409,74 +409,106 @@ pub mod exports { } } impl Guest { - pub fn call_f1( - &self, - mut store: S, - ) -> wasmtime::Result<()> { - let callee = unsafe { + pub fn func_f1(&self) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { wasmtime::component::TypedFunc::< (), (), >::new_unchecked(self.f1) - }; - let () = callee.call(store.as_context_mut(), ())?; - Ok(()) + } } - pub fn call_f2( + pub fn call_f1( &self, mut store: S, - arg0: u32, ) -> wasmtime::Result<()> { - let callee = unsafe { + let callee = self.func_f1(); + let () = callee.call(store.as_context_mut(), ())?; + Ok(()) + } + pub fn func_f2(&self) -> wasmtime::component::TypedFunc<(u32,), ()> { + unsafe { wasmtime::component::TypedFunc::< (u32,), (), >::new_unchecked(self.f2) - }; - let () = callee.call(store.as_context_mut(), (arg0,))?; - Ok(()) + } } - pub fn call_f3( + pub fn call_f2( &self, mut store: S, arg0: u32, - arg1: u32, ) -> wasmtime::Result<()> { - let callee = unsafe { + let callee = self.func_f2(); + let () = callee.call(store.as_context_mut(), (arg0,))?; + Ok(()) + } + pub fn func_f3( + &self, + ) -> wasmtime::component::TypedFunc<(u32, u32), ()> { + unsafe { wasmtime::component::TypedFunc::< (u32, u32), (), >::new_unchecked(self.f3) - }; - let () = callee.call(store.as_context_mut(), (arg0, arg1))?; - Ok(()) + } } - pub fn call_f4( + pub fn call_f3( &self, mut store: S, - ) -> wasmtime::Result { - let callee = unsafe { + arg0: u32, + arg1: u32, + ) -> wasmtime::Result<()> { + let callee = self.func_f3(); + let () = callee.call(store.as_context_mut(), (arg0, arg1))?; + Ok(()) + } + pub fn func_f4(&self) -> wasmtime::component::TypedFunc<(), (u32,)> { + unsafe { wasmtime::component::TypedFunc::< (), (u32,), >::new_unchecked(self.f4) - }; + } + } + pub fn call_f4( + &self, + mut store: S, + ) -> wasmtime::Result { + let callee = self.func_f4(); let (ret0,) = callee.call(store.as_context_mut(), ())?; Ok(ret0) } - pub fn call_f5( + pub fn func_f5( &self, - mut store: S, - ) -> wasmtime::Result<(u32, u32)> { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc<(), ((u32, u32),)> { + unsafe { wasmtime::component::TypedFunc::< (), ((u32, u32),), >::new_unchecked(self.f5) - }; + } + } + pub fn call_f5( + &self, + mut store: S, + ) -> wasmtime::Result<(u32, u32)> { + let callee = self.func_f5(); let (ret0,) = callee.call(store.as_context_mut(), ())?; Ok(ret0) } + pub fn func_f6( + &self, + ) -> wasmtime::component::TypedFunc< + (u32, u32, u32), + ((u32, u32, u32),), + > { + unsafe { + wasmtime::component::TypedFunc::< + (u32, u32, u32), + ((u32, u32, u32),), + >::new_unchecked(self.f6) + } + } pub fn call_f6( &self, mut store: S, @@ -484,12 +516,7 @@ pub mod exports { arg1: u32, arg2: u32, ) -> wasmtime::Result<(u32, u32, u32)> { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (u32, u32, u32), - ((u32, u32, u32),), - >::new_unchecked(self.f6) - }; + let callee = self.func_f6(); let (ret0,) = callee .call(store.as_context_mut(), (arg0, arg1, arg2))?; Ok(ret0) diff --git a/crates/component-macro/tests/expanded/simple-functions_async.rs b/crates/component-macro/tests/expanded/simple-functions_async.rs index 4b2f32568fab..3821245ad57c 100644 --- a/crates/component-macro/tests/expanded/simple-functions_async.rs +++ b/crates/component-macro/tests/expanded/simple-functions_async.rs @@ -449,6 +449,14 @@ pub mod exports { } } impl Guest { + pub fn func_f1(&self) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (), + >::new_unchecked(self.f1) + } + } pub async fn call_f1( &self, mut store: S, @@ -456,15 +464,18 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (), - >::new_unchecked(self.f1) - }; + let callee = self.func_f1(); let () = callee.call_async(store.as_context_mut(), ()).await?; Ok(()) } + pub fn func_f2(&self) -> wasmtime::component::TypedFunc<(u32,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (u32,), + (), + >::new_unchecked(self.f2) + } + } pub async fn call_f2( &self, mut store: S, @@ -473,17 +484,22 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (u32,), - (), - >::new_unchecked(self.f2) - }; + let callee = self.func_f2(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .await?; Ok(()) } + pub fn func_f3( + &self, + ) -> wasmtime::component::TypedFunc<(u32, u32), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (u32, u32), + (), + >::new_unchecked(self.f3) + } + } pub async fn call_f3( &self, mut store: S, @@ -493,17 +509,20 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (u32, u32), - (), - >::new_unchecked(self.f3) - }; + let callee = self.func_f3(); let () = callee .call_async(store.as_context_mut(), (arg0, arg1)) .await?; Ok(()) } + pub fn func_f4(&self) -> wasmtime::component::TypedFunc<(), (u32,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (u32,), + >::new_unchecked(self.f4) + } + } pub async fn call_f4( &self, mut store: S, @@ -511,17 +530,22 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (u32,), - >::new_unchecked(self.f4) - }; + let callee = self.func_f4(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .await?; Ok(ret0) } + pub fn func_f5( + &self, + ) -> wasmtime::component::TypedFunc<(), ((u32, u32),)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + ((u32, u32),), + >::new_unchecked(self.f5) + } + } pub async fn call_f5( &self, mut store: S, @@ -529,17 +553,25 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - ((u32, u32),), - >::new_unchecked(self.f5) - }; + let callee = self.func_f5(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .await?; Ok(ret0) } + pub fn func_f6( + &self, + ) -> wasmtime::component::TypedFunc< + (u32, u32, u32), + ((u32, u32, u32),), + > { + unsafe { + wasmtime::component::TypedFunc::< + (u32, u32, u32), + ((u32, u32, u32),), + >::new_unchecked(self.f6) + } + } pub async fn call_f6( &self, mut store: S, @@ -550,12 +582,7 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (u32, u32, u32), - ((u32, u32, u32),), - >::new_unchecked(self.f6) - }; + let callee = self.func_f6(); let (ret0,) = callee .call_async(store.as_context_mut(), (arg0, arg1, arg2)) .await?; diff --git a/crates/component-macro/tests/expanded/simple-functions_concurrent.rs b/crates/component-macro/tests/expanded/simple-functions_concurrent.rs index 4b7d4a54b28b..8b434496a63d 100644 --- a/crates/component-macro/tests/expanded/simple-functions_concurrent.rs +++ b/crates/component-macro/tests/expanded/simple-functions_concurrent.rs @@ -417,6 +417,14 @@ pub mod exports { } } impl Guest { + pub fn func_f1(&self) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (), + >::new_unchecked(self.f1) + } + } pub async fn call_f1<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -425,15 +433,18 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (), - >::new_unchecked(self.f1) - }; + let callee = self.func_f1(); let () = callee.call_concurrent(accessor, ()).await?; Ok(()) } + pub fn func_f2(&self) -> wasmtime::component::TypedFunc<(u32,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (u32,), + (), + >::new_unchecked(self.f2) + } + } pub async fn call_f2<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -443,15 +454,20 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (u32,), - (), - >::new_unchecked(self.f2) - }; + let callee = self.func_f2(); let () = callee.call_concurrent(accessor, (arg0,)).await?; Ok(()) } + pub fn func_f3( + &self, + ) -> wasmtime::component::TypedFunc<(u32, u32), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (u32, u32), + (), + >::new_unchecked(self.f3) + } + } pub async fn call_f3<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -462,15 +478,18 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (u32, u32), - (), - >::new_unchecked(self.f3) - }; + let callee = self.func_f3(); let () = callee.call_concurrent(accessor, (arg0, arg1)).await?; Ok(()) } + pub fn func_f4(&self) -> wasmtime::component::TypedFunc<(), (u32,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (u32,), + >::new_unchecked(self.f4) + } + } pub async fn call_f4<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -479,15 +498,20 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (u32,), - >::new_unchecked(self.f4) - }; + let callee = self.func_f4(); let (ret0,) = callee.call_concurrent(accessor, ()).await?; Ok(ret0) } + pub fn func_f5( + &self, + ) -> wasmtime::component::TypedFunc<(), ((u32, u32),)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + ((u32, u32),), + >::new_unchecked(self.f5) + } + } pub async fn call_f5<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -496,15 +520,23 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - ((u32, u32),), - >::new_unchecked(self.f5) - }; + let callee = self.func_f5(); let (ret0,) = callee.call_concurrent(accessor, ()).await?; Ok(ret0) } + pub fn func_f6( + &self, + ) -> wasmtime::component::TypedFunc< + (u32, u32, u32), + ((u32, u32, u32),), + > { + unsafe { + wasmtime::component::TypedFunc::< + (u32, u32, u32), + ((u32, u32, u32),), + >::new_unchecked(self.f6) + } + } pub async fn call_f6<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -516,12 +548,7 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (u32, u32, u32), - ((u32, u32, u32),), - >::new_unchecked(self.f6) - }; + let callee = self.func_f6(); let (ret0,) = callee .call_concurrent(accessor, (arg0, arg1, arg2)) .await?; diff --git a/crates/component-macro/tests/expanded/simple-functions_tracing_async.rs b/crates/component-macro/tests/expanded/simple-functions_tracing_async.rs index b9b1026b75e7..93431f1d04b4 100644 --- a/crates/component-macro/tests/expanded/simple-functions_tracing_async.rs +++ b/crates/component-macro/tests/expanded/simple-functions_tracing_async.rs @@ -537,6 +537,14 @@ pub mod exports { } } impl Guest { + pub fn func_f1(&self) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (), + >::new_unchecked(self.f1) + } + } pub async fn call_f1( &self, mut store: S, @@ -549,18 +557,21 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/simple", function = "f1", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (), - >::new_unchecked(self.f1) - }; + let callee = self.func_f1(); let () = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) .await?; Ok(()) } + pub fn func_f2(&self) -> wasmtime::component::TypedFunc<(u32,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (u32,), + (), + >::new_unchecked(self.f2) + } + } pub async fn call_f2( &self, mut store: S, @@ -574,18 +585,23 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/simple", function = "f2", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (u32,), - (), - >::new_unchecked(self.f2) - }; + let callee = self.func_f2(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .instrument(span.clone()) .await?; Ok(()) } + pub fn func_f3( + &self, + ) -> wasmtime::component::TypedFunc<(u32, u32), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (u32, u32), + (), + >::new_unchecked(self.f3) + } + } pub async fn call_f3( &self, mut store: S, @@ -600,18 +616,21 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/simple", function = "f3", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (u32, u32), - (), - >::new_unchecked(self.f3) - }; + let callee = self.func_f3(); let () = callee .call_async(store.as_context_mut(), (arg0, arg1)) .instrument(span.clone()) .await?; Ok(()) } + pub fn func_f4(&self) -> wasmtime::component::TypedFunc<(), (u32,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (u32,), + >::new_unchecked(self.f4) + } + } pub async fn call_f4( &self, mut store: S, @@ -624,18 +643,23 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/simple", function = "f4", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (u32,), - >::new_unchecked(self.f4) - }; + let callee = self.func_f4(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) .await?; Ok(ret0) } + pub fn func_f5( + &self, + ) -> wasmtime::component::TypedFunc<(), ((u32, u32),)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + ((u32, u32),), + >::new_unchecked(self.f5) + } + } pub async fn call_f5( &self, mut store: S, @@ -648,18 +672,26 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/simple", function = "f5", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - ((u32, u32),), - >::new_unchecked(self.f5) - }; + let callee = self.func_f5(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) .await?; Ok(ret0) } + pub fn func_f6( + &self, + ) -> wasmtime::component::TypedFunc< + (u32, u32, u32), + ((u32, u32, u32),), + > { + unsafe { + wasmtime::component::TypedFunc::< + (u32, u32, u32), + ((u32, u32, u32),), + >::new_unchecked(self.f6) + } + } pub async fn call_f6( &self, mut store: S, @@ -675,12 +707,7 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/simple", function = "f6", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (u32, u32, u32), - ((u32, u32, u32),), - >::new_unchecked(self.f6) - }; + let callee = self.func_f6(); let (ret0,) = callee .call_async(store.as_context_mut(), (arg0, arg1, arg2)) .instrument(span.clone()) diff --git a/crates/component-macro/tests/expanded/simple-lists.rs b/crates/component-macro/tests/expanded/simple-lists.rs index 54e9f0767e92..8c1f5694de81 100644 --- a/crates/component-macro/tests/expanded/simple-lists.rs +++ b/crates/component-macro/tests/expanded/simple-lists.rs @@ -443,45 +443,58 @@ pub mod exports { } } impl Guest { - pub fn call_simple_list1( + pub fn func_simple_list1( &self, - mut store: S, - arg0: &[u32], - ) -> wasmtime::Result<()> { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc<(&[u32],), ()> { + unsafe { wasmtime::component::TypedFunc::< (&[u32],), (), >::new_unchecked(self.simple_list1) - }; + } + } + pub fn call_simple_list1( + &self, + mut store: S, + arg0: &[u32], + ) -> wasmtime::Result<()> { + let callee = self.func_simple_list1(); let () = callee.call(store.as_context_mut(), (arg0,))?; Ok(()) } - pub fn call_simple_list2( + pub fn func_simple_list2( &self, - mut store: S, - ) -> wasmtime::Result> { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::__internal::Vec,), + > { + unsafe { wasmtime::component::TypedFunc::< (), (wasmtime::component::__internal::Vec,), >::new_unchecked(self.simple_list2) - }; + } + } + pub fn call_simple_list2( + &self, + mut store: S, + ) -> wasmtime::Result> { + let callee = self.func_simple_list2(); let (ret0,) = callee.call(store.as_context_mut(), ())?; Ok(ret0) } - pub fn call_simple_list3( + pub fn func_simple_list3( &self, - mut store: S, - arg0: &[u32], - arg1: &[u32], - ) -> wasmtime::Result< + ) -> wasmtime::component::TypedFunc< + (&[u32], &[u32]), ( - wasmtime::component::__internal::Vec, - wasmtime::component::__internal::Vec, + ( + wasmtime::component::__internal::Vec, + wasmtime::component::__internal::Vec, + ), ), > { - let callee = unsafe { + unsafe { wasmtime::component::TypedFunc::< (&[u32], &[u32]), ( @@ -491,20 +504,34 @@ pub mod exports { ), ), >::new_unchecked(self.simple_list3) - }; - let (ret0,) = callee.call(store.as_context_mut(), (arg0, arg1))?; - Ok(ret0) + } } - pub fn call_simple_list4( + pub fn call_simple_list3( &self, mut store: S, - arg0: &[wasmtime::component::__internal::Vec], + arg0: &[u32], + arg1: &[u32], ) -> wasmtime::Result< - wasmtime::component::__internal::Vec< + ( wasmtime::component::__internal::Vec, - >, + wasmtime::component::__internal::Vec, + ), + > { + let callee = self.func_simple_list3(); + let (ret0,) = callee.call(store.as_context_mut(), (arg0, arg1))?; + Ok(ret0) + } + pub fn func_simple_list4( + &self, + ) -> wasmtime::component::TypedFunc< + (&[wasmtime::component::__internal::Vec],), + ( + wasmtime::component::__internal::Vec< + wasmtime::component::__internal::Vec, + >, + ), > { - let callee = unsafe { + unsafe { wasmtime::component::TypedFunc::< (&[wasmtime::component::__internal::Vec],), ( @@ -513,7 +540,18 @@ pub mod exports { >, ), >::new_unchecked(self.simple_list4) - }; + } + } + pub fn call_simple_list4( + &self, + mut store: S, + arg0: &[wasmtime::component::__internal::Vec], + ) -> wasmtime::Result< + wasmtime::component::__internal::Vec< + wasmtime::component::__internal::Vec, + >, + > { + let callee = self.func_simple_list4(); let (ret0,) = callee.call(store.as_context_mut(), (arg0,))?; Ok(ret0) } diff --git a/crates/component-macro/tests/expanded/simple-lists_async.rs b/crates/component-macro/tests/expanded/simple-lists_async.rs index afd6a8100508..9e37f08a8b7b 100644 --- a/crates/component-macro/tests/expanded/simple-lists_async.rs +++ b/crates/component-macro/tests/expanded/simple-lists_async.rs @@ -467,6 +467,16 @@ pub mod exports { } } impl Guest { + pub fn func_simple_list1( + &self, + ) -> wasmtime::component::TypedFunc<(&[u32],), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (&[u32],), + (), + >::new_unchecked(self.simple_list1) + } + } pub async fn call_simple_list1( &self, mut store: S, @@ -475,17 +485,25 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (&[u32],), - (), - >::new_unchecked(self.simple_list1) - }; + let callee = self.func_simple_list1(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .await?; Ok(()) } + pub fn func_simple_list2( + &self, + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::__internal::Vec,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (), + (wasmtime::component::__internal::Vec,), + >::new_unchecked(self.simple_list2) + } + } pub async fn call_simple_list2( &self, mut store: S, @@ -493,17 +511,35 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (wasmtime::component::__internal::Vec,), - >::new_unchecked(self.simple_list2) - }; + let callee = self.func_simple_list2(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .await?; Ok(ret0) } + pub fn func_simple_list3( + &self, + ) -> wasmtime::component::TypedFunc< + (&[u32], &[u32]), + ( + ( + wasmtime::component::__internal::Vec, + wasmtime::component::__internal::Vec, + ), + ), + > { + unsafe { + wasmtime::component::TypedFunc::< + (&[u32], &[u32]), + ( + ( + wasmtime::component::__internal::Vec, + wasmtime::component::__internal::Vec, + ), + ), + >::new_unchecked(self.simple_list3) + } + } pub async fn call_simple_list3( &self, mut store: S, @@ -518,22 +554,33 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (&[u32], &[u32]), - ( - ( - wasmtime::component::__internal::Vec, - wasmtime::component::__internal::Vec, - ), - ), - >::new_unchecked(self.simple_list3) - }; + let callee = self.func_simple_list3(); let (ret0,) = callee .call_async(store.as_context_mut(), (arg0, arg1)) .await?; Ok(ret0) } + pub fn func_simple_list4( + &self, + ) -> wasmtime::component::TypedFunc< + (&[wasmtime::component::__internal::Vec],), + ( + wasmtime::component::__internal::Vec< + wasmtime::component::__internal::Vec, + >, + ), + > { + unsafe { + wasmtime::component::TypedFunc::< + (&[wasmtime::component::__internal::Vec],), + ( + wasmtime::component::__internal::Vec< + wasmtime::component::__internal::Vec, + >, + ), + >::new_unchecked(self.simple_list4) + } + } pub async fn call_simple_list4( &self, mut store: S, @@ -546,16 +593,7 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (&[wasmtime::component::__internal::Vec],), - ( - wasmtime::component::__internal::Vec< - wasmtime::component::__internal::Vec, - >, - ), - >::new_unchecked(self.simple_list4) - }; + let callee = self.func_simple_list4(); let (ret0,) = callee .call_async(store.as_context_mut(), (arg0,)) .await?; diff --git a/crates/component-macro/tests/expanded/simple-lists_concurrent.rs b/crates/component-macro/tests/expanded/simple-lists_concurrent.rs index bd73e4d82a31..865eadbdc8bb 100644 --- a/crates/component-macro/tests/expanded/simple-lists_concurrent.rs +++ b/crates/component-macro/tests/expanded/simple-lists_concurrent.rs @@ -426,6 +426,19 @@ pub mod exports { } } impl Guest { + pub fn func_simple_list1( + &self, + ) -> wasmtime::component::TypedFunc< + (wasmtime::component::__internal::Vec,), + (), + > { + unsafe { + wasmtime::component::TypedFunc::< + (wasmtime::component::__internal::Vec,), + (), + >::new_unchecked(self.simple_list1) + } + } pub async fn call_simple_list1<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -435,15 +448,23 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (wasmtime::component::__internal::Vec,), - (), - >::new_unchecked(self.simple_list1) - }; + let callee = self.func_simple_list1(); let () = callee.call_concurrent(accessor, (arg0,)).await?; Ok(()) } + pub fn func_simple_list2( + &self, + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::__internal::Vec,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (), + (wasmtime::component::__internal::Vec,), + >::new_unchecked(self.simple_list2) + } + } pub async fn call_simple_list2<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -452,31 +473,25 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (wasmtime::component::__internal::Vec,), - >::new_unchecked(self.simple_list2) - }; + let callee = self.func_simple_list2(); let (ret0,) = callee.call_concurrent(accessor, ()).await?; Ok(ret0) } - pub async fn call_simple_list3<_T, _D>( + pub fn func_simple_list3( &self, - accessor: &wasmtime::component::Accessor<_T, _D>, - arg0: wasmtime::component::__internal::Vec, - arg1: wasmtime::component::__internal::Vec, - ) -> wasmtime::Result< + ) -> wasmtime::component::TypedFunc< ( wasmtime::component::__internal::Vec, wasmtime::component::__internal::Vec, ), - > - where - _T: Send, - _D: wasmtime::component::HasData, - { - let callee = unsafe { + ( + ( + wasmtime::component::__internal::Vec, + wasmtime::component::__internal::Vec, + ), + ), + > { + unsafe { wasmtime::component::TypedFunc::< ( wasmtime::component::__internal::Vec, @@ -489,28 +504,44 @@ pub mod exports { ), ), >::new_unchecked(self.simple_list3) - }; - let (ret0,) = callee - .call_concurrent(accessor, (arg0, arg1)) - .await?; - Ok(ret0) + } } - pub async fn call_simple_list4<_T, _D>( + pub async fn call_simple_list3<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, - arg0: wasmtime::component::__internal::Vec< - wasmtime::component::__internal::Vec, - >, + arg0: wasmtime::component::__internal::Vec, + arg1: wasmtime::component::__internal::Vec, ) -> wasmtime::Result< - wasmtime::component::__internal::Vec< + ( wasmtime::component::__internal::Vec, - >, + wasmtime::component::__internal::Vec, + ), > where _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { + let callee = self.func_simple_list3(); + let (ret0,) = callee + .call_concurrent(accessor, (arg0, arg1)) + .await?; + Ok(ret0) + } + pub fn func_simple_list4( + &self, + ) -> wasmtime::component::TypedFunc< + ( + wasmtime::component::__internal::Vec< + wasmtime::component::__internal::Vec, + >, + ), + ( + wasmtime::component::__internal::Vec< + wasmtime::component::__internal::Vec, + >, + ), + > { + unsafe { wasmtime::component::TypedFunc::< ( wasmtime::component::__internal::Vec< @@ -523,7 +554,24 @@ pub mod exports { >, ), >::new_unchecked(self.simple_list4) - }; + } + } + pub async fn call_simple_list4<_T, _D>( + &self, + accessor: &wasmtime::component::Accessor<_T, _D>, + arg0: wasmtime::component::__internal::Vec< + wasmtime::component::__internal::Vec, + >, + ) -> wasmtime::Result< + wasmtime::component::__internal::Vec< + wasmtime::component::__internal::Vec, + >, + > + where + _T: Send, + _D: wasmtime::component::HasData, + { + let callee = self.func_simple_list4(); let (ret0,) = callee.call_concurrent(accessor, (arg0,)).await?; Ok(ret0) } diff --git a/crates/component-macro/tests/expanded/simple-lists_tracing_async.rs b/crates/component-macro/tests/expanded/simple-lists_tracing_async.rs index 7b4c2a267555..097c84a00565 100644 --- a/crates/component-macro/tests/expanded/simple-lists_tracing_async.rs +++ b/crates/component-macro/tests/expanded/simple-lists_tracing_async.rs @@ -528,6 +528,16 @@ pub mod exports { } } impl Guest { + pub fn func_simple_list1( + &self, + ) -> wasmtime::component::TypedFunc<(&[u32],), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (&[u32],), + (), + >::new_unchecked(self.simple_list1) + } + } pub async fn call_simple_list1( &self, mut store: S, @@ -541,18 +551,26 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/simple-lists", function = "simple-list1", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (&[u32],), - (), - >::new_unchecked(self.simple_list1) - }; + let callee = self.func_simple_list1(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .instrument(span.clone()) .await?; Ok(()) } + pub fn func_simple_list2( + &self, + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::__internal::Vec,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (), + (wasmtime::component::__internal::Vec,), + >::new_unchecked(self.simple_list2) + } + } pub async fn call_simple_list2( &self, mut store: S, @@ -565,18 +583,36 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/simple-lists", function = "simple-list2", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (wasmtime::component::__internal::Vec,), - >::new_unchecked(self.simple_list2) - }; + let callee = self.func_simple_list2(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) .await?; Ok(ret0) } + pub fn func_simple_list3( + &self, + ) -> wasmtime::component::TypedFunc< + (&[u32], &[u32]), + ( + ( + wasmtime::component::__internal::Vec, + wasmtime::component::__internal::Vec, + ), + ), + > { + unsafe { + wasmtime::component::TypedFunc::< + (&[u32], &[u32]), + ( + ( + wasmtime::component::__internal::Vec, + wasmtime::component::__internal::Vec, + ), + ), + >::new_unchecked(self.simple_list3) + } + } pub async fn call_simple_list3( &self, mut store: S, @@ -596,23 +632,34 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/simple-lists", function = "simple-list3", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (&[u32], &[u32]), - ( - ( - wasmtime::component::__internal::Vec, - wasmtime::component::__internal::Vec, - ), - ), - >::new_unchecked(self.simple_list3) - }; + let callee = self.func_simple_list3(); let (ret0,) = callee .call_async(store.as_context_mut(), (arg0, arg1)) .instrument(span.clone()) .await?; Ok(ret0) } + pub fn func_simple_list4( + &self, + ) -> wasmtime::component::TypedFunc< + (&[wasmtime::component::__internal::Vec],), + ( + wasmtime::component::__internal::Vec< + wasmtime::component::__internal::Vec, + >, + ), + > { + unsafe { + wasmtime::component::TypedFunc::< + (&[wasmtime::component::__internal::Vec],), + ( + wasmtime::component::__internal::Vec< + wasmtime::component::__internal::Vec, + >, + ), + >::new_unchecked(self.simple_list4) + } + } pub async fn call_simple_list4( &self, mut store: S, @@ -630,16 +677,7 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/simple-lists", function = "simple-list4", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (&[wasmtime::component::__internal::Vec],), - ( - wasmtime::component::__internal::Vec< - wasmtime::component::__internal::Vec, - >, - ), - >::new_unchecked(self.simple_list4) - }; + let callee = self.func_simple_list4(); let (ret0,) = callee .call_async(store.as_context_mut(), (arg0,)) .instrument(span.clone()) diff --git a/crates/component-macro/tests/expanded/small-anonymous.rs b/crates/component-macro/tests/expanded/small-anonymous.rs index d3f09f8837f7..f4ad77b3ee8d 100644 --- a/crates/component-macro/tests/expanded/small-anonymous.rs +++ b/crates/component-macro/tests/expanded/small-anonymous.rs @@ -413,13 +413,13 @@ pub mod exports { } } impl Guest { - pub fn call_option_test( + pub fn func_option_test( &self, - mut store: S, - ) -> wasmtime::Result< - Result, Error>, + ) -> wasmtime::component::TypedFunc< + (), + (Result, Error>,), > { - let callee = unsafe { + unsafe { wasmtime::component::TypedFunc::< (), ( @@ -429,7 +429,15 @@ pub mod exports { >, ), >::new_unchecked(self.option_test) - }; + } + } + pub fn call_option_test( + &self, + mut store: S, + ) -> wasmtime::Result< + Result, Error>, + > { + let callee = self.func_option_test(); let (ret0,) = callee.call(store.as_context_mut(), ())?; Ok(ret0) } diff --git a/crates/component-macro/tests/expanded/small-anonymous_async.rs b/crates/component-macro/tests/expanded/small-anonymous_async.rs index 914c8a90eb16..beccae413452 100644 --- a/crates/component-macro/tests/expanded/small-anonymous_async.rs +++ b/crates/component-macro/tests/expanded/small-anonymous_async.rs @@ -425,16 +425,13 @@ pub mod exports { } } impl Guest { - pub async fn call_option_test( + pub fn func_option_test( &self, - mut store: S, - ) -> wasmtime::Result< - Result, Error>, - > - where - ::Data: Send, - { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc< + (), + (Result, Error>,), + > { + unsafe { wasmtime::component::TypedFunc::< (), ( @@ -444,7 +441,18 @@ pub mod exports { >, ), >::new_unchecked(self.option_test) - }; + } + } + pub async fn call_option_test( + &self, + mut store: S, + ) -> wasmtime::Result< + Result, Error>, + > + where + ::Data: Send, + { + let callee = self.func_option_test(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .await?; diff --git a/crates/component-macro/tests/expanded/small-anonymous_concurrent.rs b/crates/component-macro/tests/expanded/small-anonymous_concurrent.rs index 6c97370b7113..41493af190ca 100644 --- a/crates/component-macro/tests/expanded/small-anonymous_concurrent.rs +++ b/crates/component-macro/tests/expanded/small-anonymous_concurrent.rs @@ -410,17 +410,13 @@ pub mod exports { } } impl Guest { - pub async fn call_option_test<_T, _D>( + pub fn func_option_test( &self, - accessor: &wasmtime::component::Accessor<_T, _D>, - ) -> wasmtime::Result< - Result, Error>, - > - where - _T: Send, - _D: wasmtime::component::HasData, - { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc< + (), + (Result, Error>,), + > { + unsafe { wasmtime::component::TypedFunc::< (), ( @@ -430,7 +426,19 @@ pub mod exports { >, ), >::new_unchecked(self.option_test) - }; + } + } + pub async fn call_option_test<_T, _D>( + &self, + accessor: &wasmtime::component::Accessor<_T, _D>, + ) -> wasmtime::Result< + Result, Error>, + > + where + _T: Send, + _D: wasmtime::component::HasData, + { + let callee = self.func_option_test(); let (ret0,) = callee.call_concurrent(accessor, ()).await?; Ok(ret0) } diff --git a/crates/component-macro/tests/expanded/small-anonymous_tracing_async.rs b/crates/component-macro/tests/expanded/small-anonymous_tracing_async.rs index d238fa7551ef..418b1258a5c8 100644 --- a/crates/component-macro/tests/expanded/small-anonymous_tracing_async.rs +++ b/crates/component-macro/tests/expanded/small-anonymous_tracing_async.rs @@ -438,6 +438,24 @@ pub mod exports { } } impl Guest { + pub fn func_option_test( + &self, + ) -> wasmtime::component::TypedFunc< + (), + (Result, Error>,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (), + ( + Result< + Option, + Error, + >, + ), + >::new_unchecked(self.option_test) + } + } pub async fn call_option_test( &self, mut store: S, @@ -452,17 +470,7 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/anon", function = "option-test", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - ( - Result< - Option, - Error, - >, - ), - >::new_unchecked(self.option_test) - }; + let callee = self.func_option_test(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) diff --git a/crates/component-macro/tests/expanded/smoke-default.rs b/crates/component-macro/tests/expanded/smoke-default.rs index 7ae565639242..9519316da261 100644 --- a/crates/component-macro/tests/expanded/smoke-default.rs +++ b/crates/component-macro/tests/expanded/smoke-default.rs @@ -180,13 +180,14 @@ const _: () = { let pre = linker.instantiate_pre(component)?; TheWorldPre::new(pre)?.instantiate_async(store).await } + pub fn func_y(&self) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { wasmtime::component::TypedFunc::<(), ()>::new_unchecked(self.y) } + } pub fn call_y( &self, mut store: S, ) -> wasmtime::Result<()> { - let callee = unsafe { - wasmtime::component::TypedFunc::<(), ()>::new_unchecked(self.y) - }; + let callee = self.func_y(); let () = callee.call(store.as_context_mut(), ())?; Ok(()) } diff --git a/crates/component-macro/tests/expanded/smoke-default_async.rs b/crates/component-macro/tests/expanded/smoke-default_async.rs index 162c1f3a3930..de2e9d926c9f 100644 --- a/crates/component-macro/tests/expanded/smoke-default_async.rs +++ b/crates/component-macro/tests/expanded/smoke-default_async.rs @@ -180,6 +180,9 @@ const _: () = { let pre = linker.instantiate_pre(component)?; TheWorldPre::new(pre)?.instantiate_async(store).await } + pub fn func_y(&self) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { wasmtime::component::TypedFunc::<(), ()>::new_unchecked(self.y) } + } pub async fn call_y( &self, mut store: S, @@ -187,9 +190,7 @@ const _: () = { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::<(), ()>::new_unchecked(self.y) - }; + let callee = self.func_y(); let () = callee.call_async(store.as_context_mut(), ()).await?; Ok(()) } diff --git a/crates/component-macro/tests/expanded/smoke-default_concurrent.rs b/crates/component-macro/tests/expanded/smoke-default_concurrent.rs index a8e2d40f74d0..4411aa3c9802 100644 --- a/crates/component-macro/tests/expanded/smoke-default_concurrent.rs +++ b/crates/component-macro/tests/expanded/smoke-default_concurrent.rs @@ -180,6 +180,9 @@ const _: () = { let pre = linker.instantiate_pre(component)?; TheWorldPre::new(pre)?.instantiate_async(store).await } + pub fn func_y(&self) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { wasmtime::component::TypedFunc::<(), ()>::new_unchecked(self.y) } + } pub async fn call_y<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -188,9 +191,7 @@ const _: () = { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::<(), ()>::new_unchecked(self.y) - }; + let callee = self.func_y(); let () = callee.call_concurrent(accessor, ()).await?; Ok(()) } diff --git a/crates/component-macro/tests/expanded/smoke-default_tracing_async.rs b/crates/component-macro/tests/expanded/smoke-default_tracing_async.rs index b7c0a8be5fad..2fdeea02d19b 100644 --- a/crates/component-macro/tests/expanded/smoke-default_tracing_async.rs +++ b/crates/component-macro/tests/expanded/smoke-default_tracing_async.rs @@ -180,6 +180,9 @@ const _: () = { let pre = linker.instantiate_pre(component)?; TheWorldPre::new(pre)?.instantiate_async(store).await } + pub fn func_y(&self) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { wasmtime::component::TypedFunc::<(), ()>::new_unchecked(self.y) } + } pub async fn call_y( &self, mut store: S, @@ -192,9 +195,7 @@ const _: () = { tracing::Level::TRACE, "wit-bindgen export", module = "default", function = "y", ); - let callee = unsafe { - wasmtime::component::TypedFunc::<(), ()>::new_unchecked(self.y) - }; + let callee = self.func_y(); let () = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) diff --git a/crates/component-macro/tests/expanded/smoke-export.rs b/crates/component-macro/tests/expanded/smoke-export.rs index b5459c5a0a19..50eb1e2814d4 100644 --- a/crates/component-macro/tests/expanded/smoke-export.rs +++ b/crates/component-macro/tests/expanded/smoke-export.rs @@ -230,13 +230,16 @@ pub mod exports { } } impl Guest { + pub fn func_y(&self) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { + wasmtime::component::TypedFunc::<(), ()>::new_unchecked(self.y) + } + } pub fn call_y( &self, mut store: S, ) -> wasmtime::Result<()> { - let callee = unsafe { - wasmtime::component::TypedFunc::<(), ()>::new_unchecked(self.y) - }; + let callee = self.func_y(); let () = callee.call(store.as_context_mut(), ())?; Ok(()) } diff --git a/crates/component-macro/tests/expanded/smoke-export_async.rs b/crates/component-macro/tests/expanded/smoke-export_async.rs index 98857b4e901e..a2c4b2bc6bef 100644 --- a/crates/component-macro/tests/expanded/smoke-export_async.rs +++ b/crates/component-macro/tests/expanded/smoke-export_async.rs @@ -230,6 +230,11 @@ pub mod exports { } } impl Guest { + pub fn func_y(&self) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { + wasmtime::component::TypedFunc::<(), ()>::new_unchecked(self.y) + } + } pub async fn call_y( &self, mut store: S, @@ -237,9 +242,7 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::<(), ()>::new_unchecked(self.y) - }; + let callee = self.func_y(); let () = callee.call_async(store.as_context_mut(), ()).await?; Ok(()) } diff --git a/crates/component-macro/tests/expanded/smoke-export_concurrent.rs b/crates/component-macro/tests/expanded/smoke-export_concurrent.rs index 0d19ddb29562..2b3584a76692 100644 --- a/crates/component-macro/tests/expanded/smoke-export_concurrent.rs +++ b/crates/component-macro/tests/expanded/smoke-export_concurrent.rs @@ -230,6 +230,11 @@ pub mod exports { } } impl Guest { + pub fn func_y(&self) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { + wasmtime::component::TypedFunc::<(), ()>::new_unchecked(self.y) + } + } pub async fn call_y<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -238,9 +243,7 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::<(), ()>::new_unchecked(self.y) - }; + let callee = self.func_y(); let () = callee.call_concurrent(accessor, ()).await?; Ok(()) } diff --git a/crates/component-macro/tests/expanded/smoke-export_tracing_async.rs b/crates/component-macro/tests/expanded/smoke-export_tracing_async.rs index bc4a5f1a7640..786cb2cbbbdf 100644 --- a/crates/component-macro/tests/expanded/smoke-export_tracing_async.rs +++ b/crates/component-macro/tests/expanded/smoke-export_tracing_async.rs @@ -230,6 +230,11 @@ pub mod exports { } } impl Guest { + pub fn func_y(&self) -> wasmtime::component::TypedFunc<(), ()> { + unsafe { + wasmtime::component::TypedFunc::<(), ()>::new_unchecked(self.y) + } + } pub async fn call_y( &self, mut store: S, @@ -242,9 +247,7 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "the-name", function = "y", ); - let callee = unsafe { - wasmtime::component::TypedFunc::<(), ()>::new_unchecked(self.y) - }; + let callee = self.func_y(); let () = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) diff --git a/crates/component-macro/tests/expanded/strings.rs b/crates/component-macro/tests/expanded/strings.rs index 1b0844bb99e9..ba4304af32b1 100644 --- a/crates/component-macro/tests/expanded/strings.rs +++ b/crates/component-macro/tests/expanded/strings.rs @@ -365,45 +365,64 @@ pub mod exports { } } impl Guest { + pub fn func_a(&self) -> wasmtime::component::TypedFunc<(&str,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (&str,), + (), + >::new_unchecked(self.a) + } + } pub fn call_a( &self, mut store: S, arg0: &str, ) -> wasmtime::Result<()> { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (&str,), - (), - >::new_unchecked(self.a) - }; + let callee = self.func_a(); let () = callee.call(store.as_context_mut(), (arg0,))?; Ok(()) } - pub fn call_b( + pub fn func_b( &self, - mut store: S, - ) -> wasmtime::Result { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::__internal::String,), + > { + unsafe { wasmtime::component::TypedFunc::< (), (wasmtime::component::__internal::String,), >::new_unchecked(self.b) - }; + } + } + pub fn call_b( + &self, + mut store: S, + ) -> wasmtime::Result { + let callee = self.func_b(); let (ret0,) = callee.call(store.as_context_mut(), ())?; Ok(ret0) } + pub fn func_c( + &self, + ) -> wasmtime::component::TypedFunc< + (&str, &str), + (wasmtime::component::__internal::String,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (&str, &str), + (wasmtime::component::__internal::String,), + >::new_unchecked(self.c) + } + } pub fn call_c( &self, mut store: S, arg0: &str, arg1: &str, ) -> wasmtime::Result { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (&str, &str), - (wasmtime::component::__internal::String,), - >::new_unchecked(self.c) - }; + let callee = self.func_c(); let (ret0,) = callee.call(store.as_context_mut(), (arg0, arg1))?; Ok(ret0) } diff --git a/crates/component-macro/tests/expanded/strings_async.rs b/crates/component-macro/tests/expanded/strings_async.rs index 46d3f216852c..470408885b41 100644 --- a/crates/component-macro/tests/expanded/strings_async.rs +++ b/crates/component-macro/tests/expanded/strings_async.rs @@ -389,6 +389,14 @@ pub mod exports { } } impl Guest { + pub fn func_a(&self) -> wasmtime::component::TypedFunc<(&str,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (&str,), + (), + >::new_unchecked(self.a) + } + } pub async fn call_a( &self, mut store: S, @@ -397,17 +405,25 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (&str,), - (), - >::new_unchecked(self.a) - }; + let callee = self.func_a(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .await?; Ok(()) } + pub fn func_b( + &self, + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::__internal::String,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (), + (wasmtime::component::__internal::String,), + >::new_unchecked(self.b) + } + } pub async fn call_b( &self, mut store: S, @@ -415,17 +431,25 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (wasmtime::component::__internal::String,), - >::new_unchecked(self.b) - }; + let callee = self.func_b(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .await?; Ok(ret0) } + pub fn func_c( + &self, + ) -> wasmtime::component::TypedFunc< + (&str, &str), + (wasmtime::component::__internal::String,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (&str, &str), + (wasmtime::component::__internal::String,), + >::new_unchecked(self.c) + } + } pub async fn call_c( &self, mut store: S, @@ -435,12 +459,7 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (&str, &str), - (wasmtime::component::__internal::String,), - >::new_unchecked(self.c) - }; + let callee = self.func_c(); let (ret0,) = callee .call_async(store.as_context_mut(), (arg0, arg1)) .await?; diff --git a/crates/component-macro/tests/expanded/strings_concurrent.rs b/crates/component-macro/tests/expanded/strings_concurrent.rs index dfc9e3615589..758b26c864a7 100644 --- a/crates/component-macro/tests/expanded/strings_concurrent.rs +++ b/crates/component-macro/tests/expanded/strings_concurrent.rs @@ -362,6 +362,19 @@ pub mod exports { } } impl Guest { + pub fn func_a( + &self, + ) -> wasmtime::component::TypedFunc< + (wasmtime::component::__internal::String,), + (), + > { + unsafe { + wasmtime::component::TypedFunc::< + (wasmtime::component::__internal::String,), + (), + >::new_unchecked(self.a) + } + } pub async fn call_a<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -371,15 +384,23 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (wasmtime::component::__internal::String,), - (), - >::new_unchecked(self.a) - }; + let callee = self.func_a(); let () = callee.call_concurrent(accessor, (arg0,)).await?; Ok(()) } + pub fn func_b( + &self, + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::__internal::String,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (), + (wasmtime::component::__internal::String,), + >::new_unchecked(self.b) + } + } pub async fn call_b<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -388,15 +409,29 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (wasmtime::component::__internal::String,), - >::new_unchecked(self.b) - }; + let callee = self.func_b(); let (ret0,) = callee.call_concurrent(accessor, ()).await?; Ok(ret0) } + pub fn func_c( + &self, + ) -> wasmtime::component::TypedFunc< + ( + wasmtime::component::__internal::String, + wasmtime::component::__internal::String, + ), + (wasmtime::component::__internal::String,), + > { + unsafe { + wasmtime::component::TypedFunc::< + ( + wasmtime::component::__internal::String, + wasmtime::component::__internal::String, + ), + (wasmtime::component::__internal::String,), + >::new_unchecked(self.c) + } + } pub async fn call_c<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -407,15 +442,7 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - ( - wasmtime::component::__internal::String, - wasmtime::component::__internal::String, - ), - (wasmtime::component::__internal::String,), - >::new_unchecked(self.c) - }; + let callee = self.func_c(); let (ret0,) = callee .call_concurrent(accessor, (arg0, arg1)) .await?; diff --git a/crates/component-macro/tests/expanded/strings_tracing_async.rs b/crates/component-macro/tests/expanded/strings_tracing_async.rs index ab31650af530..6639e51ddc39 100644 --- a/crates/component-macro/tests/expanded/strings_tracing_async.rs +++ b/crates/component-macro/tests/expanded/strings_tracing_async.rs @@ -434,6 +434,14 @@ pub mod exports { } } impl Guest { + pub fn func_a(&self) -> wasmtime::component::TypedFunc<(&str,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (&str,), + (), + >::new_unchecked(self.a) + } + } pub async fn call_a( &self, mut store: S, @@ -447,18 +455,26 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/strings", function = "a", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (&str,), - (), - >::new_unchecked(self.a) - }; + let callee = self.func_a(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .instrument(span.clone()) .await?; Ok(()) } + pub fn func_b( + &self, + ) -> wasmtime::component::TypedFunc< + (), + (wasmtime::component::__internal::String,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (), + (wasmtime::component::__internal::String,), + >::new_unchecked(self.b) + } + } pub async fn call_b( &self, mut store: S, @@ -471,18 +487,26 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/strings", function = "b", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (wasmtime::component::__internal::String,), - >::new_unchecked(self.b) - }; + let callee = self.func_b(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) .await?; Ok(ret0) } + pub fn func_c( + &self, + ) -> wasmtime::component::TypedFunc< + (&str, &str), + (wasmtime::component::__internal::String,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (&str, &str), + (wasmtime::component::__internal::String,), + >::new_unchecked(self.c) + } + } pub async fn call_c( &self, mut store: S, @@ -497,12 +521,7 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/strings", function = "c", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (&str, &str), - (wasmtime::component::__internal::String,), - >::new_unchecked(self.c) - }; + let callee = self.func_c(); let (ret0,) = callee .call_async(store.as_context_mut(), (arg0, arg1)) .instrument(span.clone()) diff --git a/crates/component-macro/tests/expanded/variants.rs b/crates/component-macro/tests/expanded/variants.rs index 11e5fc3d5710..beda10e4e486 100644 --- a/crates/component-macro/tests/expanded/variants.rs +++ b/crates/component-macro/tests/expanded/variants.rs @@ -1548,98 +1548,131 @@ pub mod exports { } } impl Guest { - pub fn call_e1_arg( + pub fn func_e1_arg( &self, - mut store: S, - arg0: E1, - ) -> wasmtime::Result<()> { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc<(E1,), ()> { + unsafe { wasmtime::component::TypedFunc::< (E1,), (), >::new_unchecked(self.e1_arg) - }; + } + } + pub fn call_e1_arg( + &self, + mut store: S, + arg0: E1, + ) -> wasmtime::Result<()> { + let callee = self.func_e1_arg(); let () = callee.call(store.as_context_mut(), (arg0,))?; Ok(()) } - pub fn call_e1_result( + pub fn func_e1_result( &self, - mut store: S, - ) -> wasmtime::Result { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc<(), (E1,)> { + unsafe { wasmtime::component::TypedFunc::< (), (E1,), >::new_unchecked(self.e1_result) - }; + } + } + pub fn call_e1_result( + &self, + mut store: S, + ) -> wasmtime::Result { + let callee = self.func_e1_result(); let (ret0,) = callee.call(store.as_context_mut(), ())?; Ok(ret0) } - pub fn call_v1_arg( + pub fn func_v1_arg( &self, - mut store: S, - arg0: &V1, - ) -> wasmtime::Result<()> { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc<(&V1,), ()> { + unsafe { wasmtime::component::TypedFunc::< (&V1,), (), >::new_unchecked(self.v1_arg) - }; + } + } + pub fn call_v1_arg( + &self, + mut store: S, + arg0: &V1, + ) -> wasmtime::Result<()> { + let callee = self.func_v1_arg(); let () = callee.call(store.as_context_mut(), (arg0,))?; Ok(()) } - pub fn call_v1_result( + pub fn func_v1_result( &self, - mut store: S, - ) -> wasmtime::Result { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc<(), (V1,)> { + unsafe { wasmtime::component::TypedFunc::< (), (V1,), >::new_unchecked(self.v1_result) - }; + } + } + pub fn call_v1_result( + &self, + mut store: S, + ) -> wasmtime::Result { + let callee = self.func_v1_result(); let (ret0,) = callee.call(store.as_context_mut(), ())?; Ok(ret0) } - pub fn call_bool_arg( + pub fn func_bool_arg( &self, - mut store: S, - arg0: bool, - ) -> wasmtime::Result<()> { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc<(bool,), ()> { + unsafe { wasmtime::component::TypedFunc::< (bool,), (), >::new_unchecked(self.bool_arg) - }; + } + } + pub fn call_bool_arg( + &self, + mut store: S, + arg0: bool, + ) -> wasmtime::Result<()> { + let callee = self.func_bool_arg(); let () = callee.call(store.as_context_mut(), (arg0,))?; Ok(()) } - pub fn call_bool_result( + pub fn func_bool_result( &self, - mut store: S, - ) -> wasmtime::Result { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc<(), (bool,)> { + unsafe { wasmtime::component::TypedFunc::< (), (bool,), >::new_unchecked(self.bool_result) - }; + } + } + pub fn call_bool_result( + &self, + mut store: S, + ) -> wasmtime::Result { + let callee = self.func_bool_result(); let (ret0,) = callee.call(store.as_context_mut(), ())?; Ok(ret0) } - pub fn call_option_arg( + pub fn func_option_arg( &self, - mut store: S, - arg0: Option, - arg1: Option<()>, - arg2: Option, - arg3: Option, - arg4: Option, - arg5: Option>, - ) -> wasmtime::Result<()> { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc< + ( + Option, + Option<()>, + Option, + Option, + Option, + Option>, + ), + (), + > { + unsafe { wasmtime::component::TypedFunc::< ( Option, @@ -1651,7 +1684,19 @@ pub mod exports { ), (), >::new_unchecked(self.option_arg) - }; + } + } + pub fn call_option_arg( + &self, + mut store: S, + arg0: Option, + arg1: Option<()>, + arg2: Option, + arg3: Option, + arg4: Option, + arg5: Option>, + ) -> wasmtime::Result<()> { + let callee = self.func_option_arg(); let () = callee .call( store.as_context_mut(), @@ -1659,20 +1704,22 @@ pub mod exports { )?; Ok(()) } - pub fn call_option_result( + pub fn func_option_result( &self, - mut store: S, - ) -> wasmtime::Result< + ) -> wasmtime::component::TypedFunc< + (), ( - Option, - Option<()>, - Option, - Option, - Option, - Option>, + ( + Option, + Option<()>, + Option, + Option, + Option, + Option>, + ), ), > { - let callee = unsafe { + unsafe { wasmtime::component::TypedFunc::< (), ( @@ -1686,10 +1733,38 @@ pub mod exports { ), ), >::new_unchecked(self.option_result) - }; + } + } + pub fn call_option_result( + &self, + mut store: S, + ) -> wasmtime::Result< + ( + Option, + Option<()>, + Option, + Option, + Option, + Option>, + ), + > { + let callee = self.func_option_result(); let (ret0,) = callee.call(store.as_context_mut(), ())?; Ok(ret0) } + pub fn func_casts( + &self, + ) -> wasmtime::component::TypedFunc< + (Casts1, Casts2, Casts3, Casts4, Casts5, Casts6), + ((Casts1, Casts2, Casts3, Casts4, Casts5, Casts6),), + > { + unsafe { + wasmtime::component::TypedFunc::< + (Casts1, Casts2, Casts3, Casts4, Casts5, Casts6), + ((Casts1, Casts2, Casts3, Casts4, Casts5, Casts6),), + >::new_unchecked(self.casts) + } + } pub fn call_casts( &self, mut store: S, @@ -1702,12 +1777,7 @@ pub mod exports { ) -> wasmtime::Result< (Casts1, Casts2, Casts3, Casts4, Casts5, Casts6), > { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (Casts1, Casts2, Casts3, Casts4, Casts5, Casts6), - ((Casts1, Casts2, Casts3, Casts4, Casts5, Casts6),), - >::new_unchecked(self.casts) - }; + let callee = self.func_casts(); let (ret0,) = callee .call( store.as_context_mut(), @@ -1715,17 +1785,20 @@ pub mod exports { )?; Ok(ret0) } - pub fn call_result_arg( + pub fn func_result_arg( &self, - mut store: S, - arg0: Result<(), ()>, - arg1: Result<(), E1>, - arg2: Result, - arg3: Result<(), ()>, - arg4: Result, - arg5: Result<&str, &[u8]>, - ) -> wasmtime::Result<()> { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc< + ( + Result<(), ()>, + Result<(), E1>, + Result, + Result<(), ()>, + Result, + Result<&str, &[u8]>, + ), + (), + > { + unsafe { wasmtime::component::TypedFunc::< ( Result<(), ()>, @@ -1737,7 +1810,19 @@ pub mod exports { ), (), >::new_unchecked(self.result_arg) - }; + } + } + pub fn call_result_arg( + &self, + mut store: S, + arg0: Result<(), ()>, + arg1: Result<(), E1>, + arg2: Result, + arg3: Result<(), ()>, + arg4: Result, + arg5: Result<&str, &[u8]>, + ) -> wasmtime::Result<()> { + let callee = self.func_result_arg(); let () = callee .call( store.as_context_mut(), @@ -1745,23 +1830,25 @@ pub mod exports { )?; Ok(()) } - pub fn call_result_result( + pub fn func_result_result( &self, - mut store: S, - ) -> wasmtime::Result< + ) -> wasmtime::component::TypedFunc< + (), ( - Result<(), ()>, - Result<(), E1>, - Result, - Result<(), ()>, - Result, - Result< - wasmtime::component::__internal::String, - wasmtime::component::__internal::Vec, - >, + ( + Result<(), ()>, + Result<(), E1>, + Result, + Result<(), ()>, + Result, + Result< + wasmtime::component::__internal::String, + wasmtime::component::__internal::Vec, + >, + ), ), > { - let callee = unsafe { + unsafe { wasmtime::component::TypedFunc::< (), ( @@ -1778,125 +1865,194 @@ pub mod exports { ), ), >::new_unchecked(self.result_result) - }; + } + } + pub fn call_result_result( + &self, + mut store: S, + ) -> wasmtime::Result< + ( + Result<(), ()>, + Result<(), E1>, + Result, + Result<(), ()>, + Result, + Result< + wasmtime::component::__internal::String, + wasmtime::component::__internal::Vec, + >, + ), + > { + let callee = self.func_result_result(); let (ret0,) = callee.call(store.as_context_mut(), ())?; Ok(ret0) } - pub fn call_return_result_sugar( + pub fn func_return_result_sugar( &self, - mut store: S, - ) -> wasmtime::Result> { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc<(), (Result,)> { + unsafe { wasmtime::component::TypedFunc::< (), (Result,), >::new_unchecked(self.return_result_sugar) - }; + } + } + pub fn call_return_result_sugar( + &self, + mut store: S, + ) -> wasmtime::Result> { + let callee = self.func_return_result_sugar(); let (ret0,) = callee.call(store.as_context_mut(), ())?; Ok(ret0) } - pub fn call_return_result_sugar2( + pub fn func_return_result_sugar2( &self, - mut store: S, - ) -> wasmtime::Result> { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc<(), (Result<(), MyErrno>,)> { + unsafe { wasmtime::component::TypedFunc::< (), (Result<(), MyErrno>,), >::new_unchecked(self.return_result_sugar2) - }; + } + } + pub fn call_return_result_sugar2( + &self, + mut store: S, + ) -> wasmtime::Result> { + let callee = self.func_return_result_sugar2(); let (ret0,) = callee.call(store.as_context_mut(), ())?; Ok(ret0) } - pub fn call_return_result_sugar3( + pub fn func_return_result_sugar3( &self, - mut store: S, - ) -> wasmtime::Result> { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc< + (), + (Result,), + > { + unsafe { wasmtime::component::TypedFunc::< (), (Result,), >::new_unchecked(self.return_result_sugar3) - }; + } + } + pub fn call_return_result_sugar3( + &self, + mut store: S, + ) -> wasmtime::Result> { + let callee = self.func_return_result_sugar3(); let (ret0,) = callee.call(store.as_context_mut(), ())?; Ok(ret0) } - pub fn call_return_result_sugar4( + pub fn func_return_result_sugar4( &self, - mut store: S, - ) -> wasmtime::Result> { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc< + (), + (Result<(i32, u32), MyErrno>,), + > { + unsafe { wasmtime::component::TypedFunc::< (), (Result<(i32, u32), MyErrno>,), >::new_unchecked(self.return_result_sugar4) - }; + } + } + pub fn call_return_result_sugar4( + &self, + mut store: S, + ) -> wasmtime::Result> { + let callee = self.func_return_result_sugar4(); let (ret0,) = callee.call(store.as_context_mut(), ())?; Ok(ret0) } - pub fn call_return_option_sugar( + pub fn func_return_option_sugar( &self, - mut store: S, - ) -> wasmtime::Result> { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc<(), (Option,)> { + unsafe { wasmtime::component::TypedFunc::< (), (Option,), >::new_unchecked(self.return_option_sugar) - }; + } + } + pub fn call_return_option_sugar( + &self, + mut store: S, + ) -> wasmtime::Result> { + let callee = self.func_return_option_sugar(); let (ret0,) = callee.call(store.as_context_mut(), ())?; Ok(ret0) } - pub fn call_return_option_sugar2( + pub fn func_return_option_sugar2( &self, - mut store: S, - ) -> wasmtime::Result> { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc<(), (Option,)> { + unsafe { wasmtime::component::TypedFunc::< (), (Option,), >::new_unchecked(self.return_option_sugar2) - }; + } + } + pub fn call_return_option_sugar2( + &self, + mut store: S, + ) -> wasmtime::Result> { + let callee = self.func_return_option_sugar2(); let (ret0,) = callee.call(store.as_context_mut(), ())?; Ok(ret0) } - pub fn call_result_simple( + pub fn func_result_simple( &self, - mut store: S, - ) -> wasmtime::Result> { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc<(), (Result,)> { + unsafe { wasmtime::component::TypedFunc::< (), (Result,), >::new_unchecked(self.result_simple) - }; + } + } + pub fn call_result_simple( + &self, + mut store: S, + ) -> wasmtime::Result> { + let callee = self.func_result_simple(); let (ret0,) = callee.call(store.as_context_mut(), ())?; Ok(ret0) } - pub fn call_is_clone_arg( + pub fn func_is_clone_arg( &self, - mut store: S, - arg0: &IsClone, - ) -> wasmtime::Result<()> { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc<(&IsClone,), ()> { + unsafe { wasmtime::component::TypedFunc::< (&IsClone,), (), >::new_unchecked(self.is_clone_arg) - }; + } + } + pub fn call_is_clone_arg( + &self, + mut store: S, + arg0: &IsClone, + ) -> wasmtime::Result<()> { + let callee = self.func_is_clone_arg(); let () = callee.call(store.as_context_mut(), (arg0,))?; Ok(()) } - pub fn call_is_clone_return( + pub fn func_is_clone_return( &self, - mut store: S, - ) -> wasmtime::Result { - let callee = unsafe { + ) -> wasmtime::component::TypedFunc<(), (IsClone,)> { + unsafe { wasmtime::component::TypedFunc::< (), (IsClone,), >::new_unchecked(self.is_clone_return) - }; + } + } + pub fn call_is_clone_return( + &self, + mut store: S, + ) -> wasmtime::Result { + let callee = self.func_is_clone_return(); let (ret0,) = callee.call(store.as_context_mut(), ())?; Ok(ret0) } diff --git a/crates/component-macro/tests/expanded/variants_async.rs b/crates/component-macro/tests/expanded/variants_async.rs index c853488fe5c2..104a3314ab59 100644 --- a/crates/component-macro/tests/expanded/variants_async.rs +++ b/crates/component-macro/tests/expanded/variants_async.rs @@ -1679,6 +1679,16 @@ pub mod exports { } } impl Guest { + pub fn func_e1_arg( + &self, + ) -> wasmtime::component::TypedFunc<(E1,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (E1,), + (), + >::new_unchecked(self.e1_arg) + } + } pub async fn call_e1_arg( &self, mut store: S, @@ -1687,17 +1697,22 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (E1,), - (), - >::new_unchecked(self.e1_arg) - }; + let callee = self.func_e1_arg(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .await?; Ok(()) } + pub fn func_e1_result( + &self, + ) -> wasmtime::component::TypedFunc<(), (E1,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (E1,), + >::new_unchecked(self.e1_result) + } + } pub async fn call_e1_result( &self, mut store: S, @@ -1705,17 +1720,22 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (E1,), - >::new_unchecked(self.e1_result) - }; + let callee = self.func_e1_result(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .await?; Ok(ret0) } + pub fn func_v1_arg( + &self, + ) -> wasmtime::component::TypedFunc<(&V1,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (&V1,), + (), + >::new_unchecked(self.v1_arg) + } + } pub async fn call_v1_arg( &self, mut store: S, @@ -1724,17 +1744,22 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (&V1,), - (), - >::new_unchecked(self.v1_arg) - }; + let callee = self.func_v1_arg(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .await?; Ok(()) } + pub fn func_v1_result( + &self, + ) -> wasmtime::component::TypedFunc<(), (V1,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (V1,), + >::new_unchecked(self.v1_result) + } + } pub async fn call_v1_result( &self, mut store: S, @@ -1742,17 +1767,22 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (V1,), - >::new_unchecked(self.v1_result) - }; + let callee = self.func_v1_result(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .await?; Ok(ret0) } + pub fn func_bool_arg( + &self, + ) -> wasmtime::component::TypedFunc<(bool,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (bool,), + (), + >::new_unchecked(self.bool_arg) + } + } pub async fn call_bool_arg( &self, mut store: S, @@ -1761,17 +1791,22 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (bool,), - (), - >::new_unchecked(self.bool_arg) - }; + let callee = self.func_bool_arg(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .await?; Ok(()) } + pub fn func_bool_result( + &self, + ) -> wasmtime::component::TypedFunc<(), (bool,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (bool,), + >::new_unchecked(self.bool_result) + } + } pub async fn call_bool_result( &self, mut store: S, @@ -1779,17 +1814,39 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (bool,), - >::new_unchecked(self.bool_result) - }; + let callee = self.func_bool_result(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .await?; Ok(ret0) } + pub fn func_option_arg( + &self, + ) -> wasmtime::component::TypedFunc< + ( + Option, + Option<()>, + Option, + Option, + Option, + Option>, + ), + (), + > { + unsafe { + wasmtime::component::TypedFunc::< + ( + Option, + Option<()>, + Option, + Option, + Option, + Option>, + ), + (), + >::new_unchecked(self.option_arg) + } + } pub async fn call_option_arg( &self, mut store: S, @@ -1803,19 +1860,7 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - ( - Option, - Option<()>, - Option, - Option, - Option, - Option>, - ), - (), - >::new_unchecked(self.option_arg) - }; + let callee = self.func_option_arg(); let () = callee .call_async( store.as_context_mut(), @@ -1824,23 +1869,22 @@ pub mod exports { .await?; Ok(()) } - pub async fn call_option_result( + pub fn func_option_result( &self, - mut store: S, - ) -> wasmtime::Result< + ) -> wasmtime::component::TypedFunc< + (), ( - Option, - Option<()>, - Option, - Option, - Option, - Option>, + ( + Option, + Option<()>, + Option, + Option, + Option, + Option>, + ), ), - > - where - ::Data: Send, - { - let callee = unsafe { + > { + unsafe { wasmtime::component::TypedFunc::< (), ( @@ -1854,12 +1898,43 @@ pub mod exports { ), ), >::new_unchecked(self.option_result) - }; + } + } + pub async fn call_option_result( + &self, + mut store: S, + ) -> wasmtime::Result< + ( + Option, + Option<()>, + Option, + Option, + Option, + Option>, + ), + > + where + ::Data: Send, + { + let callee = self.func_option_result(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .await?; Ok(ret0) } + pub fn func_casts( + &self, + ) -> wasmtime::component::TypedFunc< + (Casts1, Casts2, Casts3, Casts4, Casts5, Casts6), + ((Casts1, Casts2, Casts3, Casts4, Casts5, Casts6),), + > { + unsafe { + wasmtime::component::TypedFunc::< + (Casts1, Casts2, Casts3, Casts4, Casts5, Casts6), + ((Casts1, Casts2, Casts3, Casts4, Casts5, Casts6),), + >::new_unchecked(self.casts) + } + } pub async fn call_casts( &self, mut store: S, @@ -1875,12 +1950,7 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (Casts1, Casts2, Casts3, Casts4, Casts5, Casts6), - ((Casts1, Casts2, Casts3, Casts4, Casts5, Casts6),), - >::new_unchecked(self.casts) - }; + let callee = self.func_casts(); let (ret0,) = callee .call_async( store.as_context_mut(), @@ -1889,6 +1959,33 @@ pub mod exports { .await?; Ok(ret0) } + pub fn func_result_arg( + &self, + ) -> wasmtime::component::TypedFunc< + ( + Result<(), ()>, + Result<(), E1>, + Result, + Result<(), ()>, + Result, + Result<&str, &[u8]>, + ), + (), + > { + unsafe { + wasmtime::component::TypedFunc::< + ( + Result<(), ()>, + Result<(), E1>, + Result, + Result<(), ()>, + Result, + Result<&str, &[u8]>, + ), + (), + >::new_unchecked(self.result_arg) + } + } pub async fn call_result_arg( &self, mut store: S, @@ -1902,19 +1999,7 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - ( - Result<(), ()>, - Result<(), E1>, - Result, - Result<(), ()>, - Result, - Result<&str, &[u8]>, - ), - (), - >::new_unchecked(self.result_arg) - }; + let callee = self.func_result_arg(); let () = callee .call_async( store.as_context_mut(), @@ -1923,26 +2008,25 @@ pub mod exports { .await?; Ok(()) } - pub async fn call_result_result( + pub fn func_result_result( &self, - mut store: S, - ) -> wasmtime::Result< + ) -> wasmtime::component::TypedFunc< + (), ( - Result<(), ()>, - Result<(), E1>, - Result, - Result<(), ()>, - Result, - Result< - wasmtime::component::__internal::String, - wasmtime::component::__internal::Vec, - >, + ( + Result<(), ()>, + Result<(), E1>, + Result, + Result<(), ()>, + Result, + Result< + wasmtime::component::__internal::String, + wasmtime::component::__internal::Vec, + >, + ), ), - > - where - ::Data: Send, - { - let callee = unsafe { + > { + unsafe { wasmtime::component::TypedFunc::< (), ( @@ -1959,12 +2043,43 @@ pub mod exports { ), ), >::new_unchecked(self.result_result) - }; + } + } + pub async fn call_result_result( + &self, + mut store: S, + ) -> wasmtime::Result< + ( + Result<(), ()>, + Result<(), E1>, + Result, + Result<(), ()>, + Result, + Result< + wasmtime::component::__internal::String, + wasmtime::component::__internal::Vec, + >, + ), + > + where + ::Data: Send, + { + let callee = self.func_result_result(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .await?; Ok(ret0) } + pub fn func_return_result_sugar( + &self, + ) -> wasmtime::component::TypedFunc<(), (Result,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (Result,), + >::new_unchecked(self.return_result_sugar) + } + } pub async fn call_return_result_sugar( &self, mut store: S, @@ -1972,17 +2087,22 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (Result,), - >::new_unchecked(self.return_result_sugar) - }; + let callee = self.func_return_result_sugar(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .await?; Ok(ret0) } + pub fn func_return_result_sugar2( + &self, + ) -> wasmtime::component::TypedFunc<(), (Result<(), MyErrno>,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (Result<(), MyErrno>,), + >::new_unchecked(self.return_result_sugar2) + } + } pub async fn call_return_result_sugar2( &self, mut store: S, @@ -1990,17 +2110,25 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (Result<(), MyErrno>,), - >::new_unchecked(self.return_result_sugar2) - }; + let callee = self.func_return_result_sugar2(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .await?; Ok(ret0) } + pub fn func_return_result_sugar3( + &self, + ) -> wasmtime::component::TypedFunc< + (), + (Result,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (), + (Result,), + >::new_unchecked(self.return_result_sugar3) + } + } pub async fn call_return_result_sugar3( &self, mut store: S, @@ -2008,17 +2136,25 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (Result,), - >::new_unchecked(self.return_result_sugar3) - }; + let callee = self.func_return_result_sugar3(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .await?; Ok(ret0) } + pub fn func_return_result_sugar4( + &self, + ) -> wasmtime::component::TypedFunc< + (), + (Result<(i32, u32), MyErrno>,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (), + (Result<(i32, u32), MyErrno>,), + >::new_unchecked(self.return_result_sugar4) + } + } pub async fn call_return_result_sugar4( &self, mut store: S, @@ -2026,17 +2162,22 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (Result<(i32, u32), MyErrno>,), - >::new_unchecked(self.return_result_sugar4) - }; + let callee = self.func_return_result_sugar4(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .await?; Ok(ret0) } + pub fn func_return_option_sugar( + &self, + ) -> wasmtime::component::TypedFunc<(), (Option,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (Option,), + >::new_unchecked(self.return_option_sugar) + } + } pub async fn call_return_option_sugar( &self, mut store: S, @@ -2044,17 +2185,22 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (Option,), - >::new_unchecked(self.return_option_sugar) - }; + let callee = self.func_return_option_sugar(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .await?; Ok(ret0) } + pub fn func_return_option_sugar2( + &self, + ) -> wasmtime::component::TypedFunc<(), (Option,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (Option,), + >::new_unchecked(self.return_option_sugar2) + } + } pub async fn call_return_option_sugar2( &self, mut store: S, @@ -2062,17 +2208,22 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (Option,), - >::new_unchecked(self.return_option_sugar2) - }; + let callee = self.func_return_option_sugar2(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .await?; Ok(ret0) } + pub fn func_result_simple( + &self, + ) -> wasmtime::component::TypedFunc<(), (Result,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (Result,), + >::new_unchecked(self.result_simple) + } + } pub async fn call_result_simple( &self, mut store: S, @@ -2080,17 +2231,22 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (Result,), - >::new_unchecked(self.result_simple) - }; + let callee = self.func_result_simple(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .await?; Ok(ret0) } + pub fn func_is_clone_arg( + &self, + ) -> wasmtime::component::TypedFunc<(&IsClone,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (&IsClone,), + (), + >::new_unchecked(self.is_clone_arg) + } + } pub async fn call_is_clone_arg( &self, mut store: S, @@ -2099,17 +2255,22 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (&IsClone,), - (), - >::new_unchecked(self.is_clone_arg) - }; + let callee = self.func_is_clone_arg(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .await?; Ok(()) } + pub fn func_is_clone_return( + &self, + ) -> wasmtime::component::TypedFunc<(), (IsClone,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (IsClone,), + >::new_unchecked(self.is_clone_return) + } + } pub async fn call_is_clone_return( &self, mut store: S, @@ -2117,12 +2278,7 @@ pub mod exports { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (IsClone,), - >::new_unchecked(self.is_clone_return) - }; + let callee = self.func_is_clone_return(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .await?; diff --git a/crates/component-macro/tests/expanded/variants_concurrent.rs b/crates/component-macro/tests/expanded/variants_concurrent.rs index 1d311478d1b8..dc9cc289dc3b 100644 --- a/crates/component-macro/tests/expanded/variants_concurrent.rs +++ b/crates/component-macro/tests/expanded/variants_concurrent.rs @@ -1533,6 +1533,16 @@ pub mod exports { } } impl Guest { + pub fn func_e1_arg( + &self, + ) -> wasmtime::component::TypedFunc<(E1,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (E1,), + (), + >::new_unchecked(self.e1_arg) + } + } pub async fn call_e1_arg<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -1542,15 +1552,20 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (E1,), - (), - >::new_unchecked(self.e1_arg) - }; + let callee = self.func_e1_arg(); let () = callee.call_concurrent(accessor, (arg0,)).await?; Ok(()) } + pub fn func_e1_result( + &self, + ) -> wasmtime::component::TypedFunc<(), (E1,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (E1,), + >::new_unchecked(self.e1_result) + } + } pub async fn call_e1_result<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -1559,15 +1574,20 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (E1,), - >::new_unchecked(self.e1_result) - }; + let callee = self.func_e1_result(); let (ret0,) = callee.call_concurrent(accessor, ()).await?; Ok(ret0) } + pub fn func_v1_arg( + &self, + ) -> wasmtime::component::TypedFunc<(V1,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (V1,), + (), + >::new_unchecked(self.v1_arg) + } + } pub async fn call_v1_arg<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -1577,15 +1597,20 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (V1,), - (), - >::new_unchecked(self.v1_arg) - }; + let callee = self.func_v1_arg(); let () = callee.call_concurrent(accessor, (arg0,)).await?; Ok(()) } + pub fn func_v1_result( + &self, + ) -> wasmtime::component::TypedFunc<(), (V1,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (V1,), + >::new_unchecked(self.v1_result) + } + } pub async fn call_v1_result<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -1594,15 +1619,20 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (V1,), - >::new_unchecked(self.v1_result) - }; + let callee = self.func_v1_result(); let (ret0,) = callee.call_concurrent(accessor, ()).await?; Ok(ret0) } + pub fn func_bool_arg( + &self, + ) -> wasmtime::component::TypedFunc<(bool,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (bool,), + (), + >::new_unchecked(self.bool_arg) + } + } pub async fn call_bool_arg<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -1612,15 +1642,20 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (bool,), - (), - >::new_unchecked(self.bool_arg) - }; + let callee = self.func_bool_arg(); let () = callee.call_concurrent(accessor, (arg0,)).await?; Ok(()) } + pub fn func_bool_result( + &self, + ) -> wasmtime::component::TypedFunc<(), (bool,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (bool,), + >::new_unchecked(self.bool_result) + } + } pub async fn call_bool_result<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -1629,15 +1664,37 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (bool,), - >::new_unchecked(self.bool_result) - }; + let callee = self.func_bool_result(); let (ret0,) = callee.call_concurrent(accessor, ()).await?; Ok(ret0) } + pub fn func_option_arg( + &self, + ) -> wasmtime::component::TypedFunc< + ( + Option, + Option<()>, + Option, + Option, + Option, + Option>, + ), + (), + > { + unsafe { + wasmtime::component::TypedFunc::< + ( + Option, + Option<()>, + Option, + Option, + Option, + Option>, + ), + (), + >::new_unchecked(self.option_arg) + } + } pub async fn call_option_arg<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -1652,19 +1709,7 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - ( - Option, - Option<()>, - Option, - Option, - Option, - Option>, - ), - (), - >::new_unchecked(self.option_arg) - }; + let callee = self.func_option_arg(); let () = callee .call_concurrent( accessor, @@ -1673,6 +1718,37 @@ pub mod exports { .await?; Ok(()) } + pub fn func_option_result( + &self, + ) -> wasmtime::component::TypedFunc< + (), + ( + ( + Option, + Option<()>, + Option, + Option, + Option, + Option>, + ), + ), + > { + unsafe { + wasmtime::component::TypedFunc::< + (), + ( + ( + Option, + Option<()>, + Option, + Option, + Option, + Option>, + ), + ), + >::new_unchecked(self.option_result) + } + } pub async fn call_option_result<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -1690,24 +1766,23 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - ( - ( - Option, - Option<()>, - Option, - Option, - Option, - Option>, - ), - ), - >::new_unchecked(self.option_result) - }; + let callee = self.func_option_result(); let (ret0,) = callee.call_concurrent(accessor, ()).await?; Ok(ret0) } + pub fn func_casts( + &self, + ) -> wasmtime::component::TypedFunc< + (Casts1, Casts2, Casts3, Casts4, Casts5, Casts6), + ((Casts1, Casts2, Casts3, Casts4, Casts5, Casts6),), + > { + unsafe { + wasmtime::component::TypedFunc::< + (Casts1, Casts2, Casts3, Casts4, Casts5, Casts6), + ((Casts1, Casts2, Casts3, Casts4, Casts5, Casts6),), + >::new_unchecked(self.casts) + } + } pub async fn call_casts<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -1724,12 +1799,7 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (Casts1, Casts2, Casts3, Casts4, Casts5, Casts6), - ((Casts1, Casts2, Casts3, Casts4, Casts5, Casts6),), - >::new_unchecked(self.casts) - }; + let callee = self.func_casts(); let (ret0,) = callee .call_concurrent( accessor, @@ -1738,6 +1808,39 @@ pub mod exports { .await?; Ok(ret0) } + pub fn func_result_arg( + &self, + ) -> wasmtime::component::TypedFunc< + ( + Result<(), ()>, + Result<(), E1>, + Result, + Result<(), ()>, + Result, + Result< + wasmtime::component::__internal::String, + wasmtime::component::__internal::Vec, + >, + ), + (), + > { + unsafe { + wasmtime::component::TypedFunc::< + ( + Result<(), ()>, + Result<(), E1>, + Result, + Result<(), ()>, + Result, + Result< + wasmtime::component::__internal::String, + wasmtime::component::__internal::Vec, + >, + ), + (), + >::new_unchecked(self.result_arg) + } + } pub async fn call_result_arg<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -1755,22 +1858,7 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - ( - Result<(), ()>, - Result<(), E1>, - Result, - Result<(), ()>, - Result, - Result< - wasmtime::component::__internal::String, - wasmtime::component::__internal::Vec, - >, - ), - (), - >::new_unchecked(self.result_arg) - }; + let callee = self.func_result_arg(); let () = callee .call_concurrent( accessor, @@ -1779,6 +1867,43 @@ pub mod exports { .await?; Ok(()) } + pub fn func_result_result( + &self, + ) -> wasmtime::component::TypedFunc< + (), + ( + ( + Result<(), ()>, + Result<(), E1>, + Result, + Result<(), ()>, + Result, + Result< + wasmtime::component::__internal::String, + wasmtime::component::__internal::Vec, + >, + ), + ), + > { + unsafe { + wasmtime::component::TypedFunc::< + (), + ( + ( + Result<(), ()>, + Result<(), E1>, + Result, + Result<(), ()>, + Result, + Result< + wasmtime::component::__internal::String, + wasmtime::component::__internal::Vec, + >, + ), + ), + >::new_unchecked(self.result_result) + } + } pub async fn call_result_result<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -1799,27 +1924,20 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - ( - ( - Result<(), ()>, - Result<(), E1>, - Result, - Result<(), ()>, - Result, - Result< - wasmtime::component::__internal::String, - wasmtime::component::__internal::Vec, - >, - ), - ), - >::new_unchecked(self.result_result) - }; + let callee = self.func_result_result(); let (ret0,) = callee.call_concurrent(accessor, ()).await?; Ok(ret0) } + pub fn func_return_result_sugar( + &self, + ) -> wasmtime::component::TypedFunc<(), (Result,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (Result,), + >::new_unchecked(self.return_result_sugar) + } + } pub async fn call_return_result_sugar<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -1828,15 +1946,20 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (Result,), - >::new_unchecked(self.return_result_sugar) - }; + let callee = self.func_return_result_sugar(); let (ret0,) = callee.call_concurrent(accessor, ()).await?; Ok(ret0) } + pub fn func_return_result_sugar2( + &self, + ) -> wasmtime::component::TypedFunc<(), (Result<(), MyErrno>,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (Result<(), MyErrno>,), + >::new_unchecked(self.return_result_sugar2) + } + } pub async fn call_return_result_sugar2<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -1845,15 +1968,23 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (Result<(), MyErrno>,), - >::new_unchecked(self.return_result_sugar2) - }; + let callee = self.func_return_result_sugar2(); let (ret0,) = callee.call_concurrent(accessor, ()).await?; Ok(ret0) } + pub fn func_return_result_sugar3( + &self, + ) -> wasmtime::component::TypedFunc< + (), + (Result,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (), + (Result,), + >::new_unchecked(self.return_result_sugar3) + } + } pub async fn call_return_result_sugar3<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -1862,15 +1993,23 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (Result,), - >::new_unchecked(self.return_result_sugar3) - }; + let callee = self.func_return_result_sugar3(); let (ret0,) = callee.call_concurrent(accessor, ()).await?; Ok(ret0) } + pub fn func_return_result_sugar4( + &self, + ) -> wasmtime::component::TypedFunc< + (), + (Result<(i32, u32), MyErrno>,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (), + (Result<(i32, u32), MyErrno>,), + >::new_unchecked(self.return_result_sugar4) + } + } pub async fn call_return_result_sugar4<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -1879,15 +2018,20 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (Result<(i32, u32), MyErrno>,), - >::new_unchecked(self.return_result_sugar4) - }; + let callee = self.func_return_result_sugar4(); let (ret0,) = callee.call_concurrent(accessor, ()).await?; Ok(ret0) } + pub fn func_return_option_sugar( + &self, + ) -> wasmtime::component::TypedFunc<(), (Option,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (Option,), + >::new_unchecked(self.return_option_sugar) + } + } pub async fn call_return_option_sugar<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -1896,15 +2040,20 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (Option,), - >::new_unchecked(self.return_option_sugar) - }; + let callee = self.func_return_option_sugar(); let (ret0,) = callee.call_concurrent(accessor, ()).await?; Ok(ret0) } + pub fn func_return_option_sugar2( + &self, + ) -> wasmtime::component::TypedFunc<(), (Option,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (Option,), + >::new_unchecked(self.return_option_sugar2) + } + } pub async fn call_return_option_sugar2<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -1913,15 +2062,20 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (Option,), - >::new_unchecked(self.return_option_sugar2) - }; + let callee = self.func_return_option_sugar2(); let (ret0,) = callee.call_concurrent(accessor, ()).await?; Ok(ret0) } + pub fn func_result_simple( + &self, + ) -> wasmtime::component::TypedFunc<(), (Result,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (Result,), + >::new_unchecked(self.result_simple) + } + } pub async fn call_result_simple<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -1930,15 +2084,20 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (Result,), - >::new_unchecked(self.result_simple) - }; + let callee = self.func_result_simple(); let (ret0,) = callee.call_concurrent(accessor, ()).await?; Ok(ret0) } + pub fn func_is_clone_arg( + &self, + ) -> wasmtime::component::TypedFunc<(IsClone,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (IsClone,), + (), + >::new_unchecked(self.is_clone_arg) + } + } pub async fn call_is_clone_arg<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -1948,15 +2107,20 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (IsClone,), - (), - >::new_unchecked(self.is_clone_arg) - }; + let callee = self.func_is_clone_arg(); let () = callee.call_concurrent(accessor, (arg0,)).await?; Ok(()) } + pub fn func_is_clone_return( + &self, + ) -> wasmtime::component::TypedFunc<(), (IsClone,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (IsClone,), + >::new_unchecked(self.is_clone_return) + } + } pub async fn call_is_clone_return<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -1965,12 +2129,7 @@ pub mod exports { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (IsClone,), - >::new_unchecked(self.is_clone_return) - }; + let callee = self.func_is_clone_return(); let (ret0,) = callee.call_concurrent(accessor, ()).await?; Ok(ret0) } diff --git a/crates/component-macro/tests/expanded/variants_tracing_async.rs b/crates/component-macro/tests/expanded/variants_tracing_async.rs index 0f408b2bf05e..f105b1acc279 100644 --- a/crates/component-macro/tests/expanded/variants_tracing_async.rs +++ b/crates/component-macro/tests/expanded/variants_tracing_async.rs @@ -1977,6 +1977,16 @@ pub mod exports { } } impl Guest { + pub fn func_e1_arg( + &self, + ) -> wasmtime::component::TypedFunc<(E1,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (E1,), + (), + >::new_unchecked(self.e1_arg) + } + } pub async fn call_e1_arg( &self, mut store: S, @@ -1990,18 +2000,23 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/variants", function = "e1-arg", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (E1,), - (), - >::new_unchecked(self.e1_arg) - }; + let callee = self.func_e1_arg(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .instrument(span.clone()) .await?; Ok(()) } + pub fn func_e1_result( + &self, + ) -> wasmtime::component::TypedFunc<(), (E1,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (E1,), + >::new_unchecked(self.e1_result) + } + } pub async fn call_e1_result( &self, mut store: S, @@ -2014,18 +2029,23 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/variants", function = "e1-result", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (E1,), - >::new_unchecked(self.e1_result) - }; + let callee = self.func_e1_result(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) .await?; Ok(ret0) } + pub fn func_v1_arg( + &self, + ) -> wasmtime::component::TypedFunc<(&V1,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (&V1,), + (), + >::new_unchecked(self.v1_arg) + } + } pub async fn call_v1_arg( &self, mut store: S, @@ -2039,18 +2059,23 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/variants", function = "v1-arg", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (&V1,), - (), - >::new_unchecked(self.v1_arg) - }; + let callee = self.func_v1_arg(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .instrument(span.clone()) .await?; Ok(()) } + pub fn func_v1_result( + &self, + ) -> wasmtime::component::TypedFunc<(), (V1,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (V1,), + >::new_unchecked(self.v1_result) + } + } pub async fn call_v1_result( &self, mut store: S, @@ -2063,18 +2088,23 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/variants", function = "v1-result", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (V1,), - >::new_unchecked(self.v1_result) - }; + let callee = self.func_v1_result(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) .await?; Ok(ret0) } + pub fn func_bool_arg( + &self, + ) -> wasmtime::component::TypedFunc<(bool,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (bool,), + (), + >::new_unchecked(self.bool_arg) + } + } pub async fn call_bool_arg( &self, mut store: S, @@ -2088,18 +2118,23 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/variants", function = "bool-arg", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (bool,), - (), - >::new_unchecked(self.bool_arg) - }; + let callee = self.func_bool_arg(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .instrument(span.clone()) .await?; Ok(()) } + pub fn func_bool_result( + &self, + ) -> wasmtime::component::TypedFunc<(), (bool,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (bool,), + >::new_unchecked(self.bool_result) + } + } pub async fn call_bool_result( &self, mut store: S, @@ -2112,18 +2147,40 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/variants", function = "bool-result", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (bool,), - >::new_unchecked(self.bool_result) - }; + let callee = self.func_bool_result(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) .await?; Ok(ret0) } + pub fn func_option_arg( + &self, + ) -> wasmtime::component::TypedFunc< + ( + Option, + Option<()>, + Option, + Option, + Option, + Option>, + ), + (), + > { + unsafe { + wasmtime::component::TypedFunc::< + ( + Option, + Option<()>, + Option, + Option, + Option, + Option>, + ), + (), + >::new_unchecked(self.option_arg) + } + } pub async fn call_option_arg( &self, mut store: S, @@ -2142,19 +2199,7 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/variants", function = "option-arg", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - ( - Option, - Option<()>, - Option, - Option, - Option, - Option>, - ), - (), - >::new_unchecked(self.option_arg) - }; + let callee = self.func_option_arg(); let () = callee .call_async( store.as_context_mut(), @@ -2164,6 +2209,37 @@ pub mod exports { .await?; Ok(()) } + pub fn func_option_result( + &self, + ) -> wasmtime::component::TypedFunc< + (), + ( + ( + Option, + Option<()>, + Option, + Option, + Option, + Option>, + ), + ), + > { + unsafe { + wasmtime::component::TypedFunc::< + (), + ( + ( + Option, + Option<()>, + Option, + Option, + Option, + Option>, + ), + ), + >::new_unchecked(self.option_result) + } + } pub async fn call_option_result( &self, mut store: S, @@ -2185,27 +2261,26 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/variants", function = "option-result", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - ( - ( - Option, - Option<()>, - Option, - Option, - Option, - Option>, - ), - ), - >::new_unchecked(self.option_result) - }; + let callee = self.func_option_result(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) .await?; Ok(ret0) } + pub fn func_casts( + &self, + ) -> wasmtime::component::TypedFunc< + (Casts1, Casts2, Casts3, Casts4, Casts5, Casts6), + ((Casts1, Casts2, Casts3, Casts4, Casts5, Casts6),), + > { + unsafe { + wasmtime::component::TypedFunc::< + (Casts1, Casts2, Casts3, Casts4, Casts5, Casts6), + ((Casts1, Casts2, Casts3, Casts4, Casts5, Casts6),), + >::new_unchecked(self.casts) + } + } pub async fn call_casts( &self, mut store: S, @@ -2226,12 +2301,7 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/variants", function = "casts", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (Casts1, Casts2, Casts3, Casts4, Casts5, Casts6), - ((Casts1, Casts2, Casts3, Casts4, Casts5, Casts6),), - >::new_unchecked(self.casts) - }; + let callee = self.func_casts(); let (ret0,) = callee .call_async( store.as_context_mut(), @@ -2241,6 +2311,33 @@ pub mod exports { .await?; Ok(ret0) } + pub fn func_result_arg( + &self, + ) -> wasmtime::component::TypedFunc< + ( + Result<(), ()>, + Result<(), E1>, + Result, + Result<(), ()>, + Result, + Result<&str, &[u8]>, + ), + (), + > { + unsafe { + wasmtime::component::TypedFunc::< + ( + Result<(), ()>, + Result<(), E1>, + Result, + Result<(), ()>, + Result, + Result<&str, &[u8]>, + ), + (), + >::new_unchecked(self.result_arg) + } + } pub async fn call_result_arg( &self, mut store: S, @@ -2259,19 +2356,7 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/variants", function = "result-arg", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - ( - Result<(), ()>, - Result<(), E1>, - Result, - Result<(), ()>, - Result, - Result<&str, &[u8]>, - ), - (), - >::new_unchecked(self.result_arg) - }; + let callee = self.func_result_arg(); let () = callee .call_async( store.as_context_mut(), @@ -2281,6 +2366,43 @@ pub mod exports { .await?; Ok(()) } + pub fn func_result_result( + &self, + ) -> wasmtime::component::TypedFunc< + (), + ( + ( + Result<(), ()>, + Result<(), E1>, + Result, + Result<(), ()>, + Result, + Result< + wasmtime::component::__internal::String, + wasmtime::component::__internal::Vec, + >, + ), + ), + > { + unsafe { + wasmtime::component::TypedFunc::< + (), + ( + ( + Result<(), ()>, + Result<(), E1>, + Result, + Result<(), ()>, + Result, + Result< + wasmtime::component::__internal::String, + wasmtime::component::__internal::Vec, + >, + ), + ), + >::new_unchecked(self.result_result) + } + } pub async fn call_result_result( &self, mut store: S, @@ -2305,30 +2427,23 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/variants", function = "result-result", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - ( - ( - Result<(), ()>, - Result<(), E1>, - Result, - Result<(), ()>, - Result, - Result< - wasmtime::component::__internal::String, - wasmtime::component::__internal::Vec, - >, - ), - ), - >::new_unchecked(self.result_result) - }; + let callee = self.func_result_result(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) .await?; Ok(ret0) } + pub fn func_return_result_sugar( + &self, + ) -> wasmtime::component::TypedFunc<(), (Result,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (Result,), + >::new_unchecked(self.return_result_sugar) + } + } pub async fn call_return_result_sugar( &self, mut store: S, @@ -2341,18 +2456,23 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/variants", function = "return-result-sugar", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (Result,), - >::new_unchecked(self.return_result_sugar) - }; + let callee = self.func_return_result_sugar(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) .await?; Ok(ret0) } + pub fn func_return_result_sugar2( + &self, + ) -> wasmtime::component::TypedFunc<(), (Result<(), MyErrno>,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (Result<(), MyErrno>,), + >::new_unchecked(self.return_result_sugar2) + } + } pub async fn call_return_result_sugar2( &self, mut store: S, @@ -2365,18 +2485,26 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/variants", function = "return-result-sugar2", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (Result<(), MyErrno>,), - >::new_unchecked(self.return_result_sugar2) - }; + let callee = self.func_return_result_sugar2(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) .await?; Ok(ret0) } + pub fn func_return_result_sugar3( + &self, + ) -> wasmtime::component::TypedFunc< + (), + (Result,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (), + (Result,), + >::new_unchecked(self.return_result_sugar3) + } + } pub async fn call_return_result_sugar3( &self, mut store: S, @@ -2389,18 +2517,26 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/variants", function = "return-result-sugar3", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (Result,), - >::new_unchecked(self.return_result_sugar3) - }; + let callee = self.func_return_result_sugar3(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) .await?; Ok(ret0) } + pub fn func_return_result_sugar4( + &self, + ) -> wasmtime::component::TypedFunc< + (), + (Result<(i32, u32), MyErrno>,), + > { + unsafe { + wasmtime::component::TypedFunc::< + (), + (Result<(i32, u32), MyErrno>,), + >::new_unchecked(self.return_result_sugar4) + } + } pub async fn call_return_result_sugar4( &self, mut store: S, @@ -2413,18 +2549,23 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/variants", function = "return-result-sugar4", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (Result<(i32, u32), MyErrno>,), - >::new_unchecked(self.return_result_sugar4) - }; + let callee = self.func_return_result_sugar4(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) .await?; Ok(ret0) } + pub fn func_return_option_sugar( + &self, + ) -> wasmtime::component::TypedFunc<(), (Option,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (Option,), + >::new_unchecked(self.return_option_sugar) + } + } pub async fn call_return_option_sugar( &self, mut store: S, @@ -2437,18 +2578,23 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/variants", function = "return-option-sugar", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (Option,), - >::new_unchecked(self.return_option_sugar) - }; + let callee = self.func_return_option_sugar(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) .await?; Ok(ret0) } + pub fn func_return_option_sugar2( + &self, + ) -> wasmtime::component::TypedFunc<(), (Option,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (Option,), + >::new_unchecked(self.return_option_sugar2) + } + } pub async fn call_return_option_sugar2( &self, mut store: S, @@ -2461,18 +2607,23 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/variants", function = "return-option-sugar2", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (Option,), - >::new_unchecked(self.return_option_sugar2) - }; + let callee = self.func_return_option_sugar2(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) .await?; Ok(ret0) } + pub fn func_result_simple( + &self, + ) -> wasmtime::component::TypedFunc<(), (Result,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (Result,), + >::new_unchecked(self.result_simple) + } + } pub async fn call_result_simple( &self, mut store: S, @@ -2485,18 +2636,23 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/variants", function = "result-simple", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (Result,), - >::new_unchecked(self.result_simple) - }; + let callee = self.func_result_simple(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) .await?; Ok(ret0) } + pub fn func_is_clone_arg( + &self, + ) -> wasmtime::component::TypedFunc<(&IsClone,), ()> { + unsafe { + wasmtime::component::TypedFunc::< + (&IsClone,), + (), + >::new_unchecked(self.is_clone_arg) + } + } pub async fn call_is_clone_arg( &self, mut store: S, @@ -2510,18 +2666,23 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/variants", function = "is-clone-arg", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (&IsClone,), - (), - >::new_unchecked(self.is_clone_arg) - }; + let callee = self.func_is_clone_arg(); let () = callee .call_async(store.as_context_mut(), (arg0,)) .instrument(span.clone()) .await?; Ok(()) } + pub fn func_is_clone_return( + &self, + ) -> wasmtime::component::TypedFunc<(), (IsClone,)> { + unsafe { + wasmtime::component::TypedFunc::< + (), + (IsClone,), + >::new_unchecked(self.is_clone_return) + } + } pub async fn call_is_clone_return( &self, mut store: S, @@ -2534,12 +2695,7 @@ pub mod exports { tracing::Level::TRACE, "wit-bindgen export", module = "foo:foo/variants", function = "is-clone-return", ); - let callee = unsafe { - wasmtime::component::TypedFunc::< - (), - (IsClone,), - >::new_unchecked(self.is_clone_return) - }; + let callee = self.func_is_clone_return(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone()) diff --git a/crates/component-macro/tests/expanded/worlds-with-types.rs b/crates/component-macro/tests/expanded/worlds-with-types.rs index 19041eaaab16..d79b11d0182c 100644 --- a/crates/component-macro/tests/expanded/worlds-with-types.rs +++ b/crates/component-macro/tests/expanded/worlds-with-types.rs @@ -219,13 +219,16 @@ const _: () = { foo::foo::i::add_to_linker::(linker, host_getter)?; Ok(()) } + pub fn func_f(&self) -> wasmtime::component::TypedFunc<(), ((T, U, R),)> { + unsafe { + wasmtime::component::TypedFunc::<(), ((T, U, R),)>::new_unchecked(self.f) + } + } pub fn call_f( &self, mut store: S, ) -> wasmtime::Result<(T, U, R)> { - let callee = unsafe { - wasmtime::component::TypedFunc::<(), ((T, U, R),)>::new_unchecked(self.f) - }; + let callee = self.func_f(); let (ret0,) = callee.call(store.as_context_mut(), ())?; Ok(ret0) } diff --git a/crates/component-macro/tests/expanded/worlds-with-types_async.rs b/crates/component-macro/tests/expanded/worlds-with-types_async.rs index 796067c36cca..f61e8dfc98e2 100644 --- a/crates/component-macro/tests/expanded/worlds-with-types_async.rs +++ b/crates/component-macro/tests/expanded/worlds-with-types_async.rs @@ -219,6 +219,11 @@ const _: () = { foo::foo::i::add_to_linker::(linker, host_getter)?; Ok(()) } + pub fn func_f(&self) -> wasmtime::component::TypedFunc<(), ((T, U, R),)> { + unsafe { + wasmtime::component::TypedFunc::<(), ((T, U, R),)>::new_unchecked(self.f) + } + } pub async fn call_f( &self, mut store: S, @@ -226,9 +231,7 @@ const _: () = { where ::Data: Send, { - let callee = unsafe { - wasmtime::component::TypedFunc::<(), ((T, U, R),)>::new_unchecked(self.f) - }; + let callee = self.func_f(); let (ret0,) = callee.call_async(store.as_context_mut(), ()).await?; Ok(ret0) } diff --git a/crates/component-macro/tests/expanded/worlds-with-types_concurrent.rs b/crates/component-macro/tests/expanded/worlds-with-types_concurrent.rs index 01b7a15cd800..95a98696d88b 100644 --- a/crates/component-macro/tests/expanded/worlds-with-types_concurrent.rs +++ b/crates/component-macro/tests/expanded/worlds-with-types_concurrent.rs @@ -219,6 +219,11 @@ const _: () = { foo::foo::i::add_to_linker::(linker, host_getter)?; Ok(()) } + pub fn func_f(&self) -> wasmtime::component::TypedFunc<(), ((T, U, R),)> { + unsafe { + wasmtime::component::TypedFunc::<(), ((T, U, R),)>::new_unchecked(self.f) + } + } pub async fn call_f<_T, _D>( &self, accessor: &wasmtime::component::Accessor<_T, _D>, @@ -227,9 +232,7 @@ const _: () = { _T: Send, _D: wasmtime::component::HasData, { - let callee = unsafe { - wasmtime::component::TypedFunc::<(), ((T, U, R),)>::new_unchecked(self.f) - }; + let callee = self.func_f(); let (ret0,) = callee.call_concurrent(accessor, ()).await?; Ok(ret0) } diff --git a/crates/component-macro/tests/expanded/worlds-with-types_tracing_async.rs b/crates/component-macro/tests/expanded/worlds-with-types_tracing_async.rs index 25d4f4dca61b..6ac313d3b7a5 100644 --- a/crates/component-macro/tests/expanded/worlds-with-types_tracing_async.rs +++ b/crates/component-macro/tests/expanded/worlds-with-types_tracing_async.rs @@ -219,6 +219,11 @@ const _: () = { foo::foo::i::add_to_linker::(linker, host_getter)?; Ok(()) } + pub fn func_f(&self) -> wasmtime::component::TypedFunc<(), ((T, U, R),)> { + unsafe { + wasmtime::component::TypedFunc::<(), ((T, U, R),)>::new_unchecked(self.f) + } + } pub async fn call_f( &self, mut store: S, @@ -231,9 +236,7 @@ const _: () = { tracing::Level::TRACE, "wit-bindgen export", module = "default", function = "f", ); - let callee = unsafe { - wasmtime::component::TypedFunc::<(), ((T, U, R),)>::new_unchecked(self.f) - }; + let callee = self.func_f(); let (ret0,) = callee .call_async(store.as_context_mut(), ()) .instrument(span.clone())