Skip to content

Add inline-union support and complete pdaSeed generation#94

Merged
lorisleiva merged 1 commit into
mainfrom
loris/spec-gen-inline-unions-pda-seed
Jun 10, 2026
Merged

Add inline-union support and complete pdaSeed generation#94
lorisleiva merged 1 commit into
mainfrom
loris/spec-gen-inline-unions-pda-seed

Conversation

@lorisleiva

Copy link
Copy Markdown
Member

This PR introduces an INLINE_UNIONS allowlist in the generator so that unions without a registered<Name> twin can be emitted on an opt-in basis, with a per-union stripSuffix controlling variant naming. The infrastructure is validated end to end by completing pdaSeed, which was deliberately left out of the previous PR pending exactly this machinery. The pdaSeed category now joins count, discriminator, and link under CATEGORY_ROUTING, and codama-nodes/src/generated/pda_seed_nodes/ gains five files: per-node constant_pda_seed_node.rs and variable_pda_seed_node.rs, the inline-union constant_pda_seed_value.rs, the category-union pda_seed_node.rs, and a mod.rs. The hand-written pda_seed_nodes/*.rs files shrink to constructors and #[cfg(test)] mod tests blocks, mirroring the PR #1/#2 treatment of link and count/discriminator nodes. One bespoke impl From<ValueNode> for ConstantPdaSeedValue is added to the hand-written constant_pda_seed_node.rs to bridge the broader ValueNode enum into the new ConstantPdaSeedValue superset that includes ProgramId(ProgramIdValueNode). The ConstantPdaSeedNode.value field type changes from ValueNode to ConstantPdaSeedValue; existing call sites that pass leaf value nodes work via the auto-derived From<Variant> impls, and the one caller in codama-korok-visitors/src/set_pdas_visitor.rs that passes a resolved ValueNode flows through the new bridge.

Also lands the box-all-union heuristic: every direct (non-Vec) field whose type is a union is wrapped in Box<\u2026> (required \u2192 Box<T>; optional \u2192 Box<Option<T>>, box outside Option). This keeps every category-union variant pointer-sized for its union fields, which is what clippy::large_enum_variant actually cares about. The newly-generated pdaSeed structs box their type and value union fields accordingly; the hand-written constructors wrap with Box::new(...) and the corresponding tests dereference with *node.r#type / *node.value.

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:17 PM UTC: Graphite rebased this pull request as part of a merge.
  • Jun 10, 2:17 PM UTC: @lorisleiva merged this pull request with Graphite.

@lorisleiva lorisleiva changed the base branch from loris/spec-gen-count-discriminator to graphite-base/94 June 10, 2026 14:14
@lorisleiva lorisleiva changed the base branch from graphite-base/94 to main June 10, 2026 14:15
This PR introduces an `INLINE_UNIONS` allowlist in the generator so that unions without a `registered<Name>` twin can be emitted on an opt-in basis, with a per-union `stripSuffix` controlling variant naming. The infrastructure is validated end to end by completing `pdaSeed`, which was deliberately left out of the previous PR pending exactly this machinery. The `pdaSeed` category now joins `count`, `discriminator`, and `link` under `CATEGORY_ROUTING`, and `codama-nodes/src/generated/pda_seed_nodes/` gains five files: per-node `constant_pda_seed_node.rs` and `variable_pda_seed_node.rs`, the inline-union `constant_pda_seed_value.rs`, the category-union `pda_seed_node.rs`, and a `mod.rs`. The hand-written `pda_seed_nodes/*.rs` files shrink to constructors and `#[cfg(test)] mod tests` blocks, mirroring the PR #1/#2 treatment of link and count/discriminator nodes. One bespoke `impl From<ValueNode> for ConstantPdaSeedValue` is added to the hand-written `constant_pda_seed_node.rs` to bridge the broader `ValueNode` enum into the new `ConstantPdaSeedValue` superset that includes `ProgramId(ProgramIdValueNode)`. The `ConstantPdaSeedNode.value` field type changes from `ValueNode` to `ConstantPdaSeedValue`; existing call sites that pass leaf value nodes work via the auto-derived `From<Variant>` impls, and the one caller in `codama-korok-visitors/src/set_pdas_visitor.rs` that passes a resolved `ValueNode` flows through the new bridge.

Also lands the box-all-union heuristic: every direct (non-Vec) field whose type is a union is wrapped in `Box<\u2026>` (required \u2192 `Box<T>`; optional \u2192 `Box<Option<T>>`, box outside Option). This keeps every category-union variant pointer-sized for its union fields, which is what `clippy::large_enum_variant` actually cares about. The newly-generated pdaSeed structs box their `type` and `value` union fields accordingly; the hand-written constructors wrap with `Box::new(...)` and the corresponding tests dereference with `*node.r#type` / `*node.value`.
@lorisleiva lorisleiva force-pushed the loris/spec-gen-inline-unions-pda-seed branch from 52c15da to b91a31c Compare June 10, 2026 14:16
@lorisleiva lorisleiva merged commit 538fe6d 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