Skip to content

Keep more of the compiler concretely typed - #1053

Merged
maleadt merged 2 commits into
tb/invalidationsfrom
tb/invalidations-2
Oct 22, 2026
Merged

maleadt merged 2 commits into
tb/invalidationsfrom
tb/invalidations-2

Conversation

@maleadt

@maleadt maleadt commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #1052. With the first round of fixes, ChainRulesCore no longer invalidates the compilation pipeline when it's loaded before GPUCompiler, but other common packages still do, through different generic methods. This asserts types that are known but that inference can't see, in code that's on the path of every compilation:

  • names returned by safe_name while mangling, which are always Strings;
  • the file names of debug locations in backtrace, which are Strings or nothing;
  • the signature in classify_arguments, like in check_invocation;
  • the names of the entries in compiled, the runtime function declared by call!, the address of a relocated C global, and the library paths of the lazily loaded JLLs in ExternalBackend;
  • merge!-ing the result of a sibling compiler, which is a Dict{Any,Any} in practice and is otherwise merged behind an inference barrier;
  • the keys used to deduplicate compile units, which were tuples of unknown length.

The triggers here are e.g. FilePathsBase's joinpath and arg_gen, InlineStrings' convert(String, ...) and DataStructures' merge!, all of which are loaded by DataFrames or plotting packages.

Tested with the full test suite. Measurements (together with JuliaLLVM/LLVM.jl#703 and the other follow-ups) are in JuliaLLVM/LLVM.jl#703; e.g., the first CUDA kernel with DataFrames loaded first goes from 6.42 s on main to 2.76 s (2.12 s with nothing loaded first).

Like in the previous commits, code that operated on values inference couldn't
type (names returned by `safe_name`, debug info file names, the signature in
`classify_arguments`, entries of the `compiled` dictionary, runtime function
declarations, loaded relocation targets, JLL library paths, and the result of a
sibling compiler) was compiled with edges to the abstract signatures of generic
Base methods. Packages that extend those (e.g. DataFrames' dependencies or
FilePathsBase) then made Julia discard the precompiled code when loading
GPUCompiler. Assert the known types, and hide the remaining dynamic call.
`julia_type_words` recurses through `@nospecialize`d arguments, so its result
wasn't inferred, and building the type names of struct arguments for their
metadata was compiled with edges to generic concatenation methods (`vcat` of
values of unknown type, `Base.tail(::Any)`), which ChainRulesCore invalidates.
With it loaded first, that discarded the precompiled `finish_ir!` of the Metal
back-end, and the first Metal kernel (e.g. the one `fill!` launches) took ~2 s
longer to compile. Declare the result type and collect the words as `String`s.
@codecov

codecov Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.11765% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 92.49%. Comparing base (31f9070) to head (03a1ab5).

Files with missing lines Patch % Lines
src/driver.jl 75.00% 1 Missing ⚠️
Additional details and impacted files
@@                 Coverage Diff                  @@
##           tb/invalidations    #1053      +/-   ##
====================================================
- Coverage             92.50%   92.49%   -0.01%     
====================================================
  Files                    31       31              
  Lines                  7342     7346       +4     
====================================================
+ Hits                   6792     6795       +3     
- Misses                  550      551       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@maleadt
maleadt merged commit b11db0e into tb/invalidations Oct 22, 2026
32 of 36 checks passed
@maleadt
maleadt deleted the tb/invalidations-2 branch October 22, 2026 18:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

latency Compile time, load time, time-to-first-execution, invalidations.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant