Skip to content

[2.x] Adapt to spec 2.0.0-rc.1 - #1196

Open
lorisleiva wants to merge 1 commit into
mainfrom
10-01-adapt_to_spec_2.0.0-rc.1
Open

lorisleiva wants to merge 1 commit into
mainfrom
10-01-adapt_to_spec_2.0.0-rc.1

Conversation

@lorisleiva

@lorisleiva lorisleiva commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

This PR updates Codama to @codama/spec@2.0.0-rc.1.

  • instructionNode gains an optional returnData type node, describing the data an instruction returns to its caller. It is supported by the node types, constructors and core visitors, can be set via updateInstructionsVisitor, is counted under a new inInstructionReturnData entry of the defined type histogram, and is filled from Anchor's returns by nodes-from-anchor.
  • enumValueNode.value accepts any value node, so variants whose data is neither a struct nor a tuple can be expressed as values, e.g. enumValueNode('operation', 'amount', { value: integerValueNode('42') }). The EnumValuePayload type and ENUM_VALUE_PAYLOAD_KINDS constant are removed.
  • Regenerated docblocks pick up the new spec documentation, including the official codama.resolver and codama.extraArgument plugins.

@lorisleiva lorisleiva changed the title Adapt to spec 2.0.0-rc.1 [2.x] Adapt to spec 2.0.0-rc.1 Oct 1, 2026
@changeset-bot

changeset-bot Bot commented Oct 1, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 4d568d5

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@lorisleiva

Copy link
Copy Markdown
Member Author

@trevor-cortex

@lorisleiva
lorisleiva marked this pull request as ready for review October 1, 2026 08:52

@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

Bumps the living @codama/spec pin from 2.0.0-rc.0 to 2.0.0-rc.1 and adapts the repo to the three spec changes that shipped in it:

  • instructionNode.returnData?: TypeNode (spec #185) — regenerated node types / constructors / identityVisitor / mergeVisitor, walk-order and generic-order entries in spec-generators, a new inInstructionReturnData bucket in getDefinedTypeHistogramVisitor, returnData added to INSTRUCTION_UPDATE_KEYS, and nodes-from-anchor v00/v01 now map Anchor's returns onto it.
  • enumValueNode.value widens to any ValueNode (spec #184) — EnumValuePayload / ENUM_VALUE_PAYLOAD_KINDS removed, identity visitor asserts VALUE_NODES.
  • Official codama.* plugin docs (spec #186) and the shorter plugins docblock — docblock-only regeneration across ~90 files.

I went through the full diff (not just the first 100 files in the listing) plus the untouched consumers that the new tests exercise. The code looks correct to me:

  • createSubInstructionsFromEnumDataVisitor already spreads ...node into each sub-instruction, so returnData propagates without a source change — the new test just pins that behaviour.
  • unwrapInstructionDataDefinedTypesVisitor keys off total === 1 && directlyAsInstructionData === 1, so a type used in both data and returnData is correctly left alone (new test covers it).
  • dynamic-codecs' visitEnumVariantType already wraps any variant payload under data, so the value visitor and codec agree for integer payloads etc. And since returnData is a plain TypeNode, getNodeValueCodec([root, program, ix, ix.returnData]) already yields a return-data decoder for free — no follow-up needed there.
  • IdlV00Instruction.returns / IdlV01Instruction.returns were already typed; typeNodeFromAnchorV00 was already imported in v00; typeNodeFromAnchorV01(idlType, generics) signature matches.
  • VALUE_NODES is already imported in identityVisitor.ts.
  • Test arithmetic checks out (expectMergeVisitorCount 5 and 3, delete-nodes predicate path.length === 2 only hits the return-data integer).

Things to watch

No changeset. CONTRIBUTING.md says every user-facing change needs one, and the repo is in rc pre mode (.changeset/pre.json), so changesets are what produce the rc.1 changelog entries. This PR has several user-facing changes worth a line each: new returnData attribute (nodes/node-types/visitors-core/visitors/nodes-from-anchor), removal of EnumValuePayload + ENUM_VALUE_PAYLOAD_KINDS, and the DefinedTypeHistogram shape change (inInstructionReturnData is a new required key, so anyone constructing histograms by hand breaks). If the rc line is intentionally batching under the seeded major changeset, ignore this — but I didn't see that stated anywhere.

Positional generics shift. TReturnData is inserted after TData in InstructionNode<…> / InstructionNodeInput<…> / instructionNode<…>. Anyone passing explicit type args positionally (e.g. InstructionNode<string, [], TData, TRemainingAccounts>) will silently get the wrong slot. Generated from spec, so nothing to change here — just worth a mention in the changeset / release notes.

Pre-existing, non-blocking: getLinkUsage distinguishes data vs returnData by reference equality (child === owner.returnData). If a caller hands the same link object to both (const t = definedTypeLinkNode('x'); instructionNode({ data: t, returnData: t })), both occurrences now classify as return data, since that check runs first. The existing child === owner.data check had the same reference-equality caveat and the built-in consumers aren't affected (total is 2 either way), so I wouldn't change anything — just noting it in case a histogram test ever uses a shared reference and looks off.

For subsequent reviewers

  • Generated dirs are regenerated by CI and fail on diff, so the node-types / nodes / visitors-core bulk is mechanically verified; focus on the hand-written bits: getDefinedTypeHistogramVisitor.ts, updateInstructionsVisitor.ts, spec-generators/src/{shared/defaults,visitorsCore/options}.ts, and the two nodes-from-anchor instruction converters.
  • Confirm whether a changeset is expected on this branch.

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