Skip to content

Commit 54ab4c9

Browse files
topolarityvtjnash
andauthored
typeinfer: Enqueue CIs for ccallable entrypoints (JuliaLang#57158)
This is another step in the long-term direction to have type-inference fully-explore the code graph we want to emit, largely side-stepping the vestigial `jl_type_infer` paths that we still have in type-inference for ccallable (and OpaqueClosure) This is needed for `juliac`, since the trim checks in codegen check if code was enqueued in the workqueue as expected. --------- Co-authored-by: Jameson Nash <vtjnash@gmail.com>
1 parent bdb3f1c commit 54ab4c9

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/typeinfer.jl

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,8 +1280,20 @@ function typeinf_ext_toplevel(methods::Vector{Any}, worlds::Vector{UInt}, trim::
12801280
ci isa CodeInstance && !use_const_api(ci) && push!(tocompile, ci)
12811281
end
12821282
elseif item isa SimpleVector
1283-
push!(codeinfos, item[1]::Type)
1284-
push!(codeinfos, item[2]::Type)
1283+
(rt::Type, sig::Type) = item
1284+
# make a best-effort attempt to enqueue the relevant code for the ccallable
1285+
ptr = ccall(:jl_get_specialization1,
1286+
#= MethodInstance =# Ptr{Cvoid}, (Any, Csize_t, Cint),
1287+
sig, this_world, #= mt_cache =# 0)
1288+
if ptr !== C_NULL
1289+
mi = unsafe_pointer_to_objref(ptr)
1290+
ci = typeinf_ext(interp, mi, SOURCE_MODE_NOT_REQUIRED)
1291+
ci isa CodeInstance && !use_const_api(ci) && push!(tocompile, ci)
1292+
end
1293+
# additionally enqueue the ccallable entrypoint / adapter, which implicitly
1294+
# invokes the above ci
1295+
push!(codeinfos, rt)
1296+
push!(codeinfos, sig)
12851297
end
12861298
end
12871299
while !isempty(tocompile)

0 commit comments

Comments
 (0)