Skip to content

Commit 894f1a5

Browse files
authored
inference: refine [Inference|Optimization]Params (#47810)
This commit does 2 things: 1. refine the names of parameters, mainly lowercasing some of them (according to our naming convention) 2. add more documentations explaining the meaning of each parameter 3. add `Effects`-like keyword-based constructors
1 parent 4c90b2a commit 894f1a5

File tree

5 files changed

+231
-116
lines changed

5 files changed

+231
-116
lines changed

base/compiler/abstractinterpretation.jl

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ call_result_unused(si::StmtInfo) = !si.used
1919

2020
function get_max_methods(mod::Module, interp::AbstractInterpreter)
2121
max_methods = ccall(:jl_get_module_max_methods, Cint, (Any,), mod) % Int
22-
max_methods < 0 ? InferenceParams(interp).MAX_METHODS : max_methods
22+
max_methods < 0 ? InferenceParams(interp).max_methods : max_methods
2323
end
2424

2525
function get_max_methods(@nospecialize(f), mod::Module, interp::AbstractInterpreter)
@@ -62,7 +62,7 @@ function abstract_call_gf_by_type(interp::AbstractInterpreter, @nospecialize(f),
6262
# no overlayed calls, try an additional effort now to check if this call
6363
# isn't overlayed rather than just handling it conservatively
6464
matches = find_matching_methods(arginfo.argtypes, atype, method_table(interp),
65-
InferenceParams(interp).MAX_UNION_SPLITTING, max_methods)
65+
InferenceParams(interp).max_union_splitting, max_methods)
6666
if !isa(matches, FailedMethodMatch)
6767
nonoverlayed = matches.nonoverlayed
6868
end
@@ -78,7 +78,7 @@ function abstract_call_gf_by_type(interp::AbstractInterpreter, @nospecialize(f),
7878

7979
argtypes = arginfo.argtypes
8080
matches = find_matching_methods(argtypes, atype, method_table(interp),
81-
InferenceParams(interp).MAX_UNION_SPLITTING, max_methods)
81+
InferenceParams(interp).max_union_splitting, max_methods)
8282
if isa(matches, FailedMethodMatch)
8383
add_remark!(interp, sv, matches.reason)
8484
return CallMeta(Any, Effects(), NoCallInfo())
@@ -122,7 +122,7 @@ function abstract_call_gf_by_type(interp::AbstractInterpreter, @nospecialize(f),
122122
splitunions = false
123123
# TODO: this used to trigger a bug in inference recursion detection, and is unmaintained now
124124
# sigtuple = unwrap_unionall(sig)::DataType
125-
# splitunions = 1 < unionsplitcost(sigtuple.parameters) * napplicable <= InferenceParams(interp).MAX_UNION_SPLITTING
125+
# splitunions = 1 < unionsplitcost(sigtuple.parameters) * napplicable <= InferenceParams(interp).max_union_splitting
126126
if splitunions
127127
splitsigs = switchtupleunion(sig)
128128
for sig_n in splitsigs
@@ -276,9 +276,9 @@ end
276276
any_ambig(m::UnionSplitMethodMatches) = any(any_ambig, m.info.matches)
277277

278278
function find_matching_methods(argtypes::Vector{Any}, @nospecialize(atype), method_table::MethodTableView,
279-
union_split::Int, max_methods::Int)
279+
max_union_splitting::Int, max_methods::Int)
280280
# NOTE this is valid as far as any "constant" lattice element doesn't represent `Union` type
281-
if 1 < unionsplitcost(argtypes) <= union_split
281+
if 1 < unionsplitcost(argtypes) <= max_union_splitting
282282
split_argtypes = switchtupleunion(argtypes)
283283
infos = MethodMatchInfo[]
284284
applicable = Any[]
@@ -599,7 +599,7 @@ function abstract_call_method(interp::AbstractInterpreter, method::Method, @nosp
599599
end
600600

601601
# see if the type is actually too big (relative to the caller), and limit it if required
602-
newsig = limit_type_size(sig, comparison, hardlimit ? comparison : sv.linfo.specTypes, InferenceParams(interp).TUPLE_COMPLEXITY_LIMIT_DEPTH, spec_len)
602+
newsig = limit_type_size(sig, comparison, hardlimit ? comparison : sv.linfo.specTypes, InferenceParams(interp).tuple_complexity_limit_depth, spec_len)
603603

604604
if newsig !== sig
605605
# continue inference, but note that we've limited parameter complexity
@@ -641,7 +641,7 @@ function abstract_call_method(interp::AbstractInterpreter, method::Method, @nosp
641641
# while !(newsig in seen)
642642
# push!(seen, newsig)
643643
# lsig = length((unwrap_unionall(sig)::DataType).parameters)
644-
# newsig = limit_type_size(newsig, sig, sv.linfo.specTypes, InferenceParams(interp).TUPLE_COMPLEXITY_LIMIT_DEPTH, lsig)
644+
# newsig = limit_type_size(newsig, sig, sv.linfo.specTypes, InferenceParams(interp).tuple_complexity_limit_depth, lsig)
645645
# recomputed = ccall(:jl_type_intersection_with_env, Any, (Any, Any), newsig, method.sig)::SimpleVector
646646
# newsig = recomputed[2]
647647
# end
@@ -1436,13 +1436,13 @@ function abstract_iteration(interp::AbstractInterpreter, @nospecialize(itft), @n
14361436
calls = CallMeta[call]
14371437
stateordonet_widened = widenconst(stateordonet)
14381438

1439-
# Try to unroll the iteration up to MAX_TUPLE_SPLAT, which covers any finite
1439+
# Try to unroll the iteration up to max_tuple_splat, which covers any finite
14401440
# length iterators, or interesting prefix
14411441
while true
14421442
if stateordonet_widened === Nothing
14431443
return ret, AbstractIterationInfo(calls)
14441444
end
1445-
if Nothing <: stateordonet_widened || length(ret) >= InferenceParams(interp).MAX_TUPLE_SPLAT
1445+
if Nothing <: stateordonet_widened || length(ret) >= InferenceParams(interp).max_tuple_splat
14461446
break
14471447
end
14481448
if !isa(stateordonet_widened, DataType) || !(stateordonet_widened <: Tuple) || isvatuple(stateordonet_widened) || length(stateordonet_widened.parameters) != 2
@@ -1520,7 +1520,7 @@ function abstract_apply(interp::AbstractInterpreter, argtypes::Vector{Any}, si::
15201520
end
15211521
res = Union{}
15221522
nargs = length(aargtypes)
1523-
splitunions = 1 < unionsplitcost(aargtypes) <= InferenceParams(interp).MAX_APPLY_UNION_ENUM
1523+
splitunions = 1 < unionsplitcost(aargtypes) <= InferenceParams(interp).max_apply_union_enum
15241524
ctypes = [Any[aft]]
15251525
infos = Vector{MaybeAbstractIterationInfo}[MaybeAbstractIterationInfo[]]
15261526
effects = EFFECTS_TOTAL
@@ -1728,14 +1728,14 @@ function abstract_call_builtin(interp::AbstractInterpreter, f::Builtin, (; fargs
17281728
a = ssa_def_slot(fargs[2], sv)
17291729
a2 = argtypes[2]
17301730
if isa(a, SlotNumber)
1731-
cndt = isa_condition(a2, argtypes[3], InferenceParams(interp).MAX_UNION_SPLITTING, rt)
1731+
cndt = isa_condition(a2, argtypes[3], InferenceParams(interp).max_union_splitting, rt)
17321732
if cndt !== nothing
17331733
return Conditional(a, cndt.thentype, cndt.elsetype)
17341734
end
17351735
end
17361736
if isa(a2, MustAlias)
17371737
if !isa(rt, Const) # skip refinement when the field is known precisely (just optimization)
1738-
cndt = isa_condition(a2, argtypes[3], InferenceParams(interp).MAX_UNION_SPLITTING)
1738+
cndt = isa_condition(a2, argtypes[3], InferenceParams(interp).max_union_splitting)
17391739
if cndt !== nothing
17401740
return form_mustalias_conditional(a2, cndt.thentype, cndt.elsetype)
17411741
end
@@ -1749,18 +1749,18 @@ function abstract_call_builtin(interp::AbstractInterpreter, f::Builtin, (; fargs
17491749
# if doing a comparison to a singleton, consider returning a `Conditional` instead
17501750
if isa(aty, Const)
17511751
if isa(b, SlotNumber)
1752-
cndt = egal_condition(aty, bty, InferenceParams(interp).MAX_UNION_SPLITTING, rt)
1752+
cndt = egal_condition(aty, bty, InferenceParams(interp).max_union_splitting, rt)
17531753
return Conditional(b, cndt.thentype, cndt.elsetype)
17541754
elseif isa(bty, MustAlias) && !isa(rt, Const) # skip refinement when the field is known precisely (just optimization)
1755-
cndt = egal_condition(aty, bty.fldtyp, InferenceParams(interp).MAX_UNION_SPLITTING)
1755+
cndt = egal_condition(aty, bty.fldtyp, InferenceParams(interp).max_union_splitting)
17561756
return form_mustalias_conditional(bty, cndt.thentype, cndt.elsetype)
17571757
end
17581758
elseif isa(bty, Const)
17591759
if isa(a, SlotNumber)
1760-
cndt = egal_condition(bty, aty, InferenceParams(interp).MAX_UNION_SPLITTING, rt)
1760+
cndt = egal_condition(bty, aty, InferenceParams(interp).max_union_splitting, rt)
17611761
return Conditional(a, cndt.thentype, cndt.elsetype)
17621762
elseif isa(aty, MustAlias) && !isa(rt, Const) # skip refinement when the field is known precisely (just optimization)
1763-
cndt = egal_condition(bty, aty.fldtyp, InferenceParams(interp).MAX_UNION_SPLITTING)
1763+
cndt = egal_condition(bty, aty.fldtyp, InferenceParams(interp).max_union_splitting)
17641764
return form_mustalias_conditional(aty, cndt.thentype, cndt.elsetype)
17651765
end
17661766
end

base/compiler/ssair/inlining.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,7 +1019,7 @@ rewrite_invoke_exprargs!(expr::Expr) = (expr.args = invoke_rewrite(expr.args); e
10191019

10201020
function is_valid_type_for_apply_rewrite(@nospecialize(typ), params::OptimizationParams)
10211021
if isa(typ, Const) && (v = typ.val; isa(v, SimpleVector))
1022-
length(v) > params.MAX_TUPLE_SPLAT && return false
1022+
length(v) > params.max_tuple_splat && return false
10231023
for p in v
10241024
is_inlineable_constant(p) || return false
10251025
end
@@ -1032,7 +1032,7 @@ function is_valid_type_for_apply_rewrite(@nospecialize(typ), params::Optimizatio
10321032
end
10331033
isa(typ, DataType) || return false
10341034
if typ.name === Tuple.name
1035-
return !isvatuple(typ) && length(typ.parameters) <= params.MAX_TUPLE_SPLAT
1035+
return !isvatuple(typ) && length(typ.parameters) <= params.max_tuple_splat
10361036
else
10371037
return false
10381038
end

0 commit comments

Comments
 (0)