Skip to content

Commit 0c5637d

Browse files
committed
apply_type on Type{T} is valid whenever T is valid
removes performance bug added by 0292c42
1 parent 55b5646 commit 0c5637d

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
@@ -999,7 +999,7 @@ function apply_type_tfunc(headtypetype::ANY, args::ANY...)
999999
ai = args[i]
10001000
if isType(ai)
10011001
aip1 = ai.parameters[1]
1002-
canconst &= (isleaftype(aip1) || aip1 === Union{})
1002+
canconst &= !has_free_typevars(aip1)
10031003
push!(tparams, aip1)
10041004
elseif isa(ai, Const) && (isa(ai.val, Type) || isa(ai.val, TypeVar) || valid_tparam(ai.val))
10051005
push!(tparams, ai.val)
@@ -1775,6 +1775,10 @@ function abstract_call(f::ANY, fargs::Union{Tuple{},Vector{Any}}, argtypes::Vect
17751775
else
17761776
return Any
17771777
end
1778+
if !isa(body, Type) && !isa(body, TypeVar)
1779+
return Any
1780+
end
1781+
has_free_typevars(body) || return body
17781782
if isa(argtypes[2], Const)
17791783
tv = argtypes[2].val
17801784
elseif isa(argtypes[2], PartialTypeVar)
@@ -1785,9 +1789,6 @@ function abstract_call(f::ANY, fargs::Union{Tuple{},Vector{Any}}, argtypes::Vect
17851789
return Any
17861790
end
17871791
!isa(tv, TypeVar) && return Any
1788-
if !isa(body, Type) && !isa(body, TypeVar)
1789-
return Any
1790-
end
17911792
theunion = UnionAll(tv, body)
17921793
ret = canconst ? abstract_eval_constant(theunion) : Type{theunion}
17931794
return ret

test/inference.jl

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

0 commit comments

Comments
 (0)