Skip to content

Commit

Permalink
wasmtime-wit-bindgen: emit a definition for all types in a wit interf…
Browse files Browse the repository at this point in the history
…ace (#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 #10090

* component-macro: bless bindgen test output
  • Loading branch information
pchickey authored Feb 28, 2025
1 parent c273281 commit af31e80
Show file tree
Hide file tree
Showing 13 changed files with 365 additions and 1 deletion.
50 changes: 50 additions & 0 deletions crates/component-macro/tests/expanded/dead-code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,56 @@ pub mod a {
pub mod interface_with_dead_type {
#[allow(unused_imports)]
use wasmtime::component::__internal::{anyhow, Box};
pub type LiveType = super::super::super::a::b::interface_with_live_type::LiveType;
const _: () = {
assert!(4 == < LiveType as wasmtime::component::ComponentType >::SIZE32);
assert!(
4 == < LiveType as wasmtime::component::ComponentType >::ALIGN32
);
};
#[derive(wasmtime::component::ComponentType)]
#[derive(wasmtime::component::Lift)]
#[derive(wasmtime::component::Lower)]
#[component(record)]
#[derive(Clone, Copy)]
pub struct DeadType {
#[component(name = "a")]
pub a: u32,
}
impl core::fmt::Debug for DeadType {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.debug_struct("DeadType").field("a", &self.a).finish()
}
}
const _: () = {
assert!(4 == < DeadType as wasmtime::component::ComponentType >::SIZE32);
assert!(
4 == < DeadType as wasmtime::component::ComponentType >::ALIGN32
);
};
#[derive(wasmtime::component::ComponentType)]
#[derive(wasmtime::component::Lift)]
#[derive(wasmtime::component::Lower)]
#[component(variant)]
#[derive(Clone, Copy)]
pub enum V {
#[component(name = "a")]
A(LiveType),
#[component(name = "b")]
B(DeadType),
}
impl core::fmt::Debug for V {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
V::A(e) => f.debug_tuple("V::A").field(e).finish(),
V::B(e) => f.debug_tuple("V::B").field(e).finish(),
}
}
}
const _: () = {
assert!(8 == < V as wasmtime::component::ComponentType >::SIZE32);
assert!(4 == < V as wasmtime::component::ComponentType >::ALIGN32);
};
pub trait Host {}
pub trait GetHost<
T,
Expand Down
50 changes: 50 additions & 0 deletions crates/component-macro/tests/expanded/dead-code_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,56 @@ pub mod a {
pub mod interface_with_dead_type {
#[allow(unused_imports)]
use wasmtime::component::__internal::{anyhow, Box};
pub type LiveType = super::super::super::a::b::interface_with_live_type::LiveType;
const _: () = {
assert!(4 == < LiveType as wasmtime::component::ComponentType >::SIZE32);
assert!(
4 == < LiveType as wasmtime::component::ComponentType >::ALIGN32
);
};
#[derive(wasmtime::component::ComponentType)]
#[derive(wasmtime::component::Lift)]
#[derive(wasmtime::component::Lower)]
#[component(record)]
#[derive(Clone, Copy)]
pub struct DeadType {
#[component(name = "a")]
pub a: u32,
}
impl core::fmt::Debug for DeadType {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.debug_struct("DeadType").field("a", &self.a).finish()
}
}
const _: () = {
assert!(4 == < DeadType as wasmtime::component::ComponentType >::SIZE32);
assert!(
4 == < DeadType as wasmtime::component::ComponentType >::ALIGN32
);
};
#[derive(wasmtime::component::ComponentType)]
#[derive(wasmtime::component::Lift)]
#[derive(wasmtime::component::Lower)]
#[component(variant)]
#[derive(Clone, Copy)]
pub enum V {
#[component(name = "a")]
A(LiveType),
#[component(name = "b")]
B(DeadType),
}
impl core::fmt::Debug for V {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
V::A(e) => f.debug_tuple("V::A").field(e).finish(),
V::B(e) => f.debug_tuple("V::B").field(e).finish(),
}
}
}
const _: () = {
assert!(8 == < V as wasmtime::component::ComponentType >::SIZE32);
assert!(4 == < V as wasmtime::component::ComponentType >::ALIGN32);
};
#[wasmtime::component::__internal::trait_variant_make(::core::marker::Send)]
pub trait Host: Send {}
pub trait GetHost<
Expand Down
50 changes: 50 additions & 0 deletions crates/component-macro/tests/expanded/dead-code_concurrent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,56 @@ pub mod a {
pub mod interface_with_dead_type {
#[allow(unused_imports)]
use wasmtime::component::__internal::{anyhow, Box};
pub type LiveType = super::super::super::a::b::interface_with_live_type::LiveType;
const _: () = {
assert!(4 == < LiveType as wasmtime::component::ComponentType >::SIZE32);
assert!(
4 == < LiveType as wasmtime::component::ComponentType >::ALIGN32
);
};
#[derive(wasmtime::component::ComponentType)]
#[derive(wasmtime::component::Lift)]
#[derive(wasmtime::component::Lower)]
#[component(record)]
#[derive(Clone, Copy)]
pub struct DeadType {
#[component(name = "a")]
pub a: u32,
}
impl core::fmt::Debug for DeadType {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.debug_struct("DeadType").field("a", &self.a).finish()
}
}
const _: () = {
assert!(4 == < DeadType as wasmtime::component::ComponentType >::SIZE32);
assert!(
4 == < DeadType as wasmtime::component::ComponentType >::ALIGN32
);
};
#[derive(wasmtime::component::ComponentType)]
#[derive(wasmtime::component::Lift)]
#[derive(wasmtime::component::Lower)]
#[component(variant)]
#[derive(Clone, Copy)]
pub enum V {
#[component(name = "a")]
A(LiveType),
#[component(name = "b")]
B(DeadType),
}
impl core::fmt::Debug for V {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
V::A(e) => f.debug_tuple("V::A").field(e).finish(),
V::B(e) => f.debug_tuple("V::B").field(e).finish(),
}
}
}
const _: () = {
assert!(8 == < V as wasmtime::component::ComponentType >::SIZE32);
assert!(4 == < V as wasmtime::component::ComponentType >::ALIGN32);
};
pub trait Host {}
pub trait GetHost<
T,
Expand Down
50 changes: 50 additions & 0 deletions crates/component-macro/tests/expanded/dead-code_tracing_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,56 @@ pub mod a {
pub mod interface_with_dead_type {
#[allow(unused_imports)]
use wasmtime::component::__internal::{anyhow, Box};
pub type LiveType = super::super::super::a::b::interface_with_live_type::LiveType;
const _: () = {
assert!(4 == < LiveType as wasmtime::component::ComponentType >::SIZE32);
assert!(
4 == < LiveType as wasmtime::component::ComponentType >::ALIGN32
);
};
#[derive(wasmtime::component::ComponentType)]
#[derive(wasmtime::component::Lift)]
#[derive(wasmtime::component::Lower)]
#[component(record)]
#[derive(Clone, Copy)]
pub struct DeadType {
#[component(name = "a")]
pub a: u32,
}
impl core::fmt::Debug for DeadType {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.debug_struct("DeadType").field("a", &self.a).finish()
}
}
const _: () = {
assert!(4 == < DeadType as wasmtime::component::ComponentType >::SIZE32);
assert!(
4 == < DeadType as wasmtime::component::ComponentType >::ALIGN32
);
};
#[derive(wasmtime::component::ComponentType)]
#[derive(wasmtime::component::Lift)]
#[derive(wasmtime::component::Lower)]
#[component(variant)]
#[derive(Clone, Copy)]
pub enum V {
#[component(name = "a")]
A(LiveType),
#[component(name = "b")]
B(DeadType),
}
impl core::fmt::Debug for V {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
V::A(e) => f.debug_tuple("V::A").field(e).finish(),
V::B(e) => f.debug_tuple("V::B").field(e).finish(),
}
}
}
const _: () = {
assert!(8 == < V as wasmtime::component::ComponentType >::SIZE32);
assert!(4 == < V as wasmtime::component::ComponentType >::ALIGN32);
};
#[wasmtime::component::__internal::trait_variant_make(::core::marker::Send)]
pub trait Host: Send {}
pub trait GetHost<
Expand Down
20 changes: 20 additions & 0 deletions crates/component-macro/tests/expanded/records.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,15 @@ pub mod foo {
4 == < Aggregates as wasmtime::component::ComponentType >::ALIGN32
);
};
pub type TupleTypedef = (i32,);
const _: () = {
assert!(
4 == < TupleTypedef as wasmtime::component::ComponentType >::SIZE32
);
assert!(
4 == < TupleTypedef as wasmtime::component::ComponentType >::ALIGN32
);
};
pub type IntTypedef = i32;
const _: () = {
assert!(
Expand Down Expand Up @@ -680,6 +689,17 @@ pub mod exports {
>::ALIGN32
);
};
pub type TupleTypedef = (i32,);
const _: () = {
assert!(
4 == < TupleTypedef as wasmtime::component::ComponentType
>::SIZE32
);
assert!(
4 == < TupleTypedef as wasmtime::component::ComponentType
>::ALIGN32
);
};
pub type IntTypedef = i32;
const _: () = {
assert!(
Expand Down
20 changes: 20 additions & 0 deletions crates/component-macro/tests/expanded/records_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,15 @@ pub mod foo {
4 == < Aggregates as wasmtime::component::ComponentType >::ALIGN32
);
};
pub type TupleTypedef = (i32,);
const _: () = {
assert!(
4 == < TupleTypedef as wasmtime::component::ComponentType >::SIZE32
);
assert!(
4 == < TupleTypedef as wasmtime::component::ComponentType >::ALIGN32
);
};
pub type IntTypedef = i32;
const _: () = {
assert!(
Expand Down Expand Up @@ -714,6 +723,17 @@ pub mod exports {
>::ALIGN32
);
};
pub type TupleTypedef = (i32,);
const _: () = {
assert!(
4 == < TupleTypedef as wasmtime::component::ComponentType
>::SIZE32
);
assert!(
4 == < TupleTypedef as wasmtime::component::ComponentType
>::ALIGN32
);
};
pub type IntTypedef = i32;
const _: () = {
assert!(
Expand Down
20 changes: 20 additions & 0 deletions crates/component-macro/tests/expanded/records_concurrent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,15 @@ pub mod foo {
4 == < Aggregates as wasmtime::component::ComponentType >::ALIGN32
);
};
pub type TupleTypedef = (i32,);
const _: () = {
assert!(
4 == < TupleTypedef as wasmtime::component::ComponentType >::SIZE32
);
assert!(
4 == < TupleTypedef as wasmtime::component::ComponentType >::ALIGN32
);
};
pub type IntTypedef = i32;
const _: () = {
assert!(
Expand Down Expand Up @@ -1134,6 +1143,17 @@ pub mod exports {
>::ALIGN32
);
};
pub type TupleTypedef = (i32,);
const _: () = {
assert!(
4 == < TupleTypedef as wasmtime::component::ComponentType
>::SIZE32
);
assert!(
4 == < TupleTypedef as wasmtime::component::ComponentType
>::ALIGN32
);
};
pub type IntTypedef = i32;
const _: () = {
assert!(
Expand Down
20 changes: 20 additions & 0 deletions crates/component-macro/tests/expanded/records_tracing_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,15 @@ pub mod foo {
4 == < Aggregates as wasmtime::component::ComponentType >::ALIGN32
);
};
pub type TupleTypedef = (i32,);
const _: () = {
assert!(
4 == < TupleTypedef as wasmtime::component::ComponentType >::SIZE32
);
assert!(
4 == < TupleTypedef as wasmtime::component::ComponentType >::ALIGN32
);
};
pub type IntTypedef = i32;
const _: () = {
assert!(
Expand Down Expand Up @@ -875,6 +884,17 @@ pub mod exports {
>::ALIGN32
);
};
pub type TupleTypedef = (i32,);
const _: () = {
assert!(
4 == < TupleTypedef as wasmtime::component::ComponentType
>::SIZE32
);
assert!(
4 == < TupleTypedef as wasmtime::component::ComponentType
>::ALIGN32
);
};
pub type IntTypedef = i32;
const _: () = {
assert!(
Expand Down
19 changes: 19 additions & 0 deletions crates/component-macro/tests/expanded/simple-wasi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,25 @@ pub mod foo {
pub mod wall_clock {
#[allow(unused_imports)]
use wasmtime::component::__internal::{anyhow, Box};
#[derive(wasmtime::component::ComponentType)]
#[derive(wasmtime::component::Lift)]
#[derive(wasmtime::component::Lower)]
#[component(record)]
#[derive(Clone, Copy)]
pub struct WallClock {}
impl core::fmt::Debug for WallClock {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.debug_struct("WallClock").finish()
}
}
const _: () = {
assert!(
0 == < WallClock as wasmtime::component::ComponentType >::SIZE32
);
assert!(
1 == < WallClock as wasmtime::component::ComponentType >::ALIGN32
);
};
pub trait Host {}
pub trait GetHost<
T,
Expand Down
Loading

0 comments on commit af31e80

Please sign in to comment.