Merged
Conversation
Replace the old Rc<RefCell<T>>-based reference system with the new custom dynamic reference types: - Shared<T> becomes a type alias for SharedReference<T> - Mutable<T> becomes a type alias for MutableReference<T> - DisabledShared<T> becomes InactiveSharedReference<T> - DisabledMutable<T> becomes InactiveMutableReference<T> - VariableContent::Referenceable uses new Referenceable struct Key changes: - Added bridge methods (_legacy suffix) to SharedReference and MutableReference for backward compatibility with old map/try_map patterns that didn't require PathExtension - QqqShared<T> and QqqMutable<T> now alias directly to the reference types, collapsing the old form/wrapper type distinction - Added explicit IsArgument impls for SharedReference<AnyValue> and MutableReference<AnyValue> since the blanket impl only covers leaf types - Manual Clone impls for InactiveSharedReference/InactiveMutableReference to avoid unnecessary T: Clone bound from derive - CopyOnWrite conversions use replace_legacy pattern instead of into_content() for non-leaf types - Updated trybuild test for improved aliasing error message from new reference tracking system https://claude.ai/code/session_01XaCsWwXFYntkKqZNf8kizU
…d SpanRange Replace all _legacy bridge methods (map_legacy, try_map_legacy, map_optional_legacy, replace_legacy, emplace_unchecked_legacy) with calls using proper PathExtension values and real SpanRange values. Key changes: - Add current_span() to EmplacerCore, SharedEmplacerV2, MutableEmplacerV2, SharedReference, MutableReference, AnyRefEmplacer, and AnyMutEmplacer - Use PathExtension::Tightened(T::type_kind()) for type-narrowing operations (leaf_to_dyn, into_shared, into_mutable, into_assignee, etc.) - Use PathExtension::Child(ObjectChild(name), AnyType) for property access - Use real spans from emplacer.current_span() instead of Span::call_site() - Make AnyRef/AnyMut map methods and emplacers take PathExtension + SpanRange - Remove all _legacy bridge methods from SharedReference and MutableReference https://claude.ai/code/session_01XaCsWwXFYntkKqZNf8kizU
- Introduce MappedRef and MappedMut types with unsafe constructors to confine unsafety to construction rather than use sites - Update SharedReference/MutableReference map/try_map to accept closures returning MappedRef/MappedMut, making callers safe - Fix &mut aliasing UB in AnyMut::emplace_map by storing *mut T in emplacer state instead of duplicate &mut T - Have PropertyAccessInterface/IndexAccessInterface return MappedRef/MappedMut with proper ChildSpecifier (ObjectChild/ArrayChild) - Add output_span_range to PropertyAccessCallContext/IndexAccessCallContext - Thread SpanRange through DynResolveFrom, leaf_to_dyn, and from_argument_value to eliminate None span arguments - Remove all TODO[references] comments https://claude.ai/code/session_01XaCsWwXFYntkKqZNf8kizU
…ields private - Make MappedRef/MappedMut fields private, add into_parts() for decomposition. This preserves the invariant that construction must go through the unsafe new() constructor. - Add emplace() method back to SharedEmplacer/MutableEmplacer with lifetime-checked &'e V parameter, keeping emplace_unchecked for cases where the compiler can't prove the lifetime (e.g. __InlineMapper). - Switch callers from emplace_unchecked to emplace where the lifetime is available: SharedReference::map/try_map, MutableReference::map/ try_map, AnyRef::map_optional, AnyMut::map_optional, and leaf_to_dyn implementations in shared.rs, mutable.rs, and assignee.rs. https://claude.ai/code/session_01XaCsWwXFYntkKqZNf8kizU
…ectly - Move MappedRef to shared_reference.rs and MappedMut to mutable_reference.rs - Add new_unchecked constructors for lifetime transmute cases (__InlineMapper) - Change all emplacer emplace methods to take MappedRef/MappedMut, making them safe - Drop emplace_unchecked from all emplacers (SharedEmplacer, MutableEmplacer, AnyRefEmplacer, AnyMutEmplacer) - All unsafe is now confined to MappedRef/MappedMut constructors https://claude.ai/code/session_01XaCsWwXFYntkKqZNf8kizU
The swap_itself.stderr error was pointing to `let a = "a"` instead of the second `a` in `a.swap(a)` because enable() ignored its span parameter and creation_span was never updated from the root span. - Add set_tracked_span to SharedReference, MutableReference, and their inactive variants - Update enable() to call set_tracked_span before activate(), so borrow-conflict errors point to the usage site - Update VariableBinding::into_mut/into_shared/into_late_bound to set the tracked span before initial activation too https://claude.ai/code/session_01XaCsWwXFYntkKqZNf8kizU
Move span-setting into activate() so callers don't need a separate set_tracked_span step. Remove enable() and set_tracked_span() from Inactive*Reference types. Add new_active_shared/new_active_mutable convenience methods to Referenceable. https://claude.ai/code/session_01XaCsWwXFYntkKqZNf8kizU
…0kGrv Refactor reference types: Replace Rc<RefCell<T>> with dynamic reference system
There was a problem hiding this comment.
Pull request overview
Reworks the interpreter’s runtime reference model by replacing the prior Rc<RefCell<...>>-based “disabled” references with a custom dynamic reference tracker that supports active/inactive references, path-based aliasing checks, and richer diagnostics.
Changes:
- Introduces
src/misc/dynamic_references/*(Referenceable/Shared/Mutable, activation/deactivation, path tracking, and mapped refs/muts withPathExtension). - Refactors interpretation + type-resolution plumbing to use the new reference APIs (including
MappedRef/MappedMutfor property/index access and updated forms/argument mapping). - Adds/updates tests and trybuild UI fixtures for the new ownership/aliasing errors; extends array interface with
pop.
Reviewed changes
Copilot reviewed 61 out of 61 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/references.rs | Adds trybuild UI test runner + runtime test for distinct mutable paths. |
| tests/expressions.rs | Adds method-call tests for pop() behavior (value vs empty). |
| tests/compilation_failures/references/with_inactive_ref_attempt_mutate_its_ancestor.stderr | New expected diagnostic for inactive ref vs ancestor mutation. |
| tests/compilation_failures/references/with_inactive_ref_attempt_mutate_its_ancestor.rs | New compile-fail case covering inactive descendant reference invalidation. |
| tests/compilation_failures/references/with_inactive_mut_attempt_mutate_its_ancestor.stderr | New expected diagnostic for inactive mutable descendant vs ancestor mutation. |
| tests/compilation_failures/references/with_inactive_mut_attempt_mutate_its_ancestor.rs | New compile-fail case for my_arr[0] vs my_arr.pop() aliasing. |
| tests/compilation_failures/references/with_active_ref_attempt_mutate_its_descendent.stderr | New expected diagnostic for active mutable overlap observed by shared. |
| tests/compilation_failures/references/with_active_ref_attempt_mutate_its_descendent.rs | New compile-fail for mutating within index expression while referencing root. |
| tests/compilation_failures/functions/ref_argument_cannot_be_mutated.stderr | Updates expected error message for mutating through non-mutable ref. |
| tests/compilation_failures/expressions/swap_itself.stderr | Updates expected aliasing diagnostic for swap on same mutable reference. |
| tests/compilation_failures/expressions/array_place_destructure_multiple_muts.stderr | Updates expected diagnostic for shared-vs-mutable clash during indexing. |
| src/misc/mut_rc_ref_cell.rs | Removes old RefCell-based sub-reference helpers. |
| src/misc/mod.rs | Wires in dynamic_references module and removes old module exports. |
| src/misc/errors.rs | Adds helper to extract/expect ownership errors as syn::Error. |
| src/misc/dynamic_references/mod.rs | New module docs + exports for the dynamic reference system. |
| src/misc/dynamic_references/referenceable.rs | Implements Referenceable core + path tracking + activation checks/diagnostics. |
| src/misc/dynamic_references/reference_core.rs | Core reference tracking (IDs, emplacer, clone/drop semantics). |
| src/misc/dynamic_references/shared_reference.rs | Shared reference wrapper + mapped refs and emplacer. |
| src/misc/dynamic_references/mutable_reference.rs | Mutable reference wrapper + mapped muts, into_shared, and emplacer. |
| src/interpretation/variable_state.rs | Splits variable storage into a dedicated module using inactive dynamic refs. |
| src/interpretation/variable.rs | Switches variable definition + resolution types to new reference system. |
| src/interpretation/refs.rs | Updates AnyRef/AnyMut to map via MappedRef/MappedMut and new emplacers. |
| src/interpretation/mod.rs | Replaces bindings module with variable_state. |
| src/interpretation/interpreter.rs | Updates late-bound typing in resolver signatures. |
| src/interpretation/bindings.rs | Removes previous bindings/value ownership implementation. |
| src/internal_prelude.rs | Removes std::cell::Ref from prelude (no longer used). |
| src/expressions/values/object.rs | Reworks property/index access to return MappedRef/MappedMut with path info. |
| src/expressions/values/none.rs | Adds none() helper returning AnyValue::None. |
| src/expressions/values/function.rs | Renames stored bound-argument type to inactive argument values. |
| src/expressions/values/array.rs | Adds pop; reworks index access to return mapped refs/muts with PathExtension. |
| src/expressions/values/any_value.rs | Introduces clearer AnyValue* type aliases (LateBound/COW/etc) and updates APIs. |
| src/expressions/type_resolution/type_kinds.rs | Adds TypeKind binding comparison + narrowing helper; updates type property resolution. |
| src/expressions/type_resolution/type_data.rs | Updates property/index access interfaces to return mapped ref/mut + span context. |
| src/expressions/type_resolution/outputs.rs | Updates returned-value types to use new aliases. |
| src/expressions/type_resolution/interface_macros.rs | Updates apply helpers/macros for mapped ref/mut return types. |
| src/expressions/type_resolution/arguments.rs | Refactors argument typing/resolution traits for new ownership/value aliases. |
| src/expressions/expression_parsing.rs | Updates literal parsing to construct shared values via new constructors. |
| src/expressions/expression.rs | Updates leaf literal storage types to new shared alias. |
| src/expressions/evaluation/value_frames.rs | Renames disabled→inactive argument model; updates late-bound plumbing and spans. |
| src/expressions/evaluation/node_conversion.rs | Updates literal conversion to use new COW alias. |
| src/expressions/evaluation/evaluator.rs | Updates requested/returned/late-bound types to new aliases. |
| src/expressions/concepts/type_traits.rs | Adds covariance hook + span-carrying dyn mapper changes. |
| src/expressions/concepts/mapping.rs | Extends map_via_leaf helper for FunctionResult outputs. |
| src/expressions/concepts/forms/simple_ref.rs | Adds covariance proof + mapped-ref emplacement for shared/any-ref conversions. |
| src/expressions/concepts/forms/simple_mut.rs | Adds covariance proof + mapped-mut emplacement for mutable/assignee/any-mut conversions. |
| src/expressions/concepts/forms/shared.rs | Moves shared form onto new Shared<T> reference type and dyn mapping via MappedRef. |
| src/expressions/concepts/forms/referenceable.rs | Removes old Rc<RefCell> “referenceable” form. |
| src/expressions/concepts/forms/owned.rs | Adds covariance proof and updates dyn leaf definitions. |
| src/expressions/concepts/forms/mutable.rs | Moves mutable form onto new Mutable<T> reference type and dyn mapping via MappedMut. |
| src/expressions/concepts/forms/mod.rs | Removes referenceable form exports. |
| src/expressions/concepts/forms/late_bound.rs | Introduces unified LateBound<T> form and mapping helpers. |
| src/expressions/concepts/forms/copy_on_write.rs | Reimplements COW + inactive COW on top of new reference model. |
| src/expressions/concepts/forms/assignee.rs | Reimplements assignee wrapper on top of Mutable<T> with dyn mapping via MappedMut. |
| src/expressions/concepts/forms/argument.rs | Updates argument form leaves to new wrapper types. |
| src/expressions/concepts/forms/any_ref.rs | Updates dyn conversion and argument mapping to use MappedRef. |
| src/expressions/concepts/forms/any_mut.rs | Updates dyn conversion and argument mapping to use MappedMut. |
| src/expressions/concepts/form.rs | Adds covariance proof requirement; updates dyn-compatible and argument mapping signatures. |
| src/expressions/concepts/content.rs | Removes referenceable conversion; updates clone-to-owned result type to FunctionResult. |
| src/expressions/closures.rs | Updates closure binding storage to inactive shared/mutable variable content. |
| plans/TODO.md | Updates planning notes and records the dynamic references work. |
| plans/2026-01-types-and-forms.md | Notes related TODO tagging. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
tests/compilation_failures/references/with_inactive_mut_attempt_mutate_its_ancestor.stderr
Outdated
Show resolved
Hide resolved
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.
No description provided.