From f9ef654b6393e54ad6284d36a32f1fc56af17b05 Mon Sep 17 00:00:00 2001 From: Shuhei Kadowaki <40514306+aviatesk@users.noreply.github.com> Date: Wed, 20 Sep 2023 12:58:54 +0900 Subject: [PATCH] inference: handle `Vararg` in `abstract_call_unionall` for `argtypes` computed by `abstract_apply` (#51393) This commit adds special handling for `Vararg` types that may appear at the end of `argtypes`, as computed by `abstract_apply`. Even though PR within the abstract state, they can still be part of `argtypes`. As a result, this kind of special handling is still necessary. It remains an open question whether we can refactor `abstract_apply` to prevent `Vararg`s from appearing in `argtypes` in the first place. --- base/compiler/abstractinterpretation.jl | 7 ++++++- test/compiler/inference.jl | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/base/compiler/abstractinterpretation.jl b/base/compiler/abstractinterpretation.jl index 973c7dc6f879b..f256f5438bb90 100644 --- a/base/compiler/abstractinterpretation.jl +++ b/base/compiler/abstractinterpretation.jl @@ -1874,7 +1874,12 @@ function abstract_call_unionall(interp::AbstractInterpreter, argtypes::Vector{An a2 = argtypes[2] a3 = argtypes[3] ⊑ᵢ = ⊑(typeinf_lattice(interp)) - nothrow = a2 ⊑ᵢ TypeVar && (a3 ⊑ᵢ Type || a3 ⊑ᵢ TypeVar) + if isvarargtype(a3) + a3 = unwrapva(a3) + nothrow = false + else + nothrow = a2 ⊑ᵢ TypeVar && (a3 ⊑ᵢ Type || a3 ⊑ᵢ TypeVar) + end if isa(a3, Const) body = a3.val elseif isType(a3) diff --git a/test/compiler/inference.jl b/test/compiler/inference.jl index 8b980f1fdb17c..25190fe0c16ff 100644 --- a/test/compiler/inference.jl +++ b/test/compiler/inference.jl @@ -5,7 +5,7 @@ import Core.Compiler: Const, Conditional, ⊑, ReturnNode, GotoIfNot isdispatchelem(@nospecialize x) = !isa(x, Type) || Core.Compiler.isdispatchelem(x) using Random, Core.IR -using InteractiveUtils: code_llvm +using InteractiveUtils include("irutils.jl") @@ -5101,3 +5101,8 @@ end |> only === Val{5} @test fully_eliminated() do length(continue_const_prop(1, 5)) end + +# https://github.com/JuliaLang/julia/issues/51310 +@test code_typed() do + b{c} = d... +end |> only |> first isa Core.CodeInfo