Skip to content

Map and Set: @sharedElements; under -mm=own objects go in as Shared<T> - #41

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

ASDAlexander77 merged 1 commit into
mainfrom
own-shared-elements

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

Depends on ASDAlexander77/TypeScriptCompiler#697, which adds the compiler's @sharedElements check. Merge that one first.

Under -mm=own, an object goes into a Map or Set as Shared<T>. A plain object or any key, value or element is now a compile error at the user's code that points at Shared<T>, where it used to be errors inside lib.generics.ts.

Changes

  • @sharedElements on Map and Set. The other memory models ignore it.
  • tests.ps1 and tests.sh: a test whose first line starts with // not own is skipped under -mm=own, beside the existing // gc only. The 8 untyped new Map() tests carry the marker: map_any, map_clear, map_entries, map_forEach, map_iterator, map_keys, map_size, map_values. An untyped new Map() is Map<any, any>, which own refuses, and own never compiled those tests. They still run under gc, rc and none.
  • tests/map_shared.ts: Map and Set of Shared<Node>, covering overwrite, get, entries, values, break, delete, union and intersection. Under rc and own it checks that every count comes back.

Tests

Run with the #697 compiler against a copy of the built library carrying this change:

  • map_*/set_* under own: the same 16 pass as before. The 8 marked tests fail with the new error instead of errors inside the library.
  • Under rc, gc and none: all 24 pass.
  • map_shared passes under own, rc, gc and none, and under the JIT for own and rc.

The full suites weren't run through tests.ps1, and the library wasn't rebuilt from this branch.

🤖 Generated with Claude Code

- @SharedElements on Map and Set: under -mm=own a key, value or element has
  to be a value, a string or a Shared<T> handle; a plain object or `any` is a
  compile error at the user's code that points at Shared<T>. Needs the
  compiler's @SharedElements check; the other memory models ignore it.
- tests.ps1/tests.sh: a test whose first line starts with "// not own" is
  skipped under -mm=own; the untyped (Map<any, any>) map_* tests say so.
- tests/map_shared.ts: Map and Set of Shared<T> - overwrite, get, entries,
  values, break, delete, union, intersection; counts given back under rc
  and own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit 5acd17c into main Oct 27, 2026
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