Skip to content

Commit d1b1a5d

Browse files
authored
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)
1 parent 6ad6a8f commit d1b1a5d

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

base/compiler/abstractinterpretation.jl

+15-5
Original file line numberDiff line numberDiff line change
@@ -698,13 +698,23 @@ function abstract_call_method(interp::AbstractInterpreter,
698698
end
699699
add_remark!(interp, sv, washardlimit ? RECURSION_MSG_HARDLIMIT : RECURSION_MSG)
700700
# TODO (#48913) implement a proper recursion handling for irinterp:
701-
# This works just because currently the `:terminate` condition guarantees that
702-
# irinterp doesn't fail into unresolved cycles, but it's not a good solution.
701+
# This works just because currently the `:terminate` condition usually means this is unreachable here
702+
# for irinterp because there are not unresolved cycles, but it's not a good solution.
703703
# We should revisit this once we have a better story for handling cycles in irinterp.
704-
if isa(topmost, InferenceState)
704+
if isa(sv, InferenceState)
705+
# since the hardlimit is against the edge to the parent frame,
706+
# we should try to poison the whole edge, not just the topmost frame
705707
parentframe = frame_parent(topmost)
706-
if isa(sv, InferenceState) && isa(parentframe, InferenceState)
707-
poison_callstack!(sv, parentframe === nothing ? topmost : parentframe)
708+
while !isa(parentframe, InferenceState)
709+
# attempt to find a parent frame that can handle this LimitedAccuracy result correctly
710+
# so we don't try to cache this incomplete intermediate result
711+
parentframe === nothing && break
712+
parentframe = frame_parent(parentframe)
713+
end
714+
if isa(parentframe, InferenceState)
715+
poison_callstack!(sv, parentframe)
716+
elseif isa(topmost, InferenceState)
717+
poison_callstack!(sv, topmost)
708718
end
709719
end
710720
# n.b. this heuristic depends on the non-local state, so we must record the limit later

0 commit comments

Comments
 (0)