Skip to content

Commit

Permalink
another improvement to static parameter precision (#31001)
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Feb 9, 2019
1 parent 6e552e7 commit 89d64c6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 31 deletions.
68 changes: 37 additions & 31 deletions base/compiler/inferencestate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -136,43 +136,49 @@ function sptypes_from_meth_instance(linfo::MethodInstance)
for i = 1:length(sp)
v = sp[i]
if v isa TypeVar
ub = v.ub
while ub isa TypeVar
ub = ub.ub
fromArg = 0
# if this parameter came from arg::Type{T}, then `arg` is more precise than
# Type{T} where lb<:T<:ub
sig = linfo.def.sig
temp = sig
for j = 1:i-1
temp = temp.body
end
if has_free_typevars(ub)
ub = Any
Pi = temp.var
while temp isa UnionAll
temp = temp.body
end
lb = v.lb
while lb isa TypeVar
lb = lb.lb
end
if has_free_typevars(lb)
lb = Bottom
sigtypes = temp.parameters
for j = 1:length(sigtypes)
tj = sigtypes[j]
if isType(tj) && tj.parameters[1] === Pi
fromArg = j
break
end
end
if Any <: ub && lb <: Bottom
ty = Any
# if this parameter came from arg::Type{T}, we know that T::Type
sig = linfo.def.sig
temp = sig
for j = 1:i-1
temp = temp.body
if fromArg > 0
ty = fieldtype(linfo.specTypes, fromArg)
else
ub = v.ub
while ub isa TypeVar
ub = ub.ub
end
Pi = temp.var
while temp isa UnionAll
temp = temp.body
if has_free_typevars(ub)
ub = Any
end
sigtypes = temp.parameters
for j = 1:length(sigtypes)
tj = sigtypes[j]
if isType(tj) && tj.parameters[1] === Pi
ty = Type
break
end
lb = v.lb
while lb isa TypeVar
lb = lb.lb
end
if has_free_typevars(lb)
lb = Bottom
end
if Any <: ub && lb <: Bottom
ty = Any
else
tv = TypeVar(v.name, lb, ub)
ty = UnionAll(tv, Type{tv})
end
else
tv = TypeVar(v.name, lb, ub)
ty = UnionAll(tv, Type{tv})
end
else
ty = Const(v)
Expand Down
1 change: 1 addition & 0 deletions test/compiler/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2216,3 +2216,4 @@ _call_rttf_test() = Core.Compiler.return_type(_rttf_test, Tuple{Any})

f_with_Type_arg(::Type{T}) where {T} = T
@test Base.return_types(f_with_Type_arg, (Any,)) == Any[Type]
@test Base.return_types(f_with_Type_arg, (Type{Vector{T}} where T,)) == Any[Type{Vector{T}} where T]

0 comments on commit 89d64c6

Please sign in to comment.