Skip to content
This repository was archived by the owner on Sep 8, 2025. It is now read-only.

Commit beca86b

Browse files
authored
Re-enable concurrent bindings generation tests (#10972)
* Re-enable concurrent bindings generation tests This commit re-enables tests for bindings generation for concurrent calls in the main repo after all syncs have now finished with wasip3. This additionally adds some skeleton APIs that the bindings generator uses which are necessary to get tests passing. * Update test expectations
1 parent ef7bdf5 commit beca86b

41 files changed

Lines changed: 9081 additions & 6742 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

crates/component-macro/tests/codegen.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,14 @@ macro_rules! gentest {
1212
async: true,
1313
});
1414
}
15-
// TODO: re-enable this when wasip3 is merged back into this repo
16-
// mod concurrent {
17-
// wasmtime::component::bindgen!({
18-
// path: $path,
19-
// async: true,
20-
// concurrent_imports: true,
21-
// concurrent_exports: true,
22-
// });
23-
// }
15+
mod concurrent {
16+
wasmtime::component::bindgen!({
17+
path: $path,
18+
async: true,
19+
concurrent_imports: true,
20+
concurrent_exports: true,
21+
});
22+
}
2423
mod tracing {
2524
wasmtime::component::bindgen!({
2625
path: $path,

crates/component-macro/tests/expanded.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@ macro_rules! genexpand {
1515
stringify: true,
1616
}))?;
1717

18-
// TODO: re-enable this when wasip3 is merged back into this repo
19-
// process_expanded($path, "_concurrent", wasmtime::component::bindgen!({
20-
// path: $path,
21-
// async: true,
22-
// concurrent_imports: true,
23-
// concurrent_exports: true,
24-
// stringify: true,
25-
// }))?;
18+
process_expanded($path, "_concurrent", wasmtime::component::bindgen!({
19+
path: $path,
20+
async: true,
21+
concurrent_imports: true,
22+
concurrent_exports: true,
23+
stringify: true,
24+
}))?;
2625

2726
process_expanded($path, "_tracing_async", wasmtime::component::bindgen!({
2827
path: $path,

crates/component-macro/tests/expanded/char_concurrent.rs

Lines changed: 48 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl<_T: 'static> TheWorldPre<_T> {
4848
mut store: impl wasmtime::AsContextMut<Data = _T>,
4949
) -> wasmtime::Result<TheWorld>
5050
where
51-
_T: Send + 'static,
51+
_T: Send,
5252
{
5353
let mut store = store.as_context_mut();
5454
let instance = self.instance_pre.instantiate_async(&mut store).await?;
@@ -136,7 +136,7 @@ const _: () = {
136136
linker: &wasmtime::component::Linker<_T>,
137137
) -> wasmtime::Result<TheWorld>
138138
where
139-
_T: Send + 'static,
139+
_T: Send,
140140
{
141141
let pre = linker.instantiate_pre(component)?;
142142
TheWorldPre::new(pre)?.instantiate_async(store).await
@@ -150,16 +150,16 @@ const _: () = {
150150
let indices = TheWorldIndices::new(&instance.instance_pre(&store))?;
151151
indices.load(&mut store, instance)
152152
}
153-
pub fn add_to_linker<T, U>(
153+
pub fn add_to_linker<T, D>(
154154
linker: &mut wasmtime::component::Linker<T>,
155-
get: impl Fn(&mut T) -> &mut U + Send + Sync + Copy + 'static,
155+
host_getter: fn(&mut T) -> D::Data<'_>,
156156
) -> wasmtime::Result<()>
157157
where
158-
T: 'static,
159-
T: Send + foo::foo::chars::Host<Data = T>,
160-
U: Send + foo::foo::chars::Host<Data = T>,
158+
D: foo::foo::chars::HostConcurrent + Send,
159+
for<'a> D::Data<'a>: foo::foo::chars::Host + Send,
160+
T: 'static + Send,
161161
{
162-
foo::foo::chars::add_to_linker(linker, get)?;
162+
foo::foo::chars::add_to_linker::<T, D>(linker, host_getter)?;
163163
Ok(())
164164
}
165165
pub fn foo_foo_chars(&self) -> &exports::foo::foo::chars::Guest {
@@ -173,149 +173,61 @@ pub mod foo {
173173
pub mod chars {
174174
#[allow(unused_imports)]
175175
use wasmtime::component::__internal::{anyhow, Box};
176-
pub trait Host {
177-
type Data;
176+
#[wasmtime::component::__internal::trait_variant_make(::core::marker::Send)]
177+
pub trait HostConcurrent: wasmtime::component::HasData + Send {
178178
/// A function that accepts a character
179-
fn take_char(
180-
store: wasmtime::StoreContextMut<'_, Self::Data>,
179+
fn take_char<T: 'static>(
180+
accessor: &mut wasmtime::component::Accessor<T, Self>,
181181
x: char,
182-
) -> impl ::core::future::Future<
183-
Output = impl FnOnce(
184-
wasmtime::StoreContextMut<'_, Self::Data>,
185-
) -> () + Send + Sync + 'static,
186-
> + Send + Sync + 'static
182+
) -> impl ::core::future::Future<Output = ()> + Send
187183
where
188184
Self: Sized;
189185
/// A function that returns a character
190-
fn return_char(
191-
store: wasmtime::StoreContextMut<'_, Self::Data>,
192-
) -> impl ::core::future::Future<
193-
Output = impl FnOnce(
194-
wasmtime::StoreContextMut<'_, Self::Data>,
195-
) -> char + Send + Sync + 'static,
196-
> + Send + Sync + 'static
186+
fn return_char<T: 'static>(
187+
accessor: &mut wasmtime::component::Accessor<T, Self>,
188+
) -> impl ::core::future::Future<Output = char> + Send
197189
where
198190
Self: Sized;
199191
}
200-
pub fn add_to_linker_get_host<T, G>(
192+
#[wasmtime::component::__internal::trait_variant_make(::core::marker::Send)]
193+
pub trait Host: Send {}
194+
impl<_T: Host + ?Sized + Send> Host for &mut _T {}
195+
pub fn add_to_linker<T, D>(
201196
linker: &mut wasmtime::component::Linker<T>,
202-
host_getter: G,
197+
host_getter: fn(&mut T) -> D::Data<'_>,
203198
) -> wasmtime::Result<()>
204199
where
205-
T: 'static,
206-
G: for<'a> wasmtime::component::GetHost<
207-
&'a mut T,
208-
Host: Host<Data = T> + Send,
209-
>,
210-
T: Send + 'static,
200+
D: HostConcurrent,
201+
for<'a> D::Data<'a>: Host,
202+
T: 'static + Send,
211203
{
212204
let mut inst = linker.instance("foo:foo/chars")?;
213205
inst.func_wrap_concurrent(
214206
"take-char",
215207
move |
216-
mut caller: wasmtime::StoreContextMut<'_, T>,
208+
caller: &mut wasmtime::component::Accessor<T>,
217209
(arg0,): (char,)|
218210
{
219-
let host = caller;
220-
let r = <G::Host as Host>::take_char(host, arg0);
221-
Box::pin(async move {
222-
let fun = r.await;
223-
Box::new(move |mut caller: wasmtime::StoreContextMut<'_, T>| {
224-
let r = fun(caller);
225-
Ok(r)
226-
})
227-
as Box<
228-
dyn FnOnce(
229-
wasmtime::StoreContextMut<'_, T>,
230-
) -> wasmtime::Result<()> + Send + Sync,
231-
>
211+
wasmtime::component::__internal::Box::pin(async move {
212+
let accessor = &mut unsafe { caller.with_data(host_getter) };
213+
let r = <D as HostConcurrent>::take_char(accessor, arg0)
214+
.await;
215+
Ok(r)
232216
})
233-
as ::core::pin::Pin<
234-
Box<
235-
dyn ::core::future::Future<
236-
Output = Box<
237-
dyn FnOnce(
238-
wasmtime::StoreContextMut<'_, T>,
239-
) -> wasmtime::Result<()> + Send + Sync,
240-
>,
241-
> + Send + Sync + 'static,
242-
>,
243-
>
244217
},
245218
)?;
246219
inst.func_wrap_concurrent(
247220
"return-char",
248-
move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| {
249-
let host = caller;
250-
let r = <G::Host as Host>::return_char(host);
251-
Box::pin(async move {
252-
let fun = r.await;
253-
Box::new(move |mut caller: wasmtime::StoreContextMut<'_, T>| {
254-
let r = fun(caller);
255-
Ok((r,))
256-
})
257-
as Box<
258-
dyn FnOnce(
259-
wasmtime::StoreContextMut<'_, T>,
260-
) -> wasmtime::Result<(char,)> + Send + Sync,
261-
>
221+
move |caller: &mut wasmtime::component::Accessor<T>, (): ()| {
222+
wasmtime::component::__internal::Box::pin(async move {
223+
let accessor = &mut unsafe { caller.with_data(host_getter) };
224+
let r = <D as HostConcurrent>::return_char(accessor).await;
225+
Ok((r,))
262226
})
263-
as ::core::pin::Pin<
264-
Box<
265-
dyn ::core::future::Future<
266-
Output = Box<
267-
dyn FnOnce(
268-
wasmtime::StoreContextMut<'_, T>,
269-
) -> wasmtime::Result<(char,)> + Send + Sync,
270-
>,
271-
> + Send + Sync + 'static,
272-
>,
273-
>
274227
},
275228
)?;
276229
Ok(())
277230
}
278-
pub fn add_to_linker<T, U>(
279-
linker: &mut wasmtime::component::Linker<T>,
280-
get: impl Fn(&mut T) -> &mut U + Send + Sync + Copy + 'static,
281-
) -> wasmtime::Result<()>
282-
where
283-
T: 'static,
284-
U: Host<Data = T> + Send,
285-
T: Send + 'static,
286-
{
287-
add_to_linker_get_host(linker, get)
288-
}
289-
impl<_T: Host> Host for &mut _T {
290-
type Data = _T::Data;
291-
/// A function that accepts a character
292-
fn take_char(
293-
store: wasmtime::StoreContextMut<'_, Self::Data>,
294-
x: char,
295-
) -> impl ::core::future::Future<
296-
Output = impl FnOnce(
297-
wasmtime::StoreContextMut<'_, Self::Data>,
298-
) -> () + Send + Sync + 'static,
299-
> + Send + Sync + 'static
300-
where
301-
Self: Sized,
302-
{
303-
<_T as Host>::take_char(store, x)
304-
}
305-
/// A function that returns a character
306-
fn return_char(
307-
store: wasmtime::StoreContextMut<'_, Self::Data>,
308-
) -> impl ::core::future::Future<
309-
Output = impl FnOnce(
310-
wasmtime::StoreContextMut<'_, Self::Data>,
311-
) -> char + Send + Sync + 'static,
312-
> + Send + Sync + 'static
313-
where
314-
Self: Sized,
315-
{
316-
<_T as Host>::return_char(store)
317-
}
318-
}
319231
}
320232
}
321233
}
@@ -396,11 +308,13 @@ pub mod exports {
396308
}
397309
impl Guest {
398310
/// A function that accepts a character
399-
pub async fn call_take_char<S: wasmtime::AsContextMut>(
311+
pub fn call_take_char<S: wasmtime::AsContextMut>(
400312
&self,
401313
mut store: S,
402314
arg0: char,
403-
) -> wasmtime::Result<wasmtime::component::Promise<()>>
315+
) -> impl wasmtime::component::__internal::Future<
316+
Output = wasmtime::Result<()>,
317+
> + Send + 'static + use<S>
404318
where
405319
<S as wasmtime::AsContext>::Data: Send + 'static,
406320
{
@@ -410,16 +324,15 @@ pub mod exports {
410324
(),
411325
>::new_unchecked(self.take_char)
412326
};
413-
let promise = callee
414-
.call_concurrent(store.as_context_mut(), (arg0,))
415-
.await?;
416-
Ok(promise)
327+
callee.call_concurrent(store.as_context_mut(), (arg0,))
417328
}
418329
/// A function that returns a character
419-
pub async fn call_return_char<S: wasmtime::AsContextMut>(
330+
pub fn call_return_char<S: wasmtime::AsContextMut>(
420331
&self,
421332
mut store: S,
422-
) -> wasmtime::Result<wasmtime::component::Promise<char>>
333+
) -> impl wasmtime::component::__internal::Future<
334+
Output = wasmtime::Result<char>,
335+
> + Send + 'static + use<S>
423336
where
424337
<S as wasmtime::AsContext>::Data: Send + 'static,
425338
{
@@ -429,10 +342,10 @@ pub mod exports {
429342
(char,),
430343
>::new_unchecked(self.return_char)
431344
};
432-
let promise = callee
433-
.call_concurrent(store.as_context_mut(), ())
434-
.await?;
435-
Ok(promise.map(|(v,)| v))
345+
wasmtime::component::__internal::FutureExt::map(
346+
callee.call_concurrent(store.as_context_mut(), ()),
347+
|v| v.map(|(v,)| v),
348+
)
436349
}
437350
}
438351
}

0 commit comments

Comments
 (0)