Update to the latest wit-parser (#5694)

This notably pulls in support in WIT for types-in-worlds.
This commit is contained in:
Alex Crichton
2023-02-02 13:21:01 -06:00
committed by GitHub
parent 545749b279
commit a2a0a9ef5b
6 changed files with 53 additions and 20 deletions

4
Cargo.lock generated
View File

@@ -4062,9 +4062,9 @@ dependencies = [
[[package]]
name = "wit-parser"
version = "0.4.1"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2e60c4242d4cf4394fac7587c0d96c39b3c0fb09e638815c3f244f6bb5356f04"
checksum = "896b2d88f139eb303e8e76fd72925115b11aad1944887ec2e5b2eeac1e58526f"
dependencies = [
"anyhow",
"id-arena",

View File

@@ -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"

View File

@@ -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>
}

View File

@@ -132,6 +132,7 @@ impl Wasmtime {
);
Import::Interface { snake }
}
WorldItem::Type(_) => unreachable!(),
};
self.imports.push(import);
@@ -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);
@@ -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!(),
}
}

View File

@@ -55,6 +55,9 @@ impl Types {
self.type_info_func(resolve, f, import);
}
}
WorldItem::Type(id) => {
self.type_id_info(resolve, *id);
}
}
}
}

View File

@@ -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 <alex@alexcrichton.com>"
criteria = "safe-to-deploy"
version = "0.5.0"
notes = "The Bytecode Alliance is the author of this crate."