Skip to content

-mm=own: an object literal holding another module's fresh instance borrows it - #836

Merged
ASDAlexander77 merged 1 commit into
mainfrom
own-record-imported-fresh
Nov 13, 2026
Merged

ASDAlexander77 merged 1 commit into
mainfrom
own-record-imported-fresh

Conversation

@ASDAlexander77

@ASDAlexander77 ASDAlexander77 commented Nov 13, 2026 •

Copy link
Copy Markdown
Owner

Under -mm=own, JSON.stringify({ when: new Date(0) }) failed with "an object literal that holds a value it owns is moved only into a local or returned as it is; -mm=own cannot move it here yet". The same happens to any call given an object literal that holds a fresh instance of a class from another module. The same literal holding a class of the program's own module worked.

Cause: the signature pass decides which object literals only borrow their fields (classifyRecordBoxes, inside computeFacts) from whether each field's value is fresh. An imported class's ..new call (and a --own-facts fresh result) was marked fresh only in the loop after computeFacts. So when the literals were classified, new Date(0) was an unknown value, and the literal was refused. new C() of the module's own class is a ts.New, which is always fresh.

Fix: OwnershipSignaturePass marks those calls fresh before the facts too (isImportedFreshResult, shared with the later loop).

Test: import_record_stamp.ts + export_record_stamp.ts (-shared; compile and jit; gc, rc, own). It passes a literal holding an imported class instance to a function, to a generic, two of them in one literal, and through a local. The previous compiler fails the own tests with that error.

Testing: ctest 7042/7042 on Windows and 7023/7023 on Linux (WSL). The ownership verifier is clean. DefaultLib tests.ps1 passes under gc, rc, none and own.

🤖 Generated with Claude Code

…rrows it

JSON.stringify({ when: new Date(0) }) failed under -mm=own with "an object
literal that holds a value it owns is moved only into a local or returned
as it is". The literal's fields are classified (classifyRecordBoxes, in
computeFacts) before the imported Date..new call was marked as a fresh
result, so new Date(0) read as an unknown value. The imported `..new` and
--own-facts fresh results are now marked before the facts as well.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit 3a8735c into main Nov 13, 2026
8 checks passed
@ASDAlexander77
ASDAlexander77 deleted the own-record-imported-fresh branch November 13, 2026 08:50
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