Skip to content

Declare identifiers before parent links and clarify attribute order - #213

Merged
lorisleiva merged 2 commits into
mainfrom
11-02-declare_identifiers_before_parent_links
Nov 3, 2026
Merged

lorisleiva merged 2 commits into
mainfrom
11-02-declare_identifiers_before_parent_links

Conversation

@lorisleiva

Copy link
Copy Markdown
Member

This PR makes the attribute order of the spec the single source of truth for serialisation.

  • Link nodes now declare their identifier before their optional parent link (program or instruction), since that parent is often omitted, and valueLabelDisplayNode declares its label before its value.
  • The README presents "describing attributes first, children last" as a convention for spec authors (human text such as docs counts as describing the node), rather than a rule.
  • Generators MUST emit attributes in declaration order followed by base attributes, without regrouping them into data and child attributes.
// Before
{ "kind": "accountLinkNode", "program": { "kind": "programLinkNode", "identifier": "token" }, "identifier": "mint" }

// After
{ "kind": "accountLinkNode", "identifier": "mint", "program": { "kind": "programLinkNode", "identifier": "token" } }

@lorisleiva

Copy link
Copy Markdown
Member Author

@trevor-cortex

@trevor-cortex trevor-cortex left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Summary

Reorders the attributes of the five link nodes that carry an optional parent link (accountLinkNode, definedTypeLinkNode, instructionAccountLinkNode, instructionLinkNode, pdaLinkNode) so identifier is declared first, swaps label/value on valueLabelDisplayNode, and reframes the README's "data first, children last" rule as an authoring convention while making it explicit that generators emit declaration order verbatim (no regrouping). spec.json and docs/ are regenerated; a new test pins the link node attribute order.

The TS source, spec.json, and the regenerated docs all line up — definedTypeLinkNode keeps transforms trailing, programLinkNode is correctly untouched (no parent link), and the link node doc pages don't change because identifier/program were already split across the Data/Children tables. The only doc page diff is ValueLabelDisplayNode.md, which is expected since both label and value are classified as children there.

Things to watch

  • Docs tables vs the new README wording. The README now says docs / label "count as describing the node", but the docs renderer (isDocChild → isChildAttribute) still files every docs/text attribute under the Children table (see docs/AccountNode.md, where docs sits in Children, and ValueLabelDisplayNode.md, where label does too). It's not wrong — the updated comment in renderPages.ts now explicitly says the tables are a readability grouping only — but a reader could reasonably find it at odds with the README. A follow-up that moves docs/text into the Data table would make the two consistent; not blocking here.
  • Bump level. patch is defensible given the README's "on read, attribute order carries no semantics" rule, so nothing semantically breaks. Worth being aware that downstream codegen in codama / codama-rs will see a changed attribute order (struct field order, emitted JSON key order), so any snapshot/fixture tests there will churn when they pick up this version. Flagging for awareness, not asking for a change.

For subsequent reviewers

Nothing risky here; the generated artifacts match the source. If you want to double-check anything, confirm pnpm generate is clean on the branch (CI covers this) and that no other node has a child declared before an identifying scalar that this PR should have swept up — I checked the link nodes and found none remaining.

Comment thread generators/docs/render/renderPages.ts Resolved
Comment thread .changeset/quiet-links-lead.md Resolved

@trevor-cortex trevor-cortex left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Re-review

Since my last pass the PR picked up the docs-renderer alignment I'd flagged: isDocChild now classifies docs/text as Data (with a unit test), and the 20 regenerated doc pages move docs, label, message, intent, interpolatedIntent and flattenPrefix out of the Children tables accordingly. That resolves the README-vs-docs inconsistency, so nothing from the prior review is outstanding.

I re-checked the regenerated pages against the source declarations (AccountNode, ConstantNode, ErrorNode, ProgramNode, InstructionStatusNode, InstructionRemainingAccountsNode, VariablePdaSeedNode, StructFieldTypeNode, and all five display node pages). Rows keep declaration order within each table and the only content change is which table they land in — column widths account for the rest of the churn. InstructionDisplayNode.md now has an empty-except-plugins Children table, which is the correct output of the renderer rather than something to fix here.

One minor note (non-blocking)

isDocChild short-circuits on a top-level docs/text type but not on one nested in an array, so an array(text()) attribute would fall through to isChildAttribute and (if that treats text as a child) land in Children. No node in the spec declares such an attribute today, so this is purely a latent edge case — flagging only so it's a known gap if one is ever added.

For subsequent reviewers

Everything is generated-output + two-line renderer tweak + test on top of the already-reviewed attribute reorder. Confirming pnpm generate is clean (CI) is the only verification needed.

Comment thread generators/docs/render/renderType.ts Resolved
@lorisleiva
lorisleiva merged commit c20ef9b into main Nov 3, 2026
3 checks passed
@lorisleiva
lorisleiva deleted the 11-02-declare_identifiers_before_parent_links branch November 3, 2026 10:01
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