diff --git a/Cargo.lock b/Cargo.lock index b854e769f..af486139c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,12 @@ # It is not intended for manual editing. version = 4 +[[package]] +name = "adler2" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" + [[package]] name = "aho-corasick" version = "1.1.3" @@ -67,6 +73,18 @@ version = "1.0.98" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e16d2d3311acee920a9eb8d33b8cbc1787ce4a264e85f964c2404b969bdcd487" +[[package]] +name = "auditable-serde" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c7bf8143dfc3c0258df908843e169b5cc5fcf76c7718bd66135ef4a9cd558c5" +dependencies = [ + "semver", + "serde", + "serde_json", + "topological-sort", +] + [[package]] name = "beef" version = "0.5.2" @@ -155,6 +173,15 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" +[[package]] +name = "crc32fast" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" +dependencies = [ + "cfg-if", +] + [[package]] name = "crossbeam-deque" version = "0.8.6" @@ -180,6 +207,17 @@ version = "0.8.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" +[[package]] +name = "displaydoc" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "either" version = "1.15.0" @@ -231,6 +269,16 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" +[[package]] +name = "flate2" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ced92e76e966ca2fd84c8f7aa01a4aea65b0eb6648d72f7c8f3e2764a67fece" +dependencies = [ + "crc32fast", + "miniz_oxide", +] + [[package]] name = "fnv" version = "1.0.7" @@ -243,6 +291,15 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + [[package]] name = "futures" version = "0.3.31" @@ -354,12 +411,151 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" +[[package]] +name = "icu_collections" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db2fa452206ebee18c4b5c2274dbf1de17008e874b4dc4f0aea9d01ca79e4526" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locid" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13acbb8371917fc971be86fc8057c41a64b521c184808a698c02acc242dbf637" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_locid_transform" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01d11ac35de8e40fdeda00d9e1e9d92525f3f9d887cdd7aa81d727596788b54e" +dependencies = [ + "displaydoc", + "icu_locid", + "icu_locid_transform_data", + "icu_provider", + "tinystr", + "zerovec", +] + +[[package]] +name = "icu_locid_transform_data" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7515e6d781098bf9f7205ab3fc7e9709d34554ae0b21ddbcb5febfa4bc7df11d" + +[[package]] +name = "icu_normalizer" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19ce3e0da2ec68599d193c93d088142efd7f9c5d6fc9b803774855747dc6a84f" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "utf16_iter", + "utf8_iter", + "write16", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5e8338228bdc8ab83303f16b797e177953730f601a96c25d10cb3ab0daa0cb7" + +[[package]] +name = "icu_properties" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93d6020766cfc6302c15dbbc9c8778c37e62c14427cb7f6e601d849e092aeef5" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_locid_transform", + "icu_properties_data", + "icu_provider", + "tinystr", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85fb8799753b75aee8d2a21d7c14d9f38921b54b3dbda10f5a3c7a7b82dba5e2" + +[[package]] +name = "icu_provider" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ed421c8a8ef78d3e2dbc98a973be2f3770cb42b606e3ab18d6237c4dfde68d9" +dependencies = [ + "displaydoc", + "icu_locid", + "icu_provider_macros", + "stable_deref_trait", + "tinystr", + "writeable", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_provider_macros" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ec89e9337638ecdc08744df490b221a7399bf8d164eb52a665454e60e075ad6" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "id-arena" version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" +[[package]] +name = "idna" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "686f825264d630750a544639377bae737628043f20d38bbc029e8f29ea968a7e" +dependencies = [ + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "daca1df1c957320b2cf139ac61e7bd64fed304c5040df000a745aa1de3b4ef71" +dependencies = [ + "icu_normalizer", + "icu_properties", +] + [[package]] name = "im-rc" version = "15.1.0" @@ -427,12 +623,6 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" -[[package]] -name = "leb128" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" - [[package]] name = "leb128fmt" version = "0.1.0" @@ -451,6 +641,12 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cd945864f07fe9f5371a27ad7b52a172b4b499999f1d97574c9fa68373937e12" +[[package]] +name = "litemap" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23fb14cb19457329c82206317a5663005a4d404783dc74f4252769b0d5f42856" + [[package]] name = "log" version = "0.4.27" @@ -519,6 +715,15 @@ dependencies = [ "syn", ] +[[package]] +name = "miniz_oxide" +version = "0.8.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3be647b768db090acb35d5ec5db2b0e1f1de11133ca123b9eacf5137868f892a" +dependencies = [ + "adler2", +] + [[package]] name = "once_cell" version = "1.21.3" @@ -531,6 +736,12 @@ version = "1.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4895175b425cb1f87721b59f0f286c2092bd4af812243672510e1ac53e2e0ad" +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + [[package]] name = "petgraph" version = "0.6.5" @@ -784,6 +995,12 @@ dependencies = [ "smallvec", ] +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + [[package]] name = "strsim" version = "0.11.1" @@ -801,6 +1018,17 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "synstructure" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "terminal_size" version = "0.4.2" @@ -816,7 +1044,7 @@ name = "test-helpers" version = "0.0.0" dependencies = [ "codegen-macro", - "wasm-encoder 0.235.0", + "wasm-encoder", "wit-bindgen-core", "wit-component", "wit-parser", @@ -842,6 +1070,16 @@ dependencies = [ "syn", ] +[[package]] +name = "tinystr" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9117f5d4db391c1cf6927e7bea3db74b9a1c1add8f7eda9ffd5364f40f57b82f" +dependencies = [ + "displaydoc", + "zerovec", +] + [[package]] name = "toml" version = "0.8.23" @@ -883,6 +1121,12 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5d99f8c9a7727884afe522e9bd5edbfc91a3312b36a77b5fb8926e4c31a41801" +[[package]] +name = "topological-sort" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea68304e134ecd095ac6c3574494fc62b909f416c4fca77e440530221e549d3d" + [[package]] name = "typenum" version = "1.18.0" @@ -925,6 +1169,29 @@ version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861" +[[package]] +name = "url" +version = "2.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32f8b686cadd1473f4bd0117a5d28d36b1ade384ea9b5069a1c40aefed7fda60" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "utf16_iter" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8232dd3cdaed5356e0f716d285e4b40b932ac434100fe9b7e0e8e935b9e6246" + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + [[package]] name = "utf8parse" version = "0.2.2" @@ -939,9 +1206,8 @@ checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" [[package]] name = "wac-graph" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d94268a683b67ae20210565b5f91e106fe05034c36b931e739fe90377ed80b98" +version = "0.7.0-dev" +source = "git+https://github.com/bytecodealliance/wac#1750683b0360928baceb689e972cc2c36e137fdd" dependencies = [ "anyhow", "id-arena", @@ -951,16 +1217,15 @@ dependencies = [ "semver", "thiserror", "wac-types", - "wasm-encoder 0.202.0", - "wasm-metadata 0.202.0", - "wasmparser 0.202.0", + "wasm-encoder", + "wasm-metadata", + "wasmparser", ] [[package]] name = "wac-parser" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "616ec0c4f63641fa095b4a551263fe35a15c72c9680b650b8f08f70db0fdbd19" +version = "0.7.0-dev" +source = "git+https://github.com/bytecodealliance/wac#1750683b0360928baceb689e972cc2c36e137fdd" dependencies = [ "anyhow", "id-arena", @@ -972,23 +1237,22 @@ dependencies = [ "serde", "thiserror", "wac-graph", - "wasm-encoder 0.202.0", - "wasm-metadata 0.202.0", - "wasmparser 0.202.0", + "wasm-encoder", + "wasm-metadata", + "wasmparser", ] [[package]] name = "wac-types" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5028a15e266f4c8fed48beb95aebb76af5232dcd554fd849a305a4e5cce1563" +version = "0.7.0-dev" +source = "git+https://github.com/bytecodealliance/wac#1750683b0360928baceb689e972cc2c36e137fdd" dependencies = [ "anyhow", "id-arena", "indexmap", "semver", - "wasm-encoder 0.202.0", - "wasmparser 0.202.0", + "wasm-encoder", + "wasmparser", ] [[package]] @@ -1013,20 +1277,11 @@ dependencies = [ "serde_derive", "serde_yaml", "smallvec", - "wasm-encoder 0.235.0", - "wasmparser 0.235.0", + "wasm-encoder", + "wasmparser", "wat", ] -[[package]] -name = "wasm-encoder" -version = "0.202.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfd106365a7f5f7aa3c1916a98cbb3ad477f5ff96ddb130285a91c6e7429e67a" -dependencies = [ - "leb128", -] - [[package]] name = "wasm-encoder" version = "0.235.0" @@ -1034,46 +1289,26 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3bc393c395cb621367ff02d854179882b9a351b4e0c93d1397e6090b53a5c2a" dependencies = [ "leb128fmt", - "wasmparser 0.235.0", + "wasmparser", ] [[package]] name = "wasm-metadata" -version = "0.202.0" +version = "0.235.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "094aea3cb90e09f16ee25a4c0e324b3e8c934e7fd838bfa039aef5352f44a917" +checksum = "b055604ba04189d54b8c0ab2c2fc98848f208e103882d5c0b984f045d5ea4d20" dependencies = [ "anyhow", + "auditable-serde", + "flate2", "indexmap", "serde", "serde_derive", "serde_json", "spdx", - "wasm-encoder 0.202.0", - "wasmparser 0.202.0", -] - -[[package]] -name = "wasm-metadata" -version = "0.235.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b055604ba04189d54b8c0ab2c2fc98848f208e103882d5c0b984f045d5ea4d20" -dependencies = [ - "anyhow", - "indexmap", - "wasm-encoder 0.235.0", - "wasmparser 0.235.0", -] - -[[package]] -name = "wasmparser" -version = "0.202.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6998515d3cf3f8b980ef7c11b29a9b1017d4cf86b99ae93b546992df9931413" -dependencies = [ - "bitflags", - "indexmap", - "semver", + "url", + "wasm-encoder", + "wasmparser", ] [[package]] @@ -1099,7 +1334,7 @@ dependencies = [ "leb128fmt", "memchr", "unicode-width 0.2.1", - "wasm-encoder 0.235.0", + "wasm-encoder", ] [[package]] @@ -1282,8 +1517,8 @@ dependencies = [ "clap", "heck 0.5.0", "indexmap", - "wasm-encoder 0.235.0", - "wasm-metadata 0.235.0", + "wasm-encoder", + "wasm-metadata", "wit-bindgen-core", "wit-component", ] @@ -1295,7 +1530,7 @@ dependencies = [ "anyhow", "clap", "env_logger", - "wasm-encoder 0.235.0", + "wasm-encoder", "wit-bindgen-c", "wit-bindgen-core", "wit-bindgen-cpp", @@ -1326,8 +1561,8 @@ dependencies = [ "clap", "heck 0.5.0", "test-helpers", - "wasm-encoder 0.235.0", - "wasm-metadata 0.235.0", + "wasm-encoder", + "wasm-metadata", "wit-bindgen-c", "wit-bindgen-core", "wit-component", @@ -1341,7 +1576,7 @@ dependencies = [ "clap", "heck 0.5.0", "indexmap", - "wasm-metadata 0.235.0", + "wasm-metadata", "wit-bindgen-core", "wit-component", "wit-parser", @@ -1391,7 +1626,7 @@ dependencies = [ "serde_json", "syn", "test-helpers", - "wasm-metadata 0.235.0", + "wasm-metadata", "wit-bindgen", "wit-bindgen-core", "wit-bindgen-rt", @@ -1429,8 +1664,8 @@ dependencies = [ "wac-types", "wasi-preview1-component-adapter-provider", "wasm-compose", - "wasm-encoder 0.235.0", - "wasmparser 0.235.0", + "wasm-encoder", + "wasmparser", "wat", "wit-bindgen-csharp", "wit-component", @@ -1450,9 +1685,9 @@ dependencies = [ "serde", "serde_derive", "serde_json", - "wasm-encoder 0.235.0", - "wasm-metadata 0.235.0", - "wasmparser 0.235.0", + "wasm-encoder", + "wasm-metadata", + "wasmparser", "wat", "wit-parser", ] @@ -1472,5 +1707,84 @@ dependencies = [ "serde_derive", "serde_json", "unicode-xid", - "wasmparser 0.235.0", + "wasmparser", +] + +[[package]] +name = "write16" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1890f4022759daae28ed4fe62859b1236caebfc61ede2f63ed4e695f3f6d936" + +[[package]] +name = "writeable" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e9df38ee2d2c3c5948ea468a8406ff0db0b29ae1ffde1bcf20ef305bcc95c51" + +[[package]] +name = "yoke" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "120e6aef9aa629e3d4f52dc8cc43a015c7724194c97dfaf45180d2daf2b77f40" +dependencies = [ + "serde", + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2380878cad4ac9aac1e2435f3eb4020e8374b5f13c296cb75b4620ff8e229154" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "zerofrom" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50cc42e0333e05660c3587f3bf9d0478688e15d870fab3346451ce7f8c9fbea5" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d71e5d6e06ab090c67b5e44993ec16b72dcbaabc526db883a360057678b48502" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "zerovec" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa2b893d79df23bfb12d5461018d408ea19dfafe76c2c7ef6d4eba614f8ff079" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6eafa6dfb17584ea3e2bd6e76e0cc15ad7af12b09abdd1ca55961bed9b1063c6" +dependencies = [ + "proc-macro2", + "quote", + "syn", ] diff --git a/crates/c/src/lib.rs b/crates/c/src/lib.rs index a0f3d09e1..bc1d44489 100644 --- a/crates/c/src/lib.rs +++ b/crates/c/src/lib.rs @@ -1671,6 +1671,16 @@ impl<'a> wit_bindgen_core::AnonymousTypeGenerator<'a> for InterfaceGenerator<'a> fn anonymous_type_type(&mut self, _id: TypeId, _ty: &Type, _docs: &Docs) { todo!("print_anonymous_type for type"); } + + fn anonymous_type_fixed_size_list( + &mut self, + _id: TypeId, + _ty: &Type, + _size: u32, + _docs: &Docs, + ) { + todo!("print_anonymous_type for fixed size list"); + } } pub enum CTypeNameInfo<'a> { diff --git a/crates/core/src/abi.rs b/crates/core/src/abi.rs index 102458e67..71f583259 100644 --- a/crates/core/src/abi.rs +++ b/crates/core/src/abi.rs @@ -307,6 +307,28 @@ def_instruction! { ty: TypeId, } : [2] => [1], + /// Pops all fields for a fixed list off the stack and then composes them + /// into an array. + FixedSizeListLift { + element: &'a Type, + size: u32, + id: TypeId, + } : [*size as usize] => [1], + + /// Pops an array off the stack, decomposes the elements and then pushes them onto the stack. + FixedSizeListLower { + element: &'a Type, + size: u32, + id: TypeId, + } : [1] => [*size as usize], + + /// Pops an array and an address off the stack, passes each element to a block storing it + FixedSizeListLowerMemory { + element: &'a Type, + size: u32, + id: TypeId, + } : [2] => [0], + /// Pushes an operand onto the stack representing the list item from /// each iteration of the list. /// @@ -832,7 +854,7 @@ fn needs_deallocate(resolve: &Resolve, ty: &Type, what: Deallocate) -> bool { TypeDefKind::Flags(_) | TypeDefKind::Enum(_) => false, TypeDefKind::Future(_) | TypeDefKind::Stream(_) => what.handles(), TypeDefKind::Unknown => unreachable!(), - TypeDefKind::FixedSizeList(..) => todo!(), + TypeDefKind::FixedSizeList(t, _) => needs_deallocate(resolve, t, what), }, Type::Bool @@ -1444,7 +1466,21 @@ impl<'a, B: Bindgen> Generator<'a, B> { }); } TypeDefKind::Unknown => unreachable!(), - TypeDefKind::FixedSizeList(..) => todo!(), + TypeDefKind::FixedSizeList(ty, size) => { + self.emit(&FixedSizeListLower { + element: ty, + size: *size, + id, + }); + let mut values = self + .stack + .drain(self.stack.len() - (*size as usize)..) + .collect::>(); + for value in values.drain(..) { + self.stack.push(value); + self.lower(ty); + } + } }, } } @@ -1627,7 +1663,24 @@ impl<'a, B: Bindgen> Generator<'a, B> { }); } TypeDefKind::Unknown => unreachable!(), - TypeDefKind::FixedSizeList(..) => todo!(), + TypeDefKind::FixedSizeList(ty, size) => { + let temp = flat_types(self.resolve, ty).unwrap(); + let flat_per_elem = temp.to_vec().len(); + let flatsize = flat_per_elem * (*size as usize); + let mut lowered_args = self + .stack + .drain(self.stack.len() - flatsize..) + .collect::>(); + for _ in 0..*size { + self.stack.extend(lowered_args.drain(..flat_per_elem)); + self.lift(ty); + } + self.emit(&FixedSizeListLift { + element: ty, + size: *size, + id, + }); + } }, } } @@ -1809,7 +1862,21 @@ impl<'a, B: Bindgen> Generator<'a, B> { } TypeDefKind::Unknown => unreachable!(), - TypeDefKind::FixedSizeList(..) => todo!(), + TypeDefKind::FixedSizeList(element, size) => { + // resembles write_list_to_memory + self.push_block(); + self.emit(&IterElem { element }); + self.emit(&IterBasePointer); + let elem_addr = self.stack.pop().unwrap(); + self.write_to_memory(element, elem_addr, offset); + self.finish_block(0); + self.stack.push(addr); + self.emit(&FixedSizeListLowerMemory { + element, + size: *size, + id, + }); + } }, } } @@ -1996,7 +2063,19 @@ impl<'a, B: Bindgen> Generator<'a, B> { } TypeDefKind::Unknown => unreachable!(), - TypeDefKind::FixedSizeList(..) => todo!(), + TypeDefKind::FixedSizeList(ty, size) => { + let increment = self.bindgen.sizes().size(ty); + let mut position = offset; + for _ in 0..*size { + self.read_from_memory(ty, addr.clone(), position); + position = position + increment; + } + self.emit(&FixedSizeListLift { + element: ty, + size: *size, + id, + }); + } }, } } @@ -2305,7 +2384,7 @@ impl<'a, B: Bindgen> Generator<'a, B> { TypeDefKind::Future(_) => unreachable!(), TypeDefKind::Stream(_) => unreachable!(), TypeDefKind::Unknown => unreachable!(), - TypeDefKind::FixedSizeList(..) => todo!(), + TypeDefKind::FixedSizeList(_, _) => {} }, } } diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs index 2932b7b4b..68f87c6c1 100644 --- a/crates/core/src/lib.rs +++ b/crates/core/src/lib.rs @@ -195,6 +195,7 @@ pub trait AnonymousTypeGenerator<'a> { fn anonymous_type_option(&mut self, id: TypeId, ty: &Type, docs: &Docs); fn anonymous_type_result(&mut self, id: TypeId, ty: &Result_, docs: &Docs); fn anonymous_type_list(&mut self, id: TypeId, ty: &Type, docs: &Docs); + fn anonymous_type_fixed_size_list(&mut self, id: TypeId, ty: &Type, size: u32, docs: &Docs); fn anonymous_type_future(&mut self, id: TypeId, ty: &Option, docs: &Docs); fn anonymous_type_stream(&mut self, id: TypeId, ty: &Option, docs: &Docs); fn anonymous_type_type(&mut self, id: TypeId, ty: &Type, docs: &Docs); @@ -217,7 +218,9 @@ pub trait AnonymousTypeGenerator<'a> { TypeDefKind::Future(f) => self.anonymous_type_future(id, f, &ty.docs), TypeDefKind::Stream(s) => self.anonymous_type_stream(id, s, &ty.docs), TypeDefKind::Handle(handle) => self.anonymous_type_handle(id, handle, &ty.docs), - TypeDefKind::FixedSizeList(..) => todo!(), + TypeDefKind::FixedSizeList(t, size) => { + self.anonymous_type_fixed_size_list(id, t, *size, &ty.docs) + } TypeDefKind::Unknown => unreachable!(), } } diff --git a/crates/core/src/types.rs b/crates/core/src/types.rs index 35d6f5f6c..c3e4e107c 100644 --- a/crates/core/src/types.rs +++ b/crates/core/src/types.rs @@ -203,7 +203,9 @@ impl Types { // should use the same ownership semantics as `own` info.has_own_handle = true; } - TypeDefKind::FixedSizeList(..) => todo!(), + TypeDefKind::FixedSizeList(ty, _) => { + info = self.type_info(resolve, ty); + } TypeDefKind::Unknown => unreachable!(), } let prev = self.type_info.insert(ty, info); diff --git a/crates/cpp/src/lib.rs b/crates/cpp/src/lib.rs index d2e07ac30..2eeae305c 100644 --- a/crates/cpp/src/lib.rs +++ b/crates/cpp/src/lib.rs @@ -74,6 +74,7 @@ struct Includes { // needs wit types needs_wit: bool, needs_memory: bool, + needs_array: bool, } #[derive(Default)] @@ -399,6 +400,9 @@ impl Cpp { if self.dependencies.needs_memory { self.include(""); } + if self.dependencies.needs_array { + self.include(""); + } if self.dependencies.needs_bit { self.include(""); } @@ -1579,7 +1583,13 @@ impl CppInterfaceGenerator<'_> { TypeDefKind::Future(_) => todo!(), TypeDefKind::Stream(_) => todo!(), TypeDefKind::Type(ty) => self.type_name(ty, from_namespace, flavor), - TypeDefKind::FixedSizeList(_, _) => todo!(), + TypeDefKind::FixedSizeList(ty, size) => { + self.r#gen.dependencies.needs_array = true; + format!( + "std::array<{}, {size}>", + self.type_name(ty, from_namespace, flavor) + ) + } TypeDefKind::Unknown => todo!(), }, Type::ErrorContext => todo!(), @@ -2438,7 +2448,57 @@ impl<'a, 'b> Bindgen for FunctionBindgen<'a, 'b> { results.push(move_if_necessary(&result)); } } - abi::Instruction::IterElem { .. } => results.push("IterElem".to_string()), + abi::Instruction::FixedSizeListLift { + element, + size, + id: _, + } => { + let tmp = self.tmp(); + let result = format!("result{tmp}"); + let typename = self + .gen + .type_name(element, &self.namespace, Flavor::InStruct); + self.push_str(&format!("std::array<{typename}, {size}> {result} = {{",)); + for a in operands.drain(0..(*size as usize)) { + self.push_str(&a); + self.push_str(", "); + } + self.push_str("};\n"); + results.push(result); + } + abi::Instruction::FixedSizeListLower { .. } => todo!(), + abi::Instruction::FixedSizeListLowerMemory { + element, + size: elemsize, + id: _, + } => { + let body = self.blocks.pop().unwrap(); + let vec = operands[0].clone(); + let target = operands[1].clone(); + let size = self.r#gen.sizes.size(element); + let size_str = size.format(POINTER_SIZE_EXPRESSION); + let typename = self + .r#gen + .type_name(element, &self.namespace, Flavor::InStruct); + let ptr_type = self.r#gen.r#gen.opts.ptr_type(); + self.push_str(&format!( + "{{ + {ptr_type} outer_base = {target};\n" + )); + let target: String = "outer_base".into(); + self.push_str(&format!( + "std::array<{typename}, {elemsize}>& outer_vec = {vec};\n" + )); + let vec: String = "outer_vec".into(); + self.push_str(&format!("for (unsigned i = 0; i<{vec}.size(); ++i) {{\n",)); + self.push_str(&format!( + "{ptr_type} base = {target} + i * {size_str}; + {typename}& iter_elem = {vec}[i];\n" + )); + self.push_str(&body.0); + self.push_str("\n}\n}\n"); + } + abi::Instruction::IterElem { .. } => results.push("iter_elem".to_string()), abi::Instruction::IterBasePointer => results.push("base".to_string()), abi::Instruction::RecordLower { record, .. } => { let op = &operands[0]; @@ -2975,7 +3035,7 @@ impl<'a, 'b> Bindgen for FunctionBindgen<'a, 'b> { self.src.push_str(">("); } if *amt == 1 { - if operands[0].starts_with("std::move(") { + if operands[0].starts_with("std::move(") && !operands[0].contains('.') { // remove the std::move due to return value optimization (and complex rules about when std::move harms) self.src.push_str(&operands[0][9..]); } else { diff --git a/crates/csharp/src/function.rs b/crates/csharp/src/function.rs index 55c4fc8e3..981d0fe58 100644 --- a/crates/csharp/src/function.rs +++ b/crates/csharp/src/function.rs @@ -1251,7 +1251,10 @@ impl Bindgen for FunctionBindgen<'_, '_> { | Instruction::ErrorContextLower { .. } | Instruction::ErrorContextLift { .. } | Instruction::DropHandle { .. } - => todo!(), + => todo!(), + Instruction::FixedSizeListLift { .. } => todo!(), + Instruction::FixedSizeListLower { .. } => todo!(), + Instruction::FixedSizeListLowerMemory { .. } => todo!(), } } diff --git a/crates/moonbit/src/lib.rs b/crates/moonbit/src/lib.rs index d0d11d4ed..63e7d0033 100644 --- a/crates/moonbit/src/lib.rs +++ b/crates/moonbit/src/lib.rs @@ -2668,6 +2668,9 @@ impl Bindgen for FunctionBindgen<'_, '_> { | Instruction::ErrorContextLower { .. } | Instruction::ErrorContextLift { .. } | Instruction::DropHandle { .. } => todo!(), + Instruction::FixedSizeListLift { .. } => todo!(), + Instruction::FixedSizeListLower { .. } => todo!(), + Instruction::FixedSizeListLowerMemory { .. } => todo!(), } } diff --git a/crates/rust/src/bindgen.rs b/crates/rust/src/bindgen.rs index 9cfd1416d..7f2a228ba 100644 --- a/crates/rust/src/bindgen.rs +++ b/crates/rust/src/bindgen.rs @@ -777,6 +777,24 @@ impl Bindgen for FunctionBindgen<'_, '_> { results.push(len); } + Instruction::FixedSizeListLowerMemory { + element, + size: _, + id: _, + } => { + let body = self.blocks.pop().unwrap(); + let vec = operands[0].clone(); + let target = operands[1].clone(); + let size = self.r#gen.sizes.size(element); + self.push_str(&format!("for (i, e) in {vec}.into_iter().enumerate() {{\n",)); + self.push_str(&format!( + "let base = {target}.add(i * {});\n", + size.format(POINTER_SIZE_EXPRESSION) + )); + self.push_str(&body); + self.push_str("\n}\n"); + } + Instruction::ListLift { element, .. } => { let body = self.blocks.pop().unwrap(); let tmp = self.tmp(); @@ -1190,6 +1208,30 @@ impl Bindgen for FunctionBindgen<'_, '_> { Instruction::DropHandle { .. } => { uwriteln!(self.src, "let _ = {};", operands[0]); } + Instruction::FixedSizeListLift { + element: _, + size, + id: _, + } => { + let tmp = self.tmp(); + let result = format!("result{tmp}"); + self.push_str(&format!("let {result} = [",)); + for a in operands.drain(0..(*size as usize)) { + self.push_str(&a); + self.push_str(", "); + } + self.push_str("];\n"); + results.push(result); + } + Instruction::FixedSizeListLower { + element: _, + size, + id: _, + } => { + for i in 0..(*size as usize) { + results.push(format!("{}[{i}]", operands[0])); + } + } } } } diff --git a/crates/rust/src/interface.rs b/crates/rust/src/interface.rs index 83e331aa0..7a36fee44 100644 --- a/crates/rust/src/interface.rs +++ b/crates/rust/src/interface.rs @@ -2982,4 +2982,17 @@ impl<'a, 'b> wit_bindgen_core::AnonymousTypeGenerator<'a> for AnonTypeGenerator< self.interface.print_optional_ty(ty.as_ref(), mode); self.interface.push_str(">"); } + + fn anonymous_type_fixed_size_list(&mut self, _id: TypeId, ty: &Type, size: u32, _docs: &Docs) { + self.interface.push_str("["); + self.interface.print_ty( + ty, + TypeMode { + lifetime: None, + lists_borrowed: false, + style: TypeOwnershipStyle::Owned, + }, + ); + self.interface.push_str(&format!("; {size}]")); + } } diff --git a/crates/test/Cargo.toml b/crates/test/Cargo.toml index f5df48a09..23d031581 100644 --- a/crates/test/Cargo.toml +++ b/crates/test/Cargo.toml @@ -24,9 +24,10 @@ regex = "1.11.1" serde = { workspace = true } toml = "0.8.20" wasi-preview1-component-adapter-provider = "30.0.2" -wac-parser = "0.6.1" -wac-types = "0.6.1" -wac-graph = "0.6.1" +# We need https://github.com/bytecodealliance/wac/pull/156 which isn't released, yet +wac-parser = { git = "https://github.com/bytecodealliance/wac" } +wac-types = { git = "https://github.com/bytecodealliance/wac" } +wac-graph = { git = "https://github.com/bytecodealliance/wac" } wasm-compose = { workspace = true } indexmap = { workspace = true } wasm-encoder = { workspace = true } diff --git a/tests/runtime/fixed-size-list/runner.rs b/tests/runtime/fixed-size-list/runner.rs new file mode 100644 index 000000000..d72b653ca --- /dev/null +++ b/tests/runtime/fixed-size-list/runner.rs @@ -0,0 +1,65 @@ +include!(env!("BINDINGS")); + +use test::fixed_size_lists::to_test::*; + +fn main() { + list_param([1, 2, 3, 4]); + list_param2([[1, 2], [3, 4]]); + list_param3([ + -1, 2, -3, 4, -5, 6, -7, 8, -9, 10, -11, 12, -13, 14, -15, 16, -17, 18, -19, 20, + ]); + { + let result = list_result(); + assert_eq!(result, [b'0', b'1', b'A', b'B', b'a', b'b', 128, 255]); + } + { + let result = list_minmax16([0, 1024, 32768, 65535], [1, 2048, -32767, -2]); + assert_eq!(result, ([0, 1024, 32768, 65535], [1, 2048, -32767, -2])); + } + { + let result = list_minmax_float([2.0, -42.0], [0.25, -0.125]); + assert_eq!(result, ([2.0, -42.0], [0.25, -0.125])); + } + { + let result = list_roundtrip([b'a', b'b', b'c', b'd', 0, 1, 2, 3, b'A', b'B', b'Y', b'Z']); + assert_eq!( + result, + [b'a', b'b', b'c', b'd', 0, 1, 2, 3, b'A', b'B', b'Y', b'Z'] + ); + } + { + let result = nested_roundtrip([[1, 5], [42, 1_000_000]], [[-1, 3], [-2_000_000, 4711]]); + assert_eq!( + result, + ([[1, 5], [42, 1_000_000]], [[-1, 3], [-2_000_000, 4711]]) + ); + } + { + let result = large_roundtrip( + [[1, 5], [42, 1_000_000]], + [ + [-1, 3, -2, 4], + [-2_000_000, 4711, 99_999, -5], + [-6, 7, 8, -9], + [50, -5, 500, -5000], + ], + ); + assert_eq!( + result, + ( + [[1, 5], [42, 1_000_000]], + [ + [-1, 3, -2, 4], + [-2_000_000, 4711, 99_999, -5], + [-6, 7, 8, -9], + [50, -5, 500, -5000] + ] + ) + ); + } + { + let result = nightmare_on_cpp([Nested { l: [1, -1] }, Nested { l: [2, -2] }]); + assert_eq!(result[0].l, [1, -1]); + assert_eq!(result[1].l, [2, -2]); + } +} diff --git a/tests/runtime/fixed-size-list/test.cpp b/tests/runtime/fixed-size-list/test.cpp new file mode 100644 index 000000000..abfeabbdd --- /dev/null +++ b/tests/runtime/fixed-size-list/test.cpp @@ -0,0 +1,51 @@ +#include +#include + +using namespace exports::test::fixed_size_lists; + +void to_test::ListParam(std::array a) { + std::array b = std::array{1, 2, 3, 4}; + assert(a == b); +} +void to_test::ListParam2(std::array, 2> a) { + std::array, 2> b = std::array, 2>{std::array{1, 2}, std::array{3, 4}}; + assert(a == b); +} +void to_test::ListParam3(std::array a) { + std::array b = std::array{-1, 2, -3, 4, -5, 6, -7, 8, -9, 10, -11, 12, -13, 14, -15, 16, -17, 18, -19, 20}; + assert(a == b); +} +std::array to_test::ListResult() { + return std::array{'0', '1', 'A', 'B', 'a', 'b', 128, 255}; +} +std::tuple, std::array> +to_test::ListMinmax16(std::array a, std::array b) { + return std::tuple, std::array>(a, b); +} +std::tuple, std::array> +to_test::ListMinmaxFloat(std::array a, std::array b) { + return std::tuple, std::array>(a,b); +} +std::array to_test::ListRoundtrip(std::array a) { + return a; +} + +std::tuple, 2>, + std::array, 2>> +to_test::NestedRoundtrip(std::array, 2> a, + std::array, 2> b) { + return std::tuple, 2>, + std::array, 2>>(a, b); +} + +std::tuple, 2>, + std::array, 4>> +to_test::LargeRoundtrip(std::array, 2> a, + std::array, 4> b) { + return std::tuple, 2>, + std::array, 4>>(a, b); +} +std::array +to_test::NightmareOnCpp(std::array a) { + return a; +} diff --git a/tests/runtime/fixed-size-list/test.rs b/tests/runtime/fixed-size-list/test.rs new file mode 100644 index 000000000..669e4b858 --- /dev/null +++ b/tests/runtime/fixed-size-list/test.rs @@ -0,0 +1,43 @@ +include!(env!("BINDINGS")); + +struct Component; + +export!(Component); + +use crate::exports::test::fixed_size_lists::to_test::Nested; + +impl exports::test::fixed_size_lists::to_test::Guest for Component { + fn list_param(a: [u32; 4]) { + assert_eq!(a, [1, 2, 3, 4]); + } + fn list_param2(a: [[u32; 2]; 2]) { + assert_eq!(a, [[1, 2], [3, 4]]); + } + fn list_param3(a: [i32; 20]) { + assert_eq!( + a, + [-1, 2, -3, 4, -5, 6, -7, 8, -9, 10, -11, 12, -13, 14, -15, 16, -17, 18, -19, 20] + ); + } + fn list_minmax16(a: [u16; 4], b: [i16; 4]) -> ([u16; 4], [i16; 4]) { + (a, b) + } + fn list_minmax_float(a: [f32; 2], b: [f64; 2]) -> ([f32; 2], [f64; 2]) { + (a, b) + } + fn list_roundtrip(a: [u8; 12]) -> [u8; 12] { + a + } + fn list_result() -> [u8; 8] { + [b'0', b'1', b'A', b'B', b'a', b'b', 128, 255] + } + fn nested_roundtrip(a: [[u32; 2]; 2], b: [[i32; 2]; 2]) -> ([[u32; 2]; 2], [[i32; 2]; 2]) { + (a, b) + } + fn large_roundtrip(a: [[u32; 2]; 2], b: [[i32; 4]; 4]) -> ([[u32; 2]; 2], [[i32; 4]; 4]) { + (a, b) + } + fn nightmare_on_cpp(a: [Nested; 2]) -> [Nested; 2] { + a + } +} diff --git a/tests/runtime/fixed-size-list/test.wit b/tests/runtime/fixed-size-list/test.wit new file mode 100644 index 000000000..5f5bbd84c --- /dev/null +++ b/tests/runtime/fixed-size-list/test.wit @@ -0,0 +1,33 @@ +// run with "--runner wasmtime -W component-model-fixed-size-list" + +package test:fixed-size-lists; + +interface to-test { + list-param: func(a: list); + list-param2: func(a: list, 2>); + list-param3: func(a: list); + list-result: func() -> list; + + list-minmax16: func(a: list, b: list) -> tuple, list>; + list-minmax-float: func(a: list, b: list) + -> tuple, list>; + + list-roundtrip: func(a: list) -> list; + + nested-roundtrip: func(a: list, 2>, b: list, 2>) -> tuple,2>, list, 2>>; + large-roundtrip: func(a: list, 2>, b: list, 4>) -> tuple,2>, list, 4>>; + + record nested { + l: list, + } + + nightmare-on-cpp: func(a: list) -> list; +} + +world test { + export to-test; +} + +world runner { + import to-test; +}