Skip to content

Add functions and closures#52

Draft
dhedey wants to merge 52 commits intodevelopfrom
feat/functions
Draft

Add functions and closures#52
dhedey wants to merge 52 commits intodevelopfrom
feat/functions

Conversation

@dhedey
Copy link
Owner

@dhedey dhedey commented Jan 24, 2026

No description provided.

@dhedey dhedey changed the title feat: Add type functions with type::function(...) syntax Add functions and closures Jan 24, 2026
dhedey added 28 commits January 24, 2026 01:02
Rework Iterators to be more flexible
dhedey and others added 23 commits February 22, 2026 23:10
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
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.

2 participants