Skip to content

Commit c5b5a76

Browse files
authored
inference: emit special constant-prop' remark for LimitedAccuracy rt (#43114)
xref: <JuliaDebug/Cthulhu.jl#241 (comment)>
1 parent 8dc1fa4 commit c5b5a76

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

base/compiler/abstractinterpretation.jl

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,6 @@ const _REF_NAME = Ref.body.name
1616
call_result_unused(frame::InferenceState) =
1717
isexpr(frame.src.code[frame.currpc], :call) && isempty(frame.ssavalue_uses[frame.currpc])
1818

19-
# check if this return type is improvable (i.e. whether it's possible that with
20-
# more information, we might get a more precise type)
21-
function is_improvable(@nospecialize(rtype))
22-
if isa(rtype, Type)
23-
# Could always be improved to Const or PartialStruct, unless we're
24-
# already at Bottom
25-
return rtype !== Union{}
26-
end
27-
# Could be improved to `Const` or a more precise wrapper
28-
return isa(rtype, PartialStruct) || isa(rtype, InterConditional)
29-
end
30-
3119
function abstract_call_gf_by_type(interp::AbstractInterpreter, @nospecialize(f),
3220
arginfo::ArgInfo, @nospecialize(atype),
3321
sv::InferenceState, max_methods::Int = InferenceParams(interp).MAX_METHODS)
@@ -666,9 +654,30 @@ function const_prop_entry_heuristic(interp::AbstractInterpreter, result::MethodC
666654
add_remark!(interp, sv, "[constprop] Disabled by entry heuristic (edgecycle with unused result)")
667655
return false
668656
end
669-
is_improvable(result.rt) && return true
670-
add_remark!(interp, sv, "[constprop] Disabled by entry heuristic (unimprovable return type)")
671-
return false
657+
# check if this return type is improvable (i.e. whether it's possible that with more
658+
# information, we might get a more precise type)
659+
rt = result.rt
660+
if isa(rt, Type)
661+
# could always be improved to `Const`, `PartialStruct` or just a more precise type,
662+
# unless we're already at `Bottom`
663+
if rt === Bottom
664+
add_remark!(interp, sv, "[constprop] Disabled by entry heuristic (erroneous result)")
665+
return false
666+
else
667+
return true
668+
end
669+
elseif isa(rt, PartialStruct) || isa(rt, InterConditional)
670+
# could be improved to `Const` or a more precise wrapper
671+
return true
672+
elseif isa(rt, LimitedAccuracy)
673+
# optimizations like inlining are disabled for limited frames,
674+
# thus there won't be much benefit in constant-prop' here
675+
add_remark!(interp, sv, "[constprop] Disabled by entry heuristic (limited accuracy)")
676+
return false
677+
else
678+
add_remark!(interp, sv, "[constprop] Disabled by entry heuristic (unimprovable return type)")
679+
return false
680+
end
672681
end
673682

674683
# determines heuristically whether if constant propagation can be worthwhile

0 commit comments

Comments
 (0)