Skip to content

-mm=own: reverse and sort over class instances - #49

Merged
ASDAlexander77 merged 4 commits into
mainfrom
own-array-element-moves
Oct 27, 2026
Merged

ASDAlexander77 merged 4 commits into
mainfrom
own-array-element-moves

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

Under -mm=own, reverse and sort now work over class instances. This needs the compiler's ASDAlexander77/TypeScriptCompiler#703.

  • reverse and selectionSort swap elements with [a[i], a[j]] = [a[j], a[i]]. That compiles to an exchange that moves nothing in any memory model. Under own, a swap through a local gave an object element a second owner.
  • New tests array_reverse_class and array_sort_class. array_sort_class gives its class a toString: sort's default comparison is compiled even when a comparator is given, and it converts each element to a string in every model.

Suites with the compiler change (tests.ps1, all four builds):

  • gc: 172/172.
  • rc and none: 171/172, with one test skipped.
  • own: release compile 151/172, 10 skipped, before the forwarded-callback fix, which brings array_sort_class in.
  • Every own failure also fails against the DefaultLib build from before this change.

🤖 Generated with Claude Code

ASDAlexander77 and others added 4 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>
@ASDAlexander77
ASDAlexander77 merged commit c024b49 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