Skip to content

Commit 89729b9

Browse files
committed
IncrementalCompact: fix stateful behavior when using multiple iterators.
1 parent 1afa368 commit 89729b9

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

base/compiler/ssair/ir.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -1421,7 +1421,8 @@ function iterate(it::CompactPeekIterator, (idx, aidx, bidx)::NTuple{3, Int}=(it.
14211421
end
14221422

14231423
# This Union{Nothing, Pair{Pair{Int,Int},Any}} cannot be stack allocated, so we inline it
1424-
@inline function iterate(compact::IncrementalCompact, st::Tuple{Int, Int}=(compact.idx, 1))
1424+
@inline function iterate(compact::IncrementalCompact,
1425+
st::Tuple{Int, Int}=(compact.idx, compact.active_result_bb))
14251426
st = iterate_compact(compact, st)
14261427
st === nothing && return nothing
14271428
old_result_idx = st[1][2]

test/compiler/ssair.jl

+21
Original file line numberDiff line numberDiff line change
@@ -461,3 +461,24 @@ let ir = Base.code_ircode((Bool,Any)) do c, x
461461
end
462462
end
463463
end
464+
465+
@testset "IncrementalCompact statefulness" begin
466+
foo(i) = i == 1 ? 1 : 2
467+
ir = only(Base.code_ircode(foo, (Int,)))[1]
468+
compact = Core.Compiler.IncrementalCompact(ir)
469+
470+
# set up first iterator
471+
x = Core.Compiler.iterate(compact)
472+
x = Core.Compiler.iterate(compact, x[2])
473+
474+
# set up second iterator
475+
x = Core.Compiler.iterate(compact)
476+
477+
# consume remainder
478+
while x !== nothing
479+
x = Core.Compiler.iterate(compact, x[2])
480+
end
481+
482+
ir = Core.Compiler.complete(compact)
483+
@test Core.Compiler.verify_ir(ir) === nothing
484+
end

0 commit comments

Comments
 (0)