Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
aviatesk committed Oct 21, 2021
1 parent 4dfe96a commit 8b099e0
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 9 deletions.
3 changes: 3 additions & 0 deletions src/JET.jl
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ __init__() = foreach(@nospecialize(f)->f(), INIT_HOOKS)
# branch on https://github.com/JuliaLang/julia/pull/42082
const IS_AFTER_42082 = hasmethod(InferenceState, (InferenceResult, Symbol, AbstractInterpreter))

const IS_AFTER_42529 = isdefined(CC, :ArgInfo)
IS_AFTER_42529 && import .CC: ArgInfo

# branch on https://github.com/JuliaLang/julia/pull/42125
@static if isdefined(Base, Symbol("@constprop"))
import Base: @constprop
Expand Down
18 changes: 13 additions & 5 deletions src/abstractinterpret/typeinfer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,13 @@ end
end

function CC.abstract_call_method_with_const_args(analyzer::AbstractAnalyzer, result::MethodCallResult,
@nospecialize(f), argtypes::Argtypes, match::MethodMatch,
@nospecialize(f), arginfo::(@static IS_AFTER_42529 ? ArgInfo : Argtypes), match::MethodMatch,
sv::InferenceState, va_override::Bool)
set_cacher!(analyzer, :abstract_call_method_with_const_args => sv.result)

const_result =
@invoke CC.abstract_call_method_with_const_args(analyzer::AbstractInterpreter, result::MethodCallResult,
@nospecialize(f), argtypes::Argtypes, match::MethodMatch,
@nospecialize(f), arginfo::(@static IS_AFTER_42529 ? ArgInfo : Argtypes), match::MethodMatch,
sv::InferenceState, va_override::Bool)

# we should make sure we reset the cacher because at this point we may have not hit
Expand All @@ -212,16 +212,24 @@ function CC.abstract_call_method_with_const_args(analyzer::AbstractAnalyzer, res
return const_result
end

@static if IS_AFTER_42529
function CC.abstract_call(analyzer::AbstractAnalyzer, arginfo::ArgInfo,
sv::InferenceState, max_methods::Int = InferenceParams(analyzer).MAX_METHODS)
ret = @invoke CC.abstract_call(analyzer::AbstractInterpreter, arginfo::ArgInfo,
sv::InferenceState, max_methods::Int)
analyze_task_parallel_code!(analyzer, arginfo.argtypes, sv)
return ret
end
else # @static if IS_AFTER_42529
function CC.abstract_call(analyzer::AbstractAnalyzer, fargs::Union{Nothing,Vector{Any}}, argtypes::Argtypes,
sv::InferenceState, max_methods::Int = InferenceParams(analyzer).MAX_METHODS)
ret = @invoke CC.abstract_call(analyzer::AbstractInterpreter, fargs::Union{Nothing,Vector{Any}}, argtypes::Argtypes,
sv::InferenceState, max_methods::Int)

analyze_task_parallel_code!(analyzer, argtypes, sv)

return ret
end

end # @static if IS_AFTER_42529

"""
analyze_task_parallel_code!(analyzer::AbstractAnalyzer, argtypes::Argtypes, sv::InferenceState)
Expand Down
33 changes: 29 additions & 4 deletions src/analyzers/jetanalyzer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -305,13 +305,32 @@ get_msg(::Type{NoMethodErrorReport}, sv::InferenceState, @nospecialize(t::Type))
get_msg(::Type{NoMethodErrorReport}, sv::InferenceState, ts::Vector{Type}) =
"for $(length(ts)) of union split cases, no matching method found for call signatures ($(join(ts, ", "))))"

@static if IS_AFTER_42529
function CC.abstract_call_gf_by_type(analyzer::JETAnalyzer, @nospecialize(f),
arginfo::ArgInfo, @nospecialize(atype),
sv::InferenceState, max_methods::Int = InferenceParams(analyzer).MAX_METHODS)
ret = @invoke CC.abstract_call_gf_by_type(analyzer::AbstractAnalyzer, @nospecialize(f),
arginfo::ArgInfo, @nospecialize(atype),
sv::InferenceState, max_methods::Int)
info = ret.info
if isa(info, ConstCallInfo)
info = info.call # unwrap to `MethodMatchInfo` or `UnionSplitInfo`
end
# report passes for no matching methods error
if isa(info, UnionSplitInfo)
ReportPass(analyzer)(NoMethodErrorReport, analyzer, sv, info, arginfo.argtypes, atype)
elseif isa(info, MethodMatchInfo)
ReportPass(analyzer)(NoMethodErrorReport, analyzer, sv, info, arginfo.argtypes, atype)
end
return ret
end
else # @static if IS_AFTER_42529
function CC.abstract_call_gf_by_type(analyzer::JETAnalyzer, @nospecialize(f),
fargs::Union{Nothing,Vector{Any}}, argtypes::Argtypes, @nospecialize(atype),
sv::InferenceState, max_methods::Int = InferenceParams(analyzer).MAX_METHODS)
ret = @invoke CC.abstract_call_gf_by_type(analyzer::AbstractAnalyzer, @nospecialize(f),
fargs::Union{Nothing,Vector{Any}}, argtypes::Argtypes, @nospecialize(atype),
sv::InferenceState, max_methods::Int)

info = ret.info
if isa(info, ConstCallInfo)
info = info.call # unwrap to `MethodMatchInfo` or `UnionSplitInfo`
Expand All @@ -322,9 +341,9 @@ function CC.abstract_call_gf_by_type(analyzer::JETAnalyzer, @nospecialize(f),
elseif isa(info, MethodMatchInfo)
ReportPass(analyzer)(NoMethodErrorReport, analyzer, sv, info, argtypes, atype)
end

return ret
end
end # @static if IS_AFTER_42529

function (rp::BasicPass)(
::Type{NoMethodErrorReport}, analyzer::JETAnalyzer, sv::InferenceState,
Expand Down Expand Up @@ -466,13 +485,19 @@ function (::SoundBasicPass)(::Type{InvalidReturnTypeCall}, analyzer::AbstractAna
return false
end

@static if IS_AFTER_42529
function CC.abstract_invoke(analyzer::JETAnalyzer, arginfo::ArgInfo, sv::InferenceState)
ret = @invoke CC.abstract_invoke(analyzer::AbstractAnalyzer, arginfo::ArgInfo, sv::InferenceState)
ReportPass(analyzer)(InvalidInvokeErrorReport, analyzer, sv, ret, arginfo.argtypes)
return ret
end
else # @static if IS_AFTER_42529
function CC.abstract_invoke(analyzer::JETAnalyzer, argtypes::Argtypes, sv::InferenceState)
ret = @invoke CC.abstract_invoke(analyzer::AbstractAnalyzer, argtypes::Argtypes, sv::InferenceState)

ReportPass(analyzer)(InvalidInvokeErrorReport, analyzer, sv, ret, argtypes)

return ret
end
end # @static if IS_AFTER_42529

@reportdef struct InvalidInvokeErrorReport <: InferenceErrorReport
argtypes::Argtypes
Expand Down

0 comments on commit 8b099e0

Please sign in to comment.