@@ -675,14 +675,20 @@ function show_ir_stmt(io::IO, code::Union{IRCode, CodeInfo, IncrementalCompact},
675675 return bb_idx
676676end
677677
678- function _new_nodes_iter (stmts, new_nodes, new_nodes_info)
678+ function _new_nodes_iter (stmts, new_nodes, new_nodes_info, new_nodes_idx )
679679 new_nodes_perm = filter (i -> isassigned (new_nodes. inst, i), 1 : length (new_nodes))
680680 sort! (new_nodes_perm, by = x -> (x = new_nodes_info[x]; (x. pos, x. attach_after)))
681681 perm_idx = Ref (1 )
682682
683- return function (idx:: Int )
683+ return function get_new_node (idx:: Int )
684684 perm_idx[] <= length (new_nodes_perm) || return nothing
685685 node_idx = new_nodes_perm[perm_idx[]]
686+ if node_idx < new_nodes_idx
687+ # skip new nodes that have already been processed by incremental compact
688+ # (but don't just return nothing because there may be multiple at this pos)
689+ perm_idx[] += 1
690+ return get_new_node (idx)
691+ end
686692 if new_nodes_info[node_idx]. pos != idx
687693 return nothing
688694 end
@@ -695,18 +701,18 @@ function _new_nodes_iter(stmts, new_nodes, new_nodes_info)
695701 end
696702end
697703
698- function new_nodes_iter (ir:: IRCode )
704+ function new_nodes_iter (ir:: IRCode , new_nodes_idx = 1 )
699705 stmts = ir. stmts
700706 new_nodes = ir. new_nodes. stmts
701707 new_nodes_info = ir. new_nodes. info
702- return _new_nodes_iter (stmts, new_nodes, new_nodes_info)
708+ return _new_nodes_iter (stmts, new_nodes, new_nodes_info, new_nodes_idx )
703709end
704710
705711function new_nodes_iter (compact:: IncrementalCompact )
706712 stmts = compact. result
707713 new_nodes = compact. new_new_nodes. stmts
708714 new_nodes_info = compact. new_new_nodes. info
709- return _new_nodes_iter (stmts, new_nodes, new_nodes_info)
715+ return _new_nodes_iter (stmts, new_nodes, new_nodes_info, 1 )
710716end
711717
712718# print only line numbers on the left, some of the method names and nesting depth on the right
@@ -864,7 +870,7 @@ function show_ir(io::IO, compact::IncrementalCompact, config::IRShowConfig=defau
864870 # config.line_info_preprinter(io, "", compact.idx)
865871 printstyled (io, " ─" ^ (width- indent- 1 ), ' \n ' , color= :red )
866872
867- pop_new_node! = new_nodes_iter (compact. ir)
873+ pop_new_node! = new_nodes_iter (compact. ir, compact . new_nodes_idx )
868874 maxssaid = length (compact. ir. stmts) + Core. Compiler. length (compact. ir. new_nodes)
869875 let io = IOContext (io, :maxssaid => maxssaid)
870876 show_ir_stmts (io, compact. ir, compact. idx: length (stmts), config, used_uncompacted, cfg, bb_idx; pop_new_node!)
0 commit comments