Skip to content

Commit

Permalink
remove old compat code
Browse files Browse the repository at this point in the history
  • Loading branch information
aviatesk committed Dec 12, 2023
1 parent fd96b2f commit 9a512e7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 50 deletions.
79 changes: 35 additions & 44 deletions src/abstractinterpret/typeinfer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -326,60 +326,51 @@ end

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

let
@static if isdefined(CC, :AbstractLattice)
sigs_ex = :(lattice::CC.AbstractLattice, linfo::MethodInstance, given_argtypes::Argtypes, view::AbstractAnalyzerView)
args_ex = :(lattice, linfo, given_argtypes, get_inf_cache(view.analyzer))
function CC.cache_lookup(𝕃ᵢ::CC.AbstractLattice, mi::MethodInstance, given_argtypes::Argtypes, view::AbstractAnalyzerView)
# XXX the very dirty analyzer state observation again
# this method should only be called from the single context i.e. `abstract_call_method_with_const_args`,
# and so we should reset the cache target immediately we reach here
analyzer = view.analyzer
cache_target = get_cache_target(analyzer)
set_cache_target!(analyzer, nothing)

inf_result = cache_lookup(𝕃ᵢ, mi, given_argtypes, get_inf_cache(view.analyzer))

isa(inf_result, InferenceResult) || return inf_result

# constant prop' hits a cycle (recur into same non-constant analysis), we just bail out
@static if VERSION v"1.10.0-DEV.750"
inf_result.result === nothing && return inf_result
else
sigs_ex = :(linfo::MethodInstance, given_argtypes::Argtypes, view::AbstractAnalyzerView)
args_ex = :(linfo, given_argtypes, get_inf_cache(view.analyzer))
isa(inf_result.result, InferenceState) && return inf_result
end
@eval function CC.cache_lookup($(sigs_ex.args...))
# XXX the very dirty analyzer state observation again
# this method should only be called from the single context i.e. `abstract_call_method_with_const_args`,
# and so we should reset the cache target immediately we reach here
analyzer = view.analyzer
cache_target = get_cache_target(analyzer)
set_cache_target!(analyzer, nothing)

inf_result = cache_lookup($(args_ex.args...))

isa(inf_result, InferenceResult) || return inf_result
# cache hit, restore reports from the local report cache

# constant prop' hits a cycle (recur into same non-constant analysis), we just bail out
@static if VERSION v"1.10.0-DEV.750"
inf_result.result === nothing && return inf_result
if cache_target !== nothing
context, caller = cache_target
@static if VERSION v"1.10.0-DEV.1345"
@assert context === :const_prop_call "invalid JET analysis state"
else
isa(inf_result.result, InferenceState) && return inf_result
@assert context === :abstract_call_method_with_const_args "invalid JET analysis state"
end

# cache hit, restore reports from the local report cache

if cache_target !== nothing
context, caller = cache_target
@static if VERSION v"1.10.0-DEV.1345"
@assert context === :const_prop_call "invalid JET analysis state"
else
@assert context === :abstract_call_method_with_const_args "invalid JET analysis state"
end

# 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, linfo)

for cached in get_cached_reports(analyzer, inf_result)
restored = add_cached_report!(analyzer, caller, cached)
@static if JET_DEV_MODE
actual, expected = first(restored.vst).linfo, linfo
@assert actual === expected "invalid local cache restoration, expected $expected but got $actual"
end
stash_report!(analyzer, restored) # should be updated in `abstract_call_method_with_const_args`
# 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, mi)

for cached in get_cached_reports(analyzer, inf_result)
restored = add_cached_report!(analyzer, caller, cached)
@static if JET_DEV_MODE
actual, expected = first(restored.vst).linfo, mi
@assert actual === expected "invalid local cache restoration, expected $expected but got $actual"
end
stash_report!(analyzer, restored) # should be updated in `abstract_call_method_with_const_args`
end
return inf_result
end
return inf_result
end

CC.push!(view::AbstractAnalyzerView, inf_result::InferenceResult) = CC.push!(get_inf_cache(view.analyzer), inf_result)
Expand Down
7 changes: 1 addition & 6 deletions src/analyzers/jetanalyzer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -948,9 +948,6 @@ end
# validated exhausively by its test suite and real-world usages.
function is_corecompiler_undefglobal(gr::GlobalRef)
gr.mod === CC && return isdefined(Base, gr.name)
@static if isdefined(CC, :Sort)
gr.mod === CC.Sort && return isdefined(Base.Sort, gr.name)
end
return false
end

Expand Down Expand Up @@ -1482,9 +1479,7 @@ function (::SoundPass)(::Type{AbstractBuiltinErrorReport}, analyzer::JETAnalyzer
if isa(f, IntrinsicFunction)
nothrow = Core.Compiler.intrinsic_nothrow(f, argtypes)
else
nothrow = (@static isdefined(CC, :typeinf_lattice) ?
Core.Compiler.builtin_nothrow(CC.typeinf_lattice(analyzer), f, argtypes, rt) :
Core.Compiler.builtin_nothrow(f, argtypes, rt))
nothrow = Core.Compiler.builtin_nothrow(CC.typeinf_lattice(analyzer), f, argtypes, rt)
end
nothrow && return false
add_new_report!(analyzer, sv.result, UnsoundBuiltinErrorReport(sv, f, argtypes))
Expand Down

0 comments on commit 9a512e7

Please sign in to comment.