Skip to content

Add borrowed Ref variants of generated types - #560

Draft
leighmcculloch wants to merge 11 commits into
mainfrom
generated-ref-types
Draft

Add borrowed Ref variants of generated types#560
leighmcculloch wants to merge 11 commits into
mainfrom
generated-ref-types

Conversation

@leighmcculloch

@leighmcculloch leighmcculloch commented Jul 28, 2026

Copy link
Copy Markdown
Member

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:

  1. Add borrowed Ref variants of generated types #560 ← this PR
  2. Add const XDR serialization on View types #562
  3. Encode contract spec XDR at const evaluation time rs-soroban-sdk#1965

A second group of PRs deliver fully qualified type names in contract specs. Instead of a type having the name Context it will have the name soroban_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):

  1. Widen user-defined type name limit stellar-xdr#312
  2. Regenerate with widened UDT name limit #566
  3. Qualify user-defined type names rs-soroban-sdk#1970
  4. Update stellar-xdr to 28.0.0 rs-stellar-rpc-client#108
  5. Patch xdr and spec crates to support long type names stellar-cli#2674

What

Add a borrowing {Type}Ref<'a> counterpart for every generated type that transitively contains heap data, backed by new slice-based VecMRef/BytesMRef/StringMRef runtime types with const constructors, plus From conversions from each Ref type to its owned type and WriteXdr impls that encode identically to the owned types.

Why

The owned types require Vec-backed heap allocation to construct, so XDR values can't be built from borrowed slices of fixed-size arrays or inside const contexts; the Ref types make any generated type constructible from &[T], fully in const.

Known limitations

Ref types encode via WriteXdr/to_xdr but cannot implement ReadXdr/from_xdr (decoding must target the owned types), and they have no serde support.

@leighmcculloch
leighmcculloch changed the base branch from main to derive-default-for-cli-formats July 28, 2026 11:47
@leighmcculloch
leighmcculloch changed the base branch from derive-default-for-cli-formats to main July 28, 2026 11:47
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.

1 participant