Skip to content

Commit 4dfce5d

Browse files
authored
adjust the name and remarks of const prop heuristics (#55260)
`const_prop_entry_heuristics` currently checks the return type only, so I have given it a name that reflects this and adjusted the remarks accordingly. There are no changes to the basic behavior of inference.
1 parent 5da9468 commit 4dfce5d

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

base/compiler/abstractinterpretation.jl

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,12 +1034,12 @@ function maybe_get_const_prop_profitable(interp::AbstractInterpreter,
10341034
match::MethodMatch, sv::AbsIntState)
10351035
method = match.method
10361036
force = force_const_prop(interp, f, method)
1037-
if !const_prop_entry_heuristic(interp, result, si, sv, force)
1038-
# N.B. remarks are emitted within `const_prop_entry_heuristic`
1037+
if !const_prop_rettype_heuristic(interp, result, si, sv, force)
1038+
# N.B. remarks are emitted within `const_prop_rettype_heuristic`
10391039
return nothing
10401040
end
10411041
if !const_prop_argument_heuristic(interp, arginfo, sv)
1042-
add_remark!(interp, sv, "[constprop] Disabled by argument and rettype heuristics")
1042+
add_remark!(interp, sv, "[constprop] Disabled by argument heuristics")
10431043
return nothing
10441044
end
10451045
all_overridden = is_all_overridden(interp, arginfo, sv)
@@ -1061,28 +1061,28 @@ function maybe_get_const_prop_profitable(interp::AbstractInterpreter,
10611061
return mi
10621062
end
10631063

1064-
function const_prop_entry_heuristic(interp::AbstractInterpreter, result::MethodCallResult,
1065-
si::StmtInfo, sv::AbsIntState, force::Bool)
1066-
if result.rt isa LimitedAccuracy
1064+
function const_prop_rettype_heuristic(interp::AbstractInterpreter, result::MethodCallResult,
1065+
si::StmtInfo, sv::AbsIntState, force::Bool)
1066+
rt = result.rt
1067+
if rt isa LimitedAccuracy
10671068
# optimizations like inlining are disabled for limited frames,
10681069
# thus there won't be much benefit in constant-prop' here
10691070
# N.B. don't allow forced constprop' for safety (xref #52763)
1070-
add_remark!(interp, sv, "[constprop] Disabled by entry heuristic (limited accuracy)")
1071+
add_remark!(interp, sv, "[constprop] Disabled by rettype heuristic (limited accuracy)")
10711072
return false
10721073
elseif force
10731074
return true
10741075
elseif call_result_unused(si) && result.edgecycle
1075-
add_remark!(interp, sv, "[constprop] Disabled by entry heuristic (edgecycle with unused result)")
1076+
add_remark!(interp, sv, "[constprop] Disabled by rettype heuristic (edgecycle with unused result)")
10761077
return false
10771078
end
10781079
# check if this return type is improvable (i.e. whether it's possible that with more
10791080
# information, we might get a more precise type)
1080-
rt = result.rt
10811081
if isa(rt, Type)
10821082
# could always be improved to `Const`, `PartialStruct` or just a more precise type,
10831083
# unless we're already at `Bottom`
10841084
if rt === Bottom
1085-
add_remark!(interp, sv, "[constprop] Disabled by entry heuristic (erroneous result)")
1085+
add_remark!(interp, sv, "[constprop] Disabled by rettype heuristic (erroneous result)")
10861086
return false
10871087
end
10881088
return true
@@ -1091,14 +1091,15 @@ function const_prop_entry_heuristic(interp::AbstractInterpreter, result::MethodC
10911091
return true
10921092
elseif isa(rt, Const)
10931093
if is_nothrow(result.effects)
1094-
add_remark!(interp, sv, "[constprop] Disabled by entry heuristic (nothrow const)")
1094+
add_remark!(interp, sv, "[constprop] Disabled by rettype heuristic (nothrow const)")
10951095
return false
10961096
end
10971097
# Could still be improved to Bottom (or at least could see the effects improved)
10981098
return true
1099+
else
1100+
add_remark!(interp, sv, "[constprop] Disabled by rettype heuristic (unimprovable result)")
1101+
return false
10991102
end
1100-
add_remark!(interp, sv, "[constprop] Disabled by entry heuristic (unimprovable result)")
1101-
return false
11021103
end
11031104

11041105
# determines heuristically whether if constant propagation can be worthwhile

test/compiler/inference.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5052,13 +5052,13 @@ g() = empty_nt_values(Base.inferencebarrier(Tuple{}))
50525052
# to terminate the call.
50535053
@newinterp RecurseInterpreter
50545054
let CC = Core.Compiler
5055-
function CC.const_prop_entry_heuristic(interp::RecurseInterpreter, result::CC.MethodCallResult,
5056-
si::CC.StmtInfo, sv::CC.AbsIntState, force::Bool)
5055+
function CC.const_prop_rettype_heuristic(interp::RecurseInterpreter, result::CC.MethodCallResult,
5056+
si::CC.StmtInfo, sv::CC.AbsIntState, force::Bool)
50575057
if result.rt isa CC.LimitedAccuracy
50585058
return force # allow forced constprop to recurse into unresolved cycles
50595059
end
5060-
return @invoke CC.const_prop_entry_heuristic(interp::CC.AbstractInterpreter, result::CC.MethodCallResult,
5061-
si::CC.StmtInfo, sv::CC.AbsIntState, force::Bool)
5060+
return @invoke CC.const_prop_rettype_heuristic(interp::CC.AbstractInterpreter, result::CC.MethodCallResult,
5061+
si::CC.StmtInfo, sv::CC.AbsIntState, force::Bool)
50625062
end
50635063
end
50645064
Base.@constprop :aggressive type_level_recurse1(x...) = x[1] == 2 ? 1 : (length(x) > 100 ? x : type_level_recurse2(x[1] + 1, x..., x...))

0 commit comments

Comments
 (0)