diff --git a/Cargo.lock b/Cargo.lock index 2fc6af5f..5b289a4a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -635,7 +635,7 @@ dependencies = [ "encode_unicode", "lazy_static 1.4.0", "libc", - "unicode-width", + "unicode-width 0.1.11", "windows-sys 0.52.0", ] @@ -1057,6 +1057,12 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "foldhash" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0d2fde1f7b3d48b8395d5f2de76c18a528bd6a9cdde438df747bfcba3e05d6f" + [[package]] name = "foreign-types" version = "0.3.2" @@ -1255,7 +1261,7 @@ dependencies = [ "futures-core", "futures-sink", "http", - "indexmap 2.2.6", + "indexmap 2.7.1", "slab", "tokio", "tokio-util", @@ -1270,9 +1276,13 @@ checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" [[package]] name = "hashbrown" -version = "0.14.3" +version = "0.15.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" +checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" +dependencies = [ + "foldhash", + "serde 1.0.197", +] [[package]] name = "heck" @@ -1539,12 +1549,12 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.2.6" +version = "2.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" +checksum = "8c9c992b02b5b4c94ea26e32fe5bccb7aa7d9f390ab5c1221ff895bc7ea8b652" dependencies = [ "equivalent", - "hashbrown 0.14.3", + "hashbrown 0.15.2", "serde 1.0.197", ] @@ -1558,7 +1568,7 @@ dependencies = [ "instant", "number_prefix", "portable-atomic", - "unicode-width", + "unicode-width 0.1.11", ] [[package]] @@ -1855,7 +1865,7 @@ dependencies = [ "terminal_size", "textwrap", "thiserror", - "unicode-width", + "unicode-width 0.1.11", ] [[package]] @@ -2298,7 +2308,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e1d3afd2628e69da2be385eb6f2fd57c8ac7977ceeff6dc166ff1657b0e386a9" dependencies = [ "fixedbitset", - "indexmap 2.2.6", + "indexmap 2.7.1", ] [[package]] @@ -3184,7 +3194,7 @@ dependencies = [ "chrono", "hex", "indexmap 1.9.3", - "indexmap 2.2.6", + "indexmap 2.7.1", "serde 1.0.197", "serde_derive", "serde_json", @@ -3210,7 +3220,7 @@ version = "0.9.34+deprecated" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47" dependencies = [ - "indexmap 2.2.6", + "indexmap 2.7.1", "itoa", "ryu", "serde 1.0.197", @@ -3530,7 +3540,7 @@ checksum = "23d434d3f8967a09480fb04132ebe0a3e088c173e6d0ee7897abbdf4eab0f8b9" dependencies = [ "smawk", "unicode-linebreak", - "unicode-width", + "unicode-width 0.1.11", ] [[package]] @@ -3731,7 +3741,7 @@ version = "0.19.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" dependencies = [ - "indexmap 2.2.6", + "indexmap 2.7.1", "toml_datetime", "winnow 0.5.40", ] @@ -3742,7 +3752,7 @@ version = "0.22.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e40bb779c5187258fd7aad0eb68cb8706a0a81fa712fbea808ab43c4b8374c4" dependencies = [ - "indexmap 2.2.6", + "indexmap 2.7.1", "serde 1.0.197", "serde_spanned", "toml_datetime", @@ -3925,6 +3935,12 @@ version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" +[[package]] +name = "unicode-width" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fc81956842c57dac11422a97c3b8195a1ff727f06e85c84ed2e8aa277c9a0fd" + [[package]] name = "unicode-xid" version = "0.2.4" @@ -3984,7 +4000,7 @@ version = "0.7.0-dev" dependencies = [ "anyhow", "clap", - "indexmap 2.2.6", + "indexmap 2.7.1", "indicatif", "log", "miette", @@ -4001,7 +4017,7 @@ dependencies = [ "wac-types", "warg-client", "warg-protocol", - "wasmprinter 0.202.0", + "wasmprinter 0.224.0", "wat", "wit-component", "wit-parser", @@ -4013,7 +4029,7 @@ version = "0.7.0-dev" dependencies = [ "anyhow", "id-arena", - "indexmap 2.2.6", + "indexmap 2.7.1", "log", "petgraph", "pretty_assertions", @@ -4022,10 +4038,10 @@ dependencies = [ "serde_json", "thiserror", "wac-types", - "wasm-encoder 0.202.0", + "wasm-encoder 0.224.0", "wasm-metadata", - "wasmparser 0.202.0", - "wasmprinter 0.202.0", + "wasmparser 0.224.0", + "wasmprinter 0.224.0", "wat", "wit-component", "wit-parser", @@ -4037,7 +4053,7 @@ version = "0.7.0-dev" dependencies = [ "anyhow", "id-arena", - "indexmap 2.2.6", + "indexmap 2.7.1", "log", "logos 0.14.0", "miette", @@ -4052,10 +4068,10 @@ dependencies = [ "tokio", "wac-graph", "wac-resolver", - "wasm-encoder 0.202.0", + "wasm-encoder 0.224.0", "wasm-metadata", - "wasmparser 0.202.0", - "wasmprinter 0.202.0", + "wasmparser 0.224.0", + "wasmprinter 0.224.0", ] [[package]] @@ -4064,12 +4080,13 @@ version = "0.7.0-dev" dependencies = [ "anyhow", "futures", - "indexmap 2.2.6", + "indexmap 2.7.1", "log", "miette", "pretty_assertions", "semver", "tempdir", + "tempfile", "thiserror", "tokio", "tokio-util", @@ -4080,7 +4097,7 @@ dependencies = [ "warg-crypto", "warg-protocol", "warg-server", - "wasmprinter 0.202.0", + "wasmprinter 0.224.0", "wat", "wit-component", "wit-parser", @@ -4092,11 +4109,11 @@ version = "0.7.0-dev" dependencies = [ "anyhow", "id-arena", - "indexmap 2.2.6", + "indexmap 2.7.1", "semver", "serde 1.0.197", - "wasm-encoder 0.202.0", - "wasmparser 0.202.0", + "wasm-encoder 0.224.0", + "wasmparser 0.224.0", ] [[package]] @@ -4130,7 +4147,7 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a44b422328c3a86be288f569694aa97df958ade0cd9514ed00bc562952c6778e" dependencies = [ - "indexmap 2.2.6", + "indexmap 2.7.1", "itertools 0.12.1", "serde 1.0.197", "serde_with", @@ -4153,7 +4170,7 @@ dependencies = [ "dialoguer", "dirs", "futures-util", - "indexmap 2.2.6", + "indexmap 2.7.1", "itertools 0.12.1", "keyring", "libc", @@ -4234,7 +4251,7 @@ dependencies = [ "anyhow", "base64 0.21.7", "hex", - "indexmap 2.2.6", + "indexmap 2.7.1", "pbjson-types", "prost", "prost-types", @@ -4259,7 +4276,7 @@ dependencies = [ "bytes", "clap", "futures", - "indexmap 2.2.6", + "indexmap 2.7.1", "secrecy", "serde 1.0.197", "tempfile", @@ -4286,7 +4303,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b950a71a544b7ac8f5a5e95f43886ac97c3fe5c7080b955b1b534037596d7be" dependencies = [ "anyhow", - "indexmap 2.2.6", + "indexmap 2.7.1", "prost", "thiserror", "warg-crypto", @@ -4374,7 +4391,7 @@ dependencies = [ "anyhow", "heck 0.4.1", "im-rc", - "indexmap 2.2.6", + "indexmap 2.7.1", "log", "petgraph", "serde 1.0.197", @@ -4398,27 +4415,29 @@ dependencies = [ [[package]] name = "wasm-encoder" -version = "0.202.0" +version = "0.224.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfd106365a7f5f7aa3c1916a98cbb3ad477f5ff96ddb130285a91c6e7429e67a" +checksum = "b7249cf8cb0c6b9cb42bce90c0a5feb276fbf963fa385ff3d818ab3d90818ed6" dependencies = [ "leb128", + "wasmparser 0.224.0", ] [[package]] name = "wasm-metadata" -version = "0.202.0" +version = "0.224.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "094aea3cb90e09f16ee25a4c0e324b3e8c934e7fd838bfa039aef5352f44a917" +checksum = "79d13d93febc749413cb6f327e4fdba8c84e4d03bd69fcc4a220c66f113c8de1" dependencies = [ "anyhow", - "indexmap 2.2.6", + "indexmap 2.7.1", "serde 1.0.197", "serde_derive", "serde_json", "spdx", - "wasm-encoder 0.202.0", - "wasmparser 0.202.0", + "url", + "wasm-encoder 0.224.0", + "wasmparser 0.224.0", ] [[package]] @@ -4441,19 +4460,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9dbe55c8f9d0dbd25d9447a5a889ff90c0cc3feaa7395310d3d826b2c703eaab" dependencies = [ "bitflags 2.5.0", - "indexmap 2.2.6", + "indexmap 2.7.1", "semver", ] [[package]] name = "wasmparser" -version = "0.202.0" +version = "0.224.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6998515d3cf3f8b980ef7c11b29a9b1017d4cf86b99ae93b546992df9931413" +checksum = "65881a664fdd43646b647bb27bf186ab09c05bf56779d40aed4c6dce47d423f5" dependencies = [ "bitflags 2.5.0", - "indexmap 2.2.6", + "hashbrown 0.15.2", + "indexmap 2.7.1", "semver", + "serde 1.0.197", ] [[package]] @@ -4468,32 +4489,33 @@ dependencies = [ [[package]] name = "wasmprinter" -version = "0.202.0" +version = "0.224.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab1cc9508685eef9502e787f4d4123745f5651a1e29aec047645d3cac1e2da7a" +checksum = "bc039e211f6c2137425726f0d76fdd9c439a442e5272bc3627a19274d0eb9686" dependencies = [ "anyhow", - "wasmparser 0.202.0", + "termcolor", + "wasmparser 0.224.0", ] [[package]] name = "wast" -version = "202.0.0" +version = "224.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fbcb11204515c953c9b42ede0a46a1c5e17f82af05c4fae201a8efff1b0f4fe" +checksum = "d722a51e62b669d17e5a9f6bc8ec210178b37d869114355aa46989686c5c6391" dependencies = [ "bumpalo", "leb128", "memchr", - "unicode-width", - "wasm-encoder 0.202.0", + "unicode-width 0.2.0", + "wasm-encoder 0.224.0", ] [[package]] name = "wat" -version = "1.202.0" +version = "1.224.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4de4b15a47135c56a3573406e9977b9518787a6154459b4842a9b9d3d1684848" +checksum = "71dece6a7dd5bcbcf8d256606c7fb3faa36286d46bf3f98185407719a5ceede2" dependencies = [ "wast", ] @@ -4758,40 +4780,40 @@ dependencies = [ [[package]] name = "wit-component" -version = "0.202.0" +version = "0.224.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c836b1fd9932de0431c1758d8be08212071b6bba0151f7bac826dbc4312a2a9" +checksum = "ad555ab4f4e676474df746d937823c7279c2d6dd36c3e97a61db893d4ef64ee5" dependencies = [ "anyhow", "bitflags 2.5.0", - "indexmap 2.2.6", + "indexmap 2.7.1", "log", "serde 1.0.197", "serde_derive", "serde_json", - "wasm-encoder 0.202.0", + "wasm-encoder 0.224.0", "wasm-metadata", - "wasmparser 0.202.0", + "wasmparser 0.224.0", "wat", "wit-parser", ] [[package]] name = "wit-parser" -version = "0.202.0" +version = "0.224.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "744237b488352f4f27bca05a10acb79474415951c450e52ebd0da784c1df2bcc" +checksum = "23e2925a7365d2c6709ae17bdbb5777ffd8154fd70906b413fc01b75f0dba59e" dependencies = [ "anyhow", "id-arena", - "indexmap 2.2.6", + "indexmap 2.7.1", "log", "semver", "serde 1.0.197", "serde_derive", "serde_json", "unicode-xid", - "wasmparser 0.202.0", + "wasmparser 0.224.0", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 05979752..b7fd0ba0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,7 +47,12 @@ wit-component = { workspace = true } default = ["wit", "registry"] wat = ["wac-resolver/wat"] wit = ["wac-resolver/wit"] -registry = ["wac-resolver/registry", "dep:indicatif", "dep:warg-client", "dep:warg-protocol"] +registry = [ + "wac-resolver/registry", + "dep:indicatif", + "dep:warg-client", + "dep:warg-protocol", +] native-tls-vendored = ["warg-client?/native-tls-vendored"] [workspace] @@ -58,12 +63,12 @@ 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.202.0" -wasmparser = "0.202.0" -wit-component = "0.202.0" -wasm-encoder = "0.202.0" -wasmprinter = "0.202.0" -wasm-metadata = "0.202.0" +wit-parser = "0.224.0" +wasmparser = "0.224.0" +wit-component = "0.224.0" +wasm-encoder = "0.224.0" +wasmprinter = "0.224.0" +wasm-metadata = "0.224.0" anyhow = "1.0.81" clap = { version = "4.5.4", features = ["derive"] } semver = { version = "1.0.22", features = ["serde"] } @@ -78,7 +83,7 @@ indexmap = { version = "2.2.6", features = ["serde"] } id-arena = "2.2.1" serde = { version = "1.0.197", features = ["derive"] } serde_json = "1.0.115" -wat = "1.202.0" +wat = "1.224.0" logos = "0.14.0" miette = "7.2.0" thiserror = "1.0.58" diff --git a/crates/wac-graph/src/encoding.rs b/crates/wac-graph/src/encoding.rs index 16b82e39..5fc293d3 100644 --- a/crates/wac-graph/src/encoding.rs +++ b/crates/wac-graph/src/encoding.rs @@ -8,9 +8,10 @@ use wac_types::{ Variant, WorldId, }; use wasm_encoder::{ - Alias, ComponentBuilder, ComponentExportKind, ComponentOuterAliasKind, ComponentType, - ComponentTypeEncoder, ComponentTypeRef, ComponentValType, CoreTypeEncoder, EntityType, - GlobalType, InstanceType, MemoryType, ModuleType, TableType, TagKind, TagType, TypeBounds, + Alias, ComponentBuilder, ComponentCoreTypeEncoder, ComponentExportKind, + ComponentOuterAliasKind, ComponentType, ComponentTypeEncoder, ComponentTypeRef, + ComponentValType, EntityType, GlobalType, InstanceType, MemoryType, ModuleType, TableType, + TagKind, TagType, TypeBounds, }; /// A type used to abstract the API differences between a component builder, @@ -55,7 +56,7 @@ impl Encodable { } } - fn core_type(&mut self) -> CoreTypeEncoder { + fn core_type(&mut self) -> ComponentCoreTypeEncoder { match self { Encodable::Builder(t) => t.core_type().1, Encodable::Instance(t) => t.core_type(), @@ -268,6 +269,9 @@ impl<'a> TypeEncoder<'a> { DefinedType::Alias(ValueType::Borrow(id)) => self.borrow(state, *id), DefinedType::Alias(ValueType::Own(id)) => self.own(state, *id), DefinedType::Alias(ValueType::Defined(id)) => self.defined(state, *id), + DefinedType::Stream(ty) => self.stream(state, *ty), + DefinedType::Future(ty) => self.future(state, *ty), + DefinedType::ErrorContext => self.error_context(state), }; log::debug!("defined type encoded to type index {index}"); @@ -476,25 +480,36 @@ impl<'a> TypeEncoder<'a> { element_type, initial, maximum, + table64, + shared, } => EntityType::Table(TableType { element_type: (*element_type).into(), minimum: *initial, maximum: *maximum, + table64: *table64, + shared: *shared, }), CoreExtern::Memory { memory64, shared, initial, maximum, + page_size_log2, } => EntityType::Memory(MemoryType { minimum: *initial, maximum: *maximum, memory64: *memory64, shared: *shared, + page_size_log2: *page_size_log2, }), - CoreExtern::Global { val_type, mutable } => EntityType::Global(GlobalType { + CoreExtern::Global { + val_type, + mutable, + shared, + } => EntityType::Global(GlobalType { val_type: (*val_type).into(), mutable: *mutable, + shared: *shared, }), CoreExtern::Tag(func) => { let index = encodable.type_count(); @@ -554,6 +569,26 @@ impl<'a> TypeEncoder<'a> { index } + fn stream(&self, state: &mut State, ty: Option) -> u32 { + let ty = ty.map(|ty| self.value_type(state, ty)); + let index = state.current.encodable.type_count(); + state.current.encodable.ty().defined_type().stream(ty); + index + } + + fn future(&self, state: &mut State, ty: Option) -> u32 { + let ty = ty.map(|ty| self.value_type(state, ty)); + let index = state.current.encodable.type_count(); + state.current.encodable.ty().defined_type().future(ty); + index + } + + fn error_context(&self, state: &mut State) -> u32 { + let index = state.current.encodable.type_count(); + state.current.encodable.ty().defined_type().error_context(); + index + } + fn option(&self, state: &mut State, ty: ValueType) -> u32 { let ty = self.value_type(state, ty); let index = state.current.encodable.type_count(); diff --git a/crates/wac-graph/tests/encoding.rs b/crates/wac-graph/tests/encoding.rs index f430e36e..509e6300 100644 --- a/crates/wac-graph/tests/encoding.rs +++ b/crates/wac-graph/tests/encoding.rs @@ -133,7 +133,11 @@ impl GraphFile { ) })?; - let mut module = wit_component::dummy_module(&resolve, world); + let mut module = wit_component::dummy_module( + &resolve, + world, + wit_parser::ManglingAndAbi::Legacy(wit_parser::LiftLowerAbi::Sync), + ); wit_component::embed_component_metadata( &mut module, &resolve, @@ -147,7 +151,7 @@ impl GraphFile { ) })?; - let encoder = ComponentEncoder::default().validate(true).module(&module)?; + let mut encoder = ComponentEncoder::default().validate(true).module(&module)?; encoder .encode() .with_context(|| format!("failed to encode a component from module derived from package `{path}` for test case `{test_case}`", path = path.display())) diff --git a/crates/wac-parser/src/ast/expr.rs b/crates/wac-parser/src/ast/expr.rs index af1f0e08..6b08cc67 100644 --- a/crates/wac-parser/src/ast/expr.rs +++ b/crates/wac-parser/src/ast/expr.rs @@ -237,7 +237,7 @@ impl Peek for InstantiationArgumentName<'_> { } } -impl<'a> InstantiationArgumentName<'a> { +impl InstantiationArgumentName<'_> { /// Gets the span of the instantiation argument name. pub fn span(&self) -> SourceSpan { match self { @@ -288,7 +288,7 @@ pub enum PostfixExpr<'a> { NamedAccess(NamedAccessExpr<'a>), } -impl<'a> PostfixExpr<'a> { +impl PostfixExpr<'_> { /// Gets the span of the postfix expression. pub fn span(&self) -> SourceSpan { match self { diff --git a/crates/wac-parser/src/ast/type.rs b/crates/wac-parser/src/ast/type.rs index 8708b4a3..12af55d1 100644 --- a/crates/wac-parser/src/ast/type.rs +++ b/crates/wac-parser/src/ast/type.rs @@ -672,7 +672,7 @@ pub enum Type<'a> { Ident(Ident<'a>), } -impl<'a> Type<'a> { +impl Type<'_> { /// Gets the span of the type. pub fn span(&self) -> SourceSpan { match self { diff --git a/crates/wac-parser/src/lexer.rs b/crates/wac-parser/src/lexer.rs index b0a4e796..59502f45 100644 --- a/crates/wac-parser/src/lexer.rs +++ b/crates/wac-parser/src/lexer.rs @@ -516,7 +516,7 @@ impl<'a> Lexer<'a> { } } -impl<'a> Iterator for Lexer<'a> { +impl Iterator for Lexer<'_> { type Item = (LexerResult, SourceSpan); fn next(&mut self) -> Option { diff --git a/crates/wac-parser/src/resolution.rs b/crates/wac-parser/src/resolution.rs index a88612ca..8756aac9 100644 --- a/crates/wac-parser/src/resolution.rs +++ b/crates/wac-parser/src/resolution.rs @@ -664,7 +664,7 @@ pub struct Resolution<'a> { instantiation_spans: HashMap, } -impl<'a> Resolution<'a> { +impl Resolution<'_> { /// Gets the document that was resolved. pub fn document(&self) -> &Document { self.document diff --git a/crates/wac-resolver/Cargo.toml b/crates/wac-resolver/Cargo.toml index 8aa8a381..6200d6e0 100644 --- a/crates/wac-resolver/Cargo.toml +++ b/crates/wac-resolver/Cargo.toml @@ -34,9 +34,16 @@ warg-server = { workspace = true } pretty_assertions = { workspace = true } tokio-util = "0.7.10" tempdir = "0.3.7" +tempfile = "3.2.0" [features] default = ["registry"] wat = ["dep:wat"] wit = ["dep:wit-parser"] -registry = ["dep:warg-client", "dep:warg-protocol", "dep:warg-crypto", "dep:tokio", "dep:futures"] +registry = [ + "dep:warg-client", + "dep:warg-protocol", + "dep:warg-crypto", + "dep:tokio", + "dep:futures", +] diff --git a/crates/wac-resolver/src/fs.rs b/crates/wac-resolver/src/fs.rs index 6e5c1dcc..ecf78bf3 100644 --- a/crates/wac-resolver/src/fs.rs +++ b/crates/wac-resolver/src/fs.rs @@ -95,9 +95,7 @@ impl FileSystemPackageResolver { let (pkg, _) = resolve.push_dir(&path).map_err(pkg_res_failure)?; Some(pkg) } else if path.extension().and_then(std::ffi::OsStr::to_str) == Some("wit") { - let unresolved = wit_parser::UnresolvedPackage::parse_file(&path) - .map_err(pkg_res_failure)?; - let pkg = resolve.push(unresolved).map_err(pkg_res_failure)?; + let pkg = resolve.push_file(&path).map_err(pkg_res_failure)?; Some(pkg) } else { None @@ -105,7 +103,7 @@ impl FileSystemPackageResolver { if let Some(pkg) = pkg { packages.insert( *key, - wit_component::encode(Some(true), &resolve, pkg) + wit_component::encode(&resolve, pkg) .with_context(|| { format!( "failed to encode WIT package from `{path}`", diff --git a/crates/wac-resolver/tests/support/mod.rs b/crates/wac-resolver/tests/support/mod.rs index 2281be17..d2ddb23a 100644 --- a/crates/wac-resolver/tests/support/mod.rs +++ b/crates/wac-resolver/tests/support/mod.rs @@ -9,7 +9,7 @@ use warg_client::{ use warg_crypto::signing::PrivateKey; use warg_protocol::{operator::NamespaceState, registry::PackageName}; use warg_server::{policy::content::WasmContentPolicy, Config, Server}; -use wit_parser::{Resolve, UnresolvedPackage}; +use wit_parser::Resolve; pub fn test_operator_key() -> &'static str { "ecdsa-p256:I+UlDo0HxyBBFeelhPPWmD+LnklOpqZDkrFP5VduASk=" @@ -43,16 +43,17 @@ pub async fn publish_wit( wit: &str, init: bool, ) -> Result<()> { + use std::io::Write; let mut resolve = Resolve::new(); + let mut tmp = tempfile::NamedTempFile::new()?; + tmp.write(wit.as_bytes())?; + let path = tmp.path(); let pkg = resolve - .push( - UnresolvedPackage::parse(Path::new("foo.wit"), wit) - .context("failed to parse wit for publishing")?, - ) + .push_file(path) .context("failed to resolve wit for publishing")?; - let bytes = wit_component::encode(Some(true), &resolve, pkg) - .context("failed to encode wit for publishing")?; + let bytes = + wit_component::encode(&resolve, pkg).context("failed to encode wit for publishing")?; publish(config, &name.parse()?, version, bytes, init).await } diff --git a/crates/wac-types/src/aggregator.rs b/crates/wac-types/src/aggregator.rs index 8ba1de12..12d2b504 100644 --- a/crates/wac-types/src/aggregator.rs +++ b/crates/wac-types/src/aggregator.rs @@ -842,6 +842,9 @@ impl TypeAggregator { DefinedType::Alias(ty) => { DefinedType::Alias(self.remap_value_type(types, *ty, checker)?) } + DefinedType::Stream(s) => DefinedType::Stream(*s), + DefinedType::Future(f) => DefinedType::Future(*f), + DefinedType::ErrorContext => DefinedType::ErrorContext, }; let remapped = self.types.add_defined_type(defined); diff --git a/crates/wac-types/src/checker.rs b/crates/wac-types/src/checker.rs index 5d87bf6e..0eca18c7 100644 --- a/crates/wac-types/src/checker.rs +++ b/crates/wac-types/src/checker.rs @@ -422,11 +422,15 @@ impl<'a> SubtypeChecker<'a> { element_type: ae, initial: ai, maximum: am, + table64: _a64, + shared: _ashared, }, CoreExtern::Table { element_type: be, initial: bi, maximum: bm, + table64: _b64, + shared: _bshared, }, ) => { if ae != be { @@ -446,12 +450,14 @@ impl<'a> SubtypeChecker<'a> { shared: ashared, initial: ai, maximum: am, + page_size_log2: _apsl, }, CoreExtern::Memory { memory64: b64, shared: bshared, initial: bi, maximum: bm, + page_size_log2: _bpsl, }, ) => { if ashared != bshared { @@ -472,10 +478,12 @@ impl<'a> SubtypeChecker<'a> { CoreExtern::Global { val_type: avt, mutable: am, + shared: _ashared, }, CoreExtern::Global { val_type: bvt, mutable: bm, + shared: _bshared, }, ) => { if am != bm { diff --git a/crates/wac-types/src/component.rs b/crates/wac-types/src/component.rs index 54d7239c..56e537c2 100644 --- a/crates/wac-types/src/component.rs +++ b/crates/wac-types/src/component.rs @@ -640,7 +640,7 @@ impl serde::Serialize for ValueType { Self::Primitive(ty) => ty.serialize(serializer), Self::Borrow(id) => format!("borrow<{id}>", id = id.0.index()).serialize(serializer), Self::Own(id) => format!("own<{id}>", id = id.0.index()).serialize(serializer), - Self::Defined { id, .. } => id.serialize(serializer), + Self::Defined(id) => id.serialize(serializer), } } } @@ -673,6 +673,12 @@ pub enum DefinedType { Enum(Enum), /// The type is an alias to another value type. Alias(ValueType), + /// A stream type. + Stream(Option), + /// A futures type. + Future(Option), + /// A type for adding context to errors + ErrorContext, } impl DefinedType { @@ -694,6 +700,9 @@ impl DefinedType { Self::Flags(_) => false, Self::Enum(_) => false, Self::Alias(ty) => ty.contains_borrow(types), + Self::Stream(ty) => ty.map(|ty| ty.contains_borrow(types)).unwrap_or(false), + Self::Future(ty) => ty.map(|ty| ty.contains_borrow(types)).unwrap_or(false), + Self::ErrorContext => false, } } @@ -738,11 +747,21 @@ impl DefinedType { Ok(()) } - DefinedType::Flags(_) | DefinedType::Enum(_) | DefinedType::Alias(_) => Ok(()), + DefinedType::Flags(_) + | DefinedType::Enum(_) + | DefinedType::Alias(_) + | DefinedType::ErrorContext => Ok(()), + DefinedType::Stream(ty) | DefinedType::Future(ty) => { + if let Some(ty) = ty { + ty._visit_defined_types(types, visitor, false)?; + } + + Ok(()) + } } } - /// Gets a description of the defined type. + /// Gets atyd | DefinedType::Future(t)escription of the defined type. pub fn desc(&self, types: &Types) -> &'static str { match self { Self::Tuple(_) => "tuple", @@ -754,6 +773,9 @@ impl DefinedType { Self::Flags(_) => "flags", Self::Enum(_) => "enum", Self::Alias(ty) => ty.desc(types), + Self::Stream(_) => "stream", + Self::Future(_) => "future", + Self::ErrorContext => "error context", } } } @@ -988,7 +1010,7 @@ impl World { pub fn implicit_imported_interfaces<'a>( &'a self, types: &'a Types, - ) -> IndexMap<&str, ItemKind> { + ) -> IndexMap<&'a str, ItemKind> { let mut interfaces = IndexMap::new(); let mut add_interface_for_used_type = |used_item: &UsedType| { let used_interface_id = used_item.interface; diff --git a/crates/wac-types/src/core.rs b/crates/wac-types/src/core.rs index c7142186..c5a19143 100644 --- a/crates/wac-types/src/core.rs +++ b/crates/wac-types/src/core.rs @@ -27,9 +27,20 @@ pub enum CoreExtern { /// The table's element type. element_type: CoreRefType, /// Initial size of this table, in elements. - initial: u32, + initial: u64, /// Optional maximum size of the table, in elements. - maximum: Option, + maximum: Option, + /// Whether or not this is a 64-bit table, using i64 as an index. If this + /// is false it's a 32-bit memory using i32 as an index. + /// + /// This is part of the memory64 proposal in WebAssembly. + table64: bool, + /// Whether or not this is a "shared" memory, indicating that it should be + /// send-able across threads and the `maximum` field is always present for + /// valid types. + /// + /// This is part of the threads proposal in WebAssembly. + shared: bool, }, /// The item is a memory. #[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))] @@ -59,6 +70,16 @@ pub enum CoreExtern { /// be at most `u32::MAX` for valid types. This field is always present for /// valid wasm memories when `shared` is `true`. maximum: Option, + + /// The log base 2 of the memory's custom page size. + /// + /// Memory pages are, by default, 64KiB large (i.e. 216 or + /// `65536`). + /// + /// [The custom-page-sizes proposal] allows changing it to other values. + /// + /// [The custom-page-sizes proposal]: https://github.com/WebAssembly/custom-page-sizes + page_size_log2: Option, }, /// The item is a global. #[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))] @@ -67,6 +88,12 @@ pub enum CoreExtern { val_type: CoreType, /// Whether or not the global is mutable. mutable: bool, + /// Whether or not this is a "shared" memory, indicating that it should be + /// send-able across threads and the `maximum` field is always present for + /// valid types. + /// + /// This is part of the threads proposal in WebAssembly. + shared: bool, }, /// The item is a tag. Tag(CoreFuncType), @@ -90,6 +117,8 @@ impl From for CoreExtern { element_type: ty.element_type.into(), initial: ty.initial, maximum: ty.maximum, + table64: ty.table64, + shared: ty.shared, } } } @@ -101,6 +130,7 @@ impl From for CoreExtern { shared: ty.shared, initial: ty.initial, maximum: ty.maximum, + page_size_log2: ty.page_size_log2, } } } @@ -110,6 +140,7 @@ impl From for CoreExtern { Self::Global { val_type: ty.content_type.into(), mutable: ty.mutable, + shared: ty.shared, } } } @@ -198,6 +229,9 @@ impl fmt::Display for CoreRefType { (true, HeapType::Array) => "arrayref", (true, HeapType::I31) => "i31ref", (true, HeapType::Exn) => "exnref", + (true, HeapType::NoExn) => "nullexnref", + (true, HeapType::Cont) => "contref", + (true, HeapType::NoCont) => "nullcontref", (false, HeapType::Func) => "(ref func)", (false, HeapType::Extern) => "(ref extern)", (false, HeapType::Concrete(i)) => return write!(f, "(ref {i})"), @@ -210,6 +244,9 @@ impl fmt::Display for CoreRefType { (false, HeapType::Array) => "(ref array)", (false, HeapType::I31) => "(ref i31)", (false, HeapType::Exn) => "(ref exn)", + (false, HeapType::NoExn) => "(ref noexn)", + (false, HeapType::Cont) => "(ref cont)", + (false, HeapType::NoCont) => "(ref nocont)", }; f.write_str(s) @@ -265,22 +302,42 @@ pub enum HeapType { /// /// Introduced in the exception-handling proposal. Exn, + /// The common subtype (a.k.a. bottom) of all exception types. + /// + /// Introduced in the exception-handling proposal. + NoExn, + /// The abstract `continuation` heap type. + /// + /// Introduced in the stack-switching proposal. + Cont, + /// The common subtype (a.k.a. bottom) of all continuation types. + /// + /// Introduced in the stack-switching proposal. + NoCont, } impl From for HeapType { fn from(ty: wasmparser::HeapType) -> Self { match ty { - wasmparser::HeapType::Any => Self::Any, - wasmparser::HeapType::Func => Self::Func, - wasmparser::HeapType::Extern => Self::Extern, - wasmparser::HeapType::Eq => Self::Eq, - wasmparser::HeapType::I31 => Self::I31, - wasmparser::HeapType::None => Self::None, - wasmparser::HeapType::NoExtern => Self::NoExtern, - wasmparser::HeapType::NoFunc => Self::NoFunc, - wasmparser::HeapType::Struct => Self::Struct, - wasmparser::HeapType::Array => Self::Array, - wasmparser::HeapType::Exn => Self::Exn, + wasmparser::HeapType::Abstract { shared: false, ty } => match ty { + wasmparser::AbstractHeapType::Any => Self::Any, + wasmparser::AbstractHeapType::Func => Self::Func, + wasmparser::AbstractHeapType::Extern => Self::Extern, + wasmparser::AbstractHeapType::Eq => Self::Eq, + wasmparser::AbstractHeapType::I31 => Self::I31, + wasmparser::AbstractHeapType::None => Self::None, + wasmparser::AbstractHeapType::NoExtern => Self::NoExtern, + wasmparser::AbstractHeapType::NoFunc => Self::NoFunc, + wasmparser::AbstractHeapType::Struct => Self::Struct, + wasmparser::AbstractHeapType::Array => Self::Array, + wasmparser::AbstractHeapType::Exn => Self::Exn, + wasmparser::AbstractHeapType::NoExn => Self::NoExn, + wasmparser::AbstractHeapType::Cont => Self::Cont, + wasmparser::AbstractHeapType::NoCont => Self::NoCont, + }, + wasmparser::HeapType::Abstract { shared: true, ty } => { + panic!("shared heap types are not supported: {:?}", ty) + } wasmparser::HeapType::Concrete(index) => { Self::Concrete(index.as_module_index().unwrap()) } @@ -289,20 +346,68 @@ impl From for HeapType { } impl From for wasm_encoder::HeapType { + /// Converts a `HeapType` into a `wasm_encoder::HeapType`. + /// Shared types are not supported, so defaults to `false` + /// for Abstract types. fn from(value: HeapType) -> Self { match value { HeapType::Concrete(index) => Self::Concrete(index), - HeapType::Func => Self::Func, - HeapType::Extern => Self::Extern, - HeapType::Any => Self::Any, - HeapType::None => Self::None, - HeapType::NoExtern => Self::NoExtern, - HeapType::NoFunc => Self::NoFunc, - HeapType::Eq => Self::Eq, - HeapType::Struct => Self::Struct, - HeapType::Array => Self::Array, - HeapType::I31 => Self::I31, - HeapType::Exn => Self::Exn, + HeapType::Func => Self::Abstract { + shared: false, + ty: wasm_encoder::AbstractHeapType::Func, + }, + HeapType::Extern => Self::Abstract { + shared: false, + ty: wasm_encoder::AbstractHeapType::Extern, + }, + HeapType::Any => Self::Abstract { + shared: false, + ty: wasm_encoder::AbstractHeapType::Any, + }, + HeapType::None => Self::Abstract { + shared: false, + ty: wasm_encoder::AbstractHeapType::None, + }, + HeapType::NoExtern => Self::Abstract { + shared: false, + ty: wasm_encoder::AbstractHeapType::NoExtern, + }, + HeapType::NoFunc => Self::Abstract { + shared: false, + ty: wasm_encoder::AbstractHeapType::NoFunc, + }, + HeapType::Eq => Self::Abstract { + shared: false, + ty: wasm_encoder::AbstractHeapType::Eq, + }, + HeapType::Struct => Self::Abstract { + shared: false, + ty: wasm_encoder::AbstractHeapType::Struct, + }, + HeapType::Array => Self::Abstract { + shared: false, + ty: wasm_encoder::AbstractHeapType::Array, + }, + HeapType::I31 => Self::Abstract { + shared: false, + ty: wasm_encoder::AbstractHeapType::I31, + }, + HeapType::Exn => Self::Abstract { + shared: false, + ty: wasm_encoder::AbstractHeapType::Exn, + }, + HeapType::NoExn => Self::Abstract { + shared: false, + ty: wasm_encoder::AbstractHeapType::NoExn, + }, + HeapType::Cont => Self::Abstract { + shared: false, + ty: wasm_encoder::AbstractHeapType::Cont, + }, + HeapType::NoCont => Self::Abstract { + shared: false, + ty: wasm_encoder::AbstractHeapType::NoCont, + }, } } } diff --git a/crates/wac-types/src/package.rs b/crates/wac-types/src/package.rs index d83b440b..b5d8461e 100644 --- a/crates/wac-types/src/package.rs +++ b/crates/wac-types/src/package.rs @@ -10,8 +10,8 @@ use std::borrow::Borrow; use std::fmt; use std::{collections::HashMap, path::Path, rc::Rc}; use wasmparser::{ + component_types::{self as wasm}, names::{ComponentName, ComponentNameKind}, - types::{self as wasm, ComponentAnyTypeId}, Chunk, Encoding, Parser, Payload, ValidPayload, Validator, WasmFeatures, }; @@ -133,7 +133,7 @@ impl PartialEq for (dyn BorrowedKey + '_) { } } -impl<'a> std::hash::Hash for (dyn BorrowedKey + 'a) { +impl std::hash::Hash for (dyn BorrowedKey + '_) { fn hash(&self, state: &mut H) { self.borrowed_key().hash(state) } @@ -388,14 +388,14 @@ enum Entity { /// representations. struct TypeConverter<'a> { types: &'a mut Types, - wasm_types: Rc, + wasm_types: Rc, cache: HashMap, resource_map: HashMap, owners: HashMap, } impl<'a> TypeConverter<'a> { - fn new(types: &'a mut Types, wasm_types: wasm::Types) -> Self { + fn new(types: &'a mut Types, wasm_types: wasmparser::types::Types) -> Self { Self { types, wasm_types: Rc::new(wasm_types), @@ -594,8 +594,8 @@ impl<'a> TypeConverter<'a> { &mut self, owner: Owner, name: &str, - referenced: ComponentAnyTypeId, - created: ComponentAnyTypeId, + referenced: wasm::ComponentAnyTypeId, + created: wasm::ComponentAnyTypeId, ) { if let Some((other, orig)) = self.find_owner(referenced) { match *other { @@ -762,6 +762,17 @@ impl<'a> TypeConverter<'a> { _ => panic!("expected a resource"), }, ), + wasm::ComponentDefinedType::Stream(ty) => { + let stream = ty.map(|ty| self.component_val_type(ty)).transpose()?; + ValueType::Defined(self.types.add_defined_type(DefinedType::Stream(stream))) + } + wasm::ComponentDefinedType::Future(ty) => { + let option = ty.map(|ty| self.component_val_type(ty)).transpose()?; + ValueType::Defined(self.types.add_defined_type(DefinedType::Future(option))) + } + wasm::ComponentDefinedType::ErrorContext => { + ValueType::Defined(self.types.add_defined_type(DefinedType::ErrorContext)) + } }; self.cache.insert(key, Entity::Type(Type::Value(ty))); @@ -782,7 +793,7 @@ impl<'a> TypeConverter<'a> { let alias_id = self.types.add_resource(Resource { name: name.to_owned(), alias: Some(ResourceAlias { - owner: match self.find_owner(ComponentAnyTypeId::Resource(id)) { + owner: match self.find_owner(wasm::ComponentAnyTypeId::Resource(id)) { Some((Owner::Interface(id), _)) => Some(*id), _ => None, }, @@ -804,17 +815,17 @@ impl<'a> TypeConverter<'a> { resource_id } - fn entity_type(&self, ty: wasm::EntityType) -> CoreExtern { + fn entity_type(&self, ty: wasmparser::types::EntityType) -> CoreExtern { match ty { - wasm::EntityType::Func(ty) => CoreExtern::Func(self.func_type(ty)), - wasm::EntityType::Table(ty) => ty.into(), - wasm::EntityType::Memory(ty) => ty.into(), - wasm::EntityType::Global(ty) => ty.into(), - wasm::EntityType::Tag(ty) => CoreExtern::Tag(self.func_type(ty)), + wasmparser::types::EntityType::Func(ty) => CoreExtern::Func(self.func_type(ty)), + wasmparser::types::EntityType::Table(ty) => ty.into(), + wasmparser::types::EntityType::Memory(ty) => ty.into(), + wasmparser::types::EntityType::Global(ty) => ty.into(), + wasmparser::types::EntityType::Tag(ty) => CoreExtern::Tag(self.func_type(ty)), } } - fn func_type(&self, ty: wasm::CoreTypeId) -> CoreFuncType { + fn func_type(&self, ty: wasmparser::types::CoreTypeId) -> CoreFuncType { let func_ty = self.wasm_types[ty].unwrap_func(); CoreFuncType { params: func_ty.params().iter().copied().map(Into::into).collect(), diff --git a/src/commands/targets.rs b/src/commands/targets.rs index df3f04f7..2512e6ac 100644 --- a/src/commands/targets.rs +++ b/src/commands/targets.rs @@ -95,10 +95,9 @@ fn encode_wit_as_component(path: &Path) -> anyhow::Result> { let (pkg, _) = resolve.push_dir(path)?; pkg } else { - let unresolved = wit_parser::UnresolvedPackage::parse_file(path)?; - resolve.push(unresolved)? + resolve.push_path(path)?.0 }; - let encoded = wit_component::encode(Some(true), &resolve, pkg).with_context(|| { + let encoded = wit_component::encode(&resolve, pkg).with_context(|| { format!( "failed to encode WIT package from `{path}`", path = path.display()