Add borrowed Ref variants of types - #560
Closed
leighmcculloch wants to merge 26 commits into
Closed
leighmcculloch wants to merge 26 commits into
leighmcculloch wants to merge 26 commits into
Conversation
This was referenced Jul 28, 2026
leighmcculloch
changed the base branch from
main
to
derive-default-for-cli-formats
July 28, 2026 11:47
leighmcculloch
changed the base branch from
derive-default-for-cli-formats
to
main
July 28, 2026 11:47
This was referenced Jul 29, 2026
This was referenced Aug 8, 2026
leighmcculloch
force-pushed
the
generated-ref-types
branch
from
August 25, 2026 05:17
8834869 to
94be53b
Compare
leighmcculloch
force-pushed
the
generated-ref-types
branch
6 times, most recently
from
August 26, 2026 12:07
2fc5c3f to
ec4e8cb
Compare
leighmcculloch
force-pushed
the
generated-ref-types
branch
from
September 1, 2026 22:56
ec4e8cb to
5be67d9
Compare
3 tasks
leighmcculloch
force-pushed
the
generated-ref-types
branch
from
September 5, 2026 15:09
b60ee19 to
bc91d27
Compare
leighmcculloch
force-pushed
the
generated-ref-types
branch
from
September 7, 2026 00:14
0382122 to
d4f6049
Compare
leighmcculloch
marked this pull request as ready for review
September 8, 2026 02:23
leighmcculloch
enabled auto-merge
September 8, 2026 02:23
Contributor
There was a problem hiding this comment.
Pull request overview
Adds allocation-free borrowed Ref counterparts for heap-backed generated XDR types.
Changes:
- Adds borrowed container types, conversion support, and XDR encoding.
- Extends generator analysis/templates to emit borrowed variants.
- Regenerates XDR output and adds integration tests.
Reviewed changes
Copilot reviewed 1 out of 484 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
src/generated.rs |
Adds shared borrowed-type infrastructure. |
src/generated/*.rs |
Regenerates affected XDR types with Ref or IntoOwned implementations. |
tests/common/mod.rs |
Provides representative owned and borrowed fixtures. |
tests/ref_types.rs |
Tests construction, limits, conversion, and encoding. |
xdr-generator-rust/generator/header.rs |
Defines borrowed containers and conversion support. |
xdr-generator-rust/generator/src/generator.rs |
Analyzes which types require borrowed variants. |
xdr-generator-rust/generator/src/output.rs |
Adds borrowed-type template metadata. |
xdr-generator-rust/generator/src/tests/generator.rs |
Tests generator borrow analysis. |
xdr-generator-rust/generator/src/types.rs |
Resolves borrowed and cyclic field types. |
xdr-generator-rust/generator/templates/enum.rs.jinja |
Emits identity conversions for enums. |
xdr-generator-rust/generator/templates/into_owned.rs.jinja |
Adds reusable identity conversion generation. |
xdr-generator-rust/generator/templates/struct.rs.jinja |
Emits borrowed structs and conversions. |
xdr-generator-rust/generator/templates/typedef_newtype.rs.jinja |
Emits borrowed newtypes and conversions. |
xdr-generator-rust/generator/templates/union.rs.jinja |
Emits borrowed unions and cyclic conversions. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+655
to
+659
| let mut borrow = BorrowCfg::Never; | ||
| for def in defs { | ||
| let def_cfg = def.cfg().map(CfgExpr::render); | ||
| borrow = borrow.or(self.of_def(def).and_cfg(def_cfg.as_deref())); | ||
| } |
Member
Author
There was a problem hiding this comment.
This gap is pretty narrow and won't break compilation. I think we should defer to look at this if we ever need it.
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 change contract specs so that they are produced at compile time instead of at proc-macro execution time. This provides the foundation to construct the specs from information that is only known at compile time, like the fully qualified name of a type:
A second group of PRs changes the type names that the sdk stores in specs are fully qualified type names, and then the cli reduces them down to unique simple identifiers. During the contract build the types are given names like
::mycrate::mymod::MyTypeinstead ofMyType. Then the cli reduces them back down to simple names after spec shaking. 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 stellar/rs-soroban-sdk#1063), and optimise spec shaking data section size (stellar/rs-soroban-sdk#1978):Note that downstream clients and SDKs should see no, or little, change because the cli will during the build process reduce the fully qualified names back to simple unique names. Contracts that had colliding type names, which meant they could not be used with clients, will now work.
A third group of PRs are an optimisation to spec shaking v2, and will use the new unique type names to shake type specs by reachability, producing a dependency graph (thanks @mootz12), so that only spec entries that can't be reached from fns, like errors and events, get spec markers from dead-code-elimination:
What
Add a borrowing
{Type}Ref<'a>counterpart for every generated type that directly or transitively contains heap data.Why
The owned types require heap allocation to construct, so XDR values can't be built from borrowed slices or inside const contexts.
Known limitations
View types encode via
WriteXdr/to_xdrbut cannot implementReadXdr/from_xdr(decoding must target the owned types), and they have no serde support.