Skip to content

Commit

Permalink
Remove tupletype_len heuristic
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Ferris committed Jun 27, 2018
1 parent 7aae7c8 commit 1931d9d
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 43 deletions.
10 changes: 2 additions & 8 deletions base/compiler/abstractinterpretation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const _REF_NAME = Ref.body.name
#########

function abstract_call_gf_by_type(@nospecialize(f), argtypes::Vector{Any}, @nospecialize(atype), sv::InferenceState)
atype = limit_tuple_type(atype, sv.params)
atype_params = unwrap_unionall(atype).parameters
ft = unwrap_unionall(atype_params[1]) # TODO: ccall jl_first_argument_datatype here
isa(ft, DataType) || return Any # the function being called is unknown. can't properly handle this backedge right now
Expand Down Expand Up @@ -114,7 +113,7 @@ function abstract_call_method_with_const_args(@nospecialize(f), argtypes::Vector
method = match[3]::Method
nargs::Int = method.nargs
method.isva && (nargs -= 1)
length(argtypes) >= nargs || return Any # probably limit_tuple_type made this non-matching method apparently match
length(argtypes) >= nargs || return Any
haveconst = false
for a in argtypes
if isa(a, Const) && !isdefined(typeof(a.val), :instance) && !(isa(a.val, Type) && issingletontype(a.val))
Expand Down Expand Up @@ -388,7 +387,7 @@ function abstract_iteration(@nospecialize(itertype), vtypes::VarTable, sv::Infer
valtype = statetype = Bottom
ret = Any[]
stateordonet = widenconst(stateordonet)
while !(Nothing <: stateordonet) && length(ret) < sv.params.MAX_TUPLETYPE_LEN
while !(Nothing <: stateordonet) || length(ret) < sv.params.MAX_TUPLE_SPLAT
if !isa(stateordonet, DataType) || !(stateordonet <: Tuple) || isvatuple(stateordonet) || length(stateordonet.parameters) != 2
break
end
Expand Down Expand Up @@ -457,11 +456,6 @@ function abstract_apply(@nospecialize(aft), fargs::Vector{Any}, aargtypes::Vecto
ctypes = ctypes´
end
for ct in ctypes
if length(ct) > sv.params.MAX_TUPLETYPE_LEN
tail = tuple_tail_elem(Bottom, ct[sv.params.MAX_TUPLETYPE_LEN:end])
resize!(ct, sv.params.MAX_TUPLETYPE_LEN)
ct[end] = tail
end
if isa(aft, Const)
rt = abstract_call(aft.val, (), ct, vtypes, sv)
elseif isconstType(aft)
Expand Down
8 changes: 3 additions & 5 deletions base/compiler/params.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ struct Params
MAX_APPLY_UNION_ENUM::Int

# parameters limiting large (tuple) types
MAX_TUPLETYPE_LEN::Int
TUPLE_COMPLEXITY_LIMIT_DEPTH::Int

# when attempting to inlining _apply, abort the optimization if the tuple
Expand All @@ -43,7 +42,6 @@ struct Params
inline_nonleaf_penalty::Int = DEFAULT_PARAMS.inline_nonleaf_penalty,
inline_tupleret_bonus::Int = DEFAULT_PARAMS.inline_tupleret_bonus,
max_methods::Int = DEFAULT_PARAMS.MAX_METHODS,
tupletype_len::Int = DEFAULT_PARAMS.MAX_TUPLETYPE_LEN,
tupletype_depth::Int = DEFAULT_PARAMS.TUPLE_COMPLEXITY_LIMIT_DEPTH,
tuple_splat::Int = DEFAULT_PARAMS.MAX_TUPLE_SPLAT,
union_splitting::Int = DEFAULT_PARAMS.MAX_UNION_SPLITTING,
Expand All @@ -52,7 +50,7 @@ struct Params
world, false,
inlining, true, false, inline_cost_threshold, inline_nonleaf_penalty,
inline_tupleret_bonus, max_methods, union_splitting, apply_union_enum,
tupletype_len, tupletype_depth, tuple_splat)
tupletype_depth, tuple_splat)
end
function Params(world::UInt)
inlining = inlining_enabled()
Expand All @@ -62,8 +60,8 @@ struct Params
inlining, true, false, 100, 1000,
#=inline_tupleret_bonus, max_methods, union_splitting, apply_union_enum=#
400, 4, 4, 8,
#=tupletype_len, tupletype_depth, tuple_splat=#
31, 3, 32)
#=tupletype_depth, tuple_splat=#
3, 32)
end
end
const DEFAULT_PARAMS = Params(UInt(0))
19 changes: 6 additions & 13 deletions base/compiler/ssair/inlining.jl
Original file line number Diff line number Diff line change
Expand Up @@ -838,11 +838,11 @@ function assemble_inline_todo!(ir::IRCode, linetable::Vector{LineInfoNode}, sv::
end
isinvoke = (invoke_data !== nothing)

atype_unlimited = argtypes_to_type(atypes)
atype = argtypes_to_type(atypes)

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

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

# Compute the limited type if necessary
if length(atype_unlimited.parameters) - 1 > sv.params.MAX_TUPLETYPE_LEN
atype = limit_tuple_type(atype_unlimited, sv.params)
else
atype = atype_unlimited
end

# Ok, now figure out what method to call
if invoke_data !== nothing
method = invoke_data.entry.func
(metharg, methsp) = ccall(:jl_type_intersection_with_env, Any, (Any, Any),
atype_unlimited, method.sig)::SimpleVector
atype, method.sig)::SimpleVector
methsp = methsp::SimpleVector
result = analyze_method!(idx, f, ft, metharg, methsp, method, stmt, atypes, sv, atype_unlimited, isinvoke, isapply, invoke_data,
result = analyze_method!(idx, f, ft, metharg, methsp, method, stmt, atypes, sv, atype, isinvoke, isapply, invoke_data,
calltype)
handle_single_case!(ir, stmt, idx, result, isinvoke, todo, sv)
continue
Expand Down Expand Up @@ -942,7 +935,7 @@ function assemble_inline_todo!(ir::IRCode, linetable::Vector{LineInfoNode}, sv::
methsp = meth[1][2]::SimpleVector
method = meth[1][3]::Method
fully_covered = true
case = analyze_method!(idx, f, ft, metharg, methsp, method, stmt, atypes, sv, atype_unlimited, isinvoke, isapply, invoke_data, calltype)
case = analyze_method!(idx, f, ft, metharg, methsp, method, stmt, atypes, sv, atype, isinvoke, isapply, invoke_data, calltype)
case === nothing && continue
push!(cases, Pair{Any,Any}(metharg, case))
end
Expand All @@ -955,7 +948,7 @@ function assemble_inline_todo!(ir::IRCode, linetable::Vector{LineInfoNode}, sv::
continue
end
length(cases) == 0 && continue
push!(todo, UnionSplit(idx, fully_covered, atype_unlimited, isinvoke, cases))
push!(todo, UnionSplit(idx, fully_covered, atype, isinvoke, cases))
end
todo
end
Expand Down
2 changes: 1 addition & 1 deletion base/compiler/tfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ add_tfunc(apply_type, 1, INT_INF, apply_type_tfunc, 10)

function invoke_tfunc(@nospecialize(ft), @nospecialize(types), @nospecialize(argtype), sv::InferenceState)
argument_mt(ft) === nothing && return Any
argtype = typeintersect(types, limit_tuple_type(argtype, sv.params))
argtype = typeintersect(types, argtype)
if argtype === Bottom
return Bottom
end
Expand Down
15 changes: 0 additions & 15 deletions base/compiler/typelimits.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,6 @@ const MAX_INLINE_CONST_SIZE = 256
# limitation heuristics #
#########################

limit_tuple_type(@nospecialize(t), params::Params) = limit_tuple_type_n(t, params.MAX_TUPLETYPE_LEN)

function limit_tuple_type_n(@nospecialize(t), lim::Int)
if isa(t, UnionAll)
return UnionAll(t.var, limit_tuple_type_n(t.body, lim))
end
p = t.parameters
n = length(p)
if n > lim
tail = reduce(typejoin, Bottom, Any[p[lim:(n-1)]..., unwrapva(p[n])])
return Tuple{p[1:(lim-1)]..., Vararg{tail}}
end
return t
end

# limit the complexity of type `t` to be simpler than the comparison type `compare`
# no new values may be introduced, so the parameter `source` encodes the set of all values already present
# the outermost tuple type is permitted to have up to `allowed_tuplelen` parameters
Expand Down
2 changes: 1 addition & 1 deletion test/compiler/compiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,7 @@ function count_specializations(method::Method)
return n::Int
end

# demonstrate that inference can complete without waiting for MAX_TUPLETYPE_LEN or MAX_TYPE_DEPTH
# demonstrate that inference can complete without waiting for MAX_TYPE_DEPTH
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...)
Expand Down

0 comments on commit 1931d9d

Please sign in to comment.