Repository navigation
Fix/reference list round trip - #72
Merged
Merged
Conversation
Cache reference fields, containment fields and reference constraints, invalidating the caches when models are rebuilt. Skip unnecessary serialization work and separate parent refresh from reference resolution. Add reproducible benchmarks and regression coverage. Document ownership, list semantics and utility compatibility changes, and ignore local scratch files.
Preserve reference metadata and COW item proxies in stable sorted copies. Centralize one-level _unwrap hook handling in utils.py and reuse it in metadata, validation, comparisons, condition checks and sorting. Add regression coverage and document reference-list semantics.
plamen-neykov
marked this pull request as ready for review
November 11, 2026 19:49
plamen-neykov
marked this pull request as draft
November 11, 2026 20:08
Add skip_none=False to optionally filter None entries before sorting and key evaluation. Rebuild values and reference metadata together in remove_none, preserving occurrence order, object identity, and COW behavior. Validation: 124 targeted tests passed.
Normalize reference-list values without converting them to plain lists, retaining per-occurrence metadata through model construction. Add regression coverage for copies, slices, sorted and COW inputs, and nested builders. Validation: 132 targeted tests passed.
plamen-neykov
marked this pull request as ready for review
November 11, 2026 21:18
dschwartznyc
approved these changes
Nov 11, 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.
Summary
Resolve references stored directly in list fields and preserve their per-occurrence metadata through validation, serialization, mutation, copying, sorting, and model construction.
Callers receive actual target objects while the runtime retains whether each occurrence was supplied inline or by reference. The same target can therefore appear both ways in one list and serialize correctly.
Fixes #43.
Builds on #71.
Compatibility and release
This change is intended for runtime 3.0.0 because the runtime and generated-code contracts require a coordinated update.
3.0.0Git tag.rune.runtime>=3.0.0,<4.0.0.<3.0.0remain on runtime 2.x.rune_sortedis a separate follow-up. Adding the runtime helper does not change existing generated code.Reference-list behavior
@refentries without traversing their targets as containment children.Equality follows ordinary list value equality. A reference occurrence and an equivalent inline value compare equal.
remove(value)removes the first equal occurrence; callers should use an index when selecting a particular occurrence.Serialization
Use
PlainSerializer(..., when_used='unless-none')to handle whole-valueNonewithout explicit guards in the metadata serializers.Delegate resolved scalar-reference metadata serialization to
Reference.serialise_meta. Preserve null list entries where supported by the serializer.Sorting and proxy handling
Add
rune_sortedfor stable, shallow sorted copies that preserve reference-list metadata:skip_nonedefaults toFalse.skip_none=True, remove onlyNoneentries before evaluating the key.The built-in
sorted()and explicit conversion to a plainlistdiscard occurrence metadata.Add
rune_unwrap_proxyinutils.pyand reuse it where a single callable_unwraphook should be followed. This helper does not depend oncow.py; recursive COW unwrapping remains separate.ObjectBuilder integration
Preserve reference-list metadata during
ObjectBuilder._normalizewhile recursively normalizing its elements.Previously, the generic list branch converted copied or sorted reference lists into plain lists. Building a model from those values then serialized references as full objects.
The reference-list branch now retains occurrence metadata, including when inline elements contain nested builders.
Performance
Add
benchmarks/benchmark_list_references.pyto measure reading, writing, and validation using the same models and dependencies across revisions. PR #71 provides the comparison baseline becausemaincannot serialize these lists.Ownership and related work
When revalidation creates a new model that shares existing children, those children retain their original parent. The new model receives separate key-registry dictionaries whose entries still point to the shared targets.
These semantics are relevant to #49 and #66. This PR does not implement detached subtree copying or a broader ownership redesign.
Utility cleanup
Retain the accompanying
utils.pycleanup:__all__.TypeErrorrather thanValueErrorfor an invalidrune_add_to_listdestination.Also ignore local
.tmp/scratch files.Validation
The latest targeted run passed 132 tests, covering ObjectBuilder, reference-list serialization, sorting, COW behavior, utility helpers, and operations.
New builder regressions cover copied, sliced, sorted, and COW-backed reference lists, plus recursive normalization of nested builders. These cases failed before the normalization fix.
git diff --checkpassed.Earlier broader runs identified an existing Windows path/module-resolution failure in
test_init_invalid_directory_or_module; that issue is outside this change.