Skip to content

Commit

Permalink
inference: fix vararg normalization in rewrap (#39134)
Browse files Browse the repository at this point in the history
Fixes #39082
  • Loading branch information
vtjnash authored Jan 10, 2021
1 parent 9e7e23d commit c487dd0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
9 changes: 5 additions & 4 deletions base/compiler/typelattice.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ function ⊑(@nospecialize(a), @nospecialize(b))
(a === Any || b === NOT_FOUND) && return false
a === Union{} && return true
b === Union{} && return false
@assert !isa(a, TypeVar) "invalid lattice item"
@assert !isa(b, TypeVar) "invalid lattice item"
if isa(a, Conditional)
if isa(b, Conditional)
return issubconditional(a, b)
Expand Down Expand Up @@ -177,11 +179,10 @@ function ⊑(@nospecialize(a), @nospecialize(b))
return false
elseif isa(a, PartialTypeVar) && b === TypeVar
return true
elseif !(isa(a, Type) || isa(a, TypeVar)) ||
!(isa(b, Type) || isa(b, TypeVar))
return a === b
else
elseif isa(a, Type) && isa(b, Type)
return a <: b
else # handle this conservatively in the remaining cases
return a === b
end
end

Expand Down
2 changes: 1 addition & 1 deletion base/compiler/typeutils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#####################

function rewrap(@nospecialize(t), @nospecialize(u))
if isa(t, TypeVar) || isa(t, Type)
if isa(t, TypeVar) || isa(t, Type) || isa(t, Core.TypeofVararg)
return rewrap_unionall(t, u)
end
return t
Expand Down
8 changes: 8 additions & 0 deletions test/compiler/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ isdispatchelem(@nospecialize x) = !isa(x, Type) || Core.Compiler.isdispatchelem(
using Random, Core.IR
using InteractiveUtils: code_llvm

f39082(x::Vararg{T}) where {T <: Number} = x[1]
let ast = only(code_typed(f39082, Tuple{Vararg{Rational}}))[1]
@test ast.slottypes == Any[Const(f39082), Tuple{Vararg{Rational}}]
end
let ast = only(code_typed(f39082, Tuple{Rational, Vararg{Rational}}))[1]
@test ast.slottypes == Any[Const(f39082), Tuple{Rational, Vararg{Rational}}]
end

# demonstrate some of the type-size limits
@test Core.Compiler.limit_type_size(Ref{Complex{T} where T}, Ref, Ref, 100, 0) == Ref
@test Core.Compiler.limit_type_size(Ref{Complex{T} where T}, Ref{Complex{T} where T}, Ref, 100, 0) == Ref{Complex{T} where T}
Expand Down

0 comments on commit c487dd0

Please sign in to comment.