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(ssa refactor): safe to query cfg for single block programs #1401

Merged
merged 2 commits into from
May 25, 2023
Merged
Changes from all 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
9 changes: 8 additions & 1 deletion crates/noirc_evaluator/src/ssa_refactor/ir/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,14 @@ pub(crate) struct ControlFlowGraph {
impl ControlFlowGraph {
/// Allocate and compute the control flow graph for `func`.
pub(crate) fn with_function(func: &Function) -> Self {
let mut cfg = ControlFlowGraph { data: HashMap::new() };
// It is expected to be safe to query the control flow graph for any reachable block,
// therefore we must ensure that a node exists for the entry block, regardless of whether
// it later comes to describe any edges after calling compute.
let entry_block = func.entry_block();
let empty_node = CfgNode { predecessors: HashSet::new(), successors: HashSet::new() };
let data = HashMap::from([(entry_block, empty_node)]);

let mut cfg = ControlFlowGraph { data };
cfg.compute(func);
cfg
}
Expand Down