Skip to content

support composing with fixed size lists #156

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
68 changes: 34 additions & 34 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ wac-parser = { path = "crates/wac-parser", version = "0.7.0-dev", default-featur
wac-resolver = { path = "crates/wac-resolver", version = "0.7.0-dev", default-features = false }
wac-graph = { path = "crates/wac-graph", version = "0.7.0-dev" }
wac-types = { path = "crates/wac-types", version = "0.7.0-dev" }
wit-parser = "0.229.0"
wasmparser = "0.229.0"
wit-component = "0.229.0"
wasm-encoder = "0.229.0"
wasmprinter = "0.229.0"
wasm-metadata = "0.229.0"
wat = "1.229.0"
wit-parser = "0.230.0"
wasmparser = "0.230.0"
wit-component = "0.230.0"
wasm-encoder = "0.230.0"
wasmprinter = "0.230.0"
wasm-metadata = "0.230.0"
wat = "1.230.0"
anyhow = "1.0.81"
clap = { version = "4.5.4", features = ["derive"] }
semver = { version = "1.0.22", features = ["serde"] }
Expand Down
13 changes: 13 additions & 0 deletions crates/wac-graph/src/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ impl<'a> TypeEncoder<'a> {
let index = match ty {
DefinedType::Tuple(types) => self.tuple(state, types),
DefinedType::List(ty) => self.list(state, *ty),
DefinedType::FixedSizeList(ty, elements) => self.fixed_size_list(state, *ty, *elements),
DefinedType::Option(ty) => self.option(state, *ty),
DefinedType::Result { ok, err } => self.result(state, *ok, *err),
DefinedType::Variant(v) => self.variant(state, v),
Expand Down Expand Up @@ -552,6 +553,18 @@ impl<'a> TypeEncoder<'a> {
index
}

fn fixed_size_list(&self, state: &mut State, ty: ValueType, elements: u32) -> u32 {
let ty = self.value_type(state, ty);
let index = state.current.encodable.type_count();
state
.current
.encodable
.ty()
.defined_type()
.fixed_size_list(ty, elements);
index
}

fn stream(&self, state: &mut State, ty: Option<ValueType>) -> u32 {
let ty = ty.map(|ty| self.value_type(state, ty));
let index = state.current.encodable.type_count();
Expand Down
3 changes: 3 additions & 0 deletions crates/wac-types/src/aggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,9 @@ impl TypeAggregator {
.collect::<Result<_>>()?,
),
DefinedType::List(ty) => DefinedType::List(self.remap_value_type(types, *ty, checker)?),
DefinedType::FixedSizeList(ty, elements) => {
DefinedType::FixedSizeList(self.remap_value_type(types, *ty, checker)?, *elements)
}
DefinedType::Option(ty) => {
DefinedType::Option(self.remap_value_type(types, *ty, checker)?)
}
Expand Down
8 changes: 8 additions & 0 deletions crates/wac-types/src/checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,13 @@ impl<'a> SubtypeChecker<'a> {
(DefinedType::List(a), DefinedType::List(b)) => self
.value_type(*a, at, *b, bt)
.context("mismatched type for list element"),
(DefinedType::FixedSizeList(a, asize), DefinedType::FixedSizeList(b, bsize)) => {
if asize != bsize {
bail!("mismatched size for fixed size list element");
}
self.value_type(*a, at, *b, bt)
.context("mismatched type for fixed size list element")
}
(DefinedType::Future(a), DefinedType::Future(b)) => self
.payload(*a, at, *b, bt)
.context("mismatched type for future payload"),
Expand Down Expand Up @@ -583,6 +590,7 @@ impl<'a> SubtypeChecker<'a> {

(DefinedType::Tuple(_), _)
| (DefinedType::List(_), _)
| (DefinedType::FixedSizeList(_, _), _)
| (DefinedType::Option(_), _)
| (DefinedType::Result { .. }, _)
| (DefinedType::Variant(_), _)
Expand Down
7 changes: 5 additions & 2 deletions crates/wac-types/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,8 @@ pub enum DefinedType {
Tuple(Vec<ValueType>),
/// A list type.
List(ValueType),
/// A fixed size array
FixedSizeList(ValueType, u32),
/// An option type.
Option(ValueType),
/// A result type.
Expand Down Expand Up @@ -689,7 +691,7 @@ impl DefinedType {
pub fn contains_borrow(&self, types: &Types) -> bool {
match self {
Self::Tuple(tys) => tys.iter().any(|ty| ty.contains_borrow(types)),
Self::List(ty) => ty.contains_borrow(types),
Self::List(ty) | Self::FixedSizeList(ty, _) => ty.contains_borrow(types),
Self::Option(ty) => ty.contains_borrow(types),
Self::Result { ok, err } => {
ok.map(|ty| ty.contains_borrow(types)).unwrap_or(false)
Expand Down Expand Up @@ -721,7 +723,7 @@ impl DefinedType {

Ok(())
}
DefinedType::List(ty) | DefinedType::Option(ty) => {
DefinedType::List(ty) | DefinedType::Option(ty) | DefinedType::FixedSizeList(ty, _) => {
ty._visit_defined_types(types, visitor, false)
}
DefinedType::Result { ok, err } => {
Expand Down Expand Up @@ -765,6 +767,7 @@ impl DefinedType {
match self {
Self::Tuple(_) => "tuple",
Self::List(_) => "list",
Self::FixedSizeList(_, _) => "list<,N>",
Self::Option(_) => "option",
Self::Result { .. } => "result",
Self::Variant(_) => "variant",
Expand Down
4 changes: 4 additions & 0 deletions crates/wac-types/src/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,10 @@ impl<'a> TypeConverter<'a> {
let option = ty.map(|ty| self.component_val_type(ty)).transpose()?;
ValueType::Defined(self.types.add_defined_type(DefinedType::Future(option)))
}
wasm::ComponentDefinedType::FixedSizeList(ty, _) => {
let ty = self.component_val_type(*ty)?;
ValueType::Defined(self.types.add_defined_type(DefinedType::List(ty)))
}
};

self.cache.insert(key, Entity::Type(Type::Value(ty)));
Expand Down