Skip to content

[1.12] Defer global caching of CodeInstance to post-optimization step - #63080

Merged
maleadt merged 1 commit into
release-1.12from
tb/backport-58343-1.12
Sep 9, 2026
Merged

maleadt merged 1 commit into
release-1.12from
tb/backport-58343-1.12

Conversation

@maleadt

@maleadt maleadt commented Sep 9, 2026

Copy link
Copy Markdown
Member

Backport of #58343 to release-1.12.

On 1.12, finishinfer! publishes the CodeInstance of an inferred method to code_cache(interp)
before optimization runs, and finish! completes it afterwards with jl_update_codeinst, which also
overwrites analysis_results wholesale. Between those two points the CodeInstance is visible to
other tasks through the code cache with a valid world range, so anything attached to
analysis_results in that window is silently discarded. 1.11 and 1.13+ publish only after
finish!, so the window exists only on 1.12.

Packages that hang per-consumer data off analysis_results of cached CodeInstances
(CompilerCaching.jl, used by CUDA.jl and cuTile.jl) assume that a CodeInstance returned by
the code cache with a valid world range is final. On 1.12, a concurrent cold compilation
attaches to a CodeInstance that another task is still finalizing, and the attachment is
lost (JuliaGPU/cuTile.jl#311).

#58343 originally carried the backport-1.12 label, which was dropped in June 2025 because it did
not apply cleanly. The cherry-pick had three trivial conflicts in finish! (di vs
debuginfo naming), and the result matches the 1.13 code. JET already overloads both the
old and new finishinfer! signatures.

Assisted by: Fable 5.1

)

This PR extracts the caching improvements from
#56687, implemented by @aviatesk.
It essentially defers global caching to the post-optimization step,
giving a temporary cache to the optimizer instead of relying on the
global cache.

The issue with caching globally before optimization is that any errors
occurring within the optimizer may leave a partially initialized
`CodeInstance` in the cache, which was meant to be updated
post-optimization. Exceptions should not be thrown in the native
compilation pipeline, but abstract interpreters extending optimization
routines will frequently encounter some during an iterative development
(see JuliaComputing/DAECompiler.jl#25).

An extra benefit from deferring global caching is that the optimizer can
then more safely update `CodeInstance`s with new inference information,
as is the intent of #56687.

---------

Co-authored-by: Shuhei Kadowaki <aviatesk@gmail.com>
Co-authored-by: Cody Tapscott <84105208+topolarity@users.noreply.github.com>
(cherry picked from commit 24d2f4a)
@maleadt
maleadt merged commit a092589 into release-1.12 Sep 9, 2026
7 checks passed
@maleadt
maleadt deleted the tb/backport-58343-1.12 branch September 9, 2026 18:17
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.

2 participants