Add const XDR serialization on Ref types - #562
Draft
leighmcculloch wants to merge 10 commits into
Draft
Conversation
This was referenced Jul 29, 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 fully qualified type names in contract specs. Instead of a type having the name
Contextit will have the namesoroban_sdk::auth::Context. Qualified type names make it possible to uniquely identify types in the spec, even when they have the same name. This resolves several problems with contract specs the type identify problem (stellar/rs-soroban-sdk#1570), type aliases limitations (stellar/rs-soroban-sdk#1857), and optimise spec shaking data section size (stellar/rs-soroban-sdk#1978):What
Add a
constfeature giving every generated type const XDR serializers:const_write_xdr, which writes into a new constConstWriter;const_to_xdr, which returns a fixed-size[u8; N]; andconst_xdr_len, which gives that length. They live on the borrowingRefform for types that own heap data and on the type itself for the rest, so a value can be built from borrowed data and serialized straight into a fixed byte array at compile time.Why
XDR encoding was runtime-only, behind the
std-gatedWriteXdrtrait, so bytes couldn't be produced in a const context. It has to live on theReftypes because an ownedVecM/BytesM/StringMholds aVec, whose destructor can't run during const evaluation (E0493); theReftypes borrow instead, have no destructor, and are freely usable in const. The const encoders mirror the owned types'WriteXdr::write_xdrstatement for statement, including the same depth and length accounting, so output is byte-identical. Theconstfeature depends on nothing, so a fixed XDR value can be baked into a const in ano_std, no-allocbuild.Known limitations
Not built on the
WriteXdrtrait, since const traits aren't stable, so it is a parallel set of inherent functions rather than a trait impl.