Skip to content

Commit 1931d9d

Browse files
author
Andy Ferris
committed
Remove tupletype_len heuristic
1 parent 7aae7c8 commit 1931d9d

File tree

6 files changed

+13
-43
lines changed

6 files changed

+13
-43
lines changed

base/compiler/abstractinterpretation.jl

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ const _REF_NAME = Ref.body.name
1515
#########
1616

1717
function abstract_call_gf_by_type(@nospecialize(f), argtypes::Vector{Any}, @nospecialize(atype), sv::InferenceState)
18-
atype = limit_tuple_type(atype, sv.params)
1918
atype_params = unwrap_unionall(atype).parameters
2019
ft = unwrap_unionall(atype_params[1]) # TODO: ccall jl_first_argument_datatype here
2120
isa(ft, DataType) || return Any # the function being called is unknown. can't properly handle this backedge right now
@@ -114,7 +113,7 @@ function abstract_call_method_with_const_args(@nospecialize(f), argtypes::Vector
114113
method = match[3]::Method
115114
nargs::Int = method.nargs
116115
method.isva && (nargs -= 1)
117-
length(argtypes) >= nargs || return Any # probably limit_tuple_type made this non-matching method apparently match
116+
length(argtypes) >= nargs || return Any
118117
haveconst = false
119118
for a in argtypes
120119
if isa(a, Const) && !isdefined(typeof(a.val), :instance) && !(isa(a.val, Type) && issingletontype(a.val))
@@ -388,7 +387,7 @@ function abstract_iteration(@nospecialize(itertype), vtypes::VarTable, sv::Infer
388387
valtype = statetype = Bottom
389388
ret = Any[]
390389
stateordonet = widenconst(stateordonet)
391-
while !(Nothing <: stateordonet) && length(ret) < sv.params.MAX_TUPLETYPE_LEN
390+
while !(Nothing <: stateordonet) || length(ret) < sv.params.MAX_TUPLE_SPLAT
392391
if !isa(stateordonet, DataType) || !(stateordonet <: Tuple) || isvatuple(stateordonet) || length(stateordonet.parameters) != 2
393392
break
394393
end
@@ -457,11 +456,6 @@ function abstract_apply(@nospecialize(aft), fargs::Vector{Any}, aargtypes::Vecto
457456
ctypes = ctypes´
458457
end
459458
for ct in ctypes
460-
if length(ct) > sv.params.MAX_TUPLETYPE_LEN
461-
tail = tuple_tail_elem(Bottom, ct[sv.params.MAX_TUPLETYPE_LEN:end])
462-
resize!(ct, sv.params.MAX_TUPLETYPE_LEN)
463-
ct[end] = tail
464-
end
465459
if isa(aft, Const)
466460
rt = abstract_call(aft.val, (), ct, vtypes, sv)
467461
elseif isconstType(aft)

base/compiler/params.jl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ struct Params
2828
MAX_APPLY_UNION_ENUM::Int
2929

3030
# parameters limiting large (tuple) types
31-
MAX_TUPLETYPE_LEN::Int
3231
TUPLE_COMPLEXITY_LIMIT_DEPTH::Int
3332

3433
# when attempting to inlining _apply, abort the optimization if the tuple
@@ -43,7 +42,6 @@ struct Params
4342
inline_nonleaf_penalty::Int = DEFAULT_PARAMS.inline_nonleaf_penalty,
4443
inline_tupleret_bonus::Int = DEFAULT_PARAMS.inline_tupleret_bonus,
4544
max_methods::Int = DEFAULT_PARAMS.MAX_METHODS,
46-
tupletype_len::Int = DEFAULT_PARAMS.MAX_TUPLETYPE_LEN,
4745
tupletype_depth::Int = DEFAULT_PARAMS.TUPLE_COMPLEXITY_LIMIT_DEPTH,
4846
tuple_splat::Int = DEFAULT_PARAMS.MAX_TUPLE_SPLAT,
4947
union_splitting::Int = DEFAULT_PARAMS.MAX_UNION_SPLITTING,
@@ -52,7 +50,7 @@ struct Params
5250
world, false,
5351
inlining, true, false, inline_cost_threshold, inline_nonleaf_penalty,
5452
inline_tupleret_bonus, max_methods, union_splitting, apply_union_enum,
55-
tupletype_len, tupletype_depth, tuple_splat)
53+
tupletype_depth, tuple_splat)
5654
end
5755
function Params(world::UInt)
5856
inlining = inlining_enabled()
@@ -62,8 +60,8 @@ struct Params
6260
inlining, true, false, 100, 1000,
6361
#=inline_tupleret_bonus, max_methods, union_splitting, apply_union_enum=#
6462
400, 4, 4, 8,
65-
#=tupletype_len, tupletype_depth, tuple_splat=#
66-
31, 3, 32)
63+
#=tupletype_depth, tuple_splat=#
64+
3, 32)
6765
end
6866
end
6967
const DEFAULT_PARAMS = Params(UInt(0))

