diff --git a/base/compiler/abstractinterpretation.jl b/base/compiler/abstractinterpretation.jl index faa70830169f0..3c26f2bdef4e5 100644 --- a/base/compiler/abstractinterpretation.jl +++ b/base/compiler/abstractinterpretation.jl @@ -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) @@ -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) diff --git a/test/precompile.jl b/test/precompile.jl index 82465d700bb49..47d9a1bb7e860 100644 --- a/test/precompile.jl +++ b/test/precompile.jl @@ -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) @@ -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"), @@ -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 @@ -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