Skip to content

fix: support named fixed-length list types in code generation#1537

Open
sumleo wants to merge 1 commit intobytecodealliance:mainfrom
sumleo:fix/named-fixed-length-list
Open

fix: support named fixed-length list types in code generation#1537
sumleo wants to merge 1 commit intobytecodealliance:mainfrom
sumleo:fix/named-fixed-length-list

Conversation

@sumleo
Copy link
Contributor

@sumleo sumleo commented Feb 12, 2026

Summary

  • The define_type function in the core InterfaceGenerator trait had a todo!() for FixedLengthList, causing a panic when WIT files contained named fixed-length list types like type my-array = list<u32, 4>
  • Added type_fixed_length_list method to the InterfaceGenerator trait with a default implementation
  • Implemented it in the Rust backend following the type_list pattern, generating type aliases like pub type MyArray = [u32; 4];
  • Updated define_type dispatch to call the new method

Test plan

  • Added codegen test WIT file tests/codegen/named-fixed-length-list.wit with named fixed-length list types in both import and export positions
  • Added inline codegen test module in crates/rust/tests/codegen.rs verifying Rust codegen compiles
  • All existing workspace tests pass

@sumleo sumleo force-pushed the fix/named-fixed-length-list branch 2 times, most recently from b929b31 to 9bc1675 Compare February 12, 2026 13:42
Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Comment on lines 168 to 178
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")
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this default implementation be omitted and the todo! placed in bindings generators downstream that don't support this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

"#,
generate_all,
});
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be added to tests/codegen/*.wit?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@sumleo sumleo force-pushed the fix/named-fixed-length-list branch from 9bc1675 to de6a089 Compare February 12, 2026 16:30
Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Mind rebasing this as well to get this added to the merge queue?

@sumleo sumleo force-pushed the fix/named-fixed-length-list branch from de6a089 to f56e45a Compare February 12, 2026 23:54
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.
@sumleo sumleo force-pushed the fix/named-fixed-length-list branch from f56e45a to 41a75aa Compare February 13, 2026 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants