Skip to content

Borrow facts: name the symbol after the module's own file (JIT cache duplicate symbol) - #628

Merged
ASDAlexander77 merged 2 commits into
mainfrom
jit-cache-borrow-facts-symbol
Oct 20, 2026
Merged

ASDAlexander77 merged 2 commits into
mainfrom
jit-cache-borrow-facts-symbol

Conversation

@ASDAlexander77

@ASDAlexander77 ASDAlexander77 commented Oct 20, 2026 •

Copy link
Copy Markdown
Owner

Problem

Since #609, running a program that imports modules under the JIT (with the JIT cache) fails:

tslang: error: failed to add '...\core\input_pass.ts' to the JIT engine, error: In ...\core\__jit\input_pass.ts.<hash>.obj, duplicate definition of symbol '__tsborrow_compute_nbody_12767637287532266077'

The JIT cache compiles each imported module through runMLIRPasses with isJit off (jitcache.cpp), so BorrowFactsExportPass runs for every import. But the symbol name came from inputFilename, which is always the main program. So every cached import defined the same __tsborrow_<main>_<hash>.

Fix

transform.cpp now builds the name from the module's main source buffer, which is the file actually being compiled. Stdin (-) still uses inputFilename. moduleSymbolSuffix canonicalizes the path, so a normal --emit=obj build gives the same symbol as before.

Also: the modules the JIT cache compiles (isJit off, jitCache on) no longer export facts at all. Their objects are only loaded into the JIT, never linked, and the program run there drops imported facts (StackPromotionPass.cpp:58-63), so nothing ever read them.

Verified

  • native_ts_graphics examples/compute_nbody.ts -- -test under the JIT: Test PASSED. Before the fix it failed with the error above.
  • The new JIT cache objects carry no __tsborrow_ symbol. With the first commit alone, each had its own (__tsborrow_donut_…, __tsborrow_input_pass_…, …).
  • The 92 borrow-facts / stack-promotion / borrow tests pass locally (Windows), including test-borrow-facts-defaultlib.
  • --emit=obj core/args.ts, old vs new compiler: same __tsborrow_args_11047768023027654085 and identical facts (--print-borrow-facts).

Caches already written by pre-alpha105 hold the bad objects. A new compiler build gets a new compiler id, so it recompiles them.

🤖 Generated with Claude Code

ASDAlexander77 and others added 2 commits October 20, 2026 21:52
The JIT cache compiles each imported module through runMLIRPasses with
isJit off, so the borrow-facts export ran for every import too, but its
symbol was named from inputFilename - the main program. Every cached
import then defined the same __tsborrow_<main>_<hash>, and the JIT failed
to add the second one with a duplicate definition.

Take the name from the module's main source buffer instead; for an
--emit=obj build that is the same canonical path, so its symbol is
unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The JIT cache compiles each imported module with isJit off and jitCache
on. Those objects are only ever loaded into the JIT, never linked, and the
program run there drops imported facts (StackPromotionPass), so the facts
they carried were never read.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit 71bbf51 into main Oct 20, 2026
2 checks passed
@ASDAlexander77
ASDAlexander77 deleted the jit-cache-borrow-facts-symbol branch October 20, 2026 22:01
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