From 41b6f4d6c2f2348374fafa4af9d6692221e85f6c Mon Sep 17 00:00:00 2001 From: Christof Petig Date: Sat, 19 Apr 2025 13:05:27 +0200 Subject: [PATCH 01/10] more fixed size implementation --- crates/c/src/lib.rs | 4 ++++ crates/core/src/abi.rs | 31 ++++++++++++++++++++++++- crates/core/src/lib.rs | 3 ++- crates/core/src/types.rs | 4 +++- crates/csharp/src/function.rs | 4 +++- crates/moonbit/src/lib.rs | 2 ++ crates/rust/src/bindgen.rs | 2 ++ crates/rust/src/interface.rs | 4 ++++ tests/runtime/fixed-size-list/runner.rs | 6 +++++ tests/runtime/fixed-size-list/test.rs | 8 +++++++ tests/runtime/fixed-size-list/test.wit | 21 +++++++++++++++++ 11 files changed, 85 insertions(+), 4 deletions(-) create mode 100644 tests/runtime/fixed-size-list/runner.rs create mode 100644 tests/runtime/fixed-size-list/test.rs create mode 100644 tests/runtime/fixed-size-list/test.wit diff --git a/crates/c/src/lib.rs b/crates/c/src/lib.rs index dc331a794..a9997f470 100644 --- a/crates/c/src/lib.rs +++ b/crates/c/src/lib.rs @@ -1665,6 +1665,10 @@ 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 260496629..346edb6bb 100644 --- a/crates/core/src/abi.rs +++ b/crates/core/src/abi.rs @@ -307,6 +307,21 @@ def_instruction! { ty: TypeId, } : [2] => [1], + /// Pops all fields for a fixed list off the stack and then composes them + /// into an array. + FixedSizeListLift { + elements: &'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 { + elements: &'a Type, + size: u32, + id: TypeId, + } : [1] => [*size as usize], + /// Pushes an operand onto the stack representing the list item from /// each iteration of the list. /// @@ -1573,7 +1588,21 @@ impl<'a, B: Bindgen> Generator<'a, B> { }); } TypeDefKind::Unknown => unreachable!(), - TypeDefKind::FixedSizeList(..) => todo!(), + TypeDefKind::FixedSizeList(ty, size) => { + let mut temp = Vec::new(); + self.resolve.push_flat(&Type::Id(id), &mut temp); + let mut args = self + .stack + .drain(self.stack.len() - temp.len()..) + .collect::>(); + for _ in 0..*size { + temp.truncate(0); + self.resolve.push_flat(ty, &mut temp); + self.stack.extend(args.drain(..temp.len())); + self.lift(ty); + } + self.emit(&FixedSizeListLift { elements: ty, size: *size, id }); + } }, } } diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs index 2932b7b4b..bee672ef8 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,7 @@ 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/csharp/src/function.rs b/crates/csharp/src/function.rs index 78a084ea2..a28b96521 100644 --- a/crates/csharp/src/function.rs +++ b/crates/csharp/src/function.rs @@ -1264,7 +1264,9 @@ impl Bindgen for FunctionBindgen<'_, '_> { | Instruction::ErrorContextLower { .. } | Instruction::ErrorContextLift { .. } | Instruction::DropHandle { .. } - => todo!(), + => todo!(), + Instruction::FixedSizeListLift { .. } => todo!(), + Instruction::FixedSizeListLower { .. } => todo!(), } } diff --git a/crates/moonbit/src/lib.rs b/crates/moonbit/src/lib.rs index d0d11d4ed..f873b2dce 100644 --- a/crates/moonbit/src/lib.rs +++ b/crates/moonbit/src/lib.rs @@ -2668,6 +2668,8 @@ impl Bindgen for FunctionBindgen<'_, '_> { | Instruction::ErrorContextLower { .. } | Instruction::ErrorContextLift { .. } | Instruction::DropHandle { .. } => todo!(), + Instruction::FixedSizeListLift { .. } => todo!(), + Instruction::FixedSizeListLower { .. } => todo!(), } } diff --git a/crates/rust/src/bindgen.rs b/crates/rust/src/bindgen.rs index 419852d27..f6a06651a 100644 --- a/crates/rust/src/bindgen.rs +++ b/crates/rust/src/bindgen.rs @@ -1207,6 +1207,8 @@ impl Bindgen for FunctionBindgen<'_, '_> { Instruction::DropHandle { .. } => { uwriteln!(self.src, "let _ = {};", operands[0]); } + Instruction::FixedSizeListLift { .. } => todo!(), + Instruction::FixedSizeListLower { .. } => todo!(), } } } diff --git a/crates/rust/src/interface.rs b/crates/rust/src/interface.rs index ad8445b48..b0d349bf1 100644 --- a/crates/rust/src/interface.rs +++ b/crates/rust/src/interface.rs @@ -2919,4 +2919,8 @@ 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) { + todo!() + } } diff --git a/tests/runtime/fixed-size-list/runner.rs b/tests/runtime/fixed-size-list/runner.rs new file mode 100644 index 000000000..c0e587f9c --- /dev/null +++ b/tests/runtime/fixed-size-list/runner.rs @@ -0,0 +1,6 @@ +include!(env!("BINDINGS")); + +use test::lists::to_test::*; + +fn main() { +} diff --git a/tests/runtime/fixed-size-list/test.rs b/tests/runtime/fixed-size-list/test.rs new file mode 100644 index 000000000..58794dfa2 --- /dev/null +++ b/tests/runtime/fixed-size-list/test.rs @@ -0,0 +1,8 @@ +include!(env!("BINDINGS")); + +struct Component; + +export!(Component); + +impl exports::test::lists::to_test::Guest for Component { +} diff --git a/tests/runtime/fixed-size-list/test.wit b/tests/runtime/fixed-size-list/test.wit new file mode 100644 index 000000000..86df7f78d --- /dev/null +++ b/tests/runtime/fixed-size-list/test.wit @@ -0,0 +1,21 @@ +package test:lists; + +interface to-test { + list-param: func(a: list); + list-param2: func(a: list, 2>); + 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; +} + +world test { + export to-test; +} + +world runner { + import to-test; +} From df55ccda93bf1f717edd439e12d3f545e8034af6 Mon Sep 17 00:00:00 2001 From: Christof Petig Date: Sat, 19 Apr 2025 14:38:04 +0200 Subject: [PATCH 02/10] more fixed list implementation --- crates/core/src/abi.rs | 34 +++++++++++++++++++++++--- crates/rust/src/bindgen.rs | 20 +++++++++++++-- crates/rust/src/interface.rs | 6 +++-- tests/runtime/fixed-size-list/test.wit | 1 + 4 files changed, 53 insertions(+), 8 deletions(-) diff --git a/crates/core/src/abi.rs b/crates/core/src/abi.rs index 346edb6bb..5dddd7ad6 100644 --- a/crates/core/src/abi.rs +++ b/crates/core/src/abi.rs @@ -1401,7 +1401,17 @@ impl<'a, B: Bindgen> Generator<'a, B> { }); } TypeDefKind::Unknown => unreachable!(), - TypeDefKind::FixedSizeList(..) => todo!(), + TypeDefKind::FixedSizeList(ty, size) => { + self.emit(&FixedSizeListLower { elements: 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); + } + } }, } } @@ -1760,7 +1770,15 @@ 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.write_to_memory(ty, addr.clone(), position); + position = position + increment; + } + self.emit(&FixedSizeListLower { elements: ty, size: *size, id }); + } }, } } @@ -1947,7 +1965,15 @@ 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 { elements: ty, size: *size, id }); + } }, } } @@ -2149,7 +2175,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/rust/src/bindgen.rs b/crates/rust/src/bindgen.rs index f6a06651a..2d6b36628 100644 --- a/crates/rust/src/bindgen.rs +++ b/crates/rust/src/bindgen.rs @@ -1207,8 +1207,24 @@ impl Bindgen for FunctionBindgen<'_, '_> { Instruction::DropHandle { .. } => { uwriteln!(self.src, "let _ = {};", operands[0]); } - Instruction::FixedSizeListLift { .. } => todo!(), - Instruction::FixedSizeListLower { .. } => todo!(), + Instruction::FixedSizeListLift { elements: _, size, id: _ } => { + let tmp = self.tmp(); + let result = format!("result{tmp}"); + self.push_str(&format!( + "let mut {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 { elements: _, 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 b0d349bf1..f338ec28a 100644 --- a/crates/rust/src/interface.rs +++ b/crates/rust/src/interface.rs @@ -2920,7 +2920,9 @@ impl<'a, 'b> wit_bindgen_core::AnonymousTypeGenerator<'a> for AnonTypeGenerator< self.interface.push_str(">"); } - fn anonymous_type_fixed_size_list(&mut self, _id: TypeId, _ty: &Type, _size: u32, _docs: &Docs) { - todo!() + 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/tests/runtime/fixed-size-list/test.wit b/tests/runtime/fixed-size-list/test.wit index 86df7f78d..f6280c809 100644 --- a/tests/runtime/fixed-size-list/test.wit +++ b/tests/runtime/fixed-size-list/test.wit @@ -3,6 +3,7 @@ package test: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>; From f87010d661d02023b19c5efb8e72d853a24303a2 Mon Sep 17 00:00:00 2001 From: Christof Petig Date: Sat, 19 Apr 2025 14:39:08 +0200 Subject: [PATCH 03/10] cargo fmt --- crates/core/src/abi.rs | 24 ++++++++++++++++++++---- crates/core/src/lib.rs | 4 +++- crates/rust/src/bindgen.rs | 16 +++++++++++----- crates/rust/src/interface.rs | 11 +++++++++-- 4 files changed, 43 insertions(+), 12 deletions(-) diff --git a/crates/core/src/abi.rs b/crates/core/src/abi.rs index 5dddd7ad6..9abbe9f89 100644 --- a/crates/core/src/abi.rs +++ b/crates/core/src/abi.rs @@ -1402,7 +1402,11 @@ impl<'a, B: Bindgen> Generator<'a, B> { } TypeDefKind::Unknown => unreachable!(), TypeDefKind::FixedSizeList(ty, size) => { - self.emit(&FixedSizeListLower { elements: ty, size: *size, id }); + self.emit(&FixedSizeListLower { + elements: ty, + size: *size, + id, + }); let mut values = self .stack .drain(self.stack.len() - (*size as usize)..) @@ -1611,7 +1615,11 @@ impl<'a, B: Bindgen> Generator<'a, B> { self.stack.extend(args.drain(..temp.len())); self.lift(ty); } - self.emit(&FixedSizeListLift { elements: ty, size: *size, id }); + self.emit(&FixedSizeListLift { + elements: ty, + size: *size, + id, + }); } }, } @@ -1777,7 +1785,11 @@ impl<'a, B: Bindgen> Generator<'a, B> { self.write_to_memory(ty, addr.clone(), position); position = position + increment; } - self.emit(&FixedSizeListLower { elements: ty, size: *size, id }); + self.emit(&FixedSizeListLower { + elements: ty, + size: *size, + id, + }); } }, } @@ -1972,7 +1984,11 @@ impl<'a, B: Bindgen> Generator<'a, B> { self.read_from_memory(ty, addr.clone(), position); position = position + increment; } - self.emit(&FixedSizeListLift { elements: ty, size: *size, id }); + self.emit(&FixedSizeListLift { + elements: ty, + size: *size, + id, + }); } }, } diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs index bee672ef8..68f87c6c1 100644 --- a/crates/core/src/lib.rs +++ b/crates/core/src/lib.rs @@ -218,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(t, size) => self.anonymous_type_fixed_size_list(id, t, *size, &ty.docs), + TypeDefKind::FixedSizeList(t, size) => { + self.anonymous_type_fixed_size_list(id, t, *size, &ty.docs) + } TypeDefKind::Unknown => unreachable!(), } } diff --git a/crates/rust/src/bindgen.rs b/crates/rust/src/bindgen.rs index 2d6b36628..0ce6e1fa3 100644 --- a/crates/rust/src/bindgen.rs +++ b/crates/rust/src/bindgen.rs @@ -1207,12 +1207,14 @@ impl Bindgen for FunctionBindgen<'_, '_> { Instruction::DropHandle { .. } => { uwriteln!(self.src, "let _ = {};", operands[0]); } - Instruction::FixedSizeListLift { elements: _, size, id: _ } => { + Instruction::FixedSizeListLift { + elements: _, + size, + id: _, + } => { let tmp = self.tmp(); let result = format!("result{tmp}"); - self.push_str(&format!( - "let mut {result} = [", - )); + self.push_str(&format!("let mut {result} = [",)); for a in operands.drain(0..(*size as usize)) { self.push_str(&a); self.push_str(", "); @@ -1220,7 +1222,11 @@ impl Bindgen for FunctionBindgen<'_, '_> { self.push_str("];\n"); results.push(result); } - Instruction::FixedSizeListLower { elements: _, size, id: _ } => { + Instruction::FixedSizeListLower { + elements: _, + 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 f338ec28a..c0f521fee 100644 --- a/crates/rust/src/interface.rs +++ b/crates/rust/src/interface.rs @@ -2919,10 +2919,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.print_ty( + ty, + TypeMode { + lifetime: None, + lists_borrowed: false, + style: TypeOwnershipStyle::Owned, + }, + ); self.interface.push_str(&format!(", {size}]")); } } From c70113ec8cafd709b85ca290c7633fee32cf337a Mon Sep 17 00:00:00 2001 From: Christof Petig Date: Sun, 20 Apr 2025 14:32:33 +0200 Subject: [PATCH 04/10] test passes with modified wasmtime --- Cargo.lock | 461 ++++++++++++++++++++---- crates/c/src/lib.rs | 10 +- crates/core/src/abi.rs | 15 +- crates/rust/src/bindgen.rs | 2 +- crates/rust/src/interface.rs | 2 +- crates/test/Cargo.toml | 6 +- tests/runtime/fixed-size-list/runner.rs | 4 +- tests/runtime/fixed-size-list/test.rs | 5 +- tests/runtime/fixed-size-list/test.wit | 14 +- 9 files changed, 422 insertions(+), 97 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 389a616de..bebc4a44b 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.97" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dcfed56ad506cb2c684a14971b8861fdc3baaaae314b9e5f9bb532cbe3ba7a4f" +[[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 = "autocfg" version = "1.4.0" @@ -161,6 +179,15 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" +[[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" @@ -186,6 +213,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" @@ -237,6 +275,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" @@ -249,6 +297,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" @@ -360,12 +417,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" @@ -433,12 +629,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" @@ -457,6 +647,12 @@ version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fe7db12097d22ec582439daf8618b8fdd1a7bef6270e9af3b1ebcd30893cf413" +[[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" @@ -526,12 +722,27 @@ 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.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2806eaa3524762875e21c3dcd057bc4b7bfa01ce4da8d46be1cd43649e1cc6b" +[[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" @@ -788,6 +999,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" @@ -805,6 +1022,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" @@ -820,7 +1048,7 @@ name = "test-helpers" version = "0.0.0" dependencies = [ "codegen-macro", - "wasm-encoder 0.230.0", + "wasm-encoder", "wit-bindgen-core", "wit-component", "wit-parser", @@ -846,6 +1074,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.20" @@ -880,6 +1118,12 @@ dependencies = [ "winnow", ] +[[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" @@ -922,6 +1166,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" @@ -936,9 +1203,7 @@ 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" dependencies = [ "anyhow", "id-arena", @@ -948,16 +1213,14 @@ 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" dependencies = [ "anyhow", "id-arena", @@ -969,23 +1232,21 @@ 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" dependencies = [ "anyhow", "id-arena", "indexmap", "semver", - "wasm-encoder 0.202.0", - "wasmparser 0.202.0", + "wasm-encoder", + "wasmparser", ] [[package]] @@ -1010,20 +1271,11 @@ dependencies = [ "serde_derive", "serde_yaml", "smallvec", - "wasm-encoder 0.230.0", - "wasmparser 0.230.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.230.0" @@ -1031,46 +1283,26 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4349d0943718e6e434b51b9639e876293093dca4b96384fb136ab5bd5ce6660" dependencies = [ "leb128fmt", - "wasmparser 0.230.0", + "wasmparser", ] [[package]] name = "wasm-metadata" -version = "0.202.0" +version = "0.230.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "094aea3cb90e09f16ee25a4c0e324b3e8c934e7fd838bfa039aef5352f44a917" +checksum = "1a52e010df5494f4289ccc68ce0c2a8c17555225a5e55cc41b98f5ea28d0844b" 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.230.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a52e010df5494f4289ccc68ce0c2a8c17555225a5e55cc41b98f5ea28d0844b" -dependencies = [ - "anyhow", - "indexmap", - "wasm-encoder 0.230.0", - "wasmparser 0.230.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]] @@ -1096,7 +1328,7 @@ dependencies = [ "leb128fmt", "memchr", "unicode-width 0.2.0", - "wasm-encoder 0.230.0", + "wasm-encoder", ] [[package]] @@ -1206,8 +1438,8 @@ dependencies = [ "clap", "heck 0.5.0", "indexmap", - "wasm-encoder 0.230.0", - "wasm-metadata 0.230.0", + "wasm-encoder", + "wasm-metadata", "wit-bindgen-core", "wit-component", ] @@ -1219,7 +1451,7 @@ dependencies = [ "anyhow", "clap", "env_logger", - "wasm-encoder 0.230.0", + "wasm-encoder", "wit-bindgen-c", "wit-bindgen-core", "wit-bindgen-csharp", @@ -1249,7 +1481,7 @@ dependencies = [ "clap", "heck 0.5.0", "indexmap", - "wasm-metadata 0.230.0", + "wasm-metadata", "wit-bindgen-core", "wit-component", "wit-parser", @@ -1299,7 +1531,7 @@ dependencies = [ "serde_json", "syn", "test-helpers", - "wasm-metadata 0.230.0", + "wasm-metadata", "wit-bindgen", "wit-bindgen-core", "wit-bindgen-rt", @@ -1337,8 +1569,8 @@ dependencies = [ "wac-types", "wasi-preview1-component-adapter-provider", "wasm-compose", - "wasm-encoder 0.230.0", - "wasmparser 0.230.0", + "wasm-encoder", + "wasmparser", "wat", "wit-bindgen-csharp", "wit-component", @@ -1358,9 +1590,9 @@ dependencies = [ "serde", "serde_derive", "serde_json", - "wasm-encoder 0.230.0", - "wasm-metadata 0.230.0", - "wasmparser 0.230.0", + "wasm-encoder", + "wasm-metadata", + "wasmparser", "wat", "wit-parser", ] @@ -1380,5 +1612,84 @@ dependencies = [ "serde_derive", "serde_json", "unicode-xid", - "wasmparser 0.230.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 a9997f470..598b880de 100644 --- a/crates/c/src/lib.rs +++ b/crates/c/src/lib.rs @@ -1665,8 +1665,14 @@ 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) { + + fn anonymous_type_fixed_size_list( + &mut self, + _id: TypeId, + _ty: &Type, + _size: u32, + _docs: &Docs, + ) { todo!("print_anonymous_type for fixed size list"); } } diff --git a/crates/core/src/abi.rs b/crates/core/src/abi.rs index 9abbe9f89..20a38e1a9 100644 --- a/crates/core/src/abi.rs +++ b/crates/core/src/abi.rs @@ -1779,12 +1779,15 @@ impl<'a, B: Bindgen> Generator<'a, B> { TypeDefKind::Unknown => unreachable!(), TypeDefKind::FixedSizeList(ty, size) => { - let increment = self.bindgen.sizes().size(ty); - let mut position = offset; - for _ in 0..*size { - self.write_to_memory(ty, addr.clone(), position); - position = position + increment; - } + // let increment = self.bindgen.sizes().size(ty); + // let mut position = offset; + // let resultvar = self.stack[0]; + // for _ in 0..*size { + // // push index + // self.stack.push("", ); + // self.write_to_memory(ty, addr.clone(), position); + // position = position + increment; + // } self.emit(&FixedSizeListLower { elements: ty, size: *size, diff --git a/crates/rust/src/bindgen.rs b/crates/rust/src/bindgen.rs index 0ce6e1fa3..816bd6293 100644 --- a/crates/rust/src/bindgen.rs +++ b/crates/rust/src/bindgen.rs @@ -1214,7 +1214,7 @@ impl Bindgen for FunctionBindgen<'_, '_> { } => { let tmp = self.tmp(); let result = format!("result{tmp}"); - self.push_str(&format!("let mut {result} = [",)); + self.push_str(&format!("let {result} = [",)); for a in operands.drain(0..(*size as usize)) { self.push_str(&a); self.push_str(", "); diff --git a/crates/rust/src/interface.rs b/crates/rust/src/interface.rs index c0f521fee..bb4df8fb3 100644 --- a/crates/rust/src/interface.rs +++ b/crates/rust/src/interface.rs @@ -2930,6 +2930,6 @@ impl<'a, 'b> wit_bindgen_core::AnonymousTypeGenerator<'a> for AnonTypeGenerator< style: TypeOwnershipStyle::Owned, }, ); - self.interface.push_str(&format!(", {size}]")); + self.interface.push_str(&format!("; {size}]")); } } diff --git a/crates/test/Cargo.toml b/crates/test/Cargo.toml index f5df48a09..6a6ce708e 100644 --- a/crates/test/Cargo.toml +++ b/crates/test/Cargo.toml @@ -24,9 +24,9 @@ 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" +wac-parser = { path = "../../../wac/crates/wac-parser" } +wac-types = { path = "../../../wac/crates/wac-types" } +wac-graph = { path = "../../../wac/crates/wac-graph" } 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 index c0e587f9c..97b7d1bbc 100644 --- a/tests/runtime/fixed-size-list/runner.rs +++ b/tests/runtime/fixed-size-list/runner.rs @@ -1,6 +1,8 @@ include!(env!("BINDINGS")); -use test::lists::to_test::*; +use test::fixed_size_lists::to_test::*; fn main() { + list_param([1,2,3,4]); + list_param2([[1,2],[3,4]]); } diff --git a/tests/runtime/fixed-size-list/test.rs b/tests/runtime/fixed-size-list/test.rs index 58794dfa2..27fd86b22 100644 --- a/tests/runtime/fixed-size-list/test.rs +++ b/tests/runtime/fixed-size-list/test.rs @@ -4,5 +4,8 @@ struct Component; export!(Component); -impl exports::test::lists::to_test::Guest for Component { +impl exports::test::fixed_size_lists::to_test::Guest for Component { + fn list_param(_a: [u32; 4]) {} + fn list_param2(_a: [[u32; 2]; 2]) {} + // fn list_param3(_a: [i32; 20]) {} } diff --git a/tests/runtime/fixed-size-list/test.wit b/tests/runtime/fixed-size-list/test.wit index f6280c809..6e71e900d 100644 --- a/tests/runtime/fixed-size-list/test.wit +++ b/tests/runtime/fixed-size-list/test.wit @@ -1,16 +1,16 @@ -package test:lists; +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-param3: func(a: list);s + //list-result: func() -> list; - list-minmax16: func(a: list, b: list) -> tuple, list>; - list-minmax-float: func(a: list, b: list) - -> tuple, 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; + // list-roundtrip: func(a: list) -> list; } world test { From 0d579818db081b96e9a46495c89aaebfb3b09b01 Mon Sep 17 00:00:00 2001 From: Christof Petig Date: Sun, 20 Apr 2025 16:15:49 +0200 Subject: [PATCH 05/10] document and compare test --- tests/runtime/fixed-size-list/runner.rs | 4 ++-- tests/runtime/fixed-size-list/test.rs | 8 ++++++-- tests/runtime/fixed-size-list/test.wit | 2 ++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/runtime/fixed-size-list/runner.rs b/tests/runtime/fixed-size-list/runner.rs index 97b7d1bbc..d31e0c327 100644 --- a/tests/runtime/fixed-size-list/runner.rs +++ b/tests/runtime/fixed-size-list/runner.rs @@ -3,6 +3,6 @@ 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_param([1, 2, 3, 4]); + list_param2([[1, 2], [3, 4]]); } diff --git a/tests/runtime/fixed-size-list/test.rs b/tests/runtime/fixed-size-list/test.rs index 27fd86b22..4b66e9850 100644 --- a/tests/runtime/fixed-size-list/test.rs +++ b/tests/runtime/fixed-size-list/test.rs @@ -5,7 +5,11 @@ struct Component; export!(Component); impl exports::test::fixed_size_lists::to_test::Guest for Component { - fn list_param(_a: [u32; 4]) {} - fn list_param2(_a: [[u32; 2]; 2]) {} + 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]) {} } diff --git a/tests/runtime/fixed-size-list/test.wit b/tests/runtime/fixed-size-list/test.wit index 6e71e900d..c344b7f86 100644 --- a/tests/runtime/fixed-size-list/test.wit +++ b/tests/runtime/fixed-size-list/test.wit @@ -1,3 +1,5 @@ +// run with "--runner wasmtime -W component-model-fixed-size-list" + package test:fixed-size-lists; interface to-test { From 6cbbad61bf1b7380ed77d9228bf6fa7bdc6068b2 Mon Sep 17 00:00:00 2001 From: Christof Petig Date: Sun, 20 Apr 2025 21:13:51 +0200 Subject: [PATCH 06/10] returning a fixed size list works --- crates/core/src/abi.rs | 47 +++++++++++++++++++------ crates/csharp/src/function.rs | 1 + crates/moonbit/src/lib.rs | 1 + crates/rust/src/bindgen.rs | 25 +++++++++++-- tests/runtime/fixed-size-list/runner.rs | 8 +++-- tests/runtime/fixed-size-list/test.rs | 15 ++++---- tests/runtime/fixed-size-list/test.wit | 6 ++-- 7 files changed, 79 insertions(+), 24 deletions(-) diff --git a/crates/core/src/abi.rs b/crates/core/src/abi.rs index 20a38e1a9..2ebc1a4d6 100644 --- a/crates/core/src/abi.rs +++ b/crates/core/src/abi.rs @@ -310,18 +310,25 @@ def_instruction! { /// Pops all fields for a fixed list off the stack and then composes them /// into an array. FixedSizeListLift { - elements: &'a Type, + 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 { - elements: &'a Type, + 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 + FixedSizeListLowerBlock { + 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. /// @@ -1403,7 +1410,7 @@ impl<'a, B: Bindgen> Generator<'a, B> { TypeDefKind::Unknown => unreachable!(), TypeDefKind::FixedSizeList(ty, size) => { self.emit(&FixedSizeListLower { - elements: ty, + element: ty, size: *size, id, }); @@ -1616,7 +1623,7 @@ impl<'a, B: Bindgen> Generator<'a, B> { self.lift(ty); } self.emit(&FixedSizeListLift { - elements: ty, + element: ty, size: *size, id, }); @@ -1778,7 +1785,7 @@ impl<'a, B: Bindgen> Generator<'a, B> { } TypeDefKind::Unknown => unreachable!(), - TypeDefKind::FixedSizeList(ty, size) => { + TypeDefKind::FixedSizeList(element, size) => { // let increment = self.bindgen.sizes().size(ty); // let mut position = offset; // let resultvar = self.stack[0]; @@ -1788,11 +1795,29 @@ impl<'a, B: Bindgen> Generator<'a, B> { // self.write_to_memory(ty, addr.clone(), position); // position = position + increment; // } - self.emit(&FixedSizeListLower { - elements: ty, - size: *size, - id, - }); + // @@@@ + // self.emit(&FixedSizeListLower { + // elements: ty, + // size: *size, + // id, + // }); + + // 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, Default::default()); + self.finish_block(0); + // let target = self.stack.pop().unwrap(); + self.stack.push(addr); + self.emit(&FixedSizeListLowerBlock { element, size: *size, id }); + + // for idx in 0..*size { + // //self.write_fields_to_memory(tuple.types.iter(), addr, offset); + // self.emit(&FixedSizeListLowerElement { elements: ty, idx, }); + // self.write_to_memory(ty, addr.clone(), offset + (field_offset)); + // } } }, } @@ -1988,7 +2013,7 @@ impl<'a, B: Bindgen> Generator<'a, B> { position = position + increment; } self.emit(&FixedSizeListLift { - elements: ty, + element: ty, size: *size, id, }); diff --git a/crates/csharp/src/function.rs b/crates/csharp/src/function.rs index a28b96521..93c552f9d 100644 --- a/crates/csharp/src/function.rs +++ b/crates/csharp/src/function.rs @@ -1267,6 +1267,7 @@ impl Bindgen for FunctionBindgen<'_, '_> { => todo!(), Instruction::FixedSizeListLift { .. } => todo!(), Instruction::FixedSizeListLower { .. } => todo!(), + Instruction::FixedSizeListLowerBlock { .. } => todo!(), } } diff --git a/crates/moonbit/src/lib.rs b/crates/moonbit/src/lib.rs index f873b2dce..fa8eedb1b 100644 --- a/crates/moonbit/src/lib.rs +++ b/crates/moonbit/src/lib.rs @@ -2670,6 +2670,7 @@ impl Bindgen for FunctionBindgen<'_, '_> { | Instruction::DropHandle { .. } => todo!(), Instruction::FixedSizeListLift { .. } => todo!(), Instruction::FixedSizeListLower { .. } => todo!(), + Instruction::FixedSizeListLowerBlock { .. } => todo!(), } } diff --git a/crates/rust/src/bindgen.rs b/crates/rust/src/bindgen.rs index 816bd6293..68448b260 100644 --- a/crates/rust/src/bindgen.rs +++ b/crates/rust/src/bindgen.rs @@ -797,6 +797,27 @@ impl Bindgen for FunctionBindgen<'_, '_> { results.push(len); } + Instruction::FixedSizeListLowerBlock { element, size: _, id: _ } => { + let body = self.blocks.pop().unwrap(); + // let tmp = self.tmp(); + let vec = operands[0].clone(); + //format!("vec{tmp}"); + // self.push_str(&format!( + // "let {vec} = {operand0};\n", + // operand0 = operands[0] + // )); + let size = self.r#gen.sizes.size(element); + let target = operands[1].clone(); + // let align = self.r#gen.sizes.align(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(); @@ -1208,7 +1229,7 @@ impl Bindgen for FunctionBindgen<'_, '_> { uwriteln!(self.src, "let _ = {};", operands[0]); } Instruction::FixedSizeListLift { - elements: _, + element: _, size, id: _, } => { @@ -1223,7 +1244,7 @@ impl Bindgen for FunctionBindgen<'_, '_> { results.push(result); } Instruction::FixedSizeListLower { - elements: _, + element: _, size, id: _, } => { diff --git a/tests/runtime/fixed-size-list/runner.rs b/tests/runtime/fixed-size-list/runner.rs index d31e0c327..7850a13db 100644 --- a/tests/runtime/fixed-size-list/runner.rs +++ b/tests/runtime/fixed-size-list/runner.rs @@ -3,6 +3,10 @@ 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_param([1, 2, 3, 4]); + // list_param2([[1, 2], [3, 4]]); + { + let result = list_result(); + assert_eq!(result, [b'0', b'1', b'A', b'B', b'a', b'b', 128, 255]); + } } diff --git a/tests/runtime/fixed-size-list/test.rs b/tests/runtime/fixed-size-list/test.rs index 4b66e9850..c5ddb7bbe 100644 --- a/tests/runtime/fixed-size-list/test.rs +++ b/tests/runtime/fixed-size-list/test.rs @@ -5,11 +5,14 @@ struct Component; export!(Component); 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_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]) {} + fn list_result() -> [u8; 8] { + [b'0', b'1', b'A', b'B', b'a', b'b', 128, 255] + } } diff --git a/tests/runtime/fixed-size-list/test.wit b/tests/runtime/fixed-size-list/test.wit index c344b7f86..f4663ab79 100644 --- a/tests/runtime/fixed-size-list/test.wit +++ b/tests/runtime/fixed-size-list/test.wit @@ -3,10 +3,10 @@ package test:fixed-size-lists; interface to-test { - list-param: func(a: list); - list-param2: func(a: list, 2>); + // list-param: func(a: list); + // list-param2: func(a: list, 2>); // list-param3: func(a: list);s - //list-result: func() -> list; + list-result: func() -> list; // list-minmax16: func(a: list, b: list) -> tuple, list>; // list-minmax-float: func(a: list, b: list) From a9ea6b0b459c019c992205b85fd25606e89747aa Mon Sep 17 00:00:00 2001 From: Christof Petig Date: Sun, 20 Apr 2025 21:15:27 +0200 Subject: [PATCH 07/10] re-enable normal parameters --- tests/runtime/fixed-size-list/runner.rs | 4 ++-- tests/runtime/fixed-size-list/test.rs | 12 ++++++------ tests/runtime/fixed-size-list/test.wit | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/runtime/fixed-size-list/runner.rs b/tests/runtime/fixed-size-list/runner.rs index 7850a13db..5a41b6f5b 100644 --- a/tests/runtime/fixed-size-list/runner.rs +++ b/tests/runtime/fixed-size-list/runner.rs @@ -3,8 +3,8 @@ 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_param([1, 2, 3, 4]); + list_param2([[1, 2], [3, 4]]); { let result = list_result(); assert_eq!(result, [b'0', b'1', b'A', b'B', b'a', b'b', 128, 255]); diff --git a/tests/runtime/fixed-size-list/test.rs b/tests/runtime/fixed-size-list/test.rs index c5ddb7bbe..b49870610 100644 --- a/tests/runtime/fixed-size-list/test.rs +++ b/tests/runtime/fixed-size-list/test.rs @@ -5,12 +5,12 @@ struct Component; export!(Component); 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_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]) {} fn list_result() -> [u8; 8] { [b'0', b'1', b'A', b'B', b'a', b'b', 128, 255] diff --git a/tests/runtime/fixed-size-list/test.wit b/tests/runtime/fixed-size-list/test.wit index f4663ab79..0c358ee4e 100644 --- a/tests/runtime/fixed-size-list/test.wit +++ b/tests/runtime/fixed-size-list/test.wit @@ -3,8 +3,8 @@ package test:fixed-size-lists; interface to-test { - // list-param: func(a: list); - // list-param2: func(a: list, 2>); + list-param: func(a: list); + list-param2: func(a: list, 2>); // list-param3: func(a: list);s list-result: func() -> list; From 6c94bf2ff7a0c3f9244c52cf20d071f0d50ffba9 Mon Sep 17 00:00:00 2001 From: Christof Petig Date: Sun, 20 Apr 2025 21:26:46 +0200 Subject: [PATCH 08/10] clean up and use wac fork --- Cargo.lock | 206 ++++++++++++------------------------- crates/core/src/abi.rs | 25 +---- crates/rust/src/bindgen.rs | 9 +- crates/test/Cargo.toml | 7 +- 4 files changed, 72 insertions(+), 175 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bebc4a44b..57be3cea3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -103,15 +103,6 @@ version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c8214115b7bf84099f1309324e63141d4c5d7cc26862f97a0a857dbefe165bd" -[[package]] -name = "bitmaps" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "031043d04099746d8db04daf1fa424b2bc8bd69d92b25962dcde24da39ab64a2" -dependencies = [ - "typenum", -] - [[package]] name = "bumpalo" version = "3.17.0" @@ -153,7 +144,7 @@ version = "4.5.32" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09176aae279615badda0765c0c0b3f6ed53f4709118af73cf4655d85d1530cd7" dependencies = [ - "heck 0.5.0", + "heck", "proc-macro2", "quote", "syn", @@ -169,7 +160,7 @@ checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6" name = "codegen-macro" version = "0.0.0" dependencies = [ - "heck 0.5.0", + "heck", "quote", ] @@ -405,12 +396,6 @@ dependencies = [ "serde", ] -[[package]] -name = "heck" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" - [[package]] name = "heck" version = "0.5.0" @@ -562,20 +547,6 @@ dependencies = [ "icu_properties", ] -[[package]] -name = "im-rc" -version = "15.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af1955a75fa080c677d3972822ec4bad316169ab1cfc6c257a942c2265dbe5fe" -dependencies = [ - "bitmaps", - "rand_core", - "rand_xoshiro", - "sized-chunks", - "typenum", - "version_check", -] - [[package]] name = "indexmap" version = "2.8.0" @@ -819,21 +790,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "rand_core" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" - -[[package]] -name = "rand_xoshiro" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f97cdb2a36ed4183de61b2f824cc45c9f1037f28afe0a322e9fff4c108b5aaa" -dependencies = [ - "rand_core", -] - [[package]] name = "rayon" version = "1.10.0" @@ -952,29 +908,6 @@ dependencies = [ "serde", ] -[[package]] -name = "serde_yaml" -version = "0.9.34+deprecated" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47" -dependencies = [ - "indexmap", - "itoa", - "ryu", - "serde", - "unsafe-libyaml", -] - -[[package]] -name = "sized-chunks" -version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16d69225bde7a69b235da73377861095455d298f2b970996eec25ddbb42b3d1e" -dependencies = [ - "bitmaps", - "typenum", -] - [[package]] name = "slab" version = "0.4.9" @@ -1048,7 +981,7 @@ name = "test-helpers" version = "0.0.0" dependencies = [ "codegen-macro", - "wasm-encoder", + "wasm-encoder 0.230.0", "wit-bindgen-core", "wit-component", "wit-parser", @@ -1124,12 +1057,6 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ea68304e134ecd095ac6c3574494fc62b909f416c4fca77e440530221e549d3d" -[[package]] -name = "typenum" -version = "1.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dccffe3ce07af9386bfd29e80c0ab1a8205a2fc34e4bcd40364df902cfa8f3f" - [[package]] name = "unicase" version = "2.8.1" @@ -1160,12 +1087,6 @@ version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" -[[package]] -name = "unsafe-libyaml" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861" - [[package]] name = "url" version = "2.5.4" @@ -1195,15 +1116,10 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" -[[package]] -name = "version_check" -version = "0.9.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" - [[package]] name = "wac-graph" version = "0.7.0-dev" +source = "git+https://github.com/cpetig/wac?branch=fixed-size-lists#3d6c1a0283519b46c72d30c521bca41fb3496847" dependencies = [ "anyhow", "id-arena", @@ -1213,14 +1129,15 @@ dependencies = [ "semver", "thiserror", "wac-types", - "wasm-encoder", - "wasm-metadata", - "wasmparser", + "wasm-encoder 0.229.0", + "wasm-metadata 0.229.0", + "wasmparser 0.229.0", ] [[package]] name = "wac-parser" version = "0.7.0-dev" +source = "git+https://github.com/cpetig/wac?branch=fixed-size-lists#3d6c1a0283519b46c72d30c521bca41fb3496847" dependencies = [ "anyhow", "id-arena", @@ -1232,21 +1149,22 @@ dependencies = [ "serde", "thiserror", "wac-graph", - "wasm-encoder", - "wasm-metadata", - "wasmparser", + "wasm-encoder 0.229.0", + "wasm-metadata 0.229.0", + "wasmparser 0.229.0", ] [[package]] name = "wac-types" version = "0.7.0-dev" +source = "git+https://github.com/cpetig/wac?branch=fixed-size-lists#3d6c1a0283519b46c72d30c521bca41fb3496847" dependencies = [ "anyhow", "id-arena", "indexmap", "semver", - "wasm-encoder", - "wasmparser", + "wasm-encoder 0.229.0", + "wasmparser 0.229.0", ] [[package]] @@ -1256,24 +1174,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ddbd7f2a9e3635abe5d4df93b12cadc8d6818079785ee4fab3719ae3c85a064e" [[package]] -name = "wasm-compose" -version = "0.230.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3efe9b91ee8d09c6696e448d756a207c290deb6af2e92df6acfd8bbde3bb7f70" +name = "wasm-encoder" +version = "0.229.0" +source = "git+https://github.com/cpetig/wasm-tools?branch=fixed-length-list#9669555dd2656a5a12710682812de12c3e82da04" dependencies = [ - "anyhow", - "heck 0.4.1", - "im-rc", - "indexmap", - "log", - "petgraph", - "serde", - "serde_derive", - "serde_yaml", - "smallvec", - "wasm-encoder", - "wasmparser", - "wat", + "leb128fmt", + "wasmparser 0.229.0", ] [[package]] @@ -1283,14 +1189,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4349d0943718e6e434b51b9639e876293093dca4b96384fb136ab5bd5ce6660" dependencies = [ "leb128fmt", - "wasmparser", + "wasmparser 0.230.0", ] [[package]] name = "wasm-metadata" -version = "0.230.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a52e010df5494f4289ccc68ce0c2a8c17555225a5e55cc41b98f5ea28d0844b" +version = "0.229.0" +source = "git+https://github.com/cpetig/wasm-tools?branch=fixed-length-list#9669555dd2656a5a12710682812de12c3e82da04" dependencies = [ "anyhow", "auditable-serde", @@ -1301,8 +1206,32 @@ dependencies = [ "serde_json", "spdx", "url", - "wasm-encoder", - "wasmparser", + "wasm-encoder 0.229.0", + "wasmparser 0.229.0", +] + +[[package]] +name = "wasm-metadata" +version = "0.230.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a52e010df5494f4289ccc68ce0c2a8c17555225a5e55cc41b98f5ea28d0844b" +dependencies = [ + "anyhow", + "indexmap", + "wasm-encoder 0.230.0", + "wasmparser 0.230.0", +] + +[[package]] +name = "wasmparser" +version = "0.229.0" +source = "git+https://github.com/cpetig/wasm-tools?branch=fixed-length-list#9669555dd2656a5a12710682812de12c3e82da04" +dependencies = [ + "bitflags", + "hashbrown", + "indexmap", + "semver", + "serde", ] [[package]] @@ -1328,7 +1257,7 @@ dependencies = [ "leb128fmt", "memchr", "unicode-width 0.2.0", - "wasm-encoder", + "wasm-encoder 0.230.0", ] [[package]] @@ -1436,10 +1365,10 @@ version = "0.42.1" dependencies = [ "anyhow", "clap", - "heck 0.5.0", + "heck", "indexmap", - "wasm-encoder", - "wasm-metadata", + "wasm-encoder 0.230.0", + "wasm-metadata 0.230.0", "wit-bindgen-core", "wit-component", ] @@ -1451,7 +1380,7 @@ dependencies = [ "anyhow", "clap", "env_logger", - "wasm-encoder", + "wasm-encoder 0.230.0", "wit-bindgen-c", "wit-bindgen-core", "wit-bindgen-csharp", @@ -1468,7 +1397,7 @@ version = "0.42.1" dependencies = [ "anyhow", "clap", - "heck 0.5.0", + "heck", "serde", "wit-parser", ] @@ -1479,9 +1408,9 @@ version = "0.42.1" dependencies = [ "anyhow", "clap", - "heck 0.5.0", + "heck", "indexmap", - "wasm-metadata", + "wasm-metadata 0.230.0", "wit-bindgen-core", "wit-component", "wit-parser", @@ -1493,7 +1422,7 @@ version = "0.42.1" dependencies = [ "anyhow", "clap", - "heck 0.5.0", + "heck", "pulldown-cmark", "wit-bindgen-core", ] @@ -1504,7 +1433,7 @@ version = "0.42.1" dependencies = [ "anyhow", "clap", - "heck 0.5.0", + "heck", "wit-bindgen-core", ] @@ -1524,14 +1453,14 @@ dependencies = [ "anyhow", "clap", "futures", - "heck 0.5.0", + "heck", "indexmap", "prettyplease", "serde", "serde_json", "syn", "test-helpers", - "wasm-metadata", + "wasm-metadata 0.230.0", "wit-bindgen", "wit-bindgen-core", "wit-bindgen-rt", @@ -1557,7 +1486,7 @@ version = "0.42.1" dependencies = [ "anyhow", "clap", - "heck 0.5.0", + "heck", "indexmap", "log", "rayon", @@ -1568,9 +1497,8 @@ dependencies = [ "wac-parser", "wac-types", "wasi-preview1-component-adapter-provider", - "wasm-compose", - "wasm-encoder", - "wasmparser", + "wasm-encoder 0.230.0", + "wasmparser 0.230.0", "wat", "wit-bindgen-csharp", "wit-component", @@ -1590,9 +1518,9 @@ dependencies = [ "serde", "serde_derive", "serde_json", - "wasm-encoder", - "wasm-metadata", - "wasmparser", + "wasm-encoder 0.230.0", + "wasm-metadata 0.230.0", + "wasmparser 0.230.0", "wat", "wit-parser", ] @@ -1612,7 +1540,7 @@ dependencies = [ "serde_derive", "serde_json", "unicode-xid", - "wasmparser", + "wasmparser 0.230.0", ] [[package]] diff --git a/crates/core/src/abi.rs b/crates/core/src/abi.rs index 2ebc1a4d6..235f20316 100644 --- a/crates/core/src/abi.rs +++ b/crates/core/src/abi.rs @@ -322,7 +322,7 @@ def_instruction! { id: TypeId, } : [1] => [*size as usize], - /// Pops an array and an address off the stack, passes each element to a block + /// Pops an array and an address off the stack, passes each element to a block storing it FixedSizeListLowerBlock { element: &'a Type, size: u32, @@ -1786,22 +1786,6 @@ impl<'a, B: Bindgen> Generator<'a, B> { TypeDefKind::Unknown => unreachable!(), TypeDefKind::FixedSizeList(element, size) => { - // let increment = self.bindgen.sizes().size(ty); - // let mut position = offset; - // let resultvar = self.stack[0]; - // for _ in 0..*size { - // // push index - // self.stack.push("", ); - // self.write_to_memory(ty, addr.clone(), position); - // position = position + increment; - // } - // @@@@ - // self.emit(&FixedSizeListLower { - // elements: ty, - // size: *size, - // id, - // }); - // resembles write_list_to_memory self.push_block(); self.emit(&IterElem { element }); @@ -1809,15 +1793,8 @@ impl<'a, B: Bindgen> Generator<'a, B> { let elem_addr = self.stack.pop().unwrap(); self.write_to_memory(element, elem_addr, Default::default()); self.finish_block(0); - // let target = self.stack.pop().unwrap(); self.stack.push(addr); self.emit(&FixedSizeListLowerBlock { element, size: *size, id }); - - // for idx in 0..*size { - // //self.write_fields_to_memory(tuple.types.iter(), addr, offset); - // self.emit(&FixedSizeListLowerElement { elements: ty, idx, }); - // self.write_to_memory(ty, addr.clone(), offset + (field_offset)); - // } } }, } diff --git a/crates/rust/src/bindgen.rs b/crates/rust/src/bindgen.rs index 68448b260..8c1d17d36 100644 --- a/crates/rust/src/bindgen.rs +++ b/crates/rust/src/bindgen.rs @@ -799,16 +799,9 @@ impl Bindgen for FunctionBindgen<'_, '_> { Instruction::FixedSizeListLowerBlock { element, size: _, id: _ } => { let body = self.blocks.pop().unwrap(); - // let tmp = self.tmp(); let vec = operands[0].clone(); - //format!("vec{tmp}"); - // self.push_str(&format!( - // "let {vec} = {operand0};\n", - // operand0 = operands[0] - // )); - let size = self.r#gen.sizes.size(element); let target = operands[1].clone(); - // let align = self.r#gen.sizes.align(element); + 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", diff --git a/crates/test/Cargo.toml b/crates/test/Cargo.toml index 6a6ce708e..9d76f6498 100644 --- a/crates/test/Cargo.toml +++ b/crates/test/Cargo.toml @@ -24,10 +24,9 @@ regex = "1.11.1" serde = { workspace = true } toml = "0.8.20" wasi-preview1-component-adapter-provider = "30.0.2" -wac-parser = { path = "../../../wac/crates/wac-parser" } -wac-types = { path = "../../../wac/crates/wac-types" } -wac-graph = { path = "../../../wac/crates/wac-graph" } -wasm-compose = { workspace = true } +wac-parser = { git = "https://github.com/cpetig/wac", branch = "fixed-size-lists" } +wac-types = { git = "https://github.com/cpetig/wac", branch = "fixed-size-lists" } +wac-graph = { git = "https://github.com/cpetig/wac", branch = "fixed-size-lists" } indexmap = { workspace = true } wasm-encoder = { workspace = true } wasmparser = { workspace = true, features = ["features"] } From 8e4235eb5272bb1b6c32124ed34cc4f7490c6e55 Mon Sep 17 00:00:00 2001 From: Christof Petig Date: Sun, 20 Apr 2025 21:52:47 +0200 Subject: [PATCH 09/10] another testcase passing --- crates/core/src/abi.rs | 6 +++++- crates/rust/src/bindgen.rs | 6 +++++- tests/runtime/fixed-size-list/runner.rs | 3 +++ tests/runtime/fixed-size-list/test.rs | 7 ++++++- tests/runtime/fixed-size-list/test.wit | 2 +- 5 files changed, 20 insertions(+), 4 deletions(-) diff --git a/crates/core/src/abi.rs b/crates/core/src/abi.rs index 235f20316..0908dce3a 100644 --- a/crates/core/src/abi.rs +++ b/crates/core/src/abi.rs @@ -1794,7 +1794,11 @@ impl<'a, B: Bindgen> Generator<'a, B> { self.write_to_memory(element, elem_addr, Default::default()); self.finish_block(0); self.stack.push(addr); - self.emit(&FixedSizeListLowerBlock { element, size: *size, id }); + self.emit(&FixedSizeListLowerBlock { + element, + size: *size, + id, + }); } }, } diff --git a/crates/rust/src/bindgen.rs b/crates/rust/src/bindgen.rs index 8c1d17d36..3f4704657 100644 --- a/crates/rust/src/bindgen.rs +++ b/crates/rust/src/bindgen.rs @@ -797,7 +797,11 @@ impl Bindgen for FunctionBindgen<'_, '_> { results.push(len); } - Instruction::FixedSizeListLowerBlock { element, size: _, id: _ } => { + Instruction::FixedSizeListLowerBlock { + element, + size: _, + id: _, + } => { let body = self.blocks.pop().unwrap(); let vec = operands[0].clone(); let target = operands[1].clone(); diff --git a/tests/runtime/fixed-size-list/runner.rs b/tests/runtime/fixed-size-list/runner.rs index 5a41b6f5b..37457ef86 100644 --- a/tests/runtime/fixed-size-list/runner.rs +++ b/tests/runtime/fixed-size-list/runner.rs @@ -5,6 +5,9 @@ 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]); diff --git a/tests/runtime/fixed-size-list/test.rs b/tests/runtime/fixed-size-list/test.rs index b49870610..35d94631d 100644 --- a/tests/runtime/fixed-size-list/test.rs +++ b/tests/runtime/fixed-size-list/test.rs @@ -11,7 +11,12 @@ impl exports::test::fixed_size_lists::to_test::Guest for Component { fn list_param2(a: [[u32; 2]; 2]) { assert_eq!(a, [[1, 2], [3, 4]]); } - // fn list_param3(_a: [i32; 20]) {} + 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_result() -> [u8; 8] { [b'0', b'1', b'A', b'B', b'a', b'b', 128, 255] } diff --git a/tests/runtime/fixed-size-list/test.wit b/tests/runtime/fixed-size-list/test.wit index 0c358ee4e..3d8867922 100644 --- a/tests/runtime/fixed-size-list/test.wit +++ b/tests/runtime/fixed-size-list/test.wit @@ -5,7 +5,7 @@ package test:fixed-size-lists; interface to-test { list-param: func(a: list); list-param2: func(a: list, 2>); - // list-param3: func(a: list);s + list-param3: func(a: list); list-result: func() -> list; // list-minmax16: func(a: list, b: list) -> tuple, list>; From 0e17f59fc23c08aca781ab344e51da07632c65a2 Mon Sep 17 00:00:00 2001 From: Christof Petig Date: Sun, 20 Apr 2025 22:06:15 +0200 Subject: [PATCH 10/10] oh, two failing tests --- tests/runtime/fixed-size-list/runner.rs | 15 +++++++++++++++ tests/runtime/fixed-size-list/test.rs | 9 +++++++++ tests/runtime/fixed-size-list/test.wit | 8 ++++---- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/tests/runtime/fixed-size-list/runner.rs b/tests/runtime/fixed-size-list/runner.rs index 37457ef86..b1d356821 100644 --- a/tests/runtime/fixed-size-list/runner.rs +++ b/tests/runtime/fixed-size-list/runner.rs @@ -12,4 +12,19 @@ fn main() { 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'] + ); + } } diff --git a/tests/runtime/fixed-size-list/test.rs b/tests/runtime/fixed-size-list/test.rs index 35d94631d..930f70572 100644 --- a/tests/runtime/fixed-size-list/test.rs +++ b/tests/runtime/fixed-size-list/test.rs @@ -17,6 +17,15 @@ impl exports::test::fixed_size_lists::to_test::Guest for Component { [-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] } diff --git a/tests/runtime/fixed-size-list/test.wit b/tests/runtime/fixed-size-list/test.wit index 3d8867922..8da40dc3e 100644 --- a/tests/runtime/fixed-size-list/test.wit +++ b/tests/runtime/fixed-size-list/test.wit @@ -8,11 +8,11 @@ interface to-test { 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-minmax16: func(a: list, b: list) -> tuple, list>; + list-minmax-float: func(a: list, b: list) + -> tuple, list>; - // list-roundtrip: func(a: list) -> list; + list-roundtrip: func(a: list) -> list; } world test {