From 3eeb888a77768f5624fce09d5e7289abda9db66e Mon Sep 17 00:00:00 2001 From: Joss Date: Thu, 25 May 2023 12:34:57 +0100 Subject: [PATCH 1/2] fix(ssa refactor): safe to query cfg for single block programs --- crates/noirc_evaluator/src/ssa_refactor/ir/cfg.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/crates/noirc_evaluator/src/ssa_refactor/ir/cfg.rs b/crates/noirc_evaluator/src/ssa_refactor/ir/cfg.rs index b2d16b29bfd..c85c5f61f74 100644 --- a/crates/noirc_evaluator/src/ssa_refactor/ir/cfg.rs +++ b/crates/noirc_evaluator/src/ssa_refactor/ir/cfg.rs @@ -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 from the entry block, regardless of whether + // it 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 } From 287436f680ff4d2d88f5c0b5a8855d03026ae1fc Mon Sep 17 00:00:00 2001 From: Joss Date: Thu, 25 May 2023 12:41:28 +0100 Subject: [PATCH 2/2] chore(ssa refactor): fix comment wording --- crates/noirc_evaluator/src/ssa_refactor/ir/cfg.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/noirc_evaluator/src/ssa_refactor/ir/cfg.rs b/crates/noirc_evaluator/src/ssa_refactor/ir/cfg.rs index c85c5f61f74..6b59f24417f 100644 --- a/crates/noirc_evaluator/src/ssa_refactor/ir/cfg.rs +++ b/crates/noirc_evaluator/src/ssa_refactor/ir/cfg.rs @@ -28,8 +28,8 @@ impl ControlFlowGraph { /// Allocate and compute the control flow graph for `func`. pub(crate) fn with_function(func: &Function) -> Self { // It is expected to be safe to query the control flow graph for any reachable block, - // therefore we must ensure that a node exists from the entry block, regardless of whether - // it comes to describe any edges after calling compute. + // 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)]);