Skip to content

-mm=own under the JIT: read the default library's facts from the DLL it loads - #695

Merged
ASDAlexander77 merged 1 commit into
mainfrom
own-jit-default-lib-facts
Oct 26, 2026
Merged

ASDAlexander77 merged 1 commit into
mainfrom
own-jit-default-lib-facts

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

Under -mm=own, the JIT never read the default library's ownership facts. readOwnFacts (tslang/tslang/borrowfacts.cpp) read the __tsownfacts_ text only for an exe, from the static library:

if (!compileOptions.noDefaultLib && emitAction != Action::RunJIT)

So under --emit=jit every call into the library could destroy anything: lending a field to String.indexOf, a module-level Date given to getTime, and Map/Set's internals were errors there, though the same programs compiled to an exe.

Fix

  • Under the JIT the facts are read from the default library's DLL the JIT loads, from its file, as readBorrowFacts already does for the borrow facts. The DLL's facts text is the same as the static library's of the same build (checked: 212 identical lines).
  • The files the own facts were read from are now JIT cache dependencies (importedOwnFactsFiles, beside importedBorrowFactsFiles). --own-facts objects were not tracked either.
  • The facts spec (2026-10-25-own-facts-from-objects-design.md) says so.

Tests

  • New test-jit-own-defaultlib-facts / test-compile-own-defaultlib-facts (own-defaultlib-facts.cmake): a field lent to library methods, with the real default library; skipped when none is built, as the default-library collector tests are. With the JIT exclusion put back, the JIT test fails.
  • Windows release ctest: 5828/5828.
  • DefaultLib suite under the JIT, own: the same 97 tests pass as for an exe (before, date_getTime, regexp_test, string_split and the Map/Set tests failed only under the JIT).

🤖 Generated with Claude Code

…it loads

readOwnFacts read the default library's own facts (`__tsownfacts_`) only for an exe, from its static
library. Under the JIT it read none, so every call into the library could destroy anything: a field
lent to `String.indexOf`, a module-level `Date` given to `getTime`, and Map/Set's internals were
errors there, though the same programs compiled to an exe. Now the JIT reads them from the DLL it
loads, from its file, as readBorrowFacts already does for its borrow facts (the text is the same as
the static library's of the same build).

The files the own facts were read from are a JIT cache entry's dependencies too
(importedOwnFactsFiles, beside importedBorrowFactsFiles); --own-facts objects were not either.

Test: test-{jit,compile}-own-defaultlib-facts (own-defaultlib-facts.cmake, with the real default
library; skipped when none is built). DefaultLib suite under the JIT, own: the same 97 tests pass as
for an exe.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit 119300e into main Oct 26, 2026
2 checks passed
@ASDAlexander77
ASDAlexander77 deleted the own-jit-default-lib-facts branch October 26, 2026 18:40
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