Skip to content

Commit 8ee2e06

Browse files
committed
apply_type on Type{T} is valid whenever T is valid
removes performance bug added by 0292c42
1 parent 15e7369 commit 8ee2e06

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

base/inference.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,7 @@ function apply_type_tfunc(headtypetype::ANY, args::ANY...)
10011001
ai = args[i]
10021002
if isType(ai)
10031003
aip1 = ai.parameters[1]
1004-
canconst &= (isleaftype(aip1) || aip1 === Union{})
1004+
canconst &= !has_free_typevars(aip1)
10051005
push!(tparams, aip1)
10061006
elseif isa(ai, Const) && (isa(ai.val, Type) || isa(ai.val, TypeVar) || valid_tparam(ai.val))
10071007
push!(tparams, ai.val)
@@ -1784,6 +1784,10 @@ function abstract_call(f::ANY, fargs::Union{Tuple{},Vector{Any}}, argtypes::Vect
17841784
else
17851785
return Any
17861786
end
1787+
if !isa(body, Type) && !isa(body, TypeVar)
1788+
return Any
1789+
end
1790+
has_free_typevars(body) || return body
17871791
if isa(argtypes[2], Const)
17881792
tv = argtypes[2].val
17891793
elseif isa(argtypes[2], PartialTypeVar)
@@ -1794,9 +1798,6 @@ function abstract_call(f::ANY, fargs::Union{Tuple{},Vector{Any}}, argtypes::Vect
17941798
return Any
17951799
end
17961800
!isa(tv, TypeVar) && return Any
1797-
if !isa(body, Type) && !isa(body, TypeVar)
1798-
return Any
1799-
end
18001801
theunion = UnionAll(tv, body)
18011802
ret = canconst ? abstract_eval_constant(theunion) : Type{theunion}
18021803
return ret

test/inference.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -834,4 +834,4 @@ g21771(T) = T
834834
f21771(::Val{U}) where {U} = Tuple{g21771(U)}
835835
@test @inferred(f21771(Val{Int}())) === Tuple{Int}
836836
@test @inferred(f21771(Val{Union{}}())) === Tuple{Union{}}
837-
@test Base.return_types(f21771, typeof((Val{Integer}(),))) == Any[Type{<:Tuple{Integer}}] # apply_type might be overly conservative here
837+
@test @inferred(f21771(Val{Integer}())) === Tuple{Integer}

0 commit comments

Comments
 (0)