Skip to content

Commit

Permalink
apply_type on Type{T} is valid whenever T is valid
Browse files Browse the repository at this point in the history
removes performance bug added by 0292c42
  • Loading branch information
vtjnash committed May 22, 2017
1 parent 55b5646 commit 0c5637d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions base/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,7 @@ function apply_type_tfunc(headtypetype::ANY, args::ANY...)
ai = args[i]
if isType(ai)
aip1 = ai.parameters[1]
canconst &= (isleaftype(aip1) || aip1 === Union{})
canconst &= !has_free_typevars(aip1)
push!(tparams, aip1)
elseif isa(ai, Const) && (isa(ai.val, Type) || isa(ai.val, TypeVar) || valid_tparam(ai.val))
push!(tparams, ai.val)
Expand Down Expand Up @@ -1775,6 +1775,10 @@ function abstract_call(f::ANY, fargs::Union{Tuple{},Vector{Any}}, argtypes::Vect
else
return Any
end
if !isa(body, Type) && !isa(body, TypeVar)
return Any
end
has_free_typevars(body) || return body
if isa(argtypes[2], Const)
tv = argtypes[2].val
elseif isa(argtypes[2], PartialTypeVar)
Expand All @@ -1785,9 +1789,6 @@ function abstract_call(f::ANY, fargs::Union{Tuple{},Vector{Any}}, argtypes::Vect
return Any
end
!isa(tv, TypeVar) && return Any
if !isa(body, Type) && !isa(body, TypeVar)
return Any
end
theunion = UnionAll(tv, body)
ret = canconst ? abstract_eval_constant(theunion) : Type{theunion}
return ret
Expand Down
2 changes: 1 addition & 1 deletion test/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -794,4 +794,4 @@ g21771(T) = T
f21771(::Val{U}) where {U} = Tuple{g21771(U)}
@test @inferred(f21771(Val{Int}())) === Tuple{Int}
@test @inferred(f21771(Val{Union{}}())) === Tuple{Union{}}
@test Base.return_types(f21771, typeof((Val{Integer}(),))) == Any[Type{<:Tuple{Integer}}] # apply_type might be overly conservative here
@test @inferred(f21771(Val{Integer}())) === Tuple{Integer}

0 comments on commit 0c5637d

Please sign in to comment.