Skip to content

Commit

Permalink
Refactor wasmtime::Func to "unsplat" arguments for the async API (#8732)
Browse files Browse the repository at this point in the history
* Complete implementation in wasmtime

* Get the impl of IntoFunc to point at the new HostContext from_closure method to tie it back to the new implementation

* A little bit of cleanup to comments and naming

* Update doc comment for Func wrap_async
  • Loading branch information
ssnover committed Jun 3, 2024
1 parent 44cd002 commit 05fe628
Show file tree
Hide file tree
Showing 9 changed files with 377 additions and 271 deletions.
20 changes: 12 additions & 8 deletions benches/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,20 +367,24 @@ fn wasm_to_host(c: &mut Criterion) {

let mut typed = Linker::new(&engine);
typed
.func_wrap0_async("", "nop", |caller| {
.func_wrap_async("", "nop", |caller, _: ()| {
Box::new(async {
drop(caller);
})
})
.unwrap();
typed
.func_wrap2_async("", "nop-params-and-results", |_caller, x: i32, y: i64| {
Box::new(async move {
assert_eq!(x, 0);
assert_eq!(y, 0);
0.0f32
})
})
.func_wrap_async(
"",
"nop-params-and-results",
|_caller, (x, y): (i32, i64)| {
Box::new(async move {
assert_eq!(x, 0);
assert_eq!(y, 0);
0.0f32
})
},
)
.unwrap();
let instance = run_await(typed.instantiate_async(&mut *store, &module)).unwrap();
bench_instance(group, store, &instance, "async-typed", is_async);
Expand Down
4 changes: 2 additions & 2 deletions crates/wasmtime/src/runtime/component/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -649,9 +649,9 @@ impl<T> LinkerInstance<'_, T> {
ty: ResourceType,
dtor: impl Fn(StoreContextMut<'_, T>, u32) -> Result<()> + Send + Sync + 'static,
) -> Result<()> {
let dtor = Arc::new(crate::func::HostFunc::wrap(
let dtor = Arc::new(crate::func::HostFunc::wrap_inner(
&self.engine,
move |mut cx: crate::Caller<'_, T>, param: u32| dtor(cx.as_context_mut(), param),
move |mut cx: crate::Caller<'_, T>, (param,): (u32,)| dtor(cx.as_context_mut(), param),
));
self.insert(name, Definition::Resource(ty, dtor))?;
Ok(())
Expand Down
Loading

0 comments on commit 05fe628

Please sign in to comment.