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