Skip to content

Commit

Permalink
enable precompilation cache
Browse files Browse the repository at this point in the history
With the introduction of `CodeInstance` serialization support in
JuliaLang/julia#52852, it's now reasonable to experiment with persisting
the analysis cache during precompilation.

There's an important consideration: the `codeinst.max_world` might
occasionally be set to `WORLD_AGE_REVALIDATION_SENTINEL` on the C side
under certain conditions. This assignment should ideally be reserved for
proper `CodeInstance`s (but it is not currently) and supposed to be
fixed up by a subsequent serialization pass. To address this, this
commit also adds an `__init__` hook that overrides such `max_world`s
at package loading time.
  • Loading branch information
aviatesk committed Jan 16, 2024
1 parent 69bf5ab commit b2bba3a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
18 changes: 17 additions & 1 deletion src/JET.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ using LoweredCodeUtils:

using JuliaInterpreter:
@lookup, _INACTIVE_EXCEPTION, bypass_builtins, collect_args, #=finish!,=#
is_quotenode_egal, is_return, maybe_evaluate_builtin, moduleof
is_quotenode_egal, maybe_evaluate_builtin, moduleof

using MacroTools: @capture, MacroTools, normalise, striplines

Expand Down Expand Up @@ -1259,6 +1259,22 @@ using PrecompileTools
result = @report_opt rand(String)
show(IOContext(devnull, :color=>true), result)
end
@static VERSION v"1.11.0-DEV.1255" && let
# register an initialization callback that fixes up `max_world` which is overridden
# to `one(UInt) == WORLD_AGE_REVALIDATION_SENTINEL` by staticdata.c
# otherwise using cached analysis results would result in world age assertion error
function override_precompiled_cache()
for precache in (JET_ANALYZER_CACHE, OPT_ANALYZER_CACHE),
(_, cache) in precache,
(mi, codeinst) in cache.cache
if codeinst.max_world == one(UInt) # == WORLD_AGE_REVALIDATION_SENTINEL
codeinst.max_world = typemax(UInt)
end
end
end
override_precompiled_cache()
push_inithook!(override_precompiled_cache)
end
end

end # module JET
2 changes: 1 addition & 1 deletion src/analyzers/jetanalyzer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ struct JETAnalyzer{RP<:ReportPass} <: AbstractAnalyzer
end
function JETAnalyzer(state::AnalyzerState, report_pass::ReportPass,
config::JETAnalyzerConfig)
if (@ccall jl_generating_output()::Cint) != 0
if ((@static VERSION < v"1.11.0-DEV.1255" && true) && !iszero(@ccall jl_generating_output()::Cint))
# XXX Avoid storing analysis results into a cache that persists across the
# precompilation, as pkgimage currently doesn't support serializing
# externally created `CodeInstance`. Otherwise, `CodeInstance`s created by
Expand Down
2 changes: 1 addition & 1 deletion src/analyzers/optanalyzer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ struct OptAnalyzer{RP<:ReportPass,FF} <: AbstractAnalyzer
function_filter::FF,
skip_noncompileable_calls::Bool,
skip_unoptimized_throw_blocks::Bool) where {RP<:ReportPass,FF}
if (@ccall jl_generating_output()::Cint) != 0
if ((@static VERSION < v"1.11.0-DEV.1255" && true) && !iszero(@ccall jl_generating_output()::Cint))
# XXX Avoid storing analysis results into a cache that persists across the
# precompilation, as pkgimage currently doesn't support serializing
# externally created `CodeInstance`. Otherwise, `CodeInstance`s created by
Expand Down

0 comments on commit b2bba3a

Please sign in to comment.