Skip to content

Commit 9386218

Browse files
vtjnashKristofferC
authored andcommitted
inference: fix missing LimitedAccuracy markers (#55362)
If the LimitedAccuracy was supposed to resolve against the top-most frame (or hypothetically a non-InferenceState frame), it would not have a parentframe, preventing it from reaching the subsequent poison_callstack line that is required for reliable inference (avoiding caching bad results). This should restore the original intent of this code (pre #48913) (cherry picked from commit d1b1a5d)
1 parent 885aeda commit 9386218

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

base/compiler/abstractinterpretation.jl

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -605,13 +605,23 @@ function abstract_call_method(interp::AbstractInterpreter,
605605
end
606606
add_remark!(interp, sv, washardlimit ? RECURSION_MSG_HARDLIMIT : RECURSION_MSG)
607607
# TODO (#48913) implement a proper recursion handling for irinterp:
608-
# This works just because currently the `:terminate` condition guarantees that
609-
# irinterp doesn't fail into unresolved cycles, but it's not a good solution.
608+
# This works just because currently the `:terminate` condition usually means this is unreachable here
609+
# for irinterp because there are not unresolved cycles, but it's not a good solution.
610610
# We should revisit this once we have a better story for handling cycles in irinterp.
611-
if isa(topmost, InferenceState)
611+
if isa(sv, InferenceState)
612+
# since the hardlimit is against the edge to the parent frame,
613+
# we should try to poison the whole edge, not just the topmost frame
612614
parentframe = frame_parent(topmost)
613-
if isa(sv, InferenceState) && isa(parentframe, InferenceState)
614-
poison_callstack!(sv, parentframe === nothing ? topmost : parentframe)
615+
while !isa(parentframe, InferenceState)
616+
# attempt to find a parent frame that can handle this LimitedAccuracy result correctly
617+
# so we don't try to cache this incomplete intermediate result
618+
parentframe === nothing && break
619+
parentframe = frame_parent(parentframe)
620+
end
621+
if isa(parentframe, InferenceState)
622+
poison_callstack!(sv, parentframe)
623+
elseif isa(topmost, InferenceState)
624+
poison_callstack!(sv, topmost)
615625
end
616626
end
617627
# n.b. this heuristic depends on the non-local state, so we must record the limit later

0 commit comments

Comments
 (0)