Skip to content

Commit 2d90181

Browse files
committed
Put more constants in InferenceParams.
1 parent 1a69572 commit 2d90181

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

base/inference.jl

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ import Core: _apply, svec, apply_type, Builtin, IntrinsicFunction
55
#### parameters limiting potentially-infinite types ####
66
const MAX_TYPEUNION_LEN = 3
77
const MAX_TYPE_DEPTH = 7
8-
const MAX_TUPLETYPE_LEN = 15
98

10-
const MAX_TUPLE_SPLAT = 16
11-
const MAX_UNION_SPLITTING = 4
129
const UNION_SPLIT_MISMATCH_ERROR = false
1310

1411
immutable InferenceParams
12+
MAX_TUPLETYPE_LEN
13+
MAX_TUPLE_SPLAT
14+
MAX_UNION_SPLITTING
1515
MAX_TUPLE_DEPTH
1616
end
17-
const DEFAULT_PARAMS = InferenceParams(4)
17+
const DEFAULT_PARAMS = InferenceParams(15,16, 4, 4)
1818

1919
# alloc_elim_pass! relies on `Slot_AssignedOnce | Slot_UsedUndef` being
2020
# SSA. This should be true now but can break if we start to track conditional
@@ -637,7 +637,7 @@ function invoke_tfunc(f::ANY, types::ANY, argtype::ANY, sv::InferenceState)
637637
if !isleaftype(Type{types})
638638
return Any
639639
end
640-
argtype = typeintersect(types,limit_tuple_type(argtype))
640+
argtype = typeintersect(types,limit_tuple_type(argtype, sv))
641641
if is(argtype,Bottom)
642642
return Bottom
643643
end
@@ -752,9 +752,9 @@ function limit_tuple_depth_(params::InferenceParams, t::ANY, d::Int)
752752
Tuple{p...}
753753
end
754754

755-
limit_tuple_type = (t::ANY) -> limit_tuple_type_n(t, MAX_TUPLETYPE_LEN)
755+
limit_tuple_type = (t::ANY, sv::InferenceState) -> limit_tuple_type_n(t, sv.params.MAX_TUPLETYPE_LEN, sv)
756756

757-
function limit_tuple_type_n(t::ANY, lim::Int)
757+
function limit_tuple_type_n(t::ANY, lim::Int, sv::InferenceState)
758758
p = t.parameters
759759
n = length(p)
760760
if n > lim
@@ -776,7 +776,7 @@ function abstract_call_gf_by_type(f::ANY, argtype::ANY, sv::InferenceState)
776776
# It is important for N to be >= the number of methods in the error()
777777
# function, so we can still know that error() is always Bottom.
778778
# here I picked 4.
779-
argtype = limit_tuple_type(argtype)
779+
argtype = limit_tuple_type(argtype, sv)
780780
argtypes = argtype.parameters
781781
applicable = _methods_by_ftype(argtype, 4)
782782
rettype = Bottom
@@ -874,7 +874,7 @@ function abstract_call_gf_by_type(f::ANY, argtype::ANY, sv::InferenceState)
874874
end
875875
end
876876
if !allsame
877-
sig = limit_tuple_type_n(sig, lsig+1)
877+
sig = limit_tuple_type_n(sig, lsig+1, sv)
878878
end
879879
end
880880
end
@@ -949,9 +949,9 @@ function abstract_apply(af::ANY, fargs, aargtypes::Vector{Any}, vtypes::VarTable
949949
# can be collapsed to a call to the applied func
950950
at = append_any(Any[type_typeof(af)], ctypes...)
951951
n = length(at)
952-
if n-1 > MAX_TUPLETYPE_LEN
953-
tail = foldl((a,b)->tmerge(a,unwrapva(b)), Bottom, at[MAX_TUPLETYPE_LEN+1:n])
954-
at = vcat(at[1:MAX_TUPLETYPE_LEN], Any[Vararg{tail}])
952+
if n-1 > sv.params.MAX_TUPLETYPE_LEN
953+
tail = foldl((a,b)->tmerge(a,unwrapva(b)), Bottom, at[sv.params.MAX_TUPLETYPE_LEN+1:n])
954+
at = vcat(at[1:sv.params.MAX_TUPLETYPE_LEN], Any[Vararg{tail}])
955955
end
956956
return abstract_call(af, (), at, vtypes, sv)
957957
end
@@ -2415,7 +2415,7 @@ function inlineable(f::ANY, ft::ANY, e::Expr, atypes::Vector{Any}, sv::Inference
24152415
function invoke_NF()
24162416
# converts a :call to :invoke
24172417
local nu = countunionsplit(atypes)
2418-
nu > MAX_UNION_SPLITTING && return NF
2418+
nu > sv.params.MAX_UNION_SPLITTING && return NF
24192419

24202420
if nu > 1
24212421
local spec_hit = nothing
@@ -2519,8 +2519,8 @@ function inlineable(f::ANY, ft::ANY, e::Expr, atypes::Vector{Any}, sv::Inference
25192519
return invoke_NF()
25202520
end
25212521

2522-
if length(atype_unlimited.parameters) - 1 > MAX_TUPLETYPE_LEN
2523-
atype = limit_tuple_type(atype_unlimited)
2522+
if length(atype_unlimited.parameters) - 1 > sv.params.MAX_TUPLETYPE_LEN
2523+
atype = limit_tuple_type(atype_unlimited, sv)
25242524
else
25252525
atype = atype_unlimited
25262526
end
@@ -3055,7 +3055,7 @@ function inlining_pass(e::Expr, sv, linfo)
30553055
elseif isa(aarg, Tuple)
30563056
newargs[i-2] = Any[ QuoteNode(x) for x in aarg ]
30573057
elseif isa(t, DataType) && t.name === Tuple.name && !isvatuple(t) &&
3058-
effect_free(aarg, linfo, true) && length(t.parameters) <= MAX_TUPLE_SPLAT
3058+
effect_free(aarg, linfo, true) && length(t.parameters) <= sv.params.MAX_TUPLE_SPLAT
30593059
# apply(f,t::(x,y)) => f(t[1],t[2])
30603060
tp = t.parameters
30613061
newargs[i-2] = Any[ mk_getfield(aarg,j,tp[j]) for j=1:length(tp) ]

demo.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ end
4848
hooks = Core.Inference.InferenceHooks(call_hook)
4949

5050
# raise limits on inference parameters, performing a more exhaustive search
51-
params = Core.Inference.InferenceParams(64)
51+
params = Core.Inference.InferenceParams(15, 16, 4, 4)
5252

5353
(linfo, rettyp, inferred) =
5454
Core.Inference.typeinf_uncached(m, sig, spvals, optimize=true,

0 commit comments

Comments
 (0)