From b776be4bd1477bdf7415d9e1e1db73259dbf3cfa Mon Sep 17 00:00:00 2001 From: Shuhei Kadowaki Date: Fri, 22 Oct 2021 02:50:22 +0900 Subject: [PATCH] inference: follow up #42529, handle an edge case in `abstract_invoke` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit JET reported: ```julia julia> report_package(JET) ... [toplevel-info] analyzing from top-level definitions ... 671/671 ═════ 12 possible errors found ═════ ... ┌ @ avi-/JET/src/JET.jl:990 #self#(text, "top-level") │┌ @ avi-/JET/src/JET.jl:990 JET.#report_text#124(JET.JETAnalyzer, JET.nothing, Base.pairs(Core.NamedTuple()), #self#, text, filename) ││┌ @ avi-/JET/src/JET.jl:993 res = JET.virtual_process(text, filename, analyzer′, config) │││┌ @ avi-/JET/src/toplevel/virtualprocess.jl:301 res = JET._virtual_process!(x, filename, analyzer, config, context, JET.VirtualProcessResult(actual2virtual, context)) ││││┌ @ avi-/JET/src/toplevel/virtualprocess.jl:432 res = JET._virtual_process!(toplevelex, filename, analyzer, config, context, res) │││││┌ @ avi-/JET/src/toplevel/virtualprocess.jl:637 JET.analyze_toplevel!(analyzer, src) ││││││┌ @ avi-/JET/src/JET.jl:1142 JET.#analyze_toplevel!#133(true, #self#, analyzer, src) │││││││┌ @ avi-/JET/src/JET.jl:1160 JET.analyze_frame!(analyzer, frame) ││││││││┌ @ avi-/JET/src/JET.jl:747 JET.typeinf(analyzer, frame) │││││││││┌ @ compiler/abstractinterpretation.jl:1243 Core.Compiler.lastindex(fargs) ││││││││││ for 1 of union split cases, no matching method found for call signatures (Tuple{typeof(Core.Compiler.lastindex), Nothing})): Core.Compiler.lastindex(fargs::Union{Nothing, Vector{Any}}) │││││││││└─────────────────────────────────────────── │││││││││┌ @ compiler/abstractinterpretation.jl:1243 fargs′ = Core.Compiler.getindex(fargs, Core.Compiler.:(3, Core.Compiler.lastindex(fargs))) ││││││││││ for 1 of union split cases, no matching method found for call signatures (Tuple{typeof(Core.Compiler.getindex), Nothing, Core.Compiler.UnitRange{Int64}})): fargs′ = Core.Compiler.getindex(fargs::Union{Nothing, Vector{Any}}, Core.Compiler.:(3, Core.Compiler.lastindex(fargs::Union{Nothing, Vector{Any}})::Int64)::Core.Compiler.UnitRange{Int64}) │││││││││└─────────────────────────────────────────── │││││││││┌ @ compiler/abstractinterpretation.jl:1244 Core.Compiler.getindex(fargs, 1) ││││││││││ for 1 of union split cases, no matching method found for call signatures (Tuple{typeof(Core.Compiler.getindex), Nothing, Int64})): Core.Compiler.getindex(fargs::Union{Nothing, Vector{Any}}, 1) │││││││││└─────────────────────────────────────────── ... ``` --- base/compiler/abstractinterpretation.jl | 8 ++++++-- test/compiler/inference.jl | 5 +++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/base/compiler/abstractinterpretation.jl b/base/compiler/abstractinterpretation.jl index 3e9f38c9ad98b..ff674f2d91894 100644 --- a/base/compiler/abstractinterpretation.jl +++ b/base/compiler/abstractinterpretation.jl @@ -1240,8 +1240,12 @@ function abstract_invoke(interp::AbstractInterpreter, (; fargs, argtypes)::ArgIn const_prop_entry_heuristic(interp, result, sv) || return CallMeta(rt, InvokeCallInfo(match, nothing)) argtypes′ = argtypes[3:end] argtypes′[1] = ft - fargs′ = fargs[3:end] - fargs′[1] = fargs[1] + if fargs === nothing + fargs′ = nothing + else + fargs′ = fargs[3:end] + fargs′[1] = fargs[1] + end arginfo = ArgInfo(fargs′, argtypes′) const_prop_argument_heuristic(interp, arginfo, sv) || return CallMeta(rt, InvokeCallInfo(match, nothing)) # # typeintersect might have narrowed signature, but the accuracy gain doesn't seem worth the cost involved with the lattice comparisons diff --git a/test/compiler/inference.jl b/test/compiler/inference.jl index 72791bfaa0a28..3bff83ec0a6d2 100644 --- a/test/compiler/inference.jl +++ b/test/compiler/inference.jl @@ -3285,6 +3285,11 @@ function splat_lotta_unions() end @test Core.Compiler.return_type(splat_lotta_unions, Tuple{}) >: Tuple{Int,Int,Int} +# handle `fargs = nothing` edge cases +@test (code_typed(; optimize=false) do + Core.Compiler.return_type(invoke, Tuple{typeof(sin), Tuple{Integer}, Int}) +end; true) + # Bare Core.Argument in IR @eval f_bare_argument(x) = $(Core.Argument(2)) @test Base.return_types(f_bare_argument, (Int,))[1] == Int