base/compiler/ssair/inlining.jl

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -838,11 +838,11 @@ function assemble_inline_todo!(ir::IRCode, linetable::Vector{LineInfoNode}, sv::
838838
end
839839
isinvoke = (invoke_data !== nothing)
840840

841-
atype_unlimited = argtypes_to_type(atypes)
841+
atype = argtypes_to_type(atypes)
842842

843843
# In :invoke, make sure that the arguments we're passing are a subtype of the
844844
# signature we're invoking.
845-
(invoke_data === nothing || atype_unlimited <: invoke_data.types0) || continue
845+
(invoke_data === nothing || atype <: invoke_data.types0) || continue
846846

847847
# Bail out here if inlining is disabled
848848
sv.params.inlining || continue
@@ -852,20 +852,13 @@ function assemble_inline_todo!(ir::IRCode, linetable::Vector{LineInfoNode}, sv::
852852
continue
853853
end
854854

855-
# Compute the limited type if necessary
856-
if length(atype_unlimited.parameters) - 1 > sv.params.MAX_TUPLETYPE_LEN
857-
atype = limit_tuple_type(atype_unlimited, sv.params)
858-
else
859-
atype = atype_unlimited
860-
end
861-
862855
# Ok, now figure out what method to call
863856
if invoke_data !== nothing
864857
method = invoke_data.entry.func
865858
(metharg, methsp) = ccall(:jl_type_intersection_with_env, Any, (Any, Any),
866-
atype_unlimited, method.sig)::SimpleVector
859+
atype, method.sig)::SimpleVector
867860
methsp = methsp::SimpleVector
868-
result = analyze_method!(idx, f, ft, metharg, methsp, method, stmt, atypes, sv, atype_unlimited, isinvoke, isapply, invoke_data,
861+
result = analyze_method!(idx, f, ft, metharg, methsp, method, stmt, atypes, sv, atype, isinvoke, isapply, invoke_data,
869862
calltype)
870863
handle_single_case!(ir, stmt, idx, result, isinvoke, todo, sv)
871864
continue
@@ -942,7 +935,7 @@ function assemble_inline_todo!(ir::IRCode, linetable::Vector{LineInfoNode}, sv::
942935
methsp = meth[1][2]::SimpleVector
943936
method = meth[1][3]::Method
944937
fully_covered = true
945-
case = analyze_method!(idx, f, ft, metharg, methsp, method, stmt, atypes, sv, atype_unlimited, isinvoke, isapply, invoke_data, calltype)
938+
case = analyze_method!(idx, f, ft, metharg, methsp, method, stmt, atypes, sv, atype, isinvoke, isapply, invoke_data, calltype)
946939
case === nothing && continue
947940
push!(cases, Pair{Any,Any}(metharg, case))
948941
end
@@ -955,7 +948,7 @@ function assemble_inline_todo!(ir::IRCode, linetable::Vector{LineInfoNode}, sv::
955948
continue
956949
end
957950
length(cases) == 0 && continue
958-
push!(todo, UnionSplit(idx, fully_covered, atype_unlimited, isinvoke, cases))
951+
push!(todo, UnionSplit(idx, fully_covered, atype, isinvoke, cases))
959952
end
960953
todo
961954
end

base/compiler/tfuncs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,7 @@ add_tfunc(apply_type, 1, INT_INF, apply_type_tfunc, 10)
843843

844844
function invoke_tfunc(@nospecialize(ft), @nospecialize(types), @nospecialize(argtype), sv::InferenceState)
845845
argument_mt(ft) === nothing && return Any
846-
argtype = typeintersect(types, limit_tuple_type(argtype, sv.params))
846+
argtype = typeintersect(types, argtype)
847847
if argtype === Bottom
848848
return Bottom
849849
end

base/compiler/typelimits.jl

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,6 @@ const MAX_INLINE_CONST_SIZE = 256
1111
# limitation heuristics #
1212
#########################
1313

14-
limit_tuple_type(@nospecialize(t), params::Params) = limit_tuple_type_n(t, params.MAX_TUPLETYPE_LEN)
15-
16-
function limit_tuple_type_n(@nospecialize(t), lim::Int)
17-
if isa(t, UnionAll)
18-
return UnionAll(t.var, limit_tuple_type_n(t.body, lim))
19-
end
20-
p = t.parameters
21-
n = length(p)
22-
if n > lim
23-
tail = reduce(typejoin, Bottom, Any[p[lim:(n-1)]..., unwrapva(p[n])])
24-
return Tuple{p[1:(lim-1)]..., Vararg{tail}}
25-
end
26-
return t
27-
end
28-
2914
# limit the complexity of type `t` to be simpler than the comparison type `compare`
3015
# no new values may be introduced, so the parameter `source` encodes the set of all values already present
3116
# the outermost tuple type is permitted to have up to `allowed_tuplelen` parameters

test/compiler/compiler.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,7 @@ function count_specializations(method::Method)
10301030
return n::Int
10311031
end
10321032

1033-
# demonstrate that inference can complete without waiting for MAX_TUPLETYPE_LEN or MAX_TYPE_DEPTH
1033+
# demonstrate that inference can complete without waiting for MAX_TYPE_DEPTH
10341034
copy_dims_out(out) = ()
10351035
copy_dims_out(out, dim::Int, tail...) = copy_dims_out((out..., dim), tail...)
10361036
copy_dims_out(out, dim::Colon, tail...) = copy_dims_out((out..., dim), tail...)

0 commit comments

Comments
 (0)