Add ids to contract spec entries - #313
Closed
leighmcculloch wants to merge 3 commits into
Closed
Conversation
This was referenced Aug 10, 2026
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.
Note
Part of a stack of PRs that must merge in this order.
A first group of PRs deliver const-encoded contract specs, so that contract specs are produced at compile time instead of at proc-macro execution time. This provides the foundation for the capability to construct the specs from information that is not known at proc-macro execution and only known at compile time, like the fully qualified name of a type:
A second group of PRs deliver ids on contract spec entries and in spec references. Every entry carries an 8-byte id hashed from the fully qualified name of the item it describes, and a reference to a user-defined type carries the id of the entry it refers to, so references stay unambiguous even when items share a name. This resolves the type identity problem (stellar/rs-soroban-sdk#1570) and type alias limitations (stellar/rs-soroban-sdk#1857):
What
Add a new
SCSpecEntryV2entry that pairs an 8-byteidwith a body union reusing the existing V0 entry bodies (function, UDT struct/union/enum/error enum, event), exposed as a newSC_SPEC_ENTRY_V2arm ofSCSpecEntry. Add aSCSpecTypeUDTV2reference type carrying the referenced type's name and the id of the entry it refers to. ASC_SPEC_ID_LENconst defines the id length. The id is the truncated SHA-256 of the fully qualified name of the item the entry describes.The change is purely additive: the existing V0 entry arms, the V0 body structs, and the existing
SCSpecTypeUDTreference are unchanged, so existing specs continue to decode.Why
A bare name cannot tell two items apart: two crates, or two modules of one crate, can each define a
Flag, and a spec that names both simplyFlagcannot say which is which. An id derived from the item's fully qualified name identifies it exactly, so every entry has a unique identifier and a reference is known to refer to one entry precisely, even when entries share a name.The id lives at the top level of the entry — beside the body, not inside it — so every entry kind gets an id the same way, functions and events included, and the body structs stay unchanged.