Skip to content

Commit 806a6a9

Browse files
aviatesknalimilan
authored andcommitted
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.
1 parent 3dce9db commit 806a6a9

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

base/compiler/abstractinterpretation.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1874,7 +1874,12 @@ function abstract_call_unionall(interp::AbstractInterpreter, argtypes::Vector{An
18741874
a2 = argtypes[2]
18751875
a3 = argtypes[3]
18761876
= (typeinf_lattice(interp))
1877-
nothrow = a2 ᵢ TypeVar && (a3 ᵢ Type || a3 ᵢ TypeVar)
1877+
if isvarargtype(a3)
1878+
a3 = unwrapva(a3)
1879+
nothrow = false
1880+
else
1881+
nothrow = a2 ᵢ TypeVar && (a3 ᵢ Type || a3 ᵢ TypeVar)
1882+
end
18781883
if isa(a3, Const)
18791884
body = a3.val
18801885
elseif isType(a3)

test/compiler/inference.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Core.Compiler: Const, Conditional, ⊑, ReturnNode, GotoIfNot
55
isdispatchelem(@nospecialize x) = !isa(x, Type) || Core.Compiler.isdispatchelem(x)
66

77
using Random, Core.IR
8-
using InteractiveUtils: code_llvm
8+
using InteractiveUtils
99

1010
include("irutils.jl")
1111

@@ -5101,3 +5101,8 @@ end |> only === Val{5}
51015101
@test fully_eliminated() do
51025102
length(continue_const_prop(1, 5))
51035103
end
5104+
5105+
# https://github.com/JuliaLang/julia/issues/51310
5106+
@test code_typed() do
5107+
b{c} = d...
5108+
end |> only |> first isa Core.CodeInfo

0 commit comments

Comments
 (0)