Skip to content

Inifinite loop in add_children!() #444

@johnomotani

Description

@johnomotani

I have a case where I get stuck in an infinite loop here

function addchildren!(parent::InferenceTimingNode, cis, backedges, miidx, backtraces)
handled = Set{CodeInstance}()
for (i, ci) in pairs(cis)
ci handled && continue
# Follow the backedges to the root
j = i
be = ci
while true
found = false
for k in backedges[j]
k < j && continue # don't get caught in cycles
be = cis[k]
if be handled
j = k
found = true
break
end
end
found || break # quit when no unhandled backedge found
end
be handled && continue
# bt1, bt2 = get(backtraces, Core.Compiler.get_ci_mi(be), (nothing, nothing))
# child = InferenceTimingNode(be, make_stacktrace(bt1, bt2), parent)
child = InferenceTimingNode(be, get(backtraces, be, nothing), parent)
push!(handled, be)
addchildren!(child, handled, miidx)
end
return parent
end

I think what's happening is that be ∉ handled is true the first time it is tested, for k == j. That means that j never increments, and the loop never ends. I don't understand what's being done here, but if I change line 137 to

k  j && continue   # don't get caught in cycles

instead of k < j, then there's no infinite loop, and the output looks reasonable. Is this a correct fix?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions