Generate count and discriminator nodes#93
Merged
Conversation
Member
Author
This was referenced Jun 10, 2026
Merged
Member
Author
Merge activity
|
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.
9a6203a to
05c7e21
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

This PR extends the spec generator to cover two more node categories \u2014
countanddiscriminator\u2014 landing six generated structs and two union enums undercodama-nodes/src/generated/. Hand-written<category>/<node>.rsfiles shrink to constructors and#[cfg(test)] mod tests, mirroring the PR #1 treatment of link nodes. Integer fields backed by specinteger/u64(thevalue,offset, andsizeattributes) becomeu64for determinism; the change propagates through the four constructors, theArrayTypeNode/SetTypeNode/MapTypeNode.fixed()helpers, thediscriminator_directive'sSetOnces, and theidentify_field_types_visitor's array-length parsing, all of which now flowu64end to end. The generator gains a small heuristic that derivesCopywhen every attribute is a scalar (integer / float / boolean / enumeration) andDefaultwhen the struct is empty, eliminating per-node configuration.getEmittableUnionsnow requires aregistered<Name>sibling, which keeps the category-main unions and skips inline / synthetic ones. A separately-fixed bug: optionaldocsattributes were being wrapped inOption<Docs>; they are now emitted as bareDocsregardless of the spec'soptionalflag, matching the established convention.pdaSeedis intentionally left out of this PR \u2014 itsconstantPdaSeedNode.valuereferences a nested inline union (constantPdaSeedValue) that requires the non-flattening union machinery planned for a later PR.