From b0582e6bff9743bd58b512c46f1641d464a8257f Mon Sep 17 00:00:00 2001 From: Shuhei Kadowaki Date: Mon, 6 Nov 2023 12:38:53 +0900 Subject: [PATCH] adjust to the latest JuliaLang/julia#master --- src/JET.jl | 23 +++++++++++------------ src/abstractinterpret/typeinfer.jl | 4 ++++ src/analyzers/jetanalyzer.jl | 14 ++++++++++++-- src/toplevel/virtualprocess.jl | 2 +- 4 files changed, 28 insertions(+), 15 deletions(-) diff --git a/src/JET.jl b/src/JET.jl index 3677095a4..5e746f188 100644 --- a/src/JET.jl +++ b/src/JET.jl @@ -365,15 +365,7 @@ get_linfo(sv::State) = sv.linfo get_linfo(result::InferenceResult) = result.linfo get_linfo(linfo::MethodInstance) = linfo -function is_constant_propagated(frame::InferenceState) - @static if VERSION ≥ v"1.11.0-DEV.737" - return frame.cache_mode === :local && - is_constant_propagated(frame.result) - else - return !frame.cached && # const-prop'ed frame is never cached globally - is_constant_propagated(frame.result) - end -end +is_constant_propagated(frame::InferenceState) = is_constant_propagated(frame.result) is_constant_propagated(result::InferenceResult) = CC.any(result.overridden_by_const) # lattice @@ -755,16 +747,23 @@ end function analyze_method_instance!(analyzer::AbstractAnalyzer, mi::MethodInstance) result = InferenceResult(mi) - frame = InferenceState(result, #=cache=# :global, analyzer) + frame = InferenceState(result, #=cache_mode=#:global, analyzer) isnothing(frame) && return analyzer, result return analyze_frame!(analyzer, frame) end -function InferenceState(result::InferenceResult, cache::Symbol, analyzer::AbstractAnalyzer) +@static if VERSION ≥ v"1.11.0-DEV.843" +function InferenceState(result::InferenceResult, cache_mode::UInt8, analyzer::AbstractAnalyzer) init_result!(analyzer, result) - return @invoke InferenceState(result::InferenceResult, cache::Symbol, analyzer::AbstractInterpreter) + return @invoke InferenceState(result::InferenceResult, cache_mode::UInt8, analyzer::AbstractInterpreter) +end +else +function InferenceState(result::InferenceResult, cache_mode::Symbol, analyzer::AbstractAnalyzer) + init_result!(analyzer, result) + return @invoke InferenceState(result::InferenceResult, cache_mode::Symbol, analyzer::AbstractInterpreter) +end end function analyze_frame!(analyzer::AbstractAnalyzer, frame::InferenceState) diff --git a/src/abstractinterpret/typeinfer.jl b/src/abstractinterpret/typeinfer.jl index 2abe160ff..0c5713201 100644 --- a/src/abstractinterpret/typeinfer.jl +++ b/src/abstractinterpret/typeinfer.jl @@ -639,7 +639,11 @@ function CC.abstract_eval_special_value(analyzer::AbstractAnalyzer, @nospecializ # in this call graph, but it's highly possible this is a toplevel callsite # and we take a risk here since we can't enter the analysis otherwise val = getglobal(mod, name) + @static if VERSION ≥ v"1.11.0-DEV.797" + ret = CC.RTEffects(isa(val, AbstractGlobal) ? val.t : Const(val), ret.effects) + else ret = isa(val, AbstractGlobal) ? val.t : Const(val) + end end end end diff --git a/src/analyzers/jetanalyzer.jl b/src/analyzers/jetanalyzer.jl index b9d5413cc..4fdd23482 100644 --- a/src/analyzers/jetanalyzer.jl +++ b/src/analyzers/jetanalyzer.jl @@ -242,13 +242,23 @@ end # @static if VERSION < v"1.10.0-DEV.286" # overloads # ========= -function CC.InferenceState(result::InferenceResult, cache::Symbol, analyzer::JETAnalyzer) - frame = @invoke CC.InferenceState(result::InferenceResult, cache::Symbol, analyzer::AbstractAnalyzer) +@static if VERSION ≥ v"1.11.0-DEV.843" +function CC.InferenceState(result::InferenceResult, cache_mode::UInt8, analyzer::JETAnalyzer) + frame = @invoke CC.InferenceState(result::InferenceResult, cache_mode::UInt8, analyzer::AbstractAnalyzer) if isnothing(frame) # indicates something bad happened within `retrieve_code_info` ReportPass(analyzer)(GeneratorErrorReport, analyzer, result) end return frame end +else +function CC.InferenceState(result::InferenceResult, cache_mode::Symbol, analyzer::JETAnalyzer) + frame = @invoke CC.InferenceState(result::InferenceResult, cache_mode::Symbol, analyzer::AbstractAnalyzer) + if isnothing(frame) # indicates something bad happened within `retrieve_code_info` + ReportPass(analyzer)(GeneratorErrorReport, analyzer, result) + end + return frame +end +end function CC.finish!(analyzer::JETAnalyzer, caller::InferenceState) src = caller.result.src diff --git a/src/toplevel/virtualprocess.jl b/src/toplevel/virtualprocess.jl index 4d2d550aa..9a5872eea 100644 --- a/src/toplevel/virtualprocess.jl +++ b/src/toplevel/virtualprocess.jl @@ -1477,7 +1477,7 @@ function analyze_toplevel!(analyzer::AbstractAnalyzer, src::CodeInfo) # NOTE toplevel frames don't really need to be cached, but still better to be optimized # in order to get reasonable `UncaughtExceptionReport`, and also, otherwise # `typeinf_edge` won't add "toplevel-to-callee" edges - frame = InferenceState(result, src, #=cache=# :global, analyzer)::InferenceState + frame = InferenceState(result, src, #=cache_mode=#:global, analyzer)::InferenceState return analyze_frame!(analyzer, frame) end