Skip to content

Commit 7c79060

Browse files
authored
Merge wasip3-prototyping bindgen changes to main (#10844)
* Merge wasip3-prototyping bindgen changes to main This commit wholesale copies the `wasmtime-wit-bindgen` changes from the wasip3-prototyping repository to the Wasmtime repository here. This is done to make the future merge with `wasip3-prototyping` smaller complexity-wise. This is intended to be a no-functional-change for non-"concurrent" imports, or those for component model async. That means that it's intended that no current embedding is affected by these changes. Internally though there has been restructuring. Namely internally the generation of an interface trait, a resource trait, and a world trait are all unified in a single method now. In the future with component model async these traits are being split into async/sync versions and so it was much nicer to do this in one location rather than across three different locations. This required some minor renamings in the generated code and moving around some impls, but otherwise the generated code should mostly be the same as before (see golden output diff in the subsequent commit of this PR) * Update test expectations
1 parent 3e5e7a0 commit 7c79060

File tree

88 files changed

+3324
-3563
lines changed

Some content is hidden

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

88 files changed

+3324
-3563
lines changed

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,14 @@ const _: () = {
146146
}
147147
pub fn add_to_linker<T, D>(
148148
linker: &mut wasmtime::component::Linker<T>,
149-
get: fn(&mut T) -> D::Data<'_>,
149+
host_getter: fn(&mut T) -> D::Data<'_>,
150150
) -> wasmtime::Result<()>
151151
where
152152
D: wasmtime::component::HasData,
153153
for<'a> D::Data<'a>: foo::foo::chars::Host,
154154
T: 'static,
155155
{
156-
foo::foo::chars::add_to_linker::<T, D>(linker, get)?;
156+
foo::foo::chars::add_to_linker::<T, D>(linker, host_getter)?;
157157
Ok(())
158158
}
159159
pub fn foo_foo_chars(&self) -> &exports::foo::foo::chars::Guest {
@@ -173,6 +173,16 @@ pub mod foo {
173173
/// A function that returns a character
174174
fn return_char(&mut self) -> char;
175175
}
176+
impl<_T: Host + ?Sized> Host for &mut _T {
177+
/// A function that accepts a character
178+
fn take_char(&mut self, x: char) -> () {
179+
Host::take_char(*self, x)
180+
}
181+
/// A function that returns a character
182+
fn return_char(&mut self) -> char {
183+
Host::return_char(*self)
184+
}
185+
}
176186
pub fn add_to_linker<T, D>(
177187
linker: &mut wasmtime::component::Linker<T>,
178188
host_getter: fn(&mut T) -> D::Data<'_>,
@@ -204,16 +214,6 @@ pub mod foo {
204214
)?;
205215
Ok(())
206216
}
207-
impl<_T: Host + ?Sized> Host for &mut _T {
208-
/// A function that accepts a character
209-
fn take_char(&mut self, x: char) -> () {
210-
Host::take_char(*self, x)
211-
}
212-
/// A function that returns a character
213-
fn return_char(&mut self) -> char {
214-
Host::return_char(*self)
215-
}
216-
}
217217
}
218218
}
219219
}

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,14 @@ const _: () = {
152152
}
153153
pub fn add_to_linker<T, D>(
154154
linker: &mut wasmtime::component::Linker<T>,
155-
get: fn(&mut T) -> D::Data<'_>,
155+
host_getter: fn(&mut T) -> D::Data<'_>,
156156
) -> wasmtime::Result<()>
157157
where
158158
D: wasmtime::component::HasData,
159159
for<'a> D::Data<'a>: foo::foo::chars::Host + Send,
160-
T: Send + 'static,
160+
T: 'static + Send,
161161
{
162-
foo::foo::chars::add_to_linker::<T, D>(linker, get)?;
162+
foo::foo::chars::add_to_linker::<T, D>(linker, host_getter)?;
163163
Ok(())
164164
}
165165
pub fn foo_foo_chars(&self) -> &exports::foo::foo::chars::Guest {
@@ -180,14 +180,24 @@ pub mod foo {
180180
/// A function that returns a character
181181
async fn return_char(&mut self) -> char;
182182
}
183+
impl<_T: Host + ?Sized + Send> Host for &mut _T {
184+
/// A function that accepts a character
185+
async fn take_char(&mut self, x: char) -> () {
186+
Host::take_char(*self, x).await
187+
}
188+
/// A function that returns a character
189+
async fn return_char(&mut self) -> char {
190+
Host::return_char(*self).await
191+
}
192+
}
183193
pub fn add_to_linker<T, D>(
184194
linker: &mut wasmtime::component::Linker<T>,
185195
host_getter: fn(&mut T) -> D::Data<'_>,
186196
) -> wasmtime::Result<()>
187197
where
188198
D: wasmtime::component::HasData,
189-
for<'a> D::Data<'a>: Host + Send,
190-
T: Send + 'static,
199+
for<'a> D::Data<'a>: Host,
200+
T: 'static + Send,
191201
{
192202
let mut inst = linker.instance("foo:foo/chars")?;
193203
inst.func_wrap_async(
@@ -215,16 +225,6 @@ pub mod foo {
215225
)?;
216226
Ok(())
217227
}
218-
impl<_T: Host + ?Sized + Send> Host for &mut _T {
219-
/// A function that accepts a character
220-
async fn take_char(&mut self, x: char) -> () {
221-
Host::take_char(*self, x).await
222-
}
223-
/// A function that returns a character
224-
async fn return_char(&mut self) -> char {
225-
Host::return_char(*self).await
226-
}
227-
}
228228
}
229229
}
230230
}

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,14 @@ const _: () = {
152152
}
153153
pub fn add_to_linker<T, D>(
154154
linker: &mut wasmtime::component::Linker<T>,
155-
get: fn(&mut T) -> D::Data<'_>,
155+
host_getter: fn(&mut T) -> D::Data<'_>,
156156
) -> wasmtime::Result<()>
157157
where
158158
D: wasmtime::component::HasData,
159159
for<'a> D::Data<'a>: foo::foo::chars::Host + Send,
160-
T: Send + 'static,
160+
T: 'static + Send,
161161
{
162-
foo::foo::chars::add_to_linker::<T, D>(linker, get)?;
162+
foo::foo::chars::add_to_linker::<T, D>(linker, host_getter)?;
163163
Ok(())
164164
}
165165
pub fn foo_foo_chars(&self) -> &exports::foo::foo::chars::Guest {
@@ -180,14 +180,24 @@ pub mod foo {
180180
/// A function that returns a character
181181
async fn return_char(&mut self) -> char;
182182
}
183+
impl<_T: Host + ?Sized + Send> Host for &mut _T {
184+
/// A function that accepts a character
185+
async fn take_char(&mut self, x: char) -> () {
186+
Host::take_char(*self, x).await
187+
}
188+
/// A function that returns a character
189+
async fn return_char(&mut self) -> char {
190+
Host::return_char(*self).await
191+
}
192+
}
183193
pub fn add_to_linker<T, D>(
184194
linker: &mut wasmtime::component::Linker<T>,
185195
host_getter: fn(&mut T) -> D::Data<'_>,
186196
) -> wasmtime::Result<()>
187197
where
188198
D: wasmtime::component::HasData,
189-
for<'a> D::Data<'a>: Host + Send,
190-
T: Send + 'static,
199+
for<'a> D::Data<'a>: Host,
200+
T: 'static + Send,
191201
{
192202
let mut inst = linker.instance("foo:foo/chars")?;
193203
inst.func_wrap_async(
@@ -244,16 +254,6 @@ pub mod foo {
244254
)?;
245255
Ok(())
246256
}
247-
impl<_T: Host + ?Sized + Send> Host for &mut _T {
248-
/// A function that accepts a character
249-
async fn take_char(&mut self, x: char) -> () {
250-
Host::take_char(*self, x).await
251-
}
252-
/// A function that returns a character
253-
async fn return_char(&mut self) -> char {
254-
Host::return_char(*self).await
255-
}
256-
}
257257
}
258258
}
259259
}

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

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,14 @@ const _: () = {
148148
}
149149
pub fn add_to_linker<T, D>(
150150
linker: &mut wasmtime::component::Linker<T>,
151-
get: fn(&mut T) -> D::Data<'_>,
151+
host_getter: fn(&mut T) -> D::Data<'_>,
152152
) -> wasmtime::Result<()>
153153
where
154154
D: wasmtime::component::HasData,
155155
for<'a> D::Data<'a>: foo::foo::conventions::Host,
156156
T: 'static,
157157
{
158-
foo::foo::conventions::add_to_linker::<T, D>(linker, get)?;
158+
foo::foo::conventions::add_to_linker::<T, D>(linker, host_getter)?;
159159
Ok(())
160160
}
161161
pub fn foo_foo_conventions(&self) -> &exports::foo::foo::conventions::Guest {
@@ -221,6 +221,50 @@ pub mod foo {
221221
/// Identifiers with the same name as keywords are quoted.
222222
fn bool(&mut self) -> ();
223223
}
224+
impl<_T: Host + ?Sized> Host for &mut _T {
225+
fn kebab_case(&mut self) -> () {
226+
Host::kebab_case(*self)
227+
}
228+
fn foo(&mut self, x: LudicrousSpeed) -> () {
229+
Host::foo(*self, x)
230+
}
231+
fn function_with_dashes(&mut self) -> () {
232+
Host::function_with_dashes(*self)
233+
}
234+
fn function_with_no_weird_characters(&mut self) -> () {
235+
Host::function_with_no_weird_characters(*self)
236+
}
237+
fn apple(&mut self) -> () {
238+
Host::apple(*self)
239+
}
240+
fn apple_pear(&mut self) -> () {
241+
Host::apple_pear(*self)
242+
}
243+
fn apple_pear_grape(&mut self) -> () {
244+
Host::apple_pear_grape(*self)
245+
}
246+
fn a0(&mut self) -> () {
247+
Host::a0(*self)
248+
}
249+
/// Comment out identifiers that collide when mapped to snake_case, for now; see
250+
/// https://github.com/WebAssembly/component-model/issues/118
251+
/// APPLE: func()
252+
/// APPLE-pear-GRAPE: func()
253+
/// apple-PEAR-grape: func()
254+
fn is_xml(&mut self) -> () {
255+
Host::is_xml(*self)
256+
}
257+
fn explicit(&mut self) -> () {
258+
Host::explicit(*self)
259+
}
260+
fn explicit_kebab(&mut self) -> () {
261+
Host::explicit_kebab(*self)
262+
}
263+
/// Identifiers with the same name as keywords are quoted.
264+
fn bool(&mut self) -> () {
265+
Host::bool(*self)
266+
}
267+
}
224268
pub fn add_to_linker<T, D>(
225269
linker: &mut wasmtime::component::Linker<T>,
226270
host_getter: fn(&mut T) -> D::Data<'_>,
@@ -332,50 +376,6 @@ pub mod foo {
332376
)?;
333377
Ok(())
334378
}
335-
impl<_T: Host + ?Sized> Host for &mut _T {
336-
fn kebab_case(&mut self) -> () {
337-
Host::kebab_case(*self)
338-
}
339-
fn foo(&mut self, x: LudicrousSpeed) -> () {
340-
Host::foo(*self, x)
341-
}
342-
fn function_with_dashes(&mut self) -> () {
343-
Host::function_with_dashes(*self)
344-
}
345-
fn function_with_no_weird_characters(&mut self) -> () {
346-
Host::function_with_no_weird_characters(*self)
347-
}
348-
fn apple(&mut self) -> () {
349-
Host::apple(*self)
350-
}
351-
fn apple_pear(&mut self) -> () {
352-
Host::apple_pear(*self)
353-
}
354-
fn apple_pear_grape(&mut self) -> () {
355-
Host::apple_pear_grape(*self)
356-
}
357-
fn a0(&mut self) -> () {
358-
Host::a0(*self)
359-
}
360-
/// Comment out identifiers that collide when mapped to snake_case, for now; see
361-
/// https://github.com/WebAssembly/component-model/issues/118
362-
/// APPLE: func()
363-
/// APPLE-pear-GRAPE: func()
364-
/// apple-PEAR-grape: func()
365-
fn is_xml(&mut self) -> () {
366-
Host::is_xml(*self)
367-
}
368-
fn explicit(&mut self) -> () {
369-
Host::explicit(*self)
370-
}
371-
fn explicit_kebab(&mut self) -> () {
372-
Host::explicit_kebab(*self)
373-
}
374-
/// Identifiers with the same name as keywords are quoted.
375-
fn bool(&mut self) -> () {
376-
Host::bool(*self)
377-
}
378-
}
379379
}
380380
}
381381
}

0 commit comments

Comments
 (0)