Support programs compiled by `juliac --trim` #3888
All Vouch review confidence checks passed
Residual risk 0.27 = Change Risk (0.50) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.50 · 570 lines diff across 7 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
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.380
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #3888"
general
weight: 0.35
vchuravy
Makes Enzyme work in programs compiled ahead of time by
juliac, including with--trim, with plainReverse/Forward(noset_abi(…, InlineABI)needed). Motivated by this Discourse thread, where trimming failed with Enzyme.The example from the thread now builds to a 3.8 MB trimmed executable on 1.12.6 (reverse over an array, reverse of a scalar
Active, forward mode), and the binary does not loadlibEnzymeorlibLLVMExtraat runtime.A trimmed program runs without Julia's compiler, so every derivative has to be generated while
juliacbuilds the program and linked into the code that calls it, and nothing of Enzyme's compiler may reach the image. Five independent problems stood in the way:1.
Compiler.__init__rooted the whole compiler into the image. It registered the ~115@cfunctionrule trampolines, the handlers and the ORC JIT;__init__methods are roots of a trimmed image, so the trim verifier saw the entire compiler and LLVM.jl (~1200 errors). The compiler now initializes on first use (ensure_compiler_init!, called at the compile entry points), throughBase.OncePerProcesson 1.12+ (it resets itself when serialized) and a pid-keyed flag +__init__before.API,JIT,FFIandBLASSupportlose their__init__the same way.2.
FFIABIbakes a JIT address of the build process into the generated code, dead in the binary.aot_abisubstitutesInlineABIwhentrimming()(generating_output() && JLOptions().trim != 0).3. juliac's build process defers every package
__init__(it generates a system image:--output-o --output-incremental=no), so when thethunkgenerator ran,Enzyme_jll/LLVMExtra_jllhad never located their libraries (libEnzyme == ""), the generator threw, and the verifier reportedthunk(...)::Any.run_deferred_inits!runs those JLL__init__s (then unsets theirlib_pathso the image resolves the libraries where it runs) and LLVM's error handlers. LLVM.jl's and GPUCompiler's full__init__cannot be run there: they callatexit, and the build process is already exiting. The build script also emptiesDEPOT_PATHbefore compiling, soartifact"…"fails;with_depot_pathrestores it around the lookup.4. Link error
undefined reference to julia.safepoint. The AOT compiler partitions the module and compiles ouralwaysinlineInlineABI wrapper as a standalone function in its own partition.use_gcstack_arg!had replaced itsjulia.get_pgcstackcall with the argument, soFinalLowerGC(which on ≤1.12 only finds a pgcstack through that call in the entry block) skipped it. The wrapper's argument now carries the"gcstack"attribute (what 1.13'sgetPGCstacklooks for), and on <1.13, when generating output, ajulia.get_pgcstackcall is kept in the entry block instead of using the argument.5. The JIT disposed its target machine in an
atexithook; a process that generates output runs those before* it compiles the output.Also adds
test/juliac.jl(builds and runs a trimmed program; ~20 s; skipped on <1.12, Windows, or without a C compiler) and an FAQ section.Verification
juliac --trim=safeon 1.12.6: zero verifier errors from Enzyme; the executable runs and gives correct derivatives.callconv(the InlineABI tests),precompile,sugar,juliactest sets pass on 1.12; smoke tests on 1.10 (flag path) and 1.13-rc1."gcstack"path), but rc1 itself fails trim on JLLWrappers'unique!→issorteddispatch and onDownloads.Curl.__init__; nothing Enzyme-side.git runic --diff mainclean.Remaining limitations, all upstream (documented in the FAQ with workarounds)
__init__of Pkg'sREPLExt(Pkg comes via LazyArtifacts, REPL via GPUCompiler) and of GPUCompiler (get(stderr, :color, false)) do not pass the trim verifier; users need a two-line shim in their program until those are fixed, the wayjuliac-trim-stdlib.jlshimsPkg.__init__.-lmon Linux; a derivative callingcos/expneedsJULIA_CC="cc -Wl,--no-as-needed -lm".autodiff_deferred/deferred_codegenpaths need a JIT and are unavailable in a trimmed program.A possible follow-up: switching to
InlineABIunder anygenerating_output()(not only--trim) would likely also fix the stale-pointer@test_brokencases intest/precompile.jl; this PR keeps the change scoped to trimming.