Skip to content

Commit

Permalink
inference: significantly increase the set of cases permitted before t…
Browse files Browse the repository at this point in the history
…riggering recursion detection

This is generally sufficient to ensure we can infer "bottleneck"-type functions,
without significantly sacrificing our convergence requirements
  • Loading branch information
vtjnash committed Sep 28, 2017
1 parent b72af50 commit 888d940
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
24 changes: 23 additions & 1 deletion base/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1797,7 +1797,29 @@ function abstract_call_method(method::Method, @nospecialize(f), @nospecialize(si
topmost = nothing
break
end
topmost === nothing && (topmost = infstate)
if topmost === nothing
# inspect the parent of this edge,
# to see if they are the same Method as sv
# in which case we'll need to ensure it is convergent
# otherwise, we don't
for parent in infstate.callers_in_cycle
# check in the cycle list first
# all items in here are mutual parents of all others
if parent.linfo.def === sv.linfo.def
topmost = infstate
break
end
end
let parent = infstate.parent
# then check the parent link
if topmost === nothing && parent !== nothing
parent = parent::InferenceState
if parent.cached && parent.linfo.def === sv.linfo.def
topmost = infstate
end
end
end
end
end
# iterate through the cycle before walking to the parent
if cyclei < length(infstate.callers_in_cycle)
Expand Down
4 changes: 3 additions & 1 deletion test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5337,7 +5337,8 @@ module UnionOptimizations
using Base.Test

const boxedunions = [Union{}, Union{String, Void}]
const unboxedunions = [Union{Int8, Void}, Union{Int8, Float16, Void},
const unboxedunions = [Union{Int8, Void},
Union{Int8, Float16, Void},
Union{Int8, UInt8, Int16, UInt16, Int32, UInt32, Int64, UInt64, Int128, UInt128},
Union{Char, Date, Int}]

Expand Down Expand Up @@ -5463,6 +5464,7 @@ t4 = vcat(A23567, t2, t3)
@test t4[11:15] == A23567

for U in unboxedunions
Base.unionlen(U) > 5 && continue # larger values cause subtyping to crash
local U
for N in (1, 2, 3, 4)
A = Array{U}(ntuple(x->0, N)...)
Expand Down
8 changes: 4 additions & 4 deletions test/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -980,13 +980,13 @@ copy_dims_out(out) = ()
copy_dims_out(out, dim::Int, tail...) = copy_dims_out((out..., dim), tail...)
copy_dims_out(out, dim::Colon, tail...) = copy_dims_out((out..., dim), tail...)
@test Base.return_types(copy_dims_out, (Tuple{}, Vararg{Union{Int,Colon}})) == Any[Tuple{}, Tuple{}, Tuple{}]
@test all(m -> 2 < count_specializations(m) < 15, methods(copy_dims_out))
@test all(m -> 15 < count_specializations(m) < 45, methods(copy_dims_out))

copy_dims_pair(out) = ()
copy_dims_pair(out, dim::Int, tail...) = copy_dims_out(out => dim, tail...)
copy_dims_pair(out, dim::Colon, tail...) = copy_dims_out(out => dim, tail...)
copy_dims_pair(out, dim::Int, tail...) = copy_dims_pair(out => dim, tail...)
copy_dims_pair(out, dim::Colon, tail...) = copy_dims_pair(out => dim, tail...)
@test Base.return_types(copy_dims_pair, (Tuple{}, Vararg{Union{Int,Colon}})) == Any[Tuple{}, Tuple{}, Tuple{}]
@test all(m -> 5 < count_specializations(m) < 25, methods(copy_dims_out))
@test all(m -> 10 < count_specializations(m) < 35, methods(copy_dims_pair))

# splatting an ::Any should still allow inference to use types of parameters preceding it
f22364(::Int, ::Any...) = 0
Expand Down

0 comments on commit 888d940

Please sign in to comment.