Skip to content

Commit

Permalink
feat(hugr-passes)!: Rewrite constant_fold_pass using dataflow framewo…
Browse files Browse the repository at this point in the history
…rk (#1603)

New transformation roughly parallels the old constant-folding code +
dead-code-elimination (eliminating cases from conditionals/tail-loops
and transforming into DFGs, left for another PR). Should be
significantly more powerful, and flexible - e.g. the old code broke if
`OpType::const_fold` returned only some outputs from a leaf op.

**All the existing constant-folding tests pass!** 😀 🚀, plus at least one
that didn't just fail-to-optimize, but panicked - or, in release mode,
potentially produced an invalid hugr - [see
comment](https://github.com/CQCL/hugr/pull/1603/files#r1823146181).

closes #1322 

BREAKING CHANGE: ConstantFoldPass is no longer UnwindSafe.
BREAKING CHANGE: ConstantFoldPass is no longer RefUnwindSafe.
BREAKING CHANGE: ConstantFoldPass no longer derives Copy.
BREAKING CHANGE: fold_leaf_op function removed.
BREAKING CHANGE: find_consts function removed.
BREAKING CHANGE: ConstantFoldPass::new function removed. Instead use
ConstantFoldPass::default.
BREAKING CHANGE: Variant `ConstFoldError::SimpleReplacementError` was
removed.

---------

Co-authored-by: Douglas Wilson <[email protected]>
Co-authored-by: Douglas Wilson <[email protected]>
Co-authored-by: Craig Roy <[email protected]>
  • Loading branch information
4 people authored Dec 11, 2024
1 parent cb5d9ec commit 34ce691
Show file tree
Hide file tree
Showing 6 changed files with 871 additions and 198 deletions.
1 change: 1 addition & 0 deletions hugr-passes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ bench = false

[dependencies]
hugr-core = { path = "../hugr-core", version = "0.13.3" }
portgraph = { workspace = true }
ascent = { version = "0.7.0" }
itertools = { workspace = true }
lazy_static = { workspace = true }
Expand Down
Loading

0 comments on commit 34ce691

Please sign in to comment.