Skip to content
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

Update to the latest wit-parser #5694

Merged
merged 1 commit into from
Feb 2, 2023
Merged
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
4 changes: 2 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ wasmprinter = "0.2.49"
wasm-encoder = "0.22.0"
wasm-smith = "0.12.0"
wasm-mutate = "0.2.16"
wit-parser = "0.4.1"
wit-parser = "0.5.0"
windows-sys = "0.42.0"
env_logger = "0.9"
rustix = "0.36.7"
Expand Down
14 changes: 14 additions & 0 deletions crates/component-macro/tests/codegen/worlds-with-types.wit
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
interface i {
type t = u16
}

default world foo {
use self.i.{t as u}

type t = u32

record r {
}

export f: func() -> tuple<t, u, r>
}
44 changes: 27 additions & 17 deletions crates/wit-bindgen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ impl Wasmtime {
);
Import::Interface { snake }
}
WorldItem::Type(_) => unreachable!(),
};

self.imports.push(import);
Expand All @@ -149,6 +150,12 @@ impl Wasmtime {
self.exports.funcs.push(body);
(format!("wasmtime::component::Func"), getter)
}
WorldItem::Type(ty) => {
gen.define_type(name, *ty);
let body = mem::take(&mut gen.src);
self.src.push_str(&body);
return;
}
WorldItem::Interface(id) => {
gen.current_interface = Some(*id);
gen.types(*id);
Expand Down Expand Up @@ -465,23 +472,26 @@ impl<'a> InterfaceGenerator<'a> {

fn types(&mut self, id: InterfaceId) {
for (name, id) in self.resolve.interfaces[id].types.iter() {
let id = *id;
let ty = &self.resolve.types[id];
match &ty.kind {
TypeDefKind::Record(record) => self.type_record(id, name, record, &ty.docs),
TypeDefKind::Flags(flags) => self.type_flags(id, name, flags, &ty.docs),
TypeDefKind::Tuple(tuple) => self.type_tuple(id, name, tuple, &ty.docs),
TypeDefKind::Enum(enum_) => self.type_enum(id, name, enum_, &ty.docs),
TypeDefKind::Variant(variant) => self.type_variant(id, name, variant, &ty.docs),
TypeDefKind::Option(t) => self.type_option(id, name, t, &ty.docs),
TypeDefKind::Result(r) => self.type_result(id, name, r, &ty.docs),
TypeDefKind::Union(u) => self.type_union(id, name, u, &ty.docs),
TypeDefKind::List(t) => self.type_list(id, name, t, &ty.docs),
TypeDefKind::Type(t) => self.type_alias(id, name, t, &ty.docs),
TypeDefKind::Future(_) => todo!("generate for future"),
TypeDefKind::Stream(_) => todo!("generate for stream"),
TypeDefKind::Unknown => unreachable!(),
}
self.define_type(name, *id);
}
}

fn define_type(&mut self, name: &str, id: TypeId) {
let ty = &self.resolve.types[id];
match &ty.kind {
TypeDefKind::Record(record) => self.type_record(id, name, record, &ty.docs),
TypeDefKind::Flags(flags) => self.type_flags(id, name, flags, &ty.docs),
TypeDefKind::Tuple(tuple) => self.type_tuple(id, name, tuple, &ty.docs),
TypeDefKind::Enum(enum_) => self.type_enum(id, name, enum_, &ty.docs),
TypeDefKind::Variant(variant) => self.type_variant(id, name, variant, &ty.docs),
TypeDefKind::Option(t) => self.type_option(id, name, t, &ty.docs),
TypeDefKind::Result(r) => self.type_result(id, name, r, &ty.docs),
TypeDefKind::Union(u) => self.type_union(id, name, u, &ty.docs),
TypeDefKind::List(t) => self.type_list(id, name, t, &ty.docs),
TypeDefKind::Type(t) => self.type_alias(id, name, t, &ty.docs),
TypeDefKind::Future(_) => todo!("generate for future"),
TypeDefKind::Stream(_) => todo!("generate for stream"),
TypeDefKind::Unknown => unreachable!(),
}
}

Expand Down
3 changes: 3 additions & 0 deletions crates/wit-bindgen/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ impl Types {
self.type_info_func(resolve, f, import);
}
}
WorldItem::Type(id) => {
self.type_id_info(resolve, *id);
}
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions supply-chain/audits.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1167,3 +1167,9 @@ criteria = "safe-to-deploy"
version = "0.4.1"
notes = "The Bytecode Alliance is the author of this crate."

[[audits.wit-parser]]
who = "Alex Crichton <[email protected]>"
criteria = "safe-to-deploy"
version = "0.5.0"
notes = "The Bytecode Alliance is the author of this crate."