Skip to content

Commit

Permalink
inference: set limited flag on entire cycle
Browse files Browse the repository at this point in the history
We typically expect that all members in a cycle have the same attributes.
It may not be necessary, but that is how we record and track the items in a cycle.
  • Loading branch information
vtjnash committed Oct 24, 2018
1 parent 439f798 commit aaa9bd9
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions base/compiler/typeinfer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ function union_caller_cycle!(a::InferenceState, b::InferenceState)
return
end

function merge_call_chain!(parent::InferenceState, ancestor::InferenceState, child::InferenceState)
function merge_call_chain!(parent::InferenceState, ancestor::InferenceState, child::InferenceState, limited::Bool)
# add backedge of parent <- child
# then add all backedges of parent <- parent.parent
# and merge all of the callers into ancestor.callers_in_cycle
Expand All @@ -420,6 +420,11 @@ function merge_call_chain!(parent::InferenceState, ancestor::InferenceState, chi
parent = child.parent
child === ancestor && break
end
if limited
for caller in ancestor.callers_in_cycle
caller.limited = true
end
end
end

# Walk through `linfo`'s upstream call chain, starting at `parent`. If a parent
Expand All @@ -432,17 +437,19 @@ end
function resolve_call_cycle!(linfo::MethodInstance, parent::InferenceState)
frame = parent
uncached = false
limited = false
while isa(frame, InferenceState)
uncached |= !frame.cached # ensure we never add an uncached frame to a cycle
limited |= frame.limited
if frame.linfo === linfo
uncached && return true
merge_call_chain!(parent, frame, frame)
merge_call_chain!(parent, frame, frame, limited)
return frame
end
for caller in frame.callers_in_cycle
if caller.linfo === linfo
uncached && return true
merge_call_chain!(parent, frame, caller)
merge_call_chain!(parent, frame, caller, limited)
return caller
end
end
Expand Down

0 comments on commit aaa9bd9

Please sign in to comment.