Skip to content

Generate Rust type nodes#103

Merged
lorisleiva merged 1 commit into
mainfrom
loris/spec-gen-type-nodes
Jun 10, 2026
Merged

Generate Rust type nodes#103
lorisleiva merged 1 commit into
mainfrom
loris/spec-gen-type-nodes

Conversation

@lorisleiva

Copy link
Copy Markdown
Member

This PR generates 21 of the 28 type-category nodes from @codama/spec, completing first-class generation support for all 8 spec categories. The 7 nestable wrappers (fixedSize, sizePrefix, pre/postOffset, sentinel, hiddenPrefix/Suffix) and the four type-category unions stay hand-written, since they carry generic variant types, a cross-category Link member, and bespoke TryFrom bridges that don't fit the standard renderers — and they're the natural deletion boundary if a future spec drops nested unions.

The generator gains a NodeMacroFlavor classifier (nodeFlavor.ts) that picks the emission macro per node from the spec: nestedTypeNode.wrappers are skipped, enumVariantTypeNode members and structFieldTypeNode get #[node], and other type nodes get #[type_node]. CategoryRouting gains an emitUnions flag so type skips its bespoke unions, and struct joins the Rust keyword set so enumStructVariantTypeNode.struct renders as r#struct.

Reconciliation is mostly contained to codama-nodes/src/type_nodes/. Spec-driven type changes: amountTypeNode.decimals → u32, the enum-variant discriminator → Option<u32>, and optionTypeNode.fixed → Option<bool>. The box-all-union rule boxes array/map/set.count → Box<CountNode> and structFieldTypeNode.{type, default_value}, which cascades into a few codama-attributes/codama-koroks/codama-korok-visitors files and their tests. The hand-written nestable nodes are left untouched.

1008 cargo tests pass unchanged; pnpm test grew by 8 to 148; fmt, clippy, and the pnpm generate round-trip stay clean. The override surface is unchanged.

lorisleiva commented Jun 10, 2026

Copy link
Copy Markdown
Member Author

Merge activity

  • Jun 10, 2:13 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Jun 10, 2:35 PM UTC: Graphite rebased this pull request as part of a merge.
  • Jun 10, 2:35 PM UTC: @lorisleiva merged this pull request with Graphite.

@lorisleiva lorisleiva changed the base branch from loris/spec-gen-top-level to graphite-base/103 June 10, 2026 14:32
@lorisleiva lorisleiva changed the base branch from graphite-base/103 to main June 10, 2026 14:33
This PR generates 21 of the 28 `type`-category nodes from `@codama/spec`, completing first-class generation support for all 8 spec categories. The 7 nestable wrappers (`fixedSize`, `sizePrefix`, `pre/postOffset`, `sentinel`, `hiddenPrefix/Suffix`) and the four type-category unions stay hand-written, since they carry generic variant types, a cross-category Link member, and bespoke `TryFrom` bridges that don't fit the standard renderers — and they're the natural deletion boundary if a future spec drops nested unions.

The generator gains a `NodeMacroFlavor` classifier (`nodeFlavor.ts`) that picks the emission macro per node from the spec: `nestedTypeNode.wrappers` are skipped, `enumVariantTypeNode` members and `structFieldTypeNode` get `#[node]`, and other type nodes get `#[type_node]`. `CategoryRouting` gains an `emitUnions` flag so `type` skips its bespoke unions, and `struct` joins the Rust keyword set so `enumStructVariantTypeNode.struct` renders as `r#struct`.

Reconciliation is mostly contained to `codama-nodes/src/type_nodes/`. Spec-driven type changes: `amountTypeNode.decimals → u32`, the enum-variant `discriminator → Option<u32>`, and `optionTypeNode.fixed → Option<bool>`. The box-all-union rule boxes `array/map/set.count → Box<CountNode>` and `structFieldTypeNode.{type, default_value}`, which cascades into a few `codama-attributes`/`codama-koroks`/`codama-korok-visitors` files and their tests. The hand-written nestable nodes are left untouched.

1008 cargo tests pass unchanged; `pnpm test` grew by 8 to 148; fmt, clippy, and the `pnpm generate` round-trip stay clean. The override surface is unchanged.
@lorisleiva lorisleiva force-pushed the loris/spec-gen-type-nodes branch from afc7a35 to 9937be4 Compare June 10, 2026 14:34
@lorisleiva lorisleiva merged commit 632365f into main Jun 10, 2026
4 checks passed
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.

1 participant