Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: print ssa blocks without recursion #6715

Merged
merged 7 commits into from
Dec 6, 2024
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 4 additions & 25 deletions compiler/noirc_evaluator/src/ssa/ir/printer.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
//! This file is for pretty-printing the SSA IR in a human-readable form for debugging.
use std::{
collections::HashSet,
fmt::{Formatter, Result},
};
use std::fmt::{Formatter, Result};

use acvm::acir::AcirField;
use im::Vector;
Expand All @@ -21,28 +18,10 @@ use super::{
/// Helper function for Function's Display impl to pretty-print the function with the given formatter.
pub(crate) fn display_function(function: &Function, f: &mut Formatter) -> Result {
writeln!(f, "{} fn {} {} {{", function.runtime(), function.name(), function.id())?;
display_block_with_successors(function, function.entry_block(), &mut HashSet::new(), f)?;
write!(f, "}}")
}

/// Displays a block followed by all of its successors recursively.
/// This uses a HashSet to keep track of the visited blocks. Otherwise
/// there would be infinite recursion for any loops in the IR.
pub(crate) fn display_block_with_successors(
function: &Function,
block_id: BasicBlockId,
visited: &mut HashSet<BasicBlockId>,
f: &mut Formatter,
) -> Result {
display_block(function, block_id, f)?;
visited.insert(block_id);

for successor in function.dfg[block_id].successors() {
if !visited.contains(&successor) {
display_block_with_successors(function, successor, visited, f)?;
}
for block_id in function.reachable_blocks() {
display_block(function, block_id, f)?;
}
Ok(())
write!(f, "}}")
}

/// Display a single block. This will not display the block's successors.
Expand Down
Loading