Skip to content

Commit 9837515

Browse files
pchickeyfitzgen
authored andcommitted
wasmtime-wit-bindgen: emit a definition for all types in a wit interface (bytecodealliance#10311)
* wasmtime-wit-bindgen: emit a definition for all types in a wit The calculation of TypeInfo only reaches types which are passed to or from a function. For types which are not reachable, default to the defining them according to the ownership setting given to bindgen. I have my doubts that `with`-reuse of bindgen types actually works properly when bindgen is set to Ownership::Borrowing but thats out of scope for this PR, which is to fix bytecodealliance#10090 * component-macro: bless bindgen test output
1 parent c273281 commit 9837515

14 files changed

Lines changed: 387 additions & 2 deletions

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,56 @@ pub mod a {
248248
pub mod interface_with_dead_type {
249249
#[allow(unused_imports)]
250250
use wasmtime::component::__internal::{anyhow, Box};
251+
pub type LiveType = super::super::super::a::b::interface_with_live_type::LiveType;
252+
const _: () = {
253+
assert!(4 == < LiveType as wasmtime::component::ComponentType >::SIZE32);
254+
assert!(
255+
4 == < LiveType as wasmtime::component::ComponentType >::ALIGN32
256+
);
257+
};
258+
#[derive(wasmtime::component::ComponentType)]
259+
#[derive(wasmtime::component::Lift)]
260+
#[derive(wasmtime::component::Lower)]
261+
#[component(record)]
262+
#[derive(Clone, Copy)]
263+
pub struct DeadType {
264+
#[component(name = "a")]
265+
pub a: u32,
266+
}
267+
impl core::fmt::Debug for DeadType {
268+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
269+
f.debug_struct("DeadType").field("a", &self.a).finish()
270+
}
271+
}
272+
const _: () = {
273+
assert!(4 == < DeadType as wasmtime::component::ComponentType >::SIZE32);
274+
assert!(
275+
4 == < DeadType as wasmtime::component::ComponentType >::ALIGN32
276+
);
277+
};
278+
#[derive(wasmtime::component::ComponentType)]
279+
#[derive(wasmtime::component::Lift)]
280+
#[derive(wasmtime::component::Lower)]
281+
#[component(variant)]
282+
#[derive(Clone, Copy)]
283+
pub enum V {
284+
#[component(name = "a")]
285+
A(LiveType),
286+
#[component(name = "b")]
287+
B(DeadType),
288+
}
289+
impl core::fmt::Debug for V {
290+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
291+
match self {
292+
V::A(e) => f.debug_tuple("V::A").field(e).finish(),
293+
V::B(e) => f.debug_tuple("V::B").field(e).finish(),
294+
}
295+
}
296+
}
297+
const _: () = {
298+
assert!(8 == < V as wasmtime::component::ComponentType >::SIZE32);
299+
assert!(4 == < V as wasmtime::component::ComponentType >::ALIGN32);
300+
};
251301
pub trait Host {}
252302
pub trait GetHost<
253303
T,

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,56 @@ pub mod a {
262262
pub mod interface_with_dead_type {
263263
#[allow(unused_imports)]
264264
use wasmtime::component::__internal::{anyhow, Box};
265+
pub type LiveType = super::super::super::a::b::interface_with_live_type::LiveType;
266+
const _: () = {
267+
assert!(4 == < LiveType as wasmtime::component::ComponentType >::SIZE32);
268+
assert!(
269+
4 == < LiveType as wasmtime::component::ComponentType >::ALIGN32
270+
);
271+
};
272+
#[derive(wasmtime::component::ComponentType)]
273+
#[derive(wasmtime::component::Lift)]
274+
#[derive(wasmtime::component::Lower)]
275+
#[component(record)]
276+
#[derive(Clone, Copy)]
277+
pub struct DeadType {
278+
#[component(name = "a")]
279+
pub a: u32,
280+
}
281+
impl core::fmt::Debug for DeadType {
282+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
283+
f.debug_struct("DeadType").field("a", &self.a).finish()
284+
}
285+
}
286+
const _: () = {
287+
assert!(4 == < DeadType as wasmtime::component::ComponentType >::SIZE32);
288+
assert!(
289+
4 == < DeadType as wasmtime::component::ComponentType >::ALIGN32
290+
);
291+
};
292+
#[derive(wasmtime::component::ComponentType)]
293+
#[derive(wasmtime::component::Lift)]
294+
#[derive(wasmtime::component::Lower)]
295+
#[component(variant)]
296+
#[derive(Clone, Copy)]
297+
pub enum V {
298+
#[component(name = "a")]
299+
A(LiveType),
300+
#[component(name = "b")]
301+
B(DeadType),
302+
}
303+
impl core::fmt::Debug for V {
304+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
305+
match self {
306+
V::A(e) => f.debug_tuple("V::A").field(e).finish(),
307+
V::B(e) => f.debug_tuple("V::B").field(e).finish(),
308+
}
309+
}
310+
}
311+
const _: () = {
312+
assert!(8 == < V as wasmtime::component::ComponentType >::SIZE32);
313+
assert!(4 == < V as wasmtime::component::ComponentType >::ALIGN32);
314+
};
265315
#[wasmtime::component::__internal::trait_variant_make(::core::marker::Send)]
266316
pub trait Host: Send {}
267317
pub trait GetHost<

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,56 @@ pub mod a {
301301
pub mod interface_with_dead_type {
302302
#[allow(unused_imports)]
303303
use wasmtime::component::__internal::{anyhow, Box};
304+
pub type LiveType = super::super::super::a::b::interface_with_live_type::LiveType;
305+
const _: () = {
306+
assert!(4 == < LiveType as wasmtime::component::ComponentType >::SIZE32);
307+
assert!(
308+
4 == < LiveType as wasmtime::component::ComponentType >::ALIGN32
309+
);
310+
};
311+
#[derive(wasmtime::component::ComponentType)]
312+
#[derive(wasmtime::component::Lift)]
313+
#[derive(wasmtime::component::Lower)]
314+
#[component(record)]
315+
#[derive(Clone, Copy)]
316+
pub struct DeadType {
317+
#[component(name = "a")]
318+
pub a: u32,
319+
}
320+
impl core::fmt::Debug for DeadType {
321+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
322+
f.debug_struct("DeadType").field("a", &self.a).finish()
323+
}
324+
}
325+
const _: () = {
326+
assert!(4 == < DeadType as wasmtime::component::ComponentType >::SIZE32);
327+
assert!(
328+
4 == < DeadType as wasmtime::component::ComponentType >::ALIGN32
329+
);
330+
};
331+
#[derive(wasmtime::component::ComponentType)]
332+
#[derive(wasmtime::component::Lift)]
333+
#[derive(wasmtime::component::Lower)]
334+
#[component(variant)]
335+
#[derive(Clone, Copy)]
336+
pub enum V {
337+
#[component(name = "a")]
338+
A(LiveType),
339+
#[component(name = "b")]
340+
B(DeadType),
341+
}
342+
impl core::fmt::Debug for V {
343+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
344+
match self {
345+
V::A(e) => f.debug_tuple("V::A").field(e).finish(),
346+
V::B(e) => f.debug_tuple("V::B").field(e).finish(),
347+
}
348+
}
349+
}
350+
const _: () = {
351+
assert!(8 == < V as wasmtime::component::ComponentType >::SIZE32);
352+
assert!(4 == < V as wasmtime::component::ComponentType >::ALIGN32);
353+
};
304354
pub trait Host {}
305355
pub trait GetHost<
306356
T,

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,56 @@ pub mod a {
275275
pub mod interface_with_dead_type {
276276
#[allow(unused_imports)]
277277
use wasmtime::component::__internal::{anyhow, Box};
278+
pub type LiveType = super::super::super::a::b::interface_with_live_type::LiveType;
279+
const _: () = {
280+
assert!(4 == < LiveType as wasmtime::component::ComponentType >::SIZE32);
281+
assert!(
282+
4 == < LiveType as wasmtime::component::ComponentType >::ALIGN32
283+
);
284+
};
285+
#[derive(wasmtime::component::ComponentType)]
286+
#[derive(wasmtime::component::Lift)]
287+
#[derive(wasmtime::component::Lower)]
288+
#[component(record)]
289+
#[derive(Clone, Copy)]
290+
pub struct DeadType {
291+
#[component(name = "a")]
292+
pub a: u32,
293+
}
294+
impl core::fmt::Debug for DeadType {
295+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
296+
f.debug_struct("DeadType").field("a", &self.a).finish()
297+
}
298+
}
299+
const _: () = {
300+
assert!(4 == < DeadType as wasmtime::component::ComponentType >::SIZE32);
301+
assert!(
302+
4 == < DeadType as wasmtime::component::ComponentType >::ALIGN32
303+
);
304+
};
305+
#[derive(wasmtime::component::ComponentType)]
306+
#[derive(wasmtime::component::Lift)]
307+
#[derive(wasmtime::component::Lower)]
308+
#[component(variant)]
309+
#[derive(Clone, Copy)]
310+
pub enum V {
311+
#[component(name = "a")]
312+
A(LiveType),
313+
#[component(name = "b")]
314+
B(DeadType),
315+
}
316+
impl core::fmt::Debug for V {
317+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
318+
match self {
319+
V::A(e) => f.debug_tuple("V::A").field(e).finish(),
320+
V::B(e) => f.debug_tuple("V::B").field(e).finish(),
321+
}
322+
}
323+
}
324+
const _: () = {
325+
assert!(8 == < V as wasmtime::component::ComponentType >::SIZE32);
326+
assert!(4 == < V as wasmtime::component::ComponentType >::ALIGN32);
327+
};
278328
#[wasmtime::component::__internal::trait_variant_make(::core::marker::Send)]
279329
pub trait Host: Send {}
280330
pub trait GetHost<

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,15 @@ pub mod foo {
314314
4 == < Aggregates as wasmtime::component::ComponentType >::ALIGN32
315315
);
316316
};
317+
pub type TupleTypedef = (i32,);
318+
const _: () = {
319+
assert!(
320+
4 == < TupleTypedef as wasmtime::component::ComponentType >::SIZE32
321+
);
322+
assert!(
323+
4 == < TupleTypedef as wasmtime::component::ComponentType >::ALIGN32
324+
);
325+
};
317326
pub type IntTypedef = i32;
318327
const _: () = {
319328
assert!(
@@ -680,6 +689,17 @@ pub mod exports {
680689
>::ALIGN32
681690
);
682691
};
692+
pub type TupleTypedef = (i32,);
693+
const _: () = {
694+
assert!(
695+
4 == < TupleTypedef as wasmtime::component::ComponentType
696+
>::SIZE32
697+
);
698+
assert!(
699+
4 == < TupleTypedef as wasmtime::component::ComponentType
700+
>::ALIGN32
701+
);
702+
};
683703
pub type IntTypedef = i32;
684704
const _: () = {
685705
assert!(

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,15 @@ pub mod foo {
321321
4 == < Aggregates as wasmtime::component::ComponentType >::ALIGN32
322322
);
323323
};
324+
pub type TupleTypedef = (i32,);
325+
const _: () = {
326+
assert!(
327+
4 == < TupleTypedef as wasmtime::component::ComponentType >::SIZE32
328+
);
329+
assert!(
330+
4 == < TupleTypedef as wasmtime::component::ComponentType >::ALIGN32
331+
);
332+
};
324333
pub type IntTypedef = i32;
325334
const _: () = {
326335
assert!(
@@ -714,6 +723,17 @@ pub mod exports {
714723
>::ALIGN32
715724
);
716725
};
726+
pub type TupleTypedef = (i32,);
727+
const _: () = {
728+
assert!(
729+
4 == < TupleTypedef as wasmtime::component::ComponentType
730+
>::SIZE32
731+
);
732+
assert!(
733+
4 == < TupleTypedef as wasmtime::component::ComponentType
734+
>::ALIGN32
735+
);
736+
};
717737
pub type IntTypedef = i32;
718738
const _: () = {
719739
assert!(

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,15 @@ pub mod foo {
321321
4 == < Aggregates as wasmtime::component::ComponentType >::ALIGN32
322322
);
323323
};
324+
pub type TupleTypedef = (i32,);
325+
const _: () = {
326+
assert!(
327+
4 == < TupleTypedef as wasmtime::component::ComponentType >::SIZE32
328+
);
329+
assert!(
330+
4 == < TupleTypedef as wasmtime::component::ComponentType >::ALIGN32
331+
);
332+
};
324333
pub type IntTypedef = i32;
325334
const _: () = {
326335
assert!(
@@ -1134,6 +1143,17 @@ pub mod exports {
11341143
>::ALIGN32
11351144
);
11361145
};
1146+
pub type TupleTypedef = (i32,);
1147+
const _: () = {
1148+
assert!(
1149+
4 == < TupleTypedef as wasmtime::component::ComponentType
1150+
>::SIZE32
1151+
);
1152+
assert!(
1153+
4 == < TupleTypedef as wasmtime::component::ComponentType
1154+
>::ALIGN32
1155+
);
1156+
};
11371157
pub type IntTypedef = i32;
11381158
const _: () = {
11391159
assert!(

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,15 @@ pub mod foo {
321321
4 == < Aggregates as wasmtime::component::ComponentType >::ALIGN32
322322
);
323323
};
324+
pub type TupleTypedef = (i32,);
325+
const _: () = {
326+
assert!(
327+
4 == < TupleTypedef as wasmtime::component::ComponentType >::SIZE32
328+
);
329+
assert!(
330+
4 == < TupleTypedef as wasmtime::component::ComponentType >::ALIGN32
331+
);
332+
};
324333
pub type IntTypedef = i32;
325334
const _: () = {
326335
assert!(
@@ -875,6 +884,17 @@ pub mod exports {
875884
>::ALIGN32
876885
);
877886
};
887+
pub type TupleTypedef = (i32,);
888+
const _: () = {
889+
assert!(
890+
4 == < TupleTypedef as wasmtime::component::ComponentType
891+
>::SIZE32
892+
);
893+
assert!(
894+
4 == < TupleTypedef as wasmtime::component::ComponentType
895+
>::ALIGN32
896+
);
897+
};
878898
pub type IntTypedef = i32;
879899
const _: () = {
880900
assert!(

crates/component-macro/tests/expanded/simple-wasi.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,25 @@ pub mod foo {
300300
pub mod wall_clock {
301301
#[allow(unused_imports)]
302302
use wasmtime::component::__internal::{anyhow, Box};
303+
#[derive(wasmtime::component::ComponentType)]
304+
#[derive(wasmtime::component::Lift)]
305+
#[derive(wasmtime::component::Lower)]
306+
#[component(record)]
307+
#[derive(Clone, Copy)]
308+
pub struct WallClock {}
309+
impl core::fmt::Debug for WallClock {
310+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
311+
f.debug_struct("WallClock").finish()
312+
}
313+
}
314+
const _: () = {
315+
assert!(
316+
0 == < WallClock as wasmtime::component::ComponentType >::SIZE32
317+
);
318+
assert!(
319+
1 == < WallClock as wasmtime::component::ComponentType >::ALIGN32
320+
);
321+
};
303322
pub trait Host {}
304323
pub trait GetHost<
305324
T,

0 commit comments

Comments
 (0)