@@ -82,44 +82,53 @@ function compile_unhooked(output::Symbol, @nospecialize(job::CompilerJob); kwarg
8282 error (" No active LLVM context. Use `JuliaContext()` do-block syntax to create one." )
8383 end
8484
85- @tracepoint " Validation" begin
86- check_method (job) # not optional
87- job. config. validate && check_invocation (job)
88- end
85+ # save/restore the `current_job` global that passes read: compilation nests (the relink
86+ # pass rebuilds the runtime via `compile_unhooked` on a cold cache), and a leaked inner
87+ # `kernel=false` job would make the outer kernel-state passes misfire.
88+ global current_job
89+ prev_job = @isdefined (current_job) ? current_job : nothing
90+ try
91+ @tracepoint " Validation" begin
92+ check_method (job) # not optional
93+ job. config. validate && check_invocation (job)
94+ end
8995
90- prepare_job! (job)
96+ prepare_job! (job)
9197
9298
93- # # LLVM IR
99+ # # LLVM IR
94100
95- ir, ir_meta = emit_llvm (job)
101+ ir, ir_meta = emit_llvm (job)
96102
97- if output == :llvm
98- if job. config. strip
99- @tracepoint " strip debug info" strip_debuginfo! (ir)
100- end
103+ if output == :llvm
104+ if job. config. strip
105+ @tracepoint " strip debug info" strip_debuginfo! (ir)
106+ end
101107
102- return ir, ir_meta
103- end
108+ return ir, ir_meta
109+ end
104110
105111
106- # # machine code
112+ # # machine code
107113
108- format = if output == :asm
109- LLVM. API. LLVMAssemblyFile
110- elseif output == :obj
111- LLVM. API. LLVMObjectFile
112- else
113- error (" Unknown assembly format $output " )
114- end
115- asm, asm_meta = emit_asm (job, ir, format)
114+ format = if output == :asm
115+ LLVM. API. LLVMAssemblyFile
116+ elseif output == :obj
117+ LLVM. API. LLVMObjectFile
118+ else
119+ error (" Unknown assembly format $output " )
120+ end
121+ asm, asm_meta = emit_asm (job, ir, format)
116122
117- if output == :asm || output == :obj
118- return asm, (; asm_meta... , ir_meta... , ir)
119- end
123+ if output == :asm || output == :obj
124+ return asm, (; asm_meta... , ir_meta... , ir)
125+ end
120126
121127
122- error (" Unknown compilation output $output " )
128+ error (" Unknown compilation output $output " )
129+ finally
130+ current_job = prev_job
131+ end
123132end
124133
125134# primitive mechanism for deferred compilation, for implementing CUDA dynamic parallelism.
0 commit comments