Skip to content

-mm=own: reverse and sort move string elements by copy - #48

Merged
ASDAlexander77 merged 1 commit into
mainfrom
own-array-element-moves
Oct 27, 2026
Merged

ASDAlexander77 merged 1 commit into
mainfrom
own-array-element-moves

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

Summary

Under -mm=own, reverse and sort over strings failed.

  • reverse: it reads the element it swaps into a let, as sort's temp already did. A const borrows the slot that the next line overwrites. A let starts from a copy of a string; for a number it changes nothing.
  • sort: it no longer assigns its optional comparator parameter a default.
    • Under own, what a callback may release is known from the functions given for it. A parameter that is assigned is one nothing knows about, so callbackfn(this[i], this[j]) was a use of the two elements after a call that may release them.
    • sort now gives a selectionSort helper either the comparator it was given or the default.

The other models behave as before.

Depends on ASDAlexander77/TypeScriptCompiler#702: a string read out of the parameter the result borrows is copied into a place. Merge that first.

Tests

  • With the compiler from #702 and DefaultLib rebuilt:
    • rc, gc and none pass every test.
    • own goes from 145 to 150/170 (array_copyWithin, owning_copies, array_reverse, array_sort, string_localeCompare), with no new failures.
  • Not here: sort/reverse over class instances under own.

🤖 Generated with Claude Code

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>
@ASDAlexander77
ASDAlexander77 merged commit 6b42530 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