Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
maleadt committed Apr 9, 2024
1 parent 933ad71 commit d3a5f15
Showing 1 changed file with 33 additions and 16 deletions.
49 changes: 33 additions & 16 deletions src/jlgen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -503,25 +503,42 @@ end # HAS_INTEGRATED_CACHE
## codegen/inference integration

function ci_cache_populate(interp, cache, mi, min_world, max_world)
src = CC.typeinf_ext_toplevel(interp, mi)

# inference populates the cache, so we don't need to jl_get_method_inferred
wvc = WorldView(cache, min_world, max_world)
@assert CC.haskey(wvc, mi)

# if src is rettyp_const, the codeinfo won't cache ci.inferred
# (because it is normally not supposed to be used ever again).
# to avoid the need to re-infer, set that field here.
ci = CC.getindex(wvc, mi)
if ci !== nothing && ci.inferred === nothing
@static if VERSION >= v"1.9.0-DEV.1115"
@atomic ci.inferred = src
else
ci.inferred = src
if VERSION >= v"1.12.0-DEV.15"
inferred_ci = CC.typeinf_ext_toplevel(interp, mi, CC.SOURCE_MODE_FORCE_SOURCE) # or SOURCE_MODE_FORCE_SOURCE_UNCACHED?

# inference should have populated our cache
wvc = WorldView(cache, min_world, max_world)
@assert CC.haskey(wvc, mi)
ci = CC.getindex(wvc, mi)

# if ci is rettype_const, the inference result won't have been cached
# (because it is normally not supposed to be used ever again).
# to avoid the need to re-infer, set that field here.
if ci.inferred === nothing
CC.setindex!(wvc, inferred_ci, mi)
ci = CC.getindex(wvc, mi)
end
else
src = CC.typeinf_ext_toplevel(interp, mi)

# inference should have populated our cache
wvc = WorldView(cache, min_world, max_world)
@assert CC.haskey(wvc, mi)
ci = CC.getindex(wvc, mi)

# if ci is rettype_const, the inference result won't have been cached
# (because it is normally not supposed to be used ever again).
# to avoid the need to re-infer, set that field here.
if ci.inferred === nothing
@static if VERSION >= v"1.9.0-DEV.1115"
@atomic ci.inferred = src
else
ci.inferred = src
end
end
end

return ci
return ci::CodeInstance
end

function ci_cache_lookup(cache, mi, min_world, max_world)
Expand Down

0 comments on commit d3a5f15

Please sign in to comment.