Skip to content

Commit

Permalink
inference: handle Vararg in abstract_call_unionall for argtypes
Browse files Browse the repository at this point in the history
… 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
#42583 has ensured that `Vararg` and `TypeVar` should never appear
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.
  • Loading branch information
aviatesk authored Sep 20, 2023
1 parent 7d8ba92 commit 3290bd7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
8 changes: 6 additions & 2 deletions base/compiler/abstractinterpretation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1858,7 +1858,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)
Expand Down Expand Up @@ -2253,7 +2258,6 @@ function abstract_eval_value_expr(interp::AbstractInterpreter, e::Expr, vtypes::
return Any
end


function abstract_eval_value(interp::AbstractInterpreter, @nospecialize(e), vtypes::Union{VarTable,Nothing}, sv::AbsIntState)
if isa(e, Expr)
return abstract_eval_value_expr(interp, e, vtypes, sv)
Expand Down
7 changes: 6 additions & 1 deletion test/compiler/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -5230,3 +5230,8 @@ end |> only == Val{false}
@test Base.return_types((Bool,)) do b
Val(Core.Intrinsics.or_int(true, b))
end |> only == Val{true}

# https://github.com/JuliaLang/julia/issues/51310
@test code_typed() do
b{c} = d...
end |> only |> first isa Core.CodeInfo

0 comments on commit 3290bd7

Please sign in to comment.