Skip to content

Commit c487dd0

Browse files
authored
inference: fix vararg normalization in rewrap (#39134)
Fixes #39082
1 parent 9e7e23d commit c487dd0

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

base/compiler/typelattice.jl

+5-4
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ function ⊑(@nospecialize(a), @nospecialize(b))
122122
(a === Any || b === NOT_FOUND) && return false
123123
a === Union{} && return true
124124
b === Union{} && return false
125+
@assert !isa(a, TypeVar) "invalid lattice item"
126+
@assert !isa(b, TypeVar) "invalid lattice item"
125127
if isa(a, Conditional)
126128
if isa(b, Conditional)
127129
return issubconditional(a, b)
@@ -177,11 +179,10 @@ function ⊑(@nospecialize(a), @nospecialize(b))
177179
return false
178180
elseif isa(a, PartialTypeVar) && b === TypeVar
179181
return true
180-
elseif !(isa(a, Type) || isa(a, TypeVar)) ||
181-
!(isa(b, Type) || isa(b, TypeVar))
182-
return a === b
183-
else
182+
elseif isa(a, Type) && isa(b, Type)
184183
return a <: b
184+
else # handle this conservatively in the remaining cases
185+
return a === b
185186
end
186187
end
187188

base/compiler/typeutils.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#####################
66

77
function rewrap(@nospecialize(t), @nospecialize(u))
8-
if isa(t, TypeVar) || isa(t, Type)
8+
if isa(t, TypeVar) || isa(t, Type) || isa(t, Core.TypeofVararg)
99
return rewrap_unionall(t, u)
1010
end
1111
return t

test/compiler/inference.jl

+8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ isdispatchelem(@nospecialize x) = !isa(x, Type) || Core.Compiler.isdispatchelem(
77
using Random, Core.IR
88
using InteractiveUtils: code_llvm
99

10+
f39082(x::Vararg{T}) where {T <: Number} = x[1]
11+
let ast = only(code_typed(f39082, Tuple{Vararg{Rational}}))[1]
12+
@test ast.slottypes == Any[Const(f39082), Tuple{Vararg{Rational}}]
13+
end
14+
let ast = only(code_typed(f39082, Tuple{Rational, Vararg{Rational}}))[1]
15+
@test ast.slottypes == Any[Const(f39082), Tuple{Rational, Vararg{Rational}}]
16+
end
17+
1018
# demonstrate some of the type-size limits
1119
@test Core.Compiler.limit_type_size(Ref{Complex{T} where T}, Ref, Ref, 100, 0) == Ref
1220
@test Core.Compiler.limit_type_size(Ref{Complex{T} where T}, Ref{Complex{T} where T}, Ref, 100, 0) == Ref{Complex{T} where T}

0 commit comments

Comments
 (0)