@@ -842,9 +842,8 @@ function show_ir(io::IO, ci::CodeInfo, config::IRShowConfig=default_config(ci);
842842end 
843843
844844function  show_ir (io:: IO , compact:: IncrementalCompact , config:: IRShowConfig = default_config (compact. ir))
845-     compact_cfg =  CFG (compact. result_bbs, Int[first (compact. result_bbs[i]. stmts) for  i in  2 : length (compact. result_bbs)])
846845    cfg =  compact. ir. cfg
847-     (_, width)  =   displaysize (io) 
846+ 
848847
849848    #  First print everything that has already been compacted
850849
@@ -856,27 +855,66 @@ function show_ir(io::IO, compact::IncrementalCompact, config::IRShowConfig=defau
856855            push! (used_compacted, i)
857856        end 
858857    end 
858+ 
859+     #  while compacting, the end of the active result bb will not have been determined
860+     #  (this is done post-hoc by `finish_current_bb!`), so determine it here from scratch.
861+     result_bbs =  copy (compact. result_bbs)
862+     if  compact. active_result_bb <=  length (result_bbs)
863+         #  count the total number of nodes we'll add to this block
864+         input_bb_idx =  block_for_inst (compact. ir. cfg, compact. idx)
865+         input_bb =  compact. ir. cfg. blocks[input_bb_idx]
866+         count =  0 
867+         for  input_idx in  input_bb. stmts. start: input_bb. stmts. stop
868+             pop_new_node! =  new_nodes_iter (compact. ir)
869+             while  pop_new_node! (input_idx) != =  nothing 
870+                 count +=  1 
871+             end 
872+         end 
873+ 
874+         result_bb =  result_bbs[compact. active_result_bb]
875+         result_bbs[compact. active_result_bb] =  Core. Compiler. BasicBlock (result_bb,
876+             Core. Compiler. StmtRange (first (result_bb. stmts), last (result_bb. stmts)+ count))
877+     end 
878+     compact_cfg =  CFG (result_bbs, Int[first (result_bbs[i]. stmts) for  i in  2 : length (result_bbs)])
879+ 
859880    pop_new_node! =  new_nodes_iter (compact)
860881    maxssaid =  length (compact. result) +  Core. Compiler. length (compact. new_new_nodes)
861882    bb_idx =  let  io =  IOContext (io, :maxssaid => maxssaid)
862-         show_ir_stmts (io, compact, 1 : compact. result_idx- 1 , config, used_compacted, compact_cfg, 1 ; pop_new_node!)
883+         show_ir_stmts (io, compact, 1 : compact. result_idx- 1 , config, used_compacted,
884+                       compact_cfg, 1 ; pop_new_node!)
863885    end 
864886
887+ 
865888    #  Print uncompacted nodes from the original IR
866889
867890    #  print a separator
891+     (_, width) =  displaysize (io)
868892    stmts =  compact. ir. stmts
869893    indent =  length (string (length (stmts)))
870894    #  config.line_info_preprinter(io, "", compact.idx)
871895    printstyled (io, " ─" ^ (width- indent- 1 ), ' \n ' = :red )
872896
897+     #  while compacting, the start of the active uncompacted bb will have been overwritten.
898+     #  this manifests as a stmt range end that is less than the start, so correct that.
899+     inputs_bbs =  copy (cfg. blocks)
900+     for  (i, bb) in  enumerate (inputs_bbs)
901+         if  bb. stmts. stop <  bb. stmts. start
902+             inputs_bbs[i] =  Core. Compiler. BasicBlock (bb,
903+                 Core. Compiler. StmtRange (last (bb. stmts), last (bb. stmts)))
904+             #  this is not entirely correct, and will result in the bb starting again,
905+             #  but is the best we can do without changing how `finish_current_bb!` works.
906+         end 
907+     end 
908+     uncompacted_cfg =  CFG (inputs_bbs, Int[first (inputs_bbs[i]. stmts) for  i in  2 : length (inputs_bbs)])
909+ 
873910    pop_new_node! =  new_nodes_iter (compact. ir, compact. new_nodes_idx)
874911    maxssaid =  length (compact. ir. stmts) +  Core. Compiler. length (compact. ir. new_nodes)
875912    let  io =  IOContext (io, :maxssaid => maxssaid)
876-         show_ir_stmts (io, compact. ir, compact. idx: length (stmts), config, used_uncompacted, cfg, bb_idx; pop_new_node!)
913+         show_ir_stmts (io, compact. ir, compact. idx: length (stmts), config, used_uncompacted,
914+                       uncompacted_cfg, bb_idx; pop_new_node!)
877915    end 
878916
879-     finish_show_ir (io, cfg , config)
917+     finish_show_ir (io, uncompacted_cfg , config)
880918end 
881919
882920function  effectbits_letter (effects:: Effects , name:: Symbol , suffix:: Char )
0 commit comments