Repository navigation
Keep abstractly-typed values away from generic Base code - #702
Merged
Merged
Conversation
An untyped literal like `[id, MDString(name), val]` with `val::Metadata` isn't
inferred concretely, so `MDNode` and its conversion to `Vector{Metadata}` were
compiled for any `AbstractVector`, including ranges, whose methods packages like
ChainRulesCore invalidate by extending `*`. The empty `[]` vectors passed to the
`PassBuilder` and `PassManager` constructors similarly went through a generic
`convert(Vector{String}, ::Vector{Any})`.
This was referenced Oct 21, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. @@ Coverage Diff @@
## main #702 +/- ##
==========================================
- Coverage 94.35% 94.35% -0.01%
==========================================
Files 59 59
Lines 7850 7849 -1
==========================================
- Hits 7407 7406 -1
Misses 443 443
🚀 New features to boost your workflow:
|
maleadt
force-pushed
the
tb/invalidations
branch
from
October 21, 2026 12:54
c3f37d9 to
570e785
Compare
Much of LLVM.jl is compiled with `@nospecialize`, so values like alignments, enums and operand bundle vectors are abstractly typed. Code that formats or iterates them is compiled with edges to generic Base methods, which packages loaded before LLVM.jl (e.g. ChainRulesCore) invalidate by adding methods for promotion or arithmetic, discarding LLVM.jl's and its users' precompiled code. Format alignment errors lazily, format enum names to a string before printing them, assert the width of enum values and the type of pass parameter names, and collect views of operand bundles behind an inference barrier. With ChainRulesCore loaded first, this brings the first KernelAbstractions CPU kernel from 1.9 s to 1.1 s, and the first CUDA kernel from 3.5 s to 2.9 s.
Base only re-exports `llvmcall`, and its binding there is created lazily. Code that references `Base.llvmcall` through a `GlobalRef` therefore has an edge to a binding that may not exist yet, which Julia 1.13 reports as an invalidation every time the code is loaded (JuliaLang/julia#59135). Nothing is recompiled, but the spurious entries clutter SnoopCompile's output.
maleadt
force-pushed
the
tb/invalidations
branch
from
October 21, 2026 20:57
570e785 to
e4f20d1
Compare
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.
Packages loaded before LLVM.jl that extend Base functions like
promote_ruleor*(ChainRulesCore does both) invalidate precompiled code in LLVM.jl and its users, which Julia then recompiles on first use (JuliaGPU/GPUCompiler.jl#1048).Much of LLVM.jl is compiled with
@nospecialize, so values like alignments, enum values and operand bundle vectors are abstractly typed there. Code that formats or iterates them is compiled with edges to generic Base methods (!=(::Unsigned, ::Int64)through integer printing, range iteration throughcollect,convert(Vector{String}, ::Vector{Any})), and those are what such packages invalidate. This PR keeps these values away from generic code: typed literals for the module-flagMDNodeand the pass-name vectors, a lazily formatted alignment error, enum names formatted to aStringbefore printing, an assertion that enum values are 32-bit, and operand bundle views collected behind an inference barrier. Behaviour and error messages are unchanged.A separate commit refers to
llvmcallthroughCore.Intrinsicsin generated calls. That one is cosmetic: on Julia 1.13, edges to Base's lazily created re-export show up as spurious invalidations (JuliaLang/julia#59135, fixed in 1.14).First kernel on Julia 1.13.2, with the downstream fixes (JuliaGPU/GPUCompiler.jl#1052, maleadt/CompilerCaching.jl#33 etc.) applied and only LLVM.jl varied:
DataFrames loaded first is addressed by the follow-up, #703.