Skip to content

-mm=own: array entries, and the Array<T> class holds shared elements - #50

Merged
ASDAlexander77 merged 6 commits into
mainfrom
own-defaultlib-batch
Oct 27, 2026
Merged

ASDAlexander77 merged 6 commits into
mainfrom
own-defaultlib-batch

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

Depends on ASDAlexander77/TypeScriptCompiler#704. Merge that one first: new Array<number>() needs its defaulted-parameter fix, and the other tests below need its other -mm=own fixes.

Changes

  • entries() reads the element into a local before the yield. Own does not yet follow a tuple built from a borrow inside the yield itself. Elements that are numbers or strings work.
  • class Array<T> is @sharedElements, as Map and Set are. concat, fill and slice copy elements, and an object has one owner, so under own an object goes in as Shared<T>. new Array<Node>() is now a compile error that points at Shared<T>.
  • The class's iterators (entries, keys, values, [Symbol.iterator]) say @borrows("this"), as T[]'s do.
  • filter2 hands back T[]'s generator. As a generator itself, it returned that generator as its final value, so iterating it yielded nothing. This applies under every memory model.
  • concat no longer spreads other into a rest argument, which under own would move the arrays.
  • array_class_splice uses an Array<Item>, which own refuses by design, so it is marked // not own.

Results

Model Before After
own 150/170 159/172, 10 skipped
rc, none all pass 171/172, 1 skipped
gc all pass 172/172

Each result holds in all four passes (release and debug, compile and JIT). The own tests that now pass:

  • array_entries
  • array_every
  • array_find2, array_find3
  • catch_library_error
  • regexp_parse_examples
  • array_concat and owning_copies in the debug pass

Still failing under own

array_reduceRight, string_matchAll and string_match_lastIndex. Fixing them needs compiler work, described in #704.

🤖 Generated with Claude Code

ASDAlexander77 and others added 6 commits October 27, 2026 18:04
reverse reads the element it swaps into a `let`, as sort's `temp` did: a `const` borrows the slot
overwritten next. sort no longer assigns its optional comparator a default - a callback parameter
that is assigned is one -mm=own knows nothing about, so a call of it with two elements was a use of
them after a call that may release them; it gives a selectionSort helper the comparator or the
default. Needs the compiler's copy of a string read out of a parameter the result borrows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…], a[i]]`

The compiler's exchange of two places (spec 42) moves nothing in any model, where a swap through a
local gave an object element a second owner under -mm=own. reverse over class instances now passes
under own (array_reverse_class). sort over class instances (array_sort_class) is `// not own`: its
comparison is handed on to selectionSort through a parameter, which has no callback facts yet.
Needs the compiler's `ts.Swap`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
sort gives its optional comparison on to selectionSort, and a callback given on through a
parameter now keeps the facts of the functions passed for it (compiler spec 43), so
array_sort_class is no longer `// not own`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- entries() reads the element into the state before the yield. Own does not
  follow a tuple made from a borrow inside the yield itself yet.
- class Array<T> is @SharedElements, as Map and Set are: concat, fill and
  slice copy elements, and an object has one owner, so an object goes in as
  Shared<T>. Its iterators say @borrows("this"), as T[]'s do. filter2 hands
  back T[]'s generator; as a generator itself, it returned that generator as
  its done value. concat no longer spreads other into a rest argument, which
  under own would move the arrays.
- array_class_splice (an Array<Item>) is marked "not own".

Needs the compiler's own-defaultlib-batch for new Array<number>() (a
constructor parameter with a default) and the other own fixes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit e1350eb 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