Skip to content

Commit 671c561

Browse files
authored
Fix potential inifinite loop in add_children!() (#445)
A method can call itself, so need to skip k==j as well as k<j.
1 parent a0a03f3 commit 671c561

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

SnoopCompileCore/src/snoop_inference.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ function addchildren!(parent::InferenceTimingNode, cis, backedges, miidx, backtr
134134
while true
135135
found = false
136136
for k in backedges[j]
137-
k < j && continue # don't get caught in cycles
137+
k j && continue # don't get caught in cycles
138138
be = cis[k]
139139
if be handled
140140
j = k

test/snoop_inference.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,23 @@ end
872872
@test :printdown names
873873
end
874874

875+
function countdownrecursive(io::IO, n::Int)
876+
if n == 0
877+
return printfinal(io)
878+
end
879+
return countdownrecursive(io, n-1)
880+
end
881+
function printfinal(io::IO)
882+
println(io, "final")
883+
return nothing
884+
end
885+
@testset "cycles - recursive" begin
886+
tinf = @snoop_inference countdownrecursive(IOBuffer(), 3)
887+
names = [Method(frame).name for frame in flatten(tinf)]
888+
@test :countdownrecursive names
889+
@test :printfinal names
890+
end
891+
875892
@testset "Stale and precompile_blockers" begin
876893
cproj = Base.active_project()
877894
cd(joinpath("testmodules", "Stale")) do

0 commit comments

Comments
 (0)