Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switch to using the internal code cache #611

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/abstractinterpret/abstractanalyzer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ mutable struct AnalyzerState

# the temporal stash to keep track of the context of caller inference/optimization and
# the caller itself, to which reconstructed cached reports will be appended
cache_target::Union{Nothing,Pair{Symbol,InferenceResult}}
cache_target::(@static VERSION ≥ v"1.11.0-DEV.1552" ? Nothing : Union{Nothing,Pair{Symbol,InferenceResult}})

## abstract toplevel execution ##

Expand Down
51 changes: 49 additions & 2 deletions src/abstractinterpret/typeinfer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@
function CC.const_prop_call(analyzer::AbstractAnalyzer,
mi::MethodInstance, result::MethodCallResult, arginfo::ArgInfo, sv::InferenceState,
concrete_eval_result::Union{Nothing,CC.ConstCallResults})
@static if VERSION < v"1.11.0-DEV.1552"

Check warning on line 29 in src/abstractinterpret/typeinfer.jl

View check run for this annotation

Codecov / codecov/patch

src/abstractinterpret/typeinfer.jl#L29

Added line #L29 was not covered by tests
set_cache_target!(analyzer, :const_prop_call => sv.result)
end
const_result = @invoke CC.const_prop_call(analyzer::AbstractInterpreter,
mi::MethodInstance, result::MethodCallResult, arginfo::ArgInfo, sv::InferenceState,
concrete_eval_result::Union{Nothing,CC.ConstCallResults})
@static if VERSION < v"1.11.0-DEV.1552"

Check warning on line 35 in src/abstractinterpret/typeinfer.jl

View check run for this annotation

Codecov / codecov/patch

src/abstractinterpret/typeinfer.jl#L35

Added line #L35 was not covered by tests
@assert get_cache_target(analyzer) === nothing "invalid JET analysis state"
end
if const_result !== nothing
# successful constant prop', we need to update reports
collect_callee_reports!(analyzer, sv)
Expand Down Expand Up @@ -151,9 +155,25 @@
# ------

@static if VERSION ≥ v"1.11.0-DEV.1552"

CC.cache_owner(analyzer::AbstractAnalyzer) = AnalysisCache(analyzer)

function CC.return_cached_result(analyzer::AbstractAnalyzer, codeinst::CodeInstance, caller::InferenceState)

Check warning on line 161 in src/abstractinterpret/typeinfer.jl

View check run for this annotation

Codecov / codecov/patch

src/abstractinterpret/typeinfer.jl#L161

Added line #L161 was not covered by tests
# cache hit, now we need to append cached reports associated with this `MethodInstance`
inferred = @atomic :monotonic codeinst.inferred
for cached in (inferred::CachedAnalysisResult).reports
restored = add_cached_report!(analyzer, caller.result, cached)
@static if JET_DEV_MODE
actual, expected = first(restored.vst).linfo, codeinst.def
@assert actual === expected "invalid global cache restoration, expected $expected but got $actual"

Check warning on line 168 in src/abstractinterpret/typeinfer.jl

View check run for this annotation

Codecov / codecov/patch

src/abstractinterpret/typeinfer.jl#L163-L168

Added lines #L163 - L168 were not covered by tests
end
stash_report!(analyzer, restored) # should be updated in `abstract_call` (after exiting `typeinf_edge`)
end
return @invoke CC.return_cached_result(analyzer::AbstractInterpreter, codeinst::CodeInstance, caller::InferenceState)

Check warning on line 172 in src/abstractinterpret/typeinfer.jl

View check run for this annotation

Codecov / codecov/patch

src/abstractinterpret/typeinfer.jl#L170-L172

Added lines #L170 - L172 were not covered by tests
end

else # if VERSION ≥ v"1.11.0-DEV.1552"

function CC.code_cache(analyzer::AbstractAnalyzer)
view = AbstractAnalyzerView(analyzer)
worlds = WorldRange(get_inference_world(analyzer))
Expand Down Expand Up @@ -232,7 +252,7 @@
function (callback::JETCallback)(replaced::MethodInstance, max_world::UInt32)
delete!(callback.analysis_cache, replaced)
end
else
else # if VERSION ≥ v"1.11.0-DEV.798"
function add_jet_callback!(mi::MethodInstance, analysis_cache::AnalysisCache)
callback = JETCallback(analysis_cache)
if !isdefined(mi, :callbacks)
Expand All @@ -259,11 +279,36 @@
end
return nothing
end
end
end # if VERSION ≥ v"1.11.0-DEV.798"

end # if VERSION ≥ v"1.11.0-DEV.1552"

# local
# -----

@static if VERSION ≥ v"1.11.0-DEV.1552"

CC.get_inference_cache(analyzer::AbstractAnalyzer) = get_inf_cache(analyzer)

Check warning on line 291 in src/abstractinterpret/typeinfer.jl

View check run for this annotation

Codecov / codecov/patch

src/abstractinterpret/typeinfer.jl#L291

Added line #L291 was not covered by tests

function CC.return_cached_result(analyzer::AbstractAnalyzer, inf_result::InferenceResult, caller::InferenceState)

Check warning on line 293 in src/abstractinterpret/typeinfer.jl

View check run for this annotation

Codecov / codecov/patch

src/abstractinterpret/typeinfer.jl#L293

Added line #L293 was not covered by tests
# as the analyzer uses the reports that are cached by the abstract-interpretation
# with the extended lattice elements, here we should throw-away the error reports
# that are collected during the previous non-constant abstract-interpretation
# (see the `CC.typeinf(::AbstractAnalyzer, ::InferenceState)` overload)
filter_lineages!(analyzer, caller.result, inf_result.linfo)
for cached in get_cached_reports(analyzer, inf_result)
restored = add_cached_report!(analyzer, caller.result, cached)
@static if JET_DEV_MODE
actual, expected = first(restored.vst).linfo, inf_result.linfo
@assert actual === expected "invalid local cache restoration, expected $expected but got $actual"

Check warning on line 303 in src/abstractinterpret/typeinfer.jl

View check run for this annotation

Codecov / codecov/patch

src/abstractinterpret/typeinfer.jl#L298-L303

Added lines #L298 - L303 were not covered by tests
end
stash_report!(analyzer, restored) # should be updated in `abstract_call_method_with_const_args`
end
return @invoke CC.return_cached_result(analyzer::AbstractInterpreter, inf_result::InferenceResult, caller::InferenceState)

Check warning on line 307 in src/abstractinterpret/typeinfer.jl

View check run for this annotation

Codecov / codecov/patch

src/abstractinterpret/typeinfer.jl#L305-L307

Added lines #L305 - L307 were not covered by tests
end

else # if VERSION ≥ v"1.11.0-DEV.1552"

CC.get_inference_cache(analyzer::AbstractAnalyzer) = AbstractAnalyzerView(analyzer)

function CC.cache_lookup(𝕃ᵢ::CC.AbstractLattice, mi::MethodInstance, given_argtypes::Argtypes, view::AbstractAnalyzerView)
Expand Down Expand Up @@ -307,6 +352,8 @@

CC.push!(view::AbstractAnalyzerView, inf_result::InferenceResult) = CC.push!(get_inf_cache(view.analyzer), inf_result)

end # if VERSION ≥ v"1.11.0-DEV.1552"

# main driver
# ===========

Expand Down
Loading