@@ -182,14 +182,16 @@ function optimize!(code::CodeInfo, scope)
182182 arg1 = stmt. args[1 ]
183183 if (arg1 === :llvmcall || lookup_stmt (code. code, arg1) === Base. llvmcall) && isempty (sparams) && scope isa Method
184184 nargs = length (stmt. args)- 4
185- delete_idx = build_compiled_call! (stmt, Base. llvmcall, code, idx, nargs, sparams, evalmod)
185+ # Call via `invokelatest` to avoid compiling it until we need it
186+ delete_idx = Base. invokelatest (build_compiled_call!, stmt, Base. llvmcall, code, idx, nargs, sparams, evalmod)
186187 delete_idx === nothing && error (" llvmcall must be compiled, but exited early from build_compiled_call!" )
187188 push! (foreigncalls_idx, idx)
188189 append! (delete_idxs, delete_idx)
189190 end
190191 elseif stmt. head === :foreigncall && scope isa Method
191192 nargs = foreigncall_version == 0 ? stmt. args[5 ]:: Int : length (stmt. args[3 ]:: SimpleVector )
192- delete_idx = build_compiled_call! (stmt, :ccall , code, idx, nargs, sparams, evalmod)
193+ # Call via `invokelatest` to avoid compiling it until we need it
194+ delete_idx = Base. invokelatest (build_compiled_call!, stmt, :ccall , code, idx, nargs, sparams, evalmod)
193195 if delete_idx != = nothing
194196 push! (foreigncalls_idx, idx)
195197 append! (delete_idxs, delete_idx)
0 commit comments