Skip to content

Generate count and discriminator nodes#93

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

Generate count and discriminator nodes#93
lorisleiva merged 1 commit into
mainfrom
loris/spec-gen-count-discriminator

Conversation

@lorisleiva

Copy link
Copy Markdown
Member

This PR extends the spec generator to cover two more node categories \u2014 count and discriminator \u2014 landing six generated structs and two union enums under codama-nodes/src/generated/. Hand-written <category>/<node>.rs files shrink to constructors and #[cfg(test)] mod tests, mirroring the PR #1 treatment of link nodes. Integer fields backed by spec integer/u64 (the value, offset, and size attributes) become u64 for determinism; the change propagates through the four constructors, the ArrayTypeNode/SetTypeNode/MapTypeNode .fixed() helpers, the discriminator_directive's SetOnces, and the identify_field_types_visitor's array-length parsing, all of which now flow u64 end to end. The generator gains a small heuristic that derives Copy when every attribute is a scalar (integer / float / boolean / enumeration) and Default when the struct is empty, eliminating per-node configuration. getEmittableUnions now requires a registered<Name> sibling, which keeps the category-main unions and skips inline / synthetic ones. A separately-fixed bug: optional docs attributes were being wrapped in Option<Docs>; they are now emitted as bare Docs regardless of the spec's optional flag, matching the established convention. pdaSeed is intentionally left out of this PR \u2014 its constantPdaSeedNode.value references a nested inline union (constantPdaSeedValue) that requires the non-flattening union machinery planned for a later PR.

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

@lorisleiva lorisleiva changed the base branch from loris/spec-generators-link-nodes to graphite-base/93 June 10, 2026 14:13
@lorisleiva lorisleiva changed the base branch from graphite-base/93 to main June 10, 2026 14:13
This PR extends the spec generator to cover two more node categories \u2014 `count` and `discriminator` \u2014 landing six generated structs and two union enums under `codama-nodes/src/generated/`. Hand-written `<category>/<node>.rs` files shrink to constructors and `#[cfg(test)] mod tests`, mirroring the PR #1 treatment of link nodes. Integer fields backed by spec `integer/u64` (the `value`, `offset`, and `size` attributes) become `u64` for determinism; the change propagates through the four constructors, the `ArrayTypeNode`/`SetTypeNode`/`MapTypeNode` `.fixed()` helpers, the `discriminator_directive`'s `SetOnce`s, and the `identify_field_types_visitor`'s array-length parsing, all of which now flow `u64` end to end. The generator gains a small heuristic that derives `Copy` when every attribute is a scalar (integer / float / boolean / enumeration) and `Default` when the struct is empty, eliminating per-node configuration. `getEmittableUnions` now requires a `registered<Name>` sibling, which keeps the category-main unions and skips inline / synthetic ones. A separately-fixed bug: optional `docs` attributes were being wrapped in `Option<Docs>`; they are now emitted as bare `Docs` regardless of the spec's `optional` flag, matching the established convention. `pdaSeed` is intentionally left out of this PR \u2014 its `constantPdaSeedNode.value` references a nested inline union (`constantPdaSeedValue`) that requires the non-flattening union machinery planned for a later PR.
@lorisleiva lorisleiva force-pushed the loris/spec-gen-count-discriminator branch from 9a6203a to 05c7e21 Compare June 10, 2026 14:14
@lorisleiva lorisleiva merged commit 7f9628d 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