Skip to content

Commit

Permalink
Support invoke backedges for const (#46715)
Browse files Browse the repository at this point in the history
This is a left-over piece of #46010, triggered by const args.

Fixes #44320
  • Loading branch information
timholy authored Sep 12, 2022
1 parent 7eacf1b commit ad19f2f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 3 additions & 3 deletions base/compiler/abstractinterpretation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -876,13 +876,13 @@ end

function abstract_call_method_with_const_args(interp::AbstractInterpreter, result::MethodCallResult,
@nospecialize(f), arginfo::ArgInfo, match::MethodMatch,
sv::InferenceState)
sv::InferenceState, invoketypes=nothing)
if !const_prop_enabled(interp, sv, match)
return nothing
end
res = concrete_eval_call(interp, f, result, arginfo, sv)
if isa(res, ConstCallResults)
add_backedge!(res.const_result.mi, sv)
add_backedge!(res.const_result.mi, sv, invoketypes)
return res
end
mi = maybe_get_const_prop_profitable(interp, result, f, arginfo, match, sv)
Expand Down Expand Up @@ -1694,7 +1694,7 @@ function abstract_invoke(interp::AbstractInterpreter, (; fargs, argtypes)::ArgIn
# argtypes′[i] = t ⊑ a ? t : a
# end
const_call_result = abstract_call_method_with_const_args(interp, result,
overlayed ? nothing : singleton_type(ft′), arginfo, match, sv)
overlayed ? nothing : singleton_type(ft′), arginfo, match, sv, types)
const_result = nothing
if const_call_result !== nothing
if (typeinf_lattice(interp), const_call_result.rt, rt)
Expand Down
12 changes: 12 additions & 0 deletions test/precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,7 @@ precompile_test_harness("invoke") do dir
"""
module $InvokeModule
export f, g, h, q, fnc, gnc, hnc, qnc # nc variants do not infer to a Const
export f44320, g44320
# f is for testing invoke that occurs within a dependency
f(x::Real) = 0
f(x::Int) = x < 5 ? 1 : invoke(f, Tuple{Real}, x)
Expand All @@ -910,6 +911,11 @@ precompile_test_harness("invoke") do dir
# q will have some callers invalidated
q(x::Integer) = 0
qnc(x::Integer) = rand()-1
# Issue #44320
f44320(::Int) = 1
f44320(::Any) = 2
g44320() = invoke(f44320, Tuple{Any}, 0)
g44320()
end
""")
write(joinpath(dir, "$CallerModule.jl"),
Expand All @@ -934,6 +940,9 @@ precompile_test_harness("invoke") do dir
internalnc(x::Real) = rand()-1
internalnc(x::Int) = x < 5 ? rand()+1 : invoke(internalnc, Tuple{Real}, x)
# Issue #44320
f44320(::Real) = 3
# force precompilation
begin
Base.Experimental.@force_compile
Expand Down Expand Up @@ -1010,6 +1019,9 @@ precompile_test_harness("invoke") do dir
m = only(methods(M.callqnci))
@test m.specializations[1].specTypes == Tuple{typeof(M.callqnci), Int}

m = only(methods(M.g44320))
@test m.specializations[1].cache.max_world == typemax(UInt)

# Precompile specific methods for arbitrary arg types
invokeme(x) = 1
invokeme(::Int) = 2
Expand Down

0 comments on commit ad19f2f

Please sign in to comment.