fix: support named fixed-length list types in code generation#1537
fix: support named fixed-length list types in code generation#1537sumleo wants to merge 1 commit intobytecodealliance:mainfrom
Conversation
b929b31 to
9bc1675
Compare
crates/core/src/lib.rs
Outdated
| fn type_fixed_length_list( | ||
| &mut self, | ||
| id: TypeId, | ||
| name: &str, | ||
| ty: &Type, | ||
| size: u32, | ||
| docs: &Docs, | ||
| ) { | ||
| let _ = (id, name, ty, size, docs); | ||
| todo!("named fixed-length list types are not yet supported in this backend") | ||
| } |
There was a problem hiding this comment.
Could this default implementation be omitted and the todo! placed in bindings generators downstream that don't support this?
There was a problem hiding this comment.
Done. Removed the default implementation and added explicit type_fixed_length_list to all backends:
- Rust: generates
pub type Name = [T; N];(already existed) - Go: generates
type Name = [N]Type - Markdown: delegates to
type_alias - Moonbit: no-op (maps to
FixedArray[T]natively) - C, C++, C#: explicit
todo!()with expected test failures
crates/rust/tests/codegen.rs
Outdated
| "#, | ||
| generate_all, | ||
| }); | ||
| } |
There was a problem hiding this comment.
Could this be added to tests/codegen/*.wit?
There was a problem hiding this comment.
Done. Moved the test to tests/codegen/named-fixed-length-list.wit and removed the inline version from crates/rust/tests/codegen.rs. Added expected failures in the test infrastructure for C, C++, and C# backends that don't yet support this.
9bc1675 to
de6a089
Compare
alexcrichton
left a comment
There was a problem hiding this comment.
Thanks! Mind rebasing this as well to get this added to the merge queue?
de6a089 to
f56e45a
Compare
The `define_type` function dispatches to `type_fixed_length_list` on the `InterfaceGenerator` trait for named fixed-length list types like `type my-array = list<u32, 4>`. This makes `type_fixed_length_list` a required trait method (no default) and adds implementations in all backends: - Rust: generates `pub type Name = [T; N];` - Go: generates `type Name = [N]Type` - Markdown: delegates to `type_alias` - Moonbit: no-op (maps to `FixedArray[T]` natively) - C, C++, C#: explicit `todo!()` (not yet supported) Also adds a shared codegen test in `tests/codegen/named-fixed-length-list.wit` with expected failures for backends that don't yet support this.
f56e45a to
41a75aa
Compare
Summary
define_typefunction in the coreInterfaceGeneratortrait had atodo!()forFixedLengthList, causing a panic when WIT files contained named fixed-length list types liketype my-array = list<u32, 4>type_fixed_length_listmethod to theInterfaceGeneratortrait with a default implementationtype_listpattern, generating type aliases likepub type MyArray = [u32; 4];define_typedispatch to call the new methodTest plan
tests/codegen/named-fixed-length-list.witwith named fixed-length list types in both import and export positionscrates/rust/tests/codegen.rsverifying Rust codegen compiles