@@ -480,8 +480,32 @@ end # HAS_INTEGRATED_CACHE
480480# # codegen/inference integration
481481
482482function ci_cache_populate (interp, cache, mi, min_world, max_world)
483- if VERSION >= v " 1.12.0-DEV.15"
484- inferred_ci = CC. typeinf_ext_toplevel (interp, mi, CC. SOURCE_MODE_FORCE_SOURCE) # or SOURCE_MODE_FORCE_SOURCE_UNCACHED?
483+ @static if VERSION >= v " 1.12.0-DEV.1434"
484+ # see typeinfer.jl: typeinf_ext_toplevel
485+ ci = CC. typeinf_ext (interp, mi, CC. SOURCE_MODE_NOT_REQUIRED)
486+ inspected = IdSet {CodeInstance} ()
487+ tocompile = CodeInstance[ci]
488+ while ! isempty (tocompile)
489+ callee = pop! (tocompile)
490+ callee in inspected && continue
491+ push! (inspected, callee)
492+ # now make sure everything has source code, if desired
493+ mi = CC. get_ci_mi (callee)
494+ def = mi. def
495+ if CC. use_const_api (callee)
496+ src = CC. codeinfo_for_const (interp, mi, ci. rettype_const)
497+ elseif isa (def, Method) && ccall (:jl_get_module_infer , Cint, (Any,), def. module) == 0 && ! trim
498+ src = CC. retrieve_code_info (mi, CC. get_inference_world (interp))
499+ else
500+ # TODO : typeinf_code could return something with different edges/ages/owner/abi (needing an update to callee), which we don't handle here
501+ src = CC. typeinf_code (interp, mi, true )
502+ end
503+ if src isa CodeInfo
504+ CC. collectinvokes! (tocompile, src)
505+ end
506+ end
507+ elseif VERSION >= v " 1.12.0-DEV.15"
508+ inferred_ci = CC. typeinf_ext_toplevel (interp, mi, CC. SOURCE_MODE_FORCE_SOURCE)
485509 @assert inferred_ci != = nothing " Inference of $mi failed"
486510
487511 # inference should have populated our cache
518542function ci_cache_lookup (cache, mi, min_world, max_world)
519543 wvc = WorldView (cache, min_world, max_world)
520544 ci = CC. get (wvc, mi, nothing )
521- if ci != = nothing && ci. inferred === nothing
545+ if VERSION < v " 1.12.0-DEV.1434 " && ci != = nothing && ci. inferred === nothing
522546 # if for some reason we did end up with a codeinfo without inferred source, e.g.,
523547 # because of calling `Base.return_types` which only sets rettyp, pretend we didn't
524548 # run inference so that we re-infer now and not during codegen (which is disallowed)
@@ -622,7 +646,13 @@ function compile_method_instance(@nospecialize(job::CompilerJob))
622646 Metadata (ConstantInt (DEBUG_METADATA_VERSION ()))
623647 end
624648
625- native_code = if VERSION >= v " 1.12.0-DEV.1667"
649+ native_code = if VERSION >= v " 1.12.0-DEV.1823"
650+ # each item in the list should be a CodeInstance followed by a CodeInfo
651+ # indicating something to compile
652+ codeinstance = ci_cache_lookup (cache, job. source, job. world, job. world):: CodeInstance
653+ codeinfo = CC. typeinf_code (interp, job. source, #= trim=# true ):: CodeInfo
654+ @ccall jl_emit_native ([codeinstance, codeinfo]:: Vector{Any} , ts_mod:: LLVM.API.LLVMOrcThreadSafeModuleRef , Ref (params):: Ptr{Base.CodegenParams} , #= extern linkage=# false :: Cint ):: Ptr{Cvoid}
655+ elseif VERSION >= v " 1.12.0-DEV.1667"
626656 ccall (:jl_create_native , Ptr{Cvoid},
627657 (Vector{MethodInstance}, LLVM. API. LLVMOrcThreadSafeModuleRef, Ptr{Base. CodegenParams}, Cint, Cint, Cint, Csize_t, Ptr{Cvoid}),
628658 [job. source], ts_mod, Ref (params), CompilationPolicyExtern, #= imaging mode=# 0 , #= external linkage=# 0 , job. world, Base. unsafe_convert (Ptr{Nothing}, lookup_cb))
0 commit comments