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

update to https://github.com/JuliaLang/julia/pull/39972 #131

Merged
merged 2 commits into from
Mar 13, 2021
Merged
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
6 changes: 4 additions & 2 deletions src/abstractinterpretation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,12 @@ end

function CC.abstract_call_method_with_const_args(interp::JETInterpreter, @nospecialize(rettype),
@nospecialize(f), argtypes::Vector{Any}, match::MethodMatch,
sv::InferenceState, edgecycle::Bool)
sv::InferenceState, edgecycle::Bool,
va_override::Bool)
result, inf_result = @invoke abstract_call_method_with_const_args(interp::AbstractInterpreter, @nospecialize(rettype),
@nospecialize(f), argtypes::Vector{Any}, match::MethodMatch,
sv::InferenceState, edgecycle::Bool)
sv::InferenceState, edgecycle::Bool,
va_override::Bool)

if isa(inf_result, InferenceResult)
# successful constant prop', we also need to update reports
Expand Down
5 changes: 0 additions & 5 deletions src/abstractinterpreterinterface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,6 @@ struct AnalysisResult
argtypes::Vector{Any}
overridden_by_const::CC.BitVector
cache::Vector{InferenceErrorReportCache}
# adapted from https://github.com/JuliaLang/julia/blob/3129a5bef56bb7216024ae606c02b413b00990e3/base/compiler/types.jl#L32-L35
function AnalysisResult(linfo::MethodInstance, given_argtypes::Vector{Any}, cache::Vector{InferenceErrorReportCache})
argtypes, overridden_by_const = matching_cache_argtypes(linfo, given_argtypes)
return new(linfo, argtypes, overridden_by_const, cache)
end
end

mutable struct JETInterpreter <: AbstractInterpreter
Expand Down
13 changes: 11 additions & 2 deletions src/typeinfer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ function CC._typeinf(interp::JETInterpreter, frame::InferenceState)

if !isempty(this_caches)
if iscp
argtypes = frame.result.argtypes
result = frame.result
argtypes = result.argtypes
cache = interp.cache
@assert jet_cache_lookup(linfo, argtypes, cache) === nothing "invalid local caching $linfo, $argtypes"
local_cache = InferenceErrorReportCache[]
Expand All @@ -178,7 +179,15 @@ function CC._typeinf(interp::JETInterpreter, frame::InferenceState)
# @assert first(report.st).linfo === linfo "invalid local caching"
cache_report!(local_cache, report)
end
push!(cache, AnalysisResult(linfo, argtypes, local_cache))
# branching on https://github.com/JuliaLang/julia/pull/39972
given_argtypes, overridden_by_const = @static if VERSION ≥ v"1.7.0-DEV.705"
def = result.linfo.def
va_overwride = isa(def, Method) && def.is_for_opaque_closure
matching_cache_argtypes(linfo, argtypes, va_overwride)
else
matching_cache_argtypes(linfo, argtypes)
end
push!(cache, AnalysisResult(linfo, given_argtypes, overridden_by_const, local_cache))
elseif frame.cached # only cache when `NativeInterpreter` does
@assert !haskey(JET_GLOBAL_CACHE, linfo) || isentry "invalid global caching $linfo"
global_cache = InferenceErrorReportCache[]
Expand Down
14 changes: 14 additions & 0 deletions test/test_abstractinterpretation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -851,3 +851,17 @@ end
interp, frame = analyze_call(m.psort!, (Vector{Int},))
@test true
end

@static if VERSION ≥ v"1.7.0-DEV.705"

@testset "opaque closure" begin
# can cache const prop' result with varargs
function oc_varargs_constprop()
oc = Base.Experimental.@opaque (args...)->args[1]+args[2]+arg[3] # typo on `arg[3]`
return Val{oc(1,2,3)}()
end
interp, = @analyze_call oc_varargs_constprop()
@test !isempty(interp.cache)
end

end # @static if VERSION ≥ v"1.7.0-DEV.705"