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: Constant folding now tolerates root nodes without input/output nodes #1799

Merged
merged 1 commit into from
Dec 17, 2024
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
4 changes: 2 additions & 2 deletions hugr-passes/src/const_fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down
Loading