Skip to content

Commit 29d04b1

Browse files
authored
Move the GetHost trait used in bindgen! into Wasmtime (#10746)
* Move the `GetHost` trait used in `bindgen!` into Wasmtime Turns out we don't actually need to generate this `GetHost` trait, we can instead have it live in one location with extra documentation. There are already extra bounds on the `Host` associated type at all call-sites so there's no need to additionally have trait bounds in the trait definition, meaning the trait definition is always the same and it can move within Wasmtime. This shouldn't have any impact on any embedders today, it's just moving things around. * Review comments
1 parent 1c940b7 commit 29d04b1

File tree

119 files changed

+836
-3099
lines changed

Some content is hidden

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

119 files changed

+836
-3099
lines changed

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

+5-18
Original file line numberDiff line numberDiff line change
@@ -171,26 +171,13 @@ pub mod foo {
171171
/// A function that returns a character
172172
fn return_char(&mut self) -> char;
173173
}
174-
pub trait GetHost<
175-
T,
176-
D,
177-
>: Fn(T) -> <Self as GetHost<T, D>>::Host + Send + Sync + Copy + 'static {
178-
type Host: Host;
179-
}
180-
impl<F, T, D, O> GetHost<T, D> for F
181-
where
182-
F: Fn(T) -> O + Send + Sync + Copy + 'static,
183-
O: Host,
184-
{
185-
type Host = O;
186-
}
187-
pub fn add_to_linker_get_host<
188-
T,
189-
G: for<'a> GetHost<&'a mut T, T, Host: Host>,
190-
>(
174+
pub fn add_to_linker_get_host<T, G>(
191175
linker: &mut wasmtime::component::Linker<T>,
192176
host_getter: G,
193-
) -> wasmtime::Result<()> {
177+
) -> wasmtime::Result<()>
178+
where
179+
G: for<'a> wasmtime::component::GetHost<&'a mut T, Host: Host>,
180+
{
194181
let mut inst = linker.instance("foo:foo/chars")?;
195182
inst.func_wrap(
196183
"take-char",

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

+2-17
Original file line numberDiff line numberDiff line change
@@ -179,27 +179,12 @@ pub mod foo {
179179
/// A function that returns a character
180180
async fn return_char(&mut self) -> char;
181181
}
182-
pub trait GetHost<
183-
T,
184-
D,
185-
>: Fn(T) -> <Self as GetHost<T, D>>::Host + Send + Sync + Copy + 'static {
186-
type Host: Host + Send;
187-
}
188-
impl<F, T, D, O> GetHost<T, D> for F
189-
where
190-
F: Fn(T) -> O + Send + Sync + Copy + 'static,
191-
O: Host + Send,
192-
{
193-
type Host = O;
194-
}
195-
pub fn add_to_linker_get_host<
196-
T,
197-
G: for<'a> GetHost<&'a mut T, T, Host: Host + Send>,
198-
>(
182+
pub fn add_to_linker_get_host<T, G>(
199183
linker: &mut wasmtime::component::Linker<T>,
200184
host_getter: G,
201185
) -> wasmtime::Result<()>
202186
where
187+
G: for<'a> wasmtime::component::GetHost<&'a mut T, Host: Host + Send>,
203188
T: Send,
204189
{
205190
let mut inst = linker.instance("foo:foo/chars")?;

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

+5-17
Original file line numberDiff line numberDiff line change
@@ -196,27 +196,15 @@ pub mod foo {
196196
where
197197
Self: Sized;
198198
}
199-
pub trait GetHost<
200-
T,
201-
D,
202-
>: Fn(T) -> <Self as GetHost<T, D>>::Host + Send + Sync + Copy + 'static {
203-
type Host: Host<Data = D> + Send;
204-
}
205-
impl<F, T, D, O> GetHost<T, D> for F
206-
where
207-
F: Fn(T) -> O + Send + Sync + Copy + 'static,
208-
O: Host<Data = D> + Send,
209-
{
210-
type Host = O;
211-
}
212-
pub fn add_to_linker_get_host<
213-
T,
214-
G: for<'a> GetHost<&'a mut T, T, Host: Host<Data = T> + Send>,
215-
>(
199+
pub fn add_to_linker_get_host<T, G>(
216200
linker: &mut wasmtime::component::Linker<T>,
217201
host_getter: G,
218202
) -> wasmtime::Result<()>
219203
where
204+
G: for<'a> wasmtime::component::GetHost<
205+
&'a mut T,
206+
Host: Host<Data = T> + Send,
207+
>,
220208
T: Send + 'static,
221209
{
222210
let mut inst = linker.instance("foo:foo/chars")?;

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

+2-17
Original file line numberDiff line numberDiff line change
@@ -179,27 +179,12 @@ pub mod foo {
179179
/// A function that returns a character
180180
async fn return_char(&mut self) -> char;
181181
}
182-
pub trait GetHost<
183-
T,
184-
D,
185-
>: Fn(T) -> <Self as GetHost<T, D>>::Host + Send + Sync + Copy + 'static {
186-
type Host: Host + Send;
187-
}
188-
impl<F, T, D, O> GetHost<T, D> for F
189-
where
190-
F: Fn(T) -> O + Send + Sync + Copy + 'static,
191-
O: Host + Send,
192-
{
193-
type Host = O;
194-
}
195-
pub fn add_to_linker_get_host<
196-
T,
197-
G: for<'a> GetHost<&'a mut T, T, Host: Host + Send>,
198-
>(
182+
pub fn add_to_linker_get_host<T, G>(
199183
linker: &mut wasmtime::component::Linker<T>,
200184
host_getter: G,
201185
) -> wasmtime::Result<()>
202186
where
187+
G: for<'a> wasmtime::component::GetHost<&'a mut T, Host: Host + Send>,
203188
T: Send,
204189
{
205190
let mut inst = linker.instance("foo:foo/chars")?;

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

+5-18
Original file line numberDiff line numberDiff line change
@@ -219,26 +219,13 @@ pub mod foo {
219219
/// Identifiers with the same name as keywords are quoted.
220220
fn bool(&mut self) -> ();
221221
}
222-
pub trait GetHost<
223-
T,
224-
D,
225-
>: Fn(T) -> <Self as GetHost<T, D>>::Host + Send + Sync + Copy + 'static {
226-
type Host: Host;
227-
}
228-
impl<F, T, D, O> GetHost<T, D> for F
229-
where
230-
F: Fn(T) -> O + Send + Sync + Copy + 'static,
231-
O: Host,
232-
{
233-
type Host = O;
234-
}
235-
pub fn add_to_linker_get_host<
236-
T,
237-
G: for<'a> GetHost<&'a mut T, T, Host: Host>,
238-
>(
222+
pub fn add_to_linker_get_host<T, G>(
239223
linker: &mut wasmtime::component::Linker<T>,
240224
host_getter: G,
241-
) -> wasmtime::Result<()> {
225+
) -> wasmtime::Result<()>
226+
where
227+
G: for<'a> wasmtime::component::GetHost<&'a mut T, Host: Host>,
228+
{
242229
let mut inst = linker.instance("foo:foo/conventions")?;
243230
inst.func_wrap(
244231
"kebab-case",

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

+2-17
Original file line numberDiff line numberDiff line change
@@ -227,27 +227,12 @@ pub mod foo {
227227
/// Identifiers with the same name as keywords are quoted.
228228
async fn bool(&mut self) -> ();
229229
}
230-
pub trait GetHost<
231-
T,
232-
D,
233-
>: Fn(T) -> <Self as GetHost<T, D>>::Host + Send + Sync + Copy + 'static {
234-
type Host: Host + Send;
235-
}
236-
impl<F, T, D, O> GetHost<T, D> for F
237-
where
238-
F: Fn(T) -> O + Send + Sync + Copy + 'static,
239-
O: Host + Send,
240-
{
241-
type Host = O;
242-
}
243-
pub fn add_to_linker_get_host<
244-
T,
245-
G: for<'a> GetHost<&'a mut T, T, Host: Host + Send>,
246-
>(
230+
pub fn add_to_linker_get_host<T, G>(
247231
linker: &mut wasmtime::component::Linker<T>,
248232
host_getter: G,
249233
) -> wasmtime::Result<()>
250234
where
235+
G: for<'a> wasmtime::component::GetHost<&'a mut T, Host: Host + Send>,
251236
T: Send,
252237
{
253238
let mut inst = linker.instance("foo:foo/conventions")?;

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

+5-17
Original file line numberDiff line numberDiff line change
@@ -324,27 +324,15 @@ pub mod foo {
324324
where
325325
Self: Sized;
326326
}
327-
pub trait GetHost<
328-
T,
329-
D,
330-
>: Fn(T) -> <Self as GetHost<T, D>>::Host + Send + Sync + Copy + 'static {
331-
type Host: Host<Data = D> + Send;
332-
}
333-
impl<F, T, D, O> GetHost<T, D> for F
334-
where
335-
F: Fn(T) -> O + Send + Sync + Copy + 'static,
336-
O: Host<Data = D> + Send,
337-
{
338-
type Host = O;
339-
}
340-
pub fn add_to_linker_get_host<
341-
T,
342-
G: for<'a> GetHost<&'a mut T, T, Host: Host<Data = T> + Send>,
343-
>(
327+
pub fn add_to_linker_get_host<T, G>(
344328
linker: &mut wasmtime::component::Linker<T>,
345329
host_getter: G,
346330
) -> wasmtime::Result<()>
347331
where
332+
G: for<'a> wasmtime::component::GetHost<
333+
&'a mut T,
334+
Host: Host<Data = T> + Send,
335+
>,
348336
T: Send + 'static,
349337
{
350338
let mut inst = linker.instance("foo:foo/conventions")?;

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

+2-17
Original file line numberDiff line numberDiff line change
@@ -227,27 +227,12 @@ pub mod foo {
227227
/// Identifiers with the same name as keywords are quoted.
228228
async fn bool(&mut self) -> ();
229229
}
230-
pub trait GetHost<
231-
T,
232-
D,
233-
>: Fn(T) -> <Self as GetHost<T, D>>::Host + Send + Sync + Copy + 'static {
234-
type Host: Host + Send;
235-
}
236-
impl<F, T, D, O> GetHost<T, D> for F
237-
where
238-
F: Fn(T) -> O + Send + Sync + Copy + 'static,
239-
O: Host + Send,
240-
{
241-
type Host = O;
242-
}
243-
pub fn add_to_linker_get_host<
244-
T,
245-
G: for<'a> GetHost<&'a mut T, T, Host: Host + Send>,
246-
>(
230+
pub fn add_to_linker_get_host<T, G>(
247231
linker: &mut wasmtime::component::Linker<T>,
248232
host_getter: G,
249233
) -> wasmtime::Result<()>
250234
where
235+
G: for<'a> wasmtime::component::GetHost<&'a mut T, Host: Host + Send>,
251236
T: Send,
252237
{
253238
let mut inst = linker.instance("foo:foo/conventions")?;

crates/component-macro/tests/expanded/dead-code.rs

+10-36
Original file line numberDiff line numberDiff line change
@@ -181,26 +181,13 @@ pub mod a {
181181
pub trait Host {
182182
fn f(&mut self) -> LiveType;
183183
}
184-
pub trait GetHost<
185-
T,
186-
D,
187-
>: Fn(T) -> <Self as GetHost<T, D>>::Host + Send + Sync + Copy + 'static {
188-
type Host: Host;
189-
}
190-
impl<F, T, D, O> GetHost<T, D> for F
191-
where
192-
F: Fn(T) -> O + Send + Sync + Copy + 'static,
193-
O: Host,
194-
{
195-
type Host = O;
196-
}
197-
pub fn add_to_linker_get_host<
198-
T,
199-
G: for<'a> GetHost<&'a mut T, T, Host: Host>,
200-
>(
184+
pub fn add_to_linker_get_host<T, G>(
201185
linker: &mut wasmtime::component::Linker<T>,
202186
host_getter: G,
203-
) -> wasmtime::Result<()> {
187+
) -> wasmtime::Result<()>
188+
where
189+
G: for<'a> wasmtime::component::GetHost<&'a mut T, Host: Host>,
190+
{
204191
let mut inst = linker.instance("a:b/interface-with-live-type")?;
205192
inst.func_wrap(
206193
"f",
@@ -282,26 +269,13 @@ pub mod a {
282269
assert!(4 == < V as wasmtime::component::ComponentType >::ALIGN32);
283270
};
284271
pub trait Host {}
285-
pub trait GetHost<
286-
T,
287-
D,
288-
>: Fn(T) -> <Self as GetHost<T, D>>::Host + Send + Sync + Copy + 'static {
289-
type Host: Host;
290-
}
291-
impl<F, T, D, O> GetHost<T, D> for F
292-
where
293-
F: Fn(T) -> O + Send + Sync + Copy + 'static,
294-
O: Host,
295-
{
296-
type Host = O;
297-
}
298-
pub fn add_to_linker_get_host<
299-
T,
300-
G: for<'a> GetHost<&'a mut T, T, Host: Host>,
301-
>(
272+
pub fn add_to_linker_get_host<T, G>(
302273
linker: &mut wasmtime::component::Linker<T>,
303274
host_getter: G,
304-
) -> wasmtime::Result<()> {
275+
) -> wasmtime::Result<()>
276+
where
277+
G: for<'a> wasmtime::component::GetHost<&'a mut T, Host: Host>,
278+
{
305279
let mut inst = linker.instance("a:b/interface-with-dead-type")?;
306280
Ok(())
307281
}

crates/component-macro/tests/expanded/dead-code_async.rs

+4-34
Original file line numberDiff line numberDiff line change
@@ -189,27 +189,12 @@ pub mod a {
189189
pub trait Host: Send {
190190
async fn f(&mut self) -> LiveType;
191191
}
192-
pub trait GetHost<
193-
T,
194-
D,
195-
>: Fn(T) -> <Self as GetHost<T, D>>::Host + Send + Sync + Copy + 'static {
196-
type Host: Host + Send;
197-
}
198-
impl<F, T, D, O> GetHost<T, D> for F
199-
where
200-
F: Fn(T) -> O + Send + Sync + Copy + 'static,
201-
O: Host + Send,
202-
{
203-
type Host = O;
204-
}
205-
pub fn add_to_linker_get_host<
206-
T,
207-
G: for<'a> GetHost<&'a mut T, T, Host: Host + Send>,
208-
>(
192+
pub fn add_to_linker_get_host<T, G>(
209193
linker: &mut wasmtime::component::Linker<T>,
210194
host_getter: G,
211195
) -> wasmtime::Result<()>
212196
where
197+
G: for<'a> wasmtime::component::GetHost<&'a mut T, Host: Host + Send>,
213198
T: Send,
214199
{
215200
let mut inst = linker.instance("a:b/interface-with-live-type")?;
@@ -297,27 +282,12 @@ pub mod a {
297282
};
298283
#[wasmtime::component::__internal::trait_variant_make(::core::marker::Send)]
299284
pub trait Host: Send {}
300-
pub trait GetHost<
301-
T,
302-
D,
303-
>: Fn(T) -> <Self as GetHost<T, D>>::Host + Send + Sync + Copy + 'static {
304-
type Host: Host + Send;
305-
}
306-
impl<F, T, D, O> GetHost<T, D> for F
307-
where
308-
F: Fn(T) -> O + Send + Sync + Copy + 'static,
309-
O: Host + Send,
310-
{
311-
type Host = O;
312-
}
313-
pub fn add_to_linker_get_host<
314-
T,
315-
G: for<'a> GetHost<&'a mut T, T, Host: Host + Send>,
316-
>(
285+
pub fn add_to_linker_get_host<T, G>(
317286
linker: &mut wasmtime::component::Linker<T>,
318287
host_getter: G,
319288
) -> wasmtime::Result<()>
320289
where
290+
G: for<'a> wasmtime::component::GetHost<&'a mut T, Host: Host + Send>,
321291
T: Send,
322292
{
323293
let mut inst = linker.instance("a:b/interface-with-dead-type")?;

0 commit comments

Comments
 (0)