Skip to content

Commit

Permalink
fix: print ssa blocks without recursion
Browse files Browse the repository at this point in the history
  • Loading branch information
asterite committed Dec 5, 2024
1 parent 31640e9 commit abbd88d
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions compiler/noirc_evaluator/src/ssa/ir/printer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! This file is for pretty-printing the SSA IR in a human-readable form for debugging.
use std::{
collections::HashSet,
collections::{HashSet, VecDeque},
fmt::{Formatter, Result},
};

Expand Down Expand Up @@ -34,14 +34,22 @@ pub(crate) fn display_block_with_successors(
visited: &mut HashSet<BasicBlockId>,
f: &mut Formatter,
) -> Result {
display_block(function, block_id, f)?;
visited.insert(block_id);
// The block chain to print might be really long so we use a deque instead of recursion
// to avoid potentially hitting stack overflow (see https://github.com/noir-lang/noir/issues/6520)
let mut blocks_to_print = VecDeque::new();
blocks_to_print.push_back(block_id);

for successor in function.dfg[block_id].successors() {
if !visited.contains(&successor) {
display_block_with_successors(function, successor, visited, f)?;
while let Some(block_id) = blocks_to_print.pop_front() {
if !visited.insert(block_id) {
continue;
};
display_block(function, block_id, f)?;

for successor in function.dfg[block_id].successors() {
blocks_to_print.push_back(successor);
}
}

Ok(())
}

Expand Down

0 comments on commit abbd88d

Please sign in to comment.