Skip to content

Move the GetHost trait used in bindgen! into Wasmtime #10746

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 7, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
23 changes: 5 additions & 18 deletions crates/component-macro/tests/expanded/char.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,26 +171,13 @@ pub mod foo {
/// A function that returns a character
fn return_char(&mut self) -> char;
}
pub trait GetHost<
T,
D,
>: Fn(T) -> <Self as GetHost<T, D>>::Host + Send + Sync + Copy + 'static {
type Host: Host;
}
impl<F, T, D, O> GetHost<T, D> for F
where
F: Fn(T) -> O + Send + Sync + Copy + 'static,
O: Host,
{
type Host = O;
}
pub fn add_to_linker_get_host<
T,
G: for<'a> GetHost<&'a mut T, T, Host: Host>,
>(
pub fn add_to_linker_get_host<T, G>(
linker: &mut wasmtime::component::Linker<T>,
host_getter: G,
) -> wasmtime::Result<()> {
) -> wasmtime::Result<()>
where
G: for<'a> wasmtime::component::GetHost<&'a mut T, Host: Host>,
{
let mut inst = linker.instance("foo:foo/chars")?;
inst.func_wrap(
"take-char",
Expand Down
19 changes: 2 additions & 17 deletions crates/component-macro/tests/expanded/char_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,27 +179,12 @@ pub mod foo {
/// A function that returns a character
async fn return_char(&mut self) -> char;
}
pub trait GetHost<
T,
D,
>: Fn(T) -> <Self as GetHost<T, D>>::Host + Send + Sync + Copy + 'static {
type Host: Host + Send;
}
impl<F, T, D, O> GetHost<T, D> for F
where
F: Fn(T) -> O + Send + Sync + Copy + 'static,
O: Host + Send,
{
type Host = O;
}
pub fn add_to_linker_get_host<
T,
G: for<'a> GetHost<&'a mut T, T, Host: Host + Send>,
>(
pub fn add_to_linker_get_host<T, G>(
linker: &mut wasmtime::component::Linker<T>,
host_getter: G,
) -> wasmtime::Result<()>
where
G: for<'a> wasmtime::component::GetHost<&'a mut T, Host: Host + Send>,
T: Send,
{
let mut inst = linker.instance("foo:foo/chars")?;
Expand Down
22 changes: 5 additions & 17 deletions crates/component-macro/tests/expanded/char_concurrent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,27 +196,15 @@ pub mod foo {
where
Self: Sized;
}
pub trait GetHost<
T,
D,
>: Fn(T) -> <Self as GetHost<T, D>>::Host + Send + Sync + Copy + 'static {
type Host: Host<Data = D> + Send;
}
impl<F, T, D, O> GetHost<T, D> for F
where
F: Fn(T) -> O + Send + Sync + Copy + 'static,
O: Host<Data = D> + Send,
{
type Host = O;
}
pub fn add_to_linker_get_host<
T,
G: for<'a> GetHost<&'a mut T, T, Host: Host<Data = T> + Send>,
>(
pub fn add_to_linker_get_host<T, G>(
linker: &mut wasmtime::component::Linker<T>,
host_getter: G,
) -> wasmtime::Result<()>
where
G: for<'a> wasmtime::component::GetHost<
&'a mut T,
Host: Host<Data = T> + Send,
>,
T: Send + 'static,
{
let mut inst = linker.instance("foo:foo/chars")?;
Expand Down
19 changes: 2 additions & 17 deletions crates/component-macro/tests/expanded/char_tracing_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,27 +179,12 @@ pub mod foo {
/// A function that returns a character
async fn return_char(&mut self) -> char;
}
pub trait GetHost<
T,
D,
>: Fn(T) -> <Self as GetHost<T, D>>::Host + Send + Sync + Copy + 'static {
type Host: Host + Send;
}
impl<F, T, D, O> GetHost<T, D> for F
where
F: Fn(T) -> O + Send + Sync + Copy + 'static,
O: Host + Send,
{
type Host = O;
}
pub fn add_to_linker_get_host<
T,
G: for<'a> GetHost<&'a mut T, T, Host: Host + Send>,
>(
pub fn add_to_linker_get_host<T, G>(
linker: &mut wasmtime::component::Linker<T>,
host_getter: G,
) -> wasmtime::Result<()>
where
G: for<'a> wasmtime::component::GetHost<&'a mut T, Host: Host + Send>,
T: Send,
{
let mut inst = linker.instance("foo:foo/chars")?;
Expand Down
23 changes: 5 additions & 18 deletions crates/component-macro/tests/expanded/conventions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,26 +219,13 @@ pub mod foo {
/// Identifiers with the same name as keywords are quoted.
fn bool(&mut self) -> ();
}
pub trait GetHost<
T,
D,
>: Fn(T) -> <Self as GetHost<T, D>>::Host + Send + Sync + Copy + 'static {
type Host: Host;
}
impl<F, T, D, O> GetHost<T, D> for F
where
F: Fn(T) -> O + Send + Sync + Copy + 'static,
O: Host,
{
type Host = O;
}
pub fn add_to_linker_get_host<
T,
G: for<'a> GetHost<&'a mut T, T, Host: Host>,
>(
pub fn add_to_linker_get_host<T, G>(
linker: &mut wasmtime::component::Linker<T>,
host_getter: G,
) -> wasmtime::Result<()> {
) -> wasmtime::Result<()>
where
G: for<'a> wasmtime::component::GetHost<&'a mut T, Host: Host>,
{
let mut inst = linker.instance("foo:foo/conventions")?;
inst.func_wrap(
"kebab-case",
Expand Down
19 changes: 2 additions & 17 deletions crates/component-macro/tests/expanded/conventions_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,27 +227,12 @@ pub mod foo {
/// Identifiers with the same name as keywords are quoted.
async fn bool(&mut self) -> ();
}
pub trait GetHost<
T,
D,
>: Fn(T) -> <Self as GetHost<T, D>>::Host + Send + Sync + Copy + 'static {
type Host: Host + Send;
}
impl<F, T, D, O> GetHost<T, D> for F
where
F: Fn(T) -> O + Send + Sync + Copy + 'static,
O: Host + Send,
{
type Host = O;
}
pub fn add_to_linker_get_host<
T,
G: for<'a> GetHost<&'a mut T, T, Host: Host + Send>,
>(
pub fn add_to_linker_get_host<T, G>(
linker: &mut wasmtime::component::Linker<T>,
host_getter: G,
) -> wasmtime::Result<()>
where
G: for<'a> wasmtime::component::GetHost<&'a mut T, Host: Host + Send>,
T: Send,
{
let mut inst = linker.instance("foo:foo/conventions")?;
Expand Down
22 changes: 5 additions & 17 deletions crates/component-macro/tests/expanded/conventions_concurrent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,27 +324,15 @@ pub mod foo {
where
Self: Sized;
}
pub trait GetHost<
T,
D,
>: Fn(T) -> <Self as GetHost<T, D>>::Host + Send + Sync + Copy + 'static {
type Host: Host<Data = D> + Send;
}
impl<F, T, D, O> GetHost<T, D> for F
where
F: Fn(T) -> O + Send + Sync + Copy + 'static,
O: Host<Data = D> + Send,
{
type Host = O;
}
pub fn add_to_linker_get_host<
T,
G: for<'a> GetHost<&'a mut T, T, Host: Host<Data = T> + Send>,
>(
pub fn add_to_linker_get_host<T, G>(
linker: &mut wasmtime::component::Linker<T>,
host_getter: G,
) -> wasmtime::Result<()>
where
G: for<'a> wasmtime::component::GetHost<
&'a mut T,
Host: Host<Data = T> + Send,
>,
T: Send + 'static,
{
let mut inst = linker.instance("foo:foo/conventions")?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,27 +227,12 @@ pub mod foo {
/// Identifiers with the same name as keywords are quoted.
async fn bool(&mut self) -> ();
}
pub trait GetHost<
T,
D,
>: Fn(T) -> <Self as GetHost<T, D>>::Host + Send + Sync + Copy + 'static {
type Host: Host + Send;
}
impl<F, T, D, O> GetHost<T, D> for F
where
F: Fn(T) -> O + Send + Sync + Copy + 'static,
O: Host + Send,
{
type Host = O;
}
pub fn add_to_linker_get_host<
T,
G: for<'a> GetHost<&'a mut T, T, Host: Host + Send>,
>(
pub fn add_to_linker_get_host<T, G>(
linker: &mut wasmtime::component::Linker<T>,
host_getter: G,
) -> wasmtime::Result<()>
where
G: for<'a> wasmtime::component::GetHost<&'a mut T, Host: Host + Send>,
T: Send,
{
let mut inst = linker.instance("foo:foo/conventions")?;
Expand Down
46 changes: 10 additions & 36 deletions crates/component-macro/tests/expanded/dead-code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,26 +181,13 @@ pub mod a {
pub trait Host {
fn f(&mut self) -> LiveType;
}
pub trait GetHost<
T,
D,
>: Fn(T) -> <Self as GetHost<T, D>>::Host + Send + Sync + Copy + 'static {
type Host: Host;
}
impl<F, T, D, O> GetHost<T, D> for F
where
F: Fn(T) -> O + Send + Sync + Copy + 'static,
O: Host,
{
type Host = O;
}
pub fn add_to_linker_get_host<
T,
G: for<'a> GetHost<&'a mut T, T, Host: Host>,
>(
pub fn add_to_linker_get_host<T, G>(
linker: &mut wasmtime::component::Linker<T>,
host_getter: G,
) -> wasmtime::Result<()> {
) -> wasmtime::Result<()>
where
G: for<'a> wasmtime::component::GetHost<&'a mut T, Host: Host>,
{
let mut inst = linker.instance("a:b/interface-with-live-type")?;
inst.func_wrap(
"f",
Expand Down Expand Up @@ -282,26 +269,13 @@ pub mod a {
assert!(4 == < V as wasmtime::component::ComponentType >::ALIGN32);
};
pub trait Host {}
pub trait GetHost<
T,
D,
>: Fn(T) -> <Self as GetHost<T, D>>::Host + Send + Sync + Copy + 'static {
type Host: Host;
}
impl<F, T, D, O> GetHost<T, D> for F
where
F: Fn(T) -> O + Send + Sync + Copy + 'static,
O: Host,
{
type Host = O;
}
pub fn add_to_linker_get_host<
T,
G: for<'a> GetHost<&'a mut T, T, Host: Host>,
>(
pub fn add_to_linker_get_host<T, G>(
linker: &mut wasmtime::component::Linker<T>,
host_getter: G,
) -> wasmtime::Result<()> {
) -> wasmtime::Result<()>
where
G: for<'a> wasmtime::component::GetHost<&'a mut T, Host: Host>,
{
let mut inst = linker.instance("a:b/interface-with-dead-type")?;
Ok(())
}
Expand Down
38 changes: 4 additions & 34 deletions crates/component-macro/tests/expanded/dead-code_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,27 +189,12 @@ pub mod a {
pub trait Host: Send {
async fn f(&mut self) -> LiveType;
}
pub trait GetHost<
T,
D,
>: Fn(T) -> <Self as GetHost<T, D>>::Host + Send + Sync + Copy + 'static {
type Host: Host + Send;
}
impl<F, T, D, O> GetHost<T, D> for F
where
F: Fn(T) -> O + Send + Sync + Copy + 'static,
O: Host + Send,
{
type Host = O;
}
pub fn add_to_linker_get_host<
T,
G: for<'a> GetHost<&'a mut T, T, Host: Host + Send>,
>(
pub fn add_to_linker_get_host<T, G>(
linker: &mut wasmtime::component::Linker<T>,
host_getter: G,
) -> wasmtime::Result<()>
where
G: for<'a> wasmtime::component::GetHost<&'a mut T, Host: Host + Send>,
T: Send,
{
let mut inst = linker.instance("a:b/interface-with-live-type")?;
Expand Down Expand Up @@ -297,27 +282,12 @@ pub mod a {
};
#[wasmtime::component::__internal::trait_variant_make(::core::marker::Send)]
pub trait Host: Send {}
pub trait GetHost<
T,
D,
>: Fn(T) -> <Self as GetHost<T, D>>::Host + Send + Sync + Copy + 'static {
type Host: Host + Send;
}
impl<F, T, D, O> GetHost<T, D> for F
where
F: Fn(T) -> O + Send + Sync + Copy + 'static,
O: Host + Send,
{
type Host = O;
}
pub fn add_to_linker_get_host<
T,
G: for<'a> GetHost<&'a mut T, T, Host: Host + Send>,
>(
pub fn add_to_linker_get_host<T, G>(
linker: &mut wasmtime::component::Linker<T>,
host_getter: G,
) -> wasmtime::Result<()>
where
G: for<'a> wasmtime::component::GetHost<&'a mut T, Host: Host + Send>,
T: Send,
{
let mut inst = linker.instance("a:b/interface-with-dead-type")?;
Expand Down
Loading