From 69862dd49db79548f55d65dd8bfb56529e3e2d1c Mon Sep 17 00:00:00 2001 From: Valentin Churavy Date: Thu, 19 Nov 2026 15:26:00 +0100 Subject: [PATCH] POCL: don't rely on GPUCompiler's `:obj` metadata for exception sites On Julia 1.12, `GPUCompiler.compile(:obj, job)` returns metadata without `exception_sites`, so compiling any kernel failed with a `FieldError` since #982 (including during precompilation). GPUCompiler's precompiled `compile_unhooked` was inferred while `uses_exception_sites` returned `false` for all jobs, so it merges the metadata of `emit_llvm` with the field names of the narrower result; our method doesn't invalidate it on 1.12. Compile to `:llvm` instead, whose metadata is returned as it is, and emit the object with `emit_asm`, as the `:obj` path does. Co-Authored-By: Claude Opus 5.5 --- src/pocl/compiler/compilation.jl | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/pocl/compiler/compilation.jl b/src/pocl/compiler/compilation.jl index a2b02775c..b9308700a 100644 --- a/src/pocl/compiler/compilation.jl +++ b/src/pocl/compiler/compilation.jl @@ -294,10 +294,17 @@ function compile_to_obj(@nospecialize(job::CompilerJob)) compilations[] += 1 return JuliaContext() do ctx - obj, meta = invoke_frozen(GPUCompiler.compile, :obj, job) + # compile to LLVM IR and emit the object ourselves, rather than compiling to `:obj`: + # the latter merges the metadata of both steps, which on Julia 1.12 drops + # `exception_sites`. GPUCompiler's precompiled `compile_unhooked` was inferred when + # `uses_exception_sites` was `false` for all jobs, and isn't invalidated by our method. + llvm_ir, meta = invoke_frozen(GPUCompiler.compile, :llvm, job) # we own the IR: inspect it, then dispose of it - @dispose ir = meta.ir begin + @dispose ir = llvm_ir begin + obj, _ = invoke_frozen( + GPUCompiler.emit_asm, job, ir, meta.relocations, LLVM.CodeGenFileType.Object + ) entry = meta.entry.name device_rng = haskey(meta.entry.function_attributes, "julia.opencl.rng") (; obj, entry, device_rng, meta.exception_sites)