From 9fd0b850e338e95bf7f5a323aeb43c4da2670fea Mon Sep 17 00:00:00 2001 From: Douglas Wilson Date: Tue, 17 Dec 2024 14:00:23 +0000 Subject: [PATCH] fix: Constant folding now tolerates root nodes without input/output nodes Closes #1798 --- hugr-passes/src/const_fold.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hugr-passes/src/const_fold.rs b/hugr-passes/src/const_fold.rs index cdba48d80..ce0f82476 100644 --- a/hugr-passes/src/const_fold.rs +++ b/hugr-passes/src/const_fold.rs @@ -90,7 +90,7 @@ impl ConstantFoldPass { let results = Machine::new(&hugr).run(ConstFoldContext(hugr), inputs); let mut keep_nodes = HashSet::new(); self.find_needed_nodes(&results, &mut keep_nodes); - let [root_inp, _] = hugr.get_io(hugr.root()).unwrap(); + let mb_root_inp = hugr.get_io(hugr.root()).map(|[i, _]| i); let remove_nodes = hugr .nodes() @@ -110,7 +110,7 @@ impl ConstantFoldPass { // Avoid breaking edges from existing LoadConstant (we'd only add another) // or from root input node (any "external inputs" provided will show up here // - potentially also in other places which this won't catch) - (!hugr.get_optype(src).is_load_constant() && src != root_inp).then_some(( + (!hugr.get_optype(src).is_load_constant() && Some(src) != mb_root_inp).then_some(( n, ip, results