Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use tracing::Instrument in generated bindings to avoid holding spans across await points #9217

Merged
merged 2 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions crates/component-macro/tests/expanded/char_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,19 +225,23 @@ pub mod foo {
move |
mut caller: wasmtime::StoreContextMut<'_, T>,
(arg0,): (char,)|
wasmtime::component::__internal::Box::new(async move {
let host = &mut host_getter(caller.data_mut());
let r = Host::take_char(host, arg0).await;
Ok(r)
}),
{
wasmtime::component::__internal::Box::new(async move {
let host = &mut host_getter(caller.data_mut());
let r = Host::take_char(host, arg0).await;
Ok(r)
})
},
)?;
inst.func_wrap_async(
"return-char",
move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| wasmtime::component::__internal::Box::new(async move {
let host = &mut host_getter(caller.data_mut());
let r = Host::return_char(host).await;
Ok((r,))
}),
move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| {
wasmtime::component::__internal::Box::new(async move {
let host = &mut host_getter(caller.data_mut());
let r = Host::return_char(host).await;
Ok((r,))
})
},
)?;
Ok(())
}
Expand Down
144 changes: 84 additions & 60 deletions crates/component-macro/tests/expanded/conventions_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,102 +270,126 @@ pub mod foo {
let mut inst = linker.instance("foo:foo/conventions")?;
inst.func_wrap_async(
"kebab-case",
move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| wasmtime::component::__internal::Box::new(async move {
let host = &mut host_getter(caller.data_mut());
let r = Host::kebab_case(host).await;
Ok(r)
}),
move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| {
wasmtime::component::__internal::Box::new(async move {
let host = &mut host_getter(caller.data_mut());
let r = Host::kebab_case(host).await;
Ok(r)
})
},
)?;
inst.func_wrap_async(
"foo",
move |
mut caller: wasmtime::StoreContextMut<'_, T>,
(arg0,): (LudicrousSpeed,)|
wasmtime::component::__internal::Box::new(async move {
let host = &mut host_getter(caller.data_mut());
let r = Host::foo(host, arg0).await;
Ok(r)
}),
{
wasmtime::component::__internal::Box::new(async move {
let host = &mut host_getter(caller.data_mut());
let r = Host::foo(host, arg0).await;
Ok(r)
})
},
)?;
inst.func_wrap_async(
"function-with-dashes",
move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| wasmtime::component::__internal::Box::new(async move {
let host = &mut host_getter(caller.data_mut());
let r = Host::function_with_dashes(host).await;
Ok(r)
}),
move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| {
wasmtime::component::__internal::Box::new(async move {
let host = &mut host_getter(caller.data_mut());
let r = Host::function_with_dashes(host).await;
Ok(r)
})
},
)?;
inst.func_wrap_async(
"function-with-no-weird-characters",
move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| wasmtime::component::__internal::Box::new(async move {
let host = &mut host_getter(caller.data_mut());
let r = Host::function_with_no_weird_characters(host).await;
Ok(r)
}),
move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| {
wasmtime::component::__internal::Box::new(async move {
let host = &mut host_getter(caller.data_mut());
let r = Host::function_with_no_weird_characters(host).await;
Ok(r)
})
},
)?;
inst.func_wrap_async(
"apple",
move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| wasmtime::component::__internal::Box::new(async move {
let host = &mut host_getter(caller.data_mut());
let r = Host::apple(host).await;
Ok(r)
}),
move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| {
wasmtime::component::__internal::Box::new(async move {
let host = &mut host_getter(caller.data_mut());
let r = Host::apple(host).await;
Ok(r)
})
},
)?;
inst.func_wrap_async(
"apple-pear",
move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| wasmtime::component::__internal::Box::new(async move {
let host = &mut host_getter(caller.data_mut());
let r = Host::apple_pear(host).await;
Ok(r)
}),
move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| {
wasmtime::component::__internal::Box::new(async move {
let host = &mut host_getter(caller.data_mut());
let r = Host::apple_pear(host).await;
Ok(r)
})
},
)?;
inst.func_wrap_async(
"apple-pear-grape",
move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| wasmtime::component::__internal::Box::new(async move {
let host = &mut host_getter(caller.data_mut());
let r = Host::apple_pear_grape(host).await;
Ok(r)
}),
move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| {
wasmtime::component::__internal::Box::new(async move {
let host = &mut host_getter(caller.data_mut());
let r = Host::apple_pear_grape(host).await;
Ok(r)
})
},
)?;
inst.func_wrap_async(
"a0",
move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| wasmtime::component::__internal::Box::new(async move {
let host = &mut host_getter(caller.data_mut());
let r = Host::a0(host).await;
Ok(r)
}),
move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| {
wasmtime::component::__internal::Box::new(async move {
let host = &mut host_getter(caller.data_mut());
let r = Host::a0(host).await;
Ok(r)
})
},
)?;
inst.func_wrap_async(
"is-XML",
move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| wasmtime::component::__internal::Box::new(async move {
let host = &mut host_getter(caller.data_mut());
let r = Host::is_xml(host).await;
Ok(r)
}),
move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| {
wasmtime::component::__internal::Box::new(async move {
let host = &mut host_getter(caller.data_mut());
let r = Host::is_xml(host).await;
Ok(r)
})
},
)?;
inst.func_wrap_async(
"explicit",
move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| wasmtime::component::__internal::Box::new(async move {
let host = &mut host_getter(caller.data_mut());
let r = Host::explicit(host).await;
Ok(r)
}),
move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| {
wasmtime::component::__internal::Box::new(async move {
let host = &mut host_getter(caller.data_mut());
let r = Host::explicit(host).await;
Ok(r)
})
},
)?;
inst.func_wrap_async(
"explicit-kebab",
move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| wasmtime::component::__internal::Box::new(async move {
let host = &mut host_getter(caller.data_mut());
let r = Host::explicit_kebab(host).await;
Ok(r)
}),
move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| {
wasmtime::component::__internal::Box::new(async move {
let host = &mut host_getter(caller.data_mut());
let r = Host::explicit_kebab(host).await;
Ok(r)
})
},
)?;
inst.func_wrap_async(
"bool",
move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| wasmtime::component::__internal::Box::new(async move {
let host = &mut host_getter(caller.data_mut());
let r = Host::bool(host).await;
Ok(r)
}),
move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| {
wasmtime::component::__internal::Box::new(async move {
let host = &mut host_getter(caller.data_mut());
let r = Host::bool(host).await;
Ok(r)
})
},
)?;
Ok(())
}
Expand Down
12 changes: 7 additions & 5 deletions crates/component-macro/tests/expanded/dead-code_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,13 @@ pub mod a {
let mut inst = linker.instance("a:b/interface-with-live-type")?;
inst.func_wrap_async(
"f",
move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| wasmtime::component::__internal::Box::new(async move {
let host = &mut host_getter(caller.data_mut());
let r = Host::f(host).await;
Ok((r,))
}),
move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| {
wasmtime::component::__internal::Box::new(async move {
let host = &mut host_getter(caller.data_mut());
let r = Host::f(host).await;
Ok((r,))
})
},
)?;
Ok(())
}
Expand Down
12 changes: 7 additions & 5 deletions crates/component-macro/tests/expanded/direct-import_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,13 @@ const _: () = {
linker
.func_wrap_async(
"foo",
move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| wasmtime::component::__internal::Box::new(async move {
let host = &mut host_getter(caller.data_mut());
let r = FooImports::foo(host).await;
Ok(r)
}),
move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| {
wasmtime::component::__internal::Box::new(async move {
let host = &mut host_getter(caller.data_mut());
let r = FooImports::foo(host).await;
Ok(r)
})
},
)?;
Ok(())
}
Expand Down
84 changes: 49 additions & 35 deletions crates/component-macro/tests/expanded/flags_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,77 +342,91 @@ pub mod foo {
move |
mut caller: wasmtime::StoreContextMut<'_, T>,
(arg0,): (Flag1,)|
wasmtime::component::__internal::Box::new(async move {
let host = &mut host_getter(caller.data_mut());
let r = Host::roundtrip_flag1(host, arg0).await;
Ok((r,))
}),
{
wasmtime::component::__internal::Box::new(async move {
let host = &mut host_getter(caller.data_mut());
let r = Host::roundtrip_flag1(host, arg0).await;
Ok((r,))
})
},
)?;
inst.func_wrap_async(
"roundtrip-flag2",
move |
mut caller: wasmtime::StoreContextMut<'_, T>,
(arg0,): (Flag2,)|
wasmtime::component::__internal::Box::new(async move {
let host = &mut host_getter(caller.data_mut());
let r = Host::roundtrip_flag2(host, arg0).await;
Ok((r,))
}),
{
wasmtime::component::__internal::Box::new(async move {
let host = &mut host_getter(caller.data_mut());
let r = Host::roundtrip_flag2(host, arg0).await;
Ok((r,))
})
},
)?;
inst.func_wrap_async(
"roundtrip-flag4",
move |
mut caller: wasmtime::StoreContextMut<'_, T>,
(arg0,): (Flag4,)|
wasmtime::component::__internal::Box::new(async move {
let host = &mut host_getter(caller.data_mut());
let r = Host::roundtrip_flag4(host, arg0).await;
Ok((r,))
}),
{
wasmtime::component::__internal::Box::new(async move {
let host = &mut host_getter(caller.data_mut());
let r = Host::roundtrip_flag4(host, arg0).await;
Ok((r,))
})
},
)?;
inst.func_wrap_async(
"roundtrip-flag8",
move |
mut caller: wasmtime::StoreContextMut<'_, T>,
(arg0,): (Flag8,)|
wasmtime::component::__internal::Box::new(async move {
let host = &mut host_getter(caller.data_mut());
let r = Host::roundtrip_flag8(host, arg0).await;
Ok((r,))
}),
{
wasmtime::component::__internal::Box::new(async move {
let host = &mut host_getter(caller.data_mut());
let r = Host::roundtrip_flag8(host, arg0).await;
Ok((r,))
})
},
)?;
inst.func_wrap_async(
"roundtrip-flag16",
move |
mut caller: wasmtime::StoreContextMut<'_, T>,
(arg0,): (Flag16,)|
wasmtime::component::__internal::Box::new(async move {
let host = &mut host_getter(caller.data_mut());
let r = Host::roundtrip_flag16(host, arg0).await;
Ok((r,))
}),
{
wasmtime::component::__internal::Box::new(async move {
let host = &mut host_getter(caller.data_mut());
let r = Host::roundtrip_flag16(host, arg0).await;
Ok((r,))
})
},
)?;
inst.func_wrap_async(
"roundtrip-flag32",
move |
mut caller: wasmtime::StoreContextMut<'_, T>,
(arg0,): (Flag32,)|
wasmtime::component::__internal::Box::new(async move {
let host = &mut host_getter(caller.data_mut());
let r = Host::roundtrip_flag32(host, arg0).await;
Ok((r,))
}),
{
wasmtime::component::__internal::Box::new(async move {
let host = &mut host_getter(caller.data_mut());
let r = Host::roundtrip_flag32(host, arg0).await;
Ok((r,))
})
},
)?;
inst.func_wrap_async(
"roundtrip-flag64",
move |
mut caller: wasmtime::StoreContextMut<'_, T>,
(arg0,): (Flag64,)|
wasmtime::component::__internal::Box::new(async move {
let host = &mut host_getter(caller.data_mut());
let r = Host::roundtrip_flag64(host, arg0).await;
Ok((r,))
}),
{
wasmtime::component::__internal::Box::new(async move {
let host = &mut host_getter(caller.data_mut());
let r = Host::roundtrip_flag64(host, arg0).await;
Ok((r,))
})
},
)?;
Ok(())
}
Expand Down
Loading