Repository navigation
Add a do-block form of compile that manages the IR's context - #1124
Merged
Merged
Conversation
compile(f, target, job) compiles in a JuliaContext of its own, runs f with the result, and frees the IR and its context afterwards. Most callers create a context only to read a few values from the IR, e.g. the entry point's name, and then dispose of it; this does that for them. The llvmgpu toolchain (#1122) needs it: there, the IR can belong to another LLVM library than the context the caller created, and reading it from the wrong one crashes.
This was referenced Nov 25, 2026
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.
Most callers of
compilecreate aJuliaContextonly to read a few values from the IR (the entry point's name, an attribute, the undefined functions) and then dispose of it:compile(f, target, job)does that for them:It compiles in a context of its own, runs
f(result, meta)with the IR's context active, and frees the IR and its context afterwards.resultis the module for:llvm, and the code otherwise.The reason is #1122. With its llvmgpu toolchain, the IR can belong to libLLVMGPU rather than to the Julia context the caller created. LLVM.jl then passes values such as
meta.entryto Julia's LLVM unless the caller activates the IR's context first, and that crashes or hangs. That is what fails on #1122's Buildkite: KernelAbstractions' POCL back-end readsmeta.entry.namein its precompile workload. With this form, #1122 only has to runfin the IR's context, and back-ends don't need to know which LLVM library ran.