Skip to content

Replace GetHost with a function pointer, add HasData #10770

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

Merged
merged 2 commits into from
May 13, 2025
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 9 additions & 8 deletions crates/component-macro/tests/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ macro_rules! gentest {
async: true,
});
}
mod concurrent {
wasmtime::component::bindgen!({
path: $path,
async: true,
concurrent_imports: true,
concurrent_exports: true,
});
}
// TODO: re-enable this when wasip3 is merged back into this repo
// mod concurrent {
// wasmtime::component::bindgen!({
// path: $path,
// async: true,
// concurrent_imports: true,
// concurrent_exports: true,
// });
// }
mod tracing {
wasmtime::component::bindgen!({
path: $path,
Expand Down
15 changes: 8 additions & 7 deletions crates/component-macro/tests/expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ macro_rules! genexpand {
stringify: true,
}))?;

process_expanded($path, "_concurrent", wasmtime::component::bindgen!({
path: $path,
async: true,
concurrent_imports: true,
concurrent_exports: true,
stringify: true,
}))?;
// TODO: re-enable this when wasip3 is merged back into this repo
// process_expanded($path, "_concurrent", wasmtime::component::bindgen!({
// path: $path,
// async: true,
// concurrent_imports: true,
// concurrent_exports: true,
// stringify: true,
// }))?;

process_expanded($path, "_tracing_async", wasmtime::component::bindgen!({
path: $path,
Expand Down
26 changes: 9 additions & 17 deletions crates/component-macro/tests/expanded/char.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,16 @@ const _: () = {
let indices = TheWorldIndices::new(&instance.instance_pre(&store))?;
indices.load(&mut store, instance)
}
pub fn add_to_linker<T, U>(
pub fn add_to_linker<T, D>(
linker: &mut wasmtime::component::Linker<T>,
get: impl Fn(&mut T) -> &mut U + Send + Sync + Copy + 'static,
get: fn(&mut T) -> D::Data<'_>,
) -> wasmtime::Result<()>
where
D: wasmtime::component::HasData,
for<'a> D::Data<'a>: foo::foo::chars::Host,
T: 'static,
U: foo::foo::chars::Host,
{
foo::foo::chars::add_to_linker(linker, get)?;
foo::foo::chars::add_to_linker::<T, D>(linker, get)?;
Ok(())
}
pub fn foo_foo_chars(&self) -> &exports::foo::foo::chars::Guest {
Expand All @@ -172,13 +173,14 @@ pub mod foo {
/// A function that returns a character
fn return_char(&mut self) -> char;
}
pub fn add_to_linker_get_host<T, G>(
pub fn add_to_linker<T, D>(
linker: &mut wasmtime::component::Linker<T>,
host_getter: G,
host_getter: fn(&mut T) -> D::Data<'_>,
) -> wasmtime::Result<()>
where
D: wasmtime::component::HasData,
for<'a> D::Data<'a>: Host,
T: 'static,
G: for<'a> wasmtime::component::GetHost<&'a mut T, Host: Host>,
{
let mut inst = linker.instance("foo:foo/chars")?;
inst.func_wrap(
Expand All @@ -202,16 +204,6 @@ pub mod foo {
)?;
Ok(())
}
pub fn add_to_linker<T, U>(
linker: &mut wasmtime::component::Linker<T>,
get: impl Fn(&mut T) -> &mut U + Send + Sync + Copy + 'static,
) -> wasmtime::Result<()>
where
T: 'static,
U: Host,
{
add_to_linker_get_host(linker, get)
}
impl<_T: Host + ?Sized> Host for &mut _T {
/// A function that accepts a character
fn take_char(&mut self, x: char) -> () {
Expand Down
33 changes: 11 additions & 22 deletions crates/component-macro/tests/expanded/char_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,16 @@ const _: () = {
let indices = TheWorldIndices::new(&instance.instance_pre(&store))?;
indices.load(&mut store, instance)
}
pub fn add_to_linker<T, U>(
pub fn add_to_linker<T, D>(
linker: &mut wasmtime::component::Linker<T>,
get: impl Fn(&mut T) -> &mut U + Send + Sync + Copy + 'static,
get: fn(&mut T) -> D::Data<'_>,
) -> wasmtime::Result<()>
where
T: 'static,
T: Send,
U: foo::foo::chars::Host + Send,
D: wasmtime::component::HasData,
for<'a> D::Data<'a>: foo::foo::chars::Host + Send,
T: Send + 'static,
{
foo::foo::chars::add_to_linker(linker, get)?;
foo::foo::chars::add_to_linker::<T, D>(linker, get)?;
Ok(())
}
pub fn foo_foo_chars(&self) -> &exports::foo::foo::chars::Guest {
Expand All @@ -180,14 +180,14 @@ pub mod foo {
/// A function that returns a character
async fn return_char(&mut self) -> char;
}
pub fn add_to_linker_get_host<T, G>(
pub fn add_to_linker<T, D>(
linker: &mut wasmtime::component::Linker<T>,
host_getter: G,
host_getter: fn(&mut T) -> D::Data<'_>,
) -> wasmtime::Result<()>
where
T: 'static,
G: for<'a> wasmtime::component::GetHost<&'a mut T, Host: Host + Send>,
T: Send,
D: wasmtime::component::HasData,
for<'a> D::Data<'a>: Host + Send,
T: Send + 'static,
{
let mut inst = linker.instance("foo:foo/chars")?;
inst.func_wrap_async(
Expand Down Expand Up @@ -215,17 +215,6 @@ pub mod foo {
)?;
Ok(())
}
pub fn add_to_linker<T, U>(
linker: &mut wasmtime::component::Linker<T>,
get: impl Fn(&mut T) -> &mut U + Send + Sync + Copy + 'static,
) -> wasmtime::Result<()>
where
T: 'static,
U: Host + Send,
T: Send,
{
add_to_linker_get_host(linker, get)
}
impl<_T: Host + ?Sized + Send> Host for &mut _T {
/// A function that accepts a character
async fn take_char(&mut self, x: char) -> () {
Expand Down
33 changes: 11 additions & 22 deletions crates/component-macro/tests/expanded/char_tracing_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,16 @@ const _: () = {
let indices = TheWorldIndices::new(&instance.instance_pre(&store))?;
indices.load(&mut store, instance)
}
pub fn add_to_linker<T, U>(
pub fn add_to_linker<T, D>(
linker: &mut wasmtime::component::Linker<T>,
get: impl Fn(&mut T) -> &mut U + Send + Sync + Copy + 'static,
get: fn(&mut T) -> D::Data<'_>,
) -> wasmtime::Result<()>
where
T: 'static,
T: Send,
U: foo::foo::chars::Host + Send,
D: wasmtime::component::HasData,
for<'a> D::Data<'a>: foo::foo::chars::Host + Send,
T: Send + 'static,
{
foo::foo::chars::add_to_linker(linker, get)?;
foo::foo::chars::add_to_linker::<T, D>(linker, get)?;
Ok(())
}
pub fn foo_foo_chars(&self) -> &exports::foo::foo::chars::Guest {
Expand All @@ -180,14 +180,14 @@ pub mod foo {
/// A function that returns a character
async fn return_char(&mut self) -> char;
}
pub fn add_to_linker_get_host<T, G>(
pub fn add_to_linker<T, D>(
linker: &mut wasmtime::component::Linker<T>,
host_getter: G,
host_getter: fn(&mut T) -> D::Data<'_>,
) -> wasmtime::Result<()>
where
T: 'static,
G: for<'a> wasmtime::component::GetHost<&'a mut T, Host: Host + Send>,
T: Send,
D: wasmtime::component::HasData,
for<'a> D::Data<'a>: Host + Send,
T: Send + 'static,
{
let mut inst = linker.instance("foo:foo/chars")?;
inst.func_wrap_async(
Expand Down Expand Up @@ -244,17 +244,6 @@ pub mod foo {
)?;
Ok(())
}
pub fn add_to_linker<T, U>(
linker: &mut wasmtime::component::Linker<T>,
get: impl Fn(&mut T) -> &mut U + Send + Sync + Copy + 'static,
) -> wasmtime::Result<()>
where
T: 'static,
U: Host + Send,
T: Send,
{
add_to_linker_get_host(linker, get)
}
impl<_T: Host + ?Sized + Send> Host for &mut _T {
/// A function that accepts a character
async fn take_char(&mut self, x: char) -> () {
Expand Down
26 changes: 9 additions & 17 deletions crates/component-macro/tests/expanded/conventions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,16 @@ const _: () = {
let indices = TheWorldIndices::new(&instance.instance_pre(&store))?;
indices.load(&mut store, instance)
}
pub fn add_to_linker<T, U>(
pub fn add_to_linker<T, D>(
linker: &mut wasmtime::component::Linker<T>,
get: impl Fn(&mut T) -> &mut U + Send + Sync + Copy + 'static,
get: fn(&mut T) -> D::Data<'_>,
) -> wasmtime::Result<()>
where
D: wasmtime::component::HasData,
for<'a> D::Data<'a>: foo::foo::conventions::Host,
T: 'static,
U: foo::foo::conventions::Host,
{
foo::foo::conventions::add_to_linker(linker, get)?;
foo::foo::conventions::add_to_linker::<T, D>(linker, get)?;
Ok(())
}
pub fn foo_foo_conventions(&self) -> &exports::foo::foo::conventions::Guest {
Expand Down Expand Up @@ -220,13 +221,14 @@ pub mod foo {
/// Identifiers with the same name as keywords are quoted.
fn bool(&mut self) -> ();
}
pub fn add_to_linker_get_host<T, G>(
pub fn add_to_linker<T, D>(
linker: &mut wasmtime::component::Linker<T>,
host_getter: G,
host_getter: fn(&mut T) -> D::Data<'_>,
) -> wasmtime::Result<()>
where
D: wasmtime::component::HasData,
for<'a> D::Data<'a>: Host,
T: 'static,
G: for<'a> wasmtime::component::GetHost<&'a mut T, Host: Host>,
{
let mut inst = linker.instance("foo:foo/conventions")?;
inst.func_wrap(
Expand Down Expand Up @@ -330,16 +332,6 @@ pub mod foo {
)?;
Ok(())
}
pub fn add_to_linker<T, U>(
linker: &mut wasmtime::component::Linker<T>,
get: impl Fn(&mut T) -> &mut U + Send + Sync + Copy + 'static,
) -> wasmtime::Result<()>
where
T: 'static,
U: Host,
{
add_to_linker_get_host(linker, get)
}
impl<_T: Host + ?Sized> Host for &mut _T {
fn kebab_case(&mut self) -> () {
Host::kebab_case(*self)
Expand Down
33 changes: 11 additions & 22 deletions crates/component-macro/tests/expanded/conventions_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,16 +152,16 @@ const _: () = {
let indices = TheWorldIndices::new(&instance.instance_pre(&store))?;
indices.load(&mut store, instance)
}
pub fn add_to_linker<T, U>(
pub fn add_to_linker<T, D>(
linker: &mut wasmtime::component::Linker<T>,
get: impl Fn(&mut T) -> &mut U + Send + Sync + Copy + 'static,
get: fn(&mut T) -> D::Data<'_>,
) -> wasmtime::Result<()>
where
T: 'static,
T: Send,
U: foo::foo::conventions::Host + Send,
D: wasmtime::component::HasData,
for<'a> D::Data<'a>: foo::foo::conventions::Host + Send,
T: Send + 'static,
{
foo::foo::conventions::add_to_linker(linker, get)?;
foo::foo::conventions::add_to_linker::<T, D>(linker, get)?;
Ok(())
}
pub fn foo_foo_conventions(&self) -> &exports::foo::foo::conventions::Guest {
Expand Down Expand Up @@ -228,14 +228,14 @@ pub mod foo {
/// Identifiers with the same name as keywords are quoted.
async fn bool(&mut self) -> ();
}
pub fn add_to_linker_get_host<T, G>(
pub fn add_to_linker<T, D>(
linker: &mut wasmtime::component::Linker<T>,
host_getter: G,
host_getter: fn(&mut T) -> D::Data<'_>,
) -> wasmtime::Result<()>
where
T: 'static,
G: for<'a> wasmtime::component::GetHost<&'a mut T, Host: Host + Send>,
T: Send,
D: wasmtime::component::HasData,
for<'a> D::Data<'a>: Host + Send,
T: Send + 'static,
{
let mut inst = linker.instance("foo:foo/conventions")?;
inst.func_wrap_async(
Expand Down Expand Up @@ -363,17 +363,6 @@ pub mod foo {
)?;
Ok(())
}
pub fn add_to_linker<T, U>(
linker: &mut wasmtime::component::Linker<T>,
get: impl Fn(&mut T) -> &mut U + Send + Sync + Copy + 'static,
) -> wasmtime::Result<()>
where
T: 'static,
U: Host + Send,
T: Send,
{
add_to_linker_get_host(linker, get)
}
impl<_T: Host + ?Sized + Send> Host for &mut _T {
async fn kebab_case(&mut self) -> () {
Host::kebab_case(*self).await
Expand Down
Loading