Repository navigation
JIT cache: each .ts file is compiled into an object kept in __jit - #405
Merged
Merged
Conversation
Under --emit=jit the program and every .ts module it imports (directly or through another) are each compiled into an object of their own, stored in a `__jit` folder beside the source with a manifest of what it was compiled from (the sources read - itself, references, imports, lib.d.ts - the imported shared libraries, and the tslang build). The next run loads the objects into the LLJIT instead of compiling again while all of that is unchanged; an edited module is recompiled together with its importers. Options are part of the object's name, so runs with other options keep objects of their own. - An import pointing to a .ts file is a declaration again under the JIT, as it is compiled; the module's object provides the bodies. MLIRGen records the .ts files imported (dependencies first) and the libraries imported. - Each object's llvm.global_ctors are moved into one init function, called in dependency order before the program starts (the JIT runs no object's global_ctors). On ELF, COMDAT definitions (a class's `.size`, defined by the module and its importers) are made weak so ORC keeps one. - A program in an import cycle is compiled as one module with the imports' bodies included (a module in a cycle can't be compiled on its own, the same holds for --emit=obj) and cached as one object. - Writes are atomic (temp file + rename), so concurrent runs share a cache. - --jit-cache=false keeps the previous behaviour (one module, every run); --jit-cache-dir=<folder> puts all objects in one folder. Not used for stdin input or --dump-object-file. - runJit is split into reusable parts (process setup, library loading, JIT creation, program run) shared with the cached path; on Win64 the _CxxThrowException shim now finds the image base of the object the ThrowInfo is in, since there can be more than one JIT'd object. Tests: jit-cache/ (diamond imports with initialization order, an import cycle) and jit-cache.cmake (cache reused without rewriting, recompiled after an imported module changes). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VPAHhg8c9NEdoYNw52AtTg
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VPAHhg8c9NEdoYNw52AtTg
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #404. Instead of including every imported
.tsmodule into the program's own module on each run,--emit=jitnow compiles the program and each.tsmodule it imports into an object of its own. The objects are cached and reused on later runs.What changes
--emit=jitthe program and every.tsmodule it imports, directly or through another module, are each compiled into their own object. The objects are stored in a__jitfolder beside the source.lib.d.ts;.tsfile under the JIT. It is a declaration again, as it is when compiling; the module's own object provides the bodies. MLIRGen records the.tsfiles imported (dependencies first) and the libraries imported.llvm.global_ctorsare moved into one init function, and these are called in dependency order before the program starts, because the JIT runs no object'sglobal_ctors. On ELF, COMDAT definitions (for example a class's.size, which is defined by the module and by its importers) are made weak, so ORC keeps one.--emit=obj.--jit-cache=falsekeeps the previous behaviour (one module, compiled every run).--jit-cache-dir=<folder>puts all objects in one folder. The cache is not used for stdin input or--dump-object-file.runJitrefactor. It is split into reusable parts (process setup, library loading, JIT creation, program run), which are shared with the cached path._CxxThrowExceptionshim now finds the image base of the object that holds the ThrowInfo, since there can be more than one JIT'd object.Tests
jit-cache/: diamond imports with initialization order, and an import cycle.jit-cache.cmake: the cache is reused without being rewritten, and is recompiled after an imported module changes.Testing
Linux, Release build with the prebuilt LLVM 22.1.8: the full
ctestsuite passes (3190 passed, 0 failed). Not built or tested on Windows, so the Win64_CxxThrowExceptionchange is untested.🤖 Generated with Claude Code
https://claude.ai/code/session_01VPAHhg8c9NEdoYNw52AtTg
Generated by Claude Code