Skip to content

-mm=own: objects in Map and Set go through Shared<T> - #697

Merged
ASDAlexander77 merged 1 commit into
mainfrom
own-shared-container-elements
Oct 27, 2026
Merged

ASDAlexander77 merged 1 commit into
mainfrom
own-shared-container-elements

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

Under -mm=own, an object goes into a Map or Set as a Shared<T> handle. A plain object or any element is now a compile error at the user's code that points at Shared<T>, where it used to be four errors inside lib.generics.ts. Spec: section 6 of 2026-10-26-own-generic-containers-design.md.

Changes

  • @sharedElements, a class decorator. Under own, each type argument of a class that carries it must be a value, a string, or a Shared<T> handle. checkSharedElements runs in both instantiateSpecializedClassType overloads, with the location of the user's new or annotation, before the class members are generated:
    error: -mm=own: 'Set' cannot hold 'Node' (its 'V'): an element has to be a value, a string or a Shared<T> handle; use 'Shared<Node>'
    error: -mm=own: 'Map' cannot hold 'any' (its 'V'): an element has to be a value, a string or a Shared<T> handle; give it one of those types
    
    When a new has its inferred type arguments refused, it no longer falls back to the default type arguments, which would report any a second time. The other memory models ignore the decorator. The compiler doesn't name Map or Set anywhere; the DefaultLib PR adds the decorator to them.
  • A handle in a tuple entry (copyIntoTuple). When a tuple is made of a handle and borrowed strings, it now retains the handle, just as it copies the strings.
  • A handle a yield takes out of generator state. When a yield reads a field, the state's count passes to the caller, and the state's release of the old value is erased. The filter that keeps every handle retain and release, as rc counting requires, had been keeping this release too. So each step released the previous handle twice: walking a Map of two handles with for…of freed the first one.
  • The owned result of a virtual call (OwnedReturnConsumptionPass). Whether the call returns +1 used to be decided over every method of that name in the module. With the default library loaded, A.get was grouped with Headers.get and similar methods, and a Shared<T> returned through a vtable leaked under rc. Now it's decided over the receiver's class chain only (onReceiverChain).

Tests

  • own_shared_elements: a local @sharedElements container of numbers, strings and handles, under gc, rc, none and own.
  • own_shared_yield_count, under rc and own: two entries walked, a yielded pair, and a break; counts are checked after each. It fails without the yield fix.
  • own_err_shared_elements_object, _any, _inferred.
  • Full suite: 5845 passed, 0 failed.
  • With the DefaultLib change applied to a copy of the built library:
    • map_*/set_* under own: the same 16 pass as before. The 8 untyped new Map() tests now fail with the new error.
    • Under rc, gc and none: all 24 pass.
    • The new map_shared passes under all four models, and under the JIT for own and rc.

The DefaultLib PR depends on this one.

🤖 Generated with Claude Code

- @SharedElements on a generic class: under own each type argument has to be
  a value, a string or a Shared<T> handle. Checked where the class is
  specialized, at the user's `new` or annotation, before its members are
  generated; a plain object or `any` is an error that points at Shared<T>.
  A `new` whose inferred arguments were refused does not fall back to the
  defaults (which would report `any` again).
- A tuple entry made of a handle beside borrowed strings retains the handle.
- A yield that takes a handle out of a generator's state hands the state's
  count to the caller: the state's release of the old value is now erased for
  a handle as for any value. Walking a Map of two handles freed the first.
- The owned result of a virtual call is decided over the methods on the
  receiver's class chain only, not every method of that name in the module:
  with the default library loaded, a Shared<T> returned through a vtable
  leaked under rc.

Tests: own_shared_elements, own_shared_yield_count,
own_err_shared_elements_object/_any/_inferred. Spec section 6 of
2026-10-26-own-generic-containers-design.md; docs limits updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit 6584976 into main Oct 27, 2026
2 checks passed
@ASDAlexander77
ASDAlexander77 deleted the own-shared-container-elements branch October 27, 2026 00:07
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