jit: do not compile methods with different optlevel in the same llvm module #62034
All Vouch review confidence checks passed
Residual risk 0.11 = Change Risk (0.61) × (1 − Review Confidence (0.83)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.61 · 248 lines diff across 4 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.93 · 5 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.330
Self Review
self_review
0.140
Real PR Conversation Timeline
6 items
Maybe this won't test what it is supposed to test if bounds checking is forced on. Have to check.
Seems to work even with --check-bounds=yes, but does require O2.
julia +nightly --check-bounds=yes /tmp/test_opt.jl
per-module optlevel does not leak across co-compiled modules: Test Failed at /tmp/test_opt.jl:29
Expression: OptLevelNoLeakHeavy.ksum2(a) === expected
Evaluated: 33348.18205471307 === 33348.18205471279
...
julia +nightly --check-bounds=yes -O0 /tmp/test_opt.jl
Test Summary: | Pass Total Time
per-module optlevel does not leak across co-compiled modules | 1 1 0.1s
julia +nightly --check-bounds=yes -O1 /tmp/test_opt.jl
Test Summary: | Pass Total Time
per-module optlevel does not leak across co-compiled modules | 1 1 0.1s
I believe this reintroduces a more subtle version of the bug #61255 was intended to fix. In the current design, it is important that all of the CodeInfos passed to jl_emit_codeinsts_to_jit_impl be added to the JIT with a single addOutput call.
Thoughts about the updated revision?
Bump (@xal-0). I know you are planning on rewriting this, but maybe there is some value in getting this in in the meantime.
KristofferC
The JIT compiles a batch of
CodeInstances into one LLVM module, andselectOptLeveloptimizes that module at the lowestjulia-optimization-levelamong its functions. So a method first reached through a caller in an@optlevel 0module was compiled at-O0. Its code, and with@simdreassociation its results, then depended on which caller happened to compile it first. Always-inline bodies emitted from such a module had the same effect on their host module.This partitions the batch by effective optimization level and emits one module per level. All of the modules are defined in the JIT under a single
LinkerMutexhold (addOutputs), so the batch stays atomic as in #61255. Calls between groups link directly to the callee rather than through atojlinvoketrampoline; I checked this by disassembling the caller and following its call stub to the callee'sspecptr. The grouping usesjl_requested_optlevel, the same function codegen uses for the function attribute, and always-inline bodies no longer carry the attribute.| | nightly | this PR |
|---|---|---|
| callee first reached via
@optlevel 0caller | compiled at-O0| compiled at default level || always-inline body from
@optlevel 0module | drags host to-O0| no effect || call between groups in one batch | n/a | direct (no trampoline) |
Written with Claude Code (Opus 5.5). The author has not yet read this description in full.
🤖 Generated with Claude Code