Skip to content
Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
b9e2af9
Generalize InlineDFG to any HugrNode
acl-cqc Sep 23, 2025
e39db0b
Generalize merge_bbs to any HugrNode
acl-cqc Sep 23, 2025
fbfa4de
factor out mk_rep2
acl-cqc Sep 23, 2025
26e3668
Option -> parametrize
acl-cqc Sep 23, 2025
a571810
factor out add_unpack
acl-cqc Sep 23, 2025
4777809
Add normalize_cfgs and error/result enums, deprecate merge_basic_blocks
acl-cqc Sep 23, 2025
d5ae400
Combine two entry-elisions, plus some missing edges/ports; revert mk_…
acl-cqc Sep 23, 2025
c4de50a
Some fixes, docs
acl-cqc Sep 26, 2025
ad58ea3
Attempt first test == elision. Resulting structure is a PITA to inspect
acl-cqc Sep 26, 2025
43ecfba
Do elision as separate case, w/ take_inputs
acl-cqc Sep 26, 2025
271fe8a
Rename cfg->h, outline cfg_node
acl-cqc Sep 26, 2025
80c31a9
Test adding some unreachable blocks
acl-cqc Sep 26, 2025
02d39eb
Inline unary_unit_sum, sort out imports
acl-cqc Sep 26, 2025
9242b4c
Test removing entry block
acl-cqc Sep 26, 2025
6f29698
fix test (and business logic)
acl-cqc Sep 26, 2025
1d4780b
update numbers of ports
acl-cqc Sep 26, 2025
4a9de85
Test removing block before exit
acl-cqc Sep 26, 2025
32f5e32
rename add_unpack => wire_unpack_first
acl-cqc Sep 27, 2025
6f9a7ae
common up unpack_before_output (via an extra clone of a typerow)
acl-cqc Sep 27, 2025
6f5e595
simplify test checks using strings
acl-cqc Sep 27, 2025
3251918
Convert triple-BB test to use normalize_cfgs
acl-cqc Sep 27, 2025
4fa1f40
elide_cfg only tests w/ unreachable entry-predecessor
acl-cqc Sep 27, 2025
3593a66
docs
acl-cqc Sep 29, 2025
6ad9ff4
InlineDFG defaults to Node
acl-cqc Sep 29, 2025
d60928f
fmt
acl-cqc Sep 29, 2025
d89a65f
Generalize normalize_cfg to any node type
acl-cqc Sep 29, 2025
8f44608
WIP test on nested cfg
acl-cqc Sep 29, 2025
476e97f
test result, validate, test structure; fix entrypoint
acl-cqc Sep 29, 2025
3830caf
Test predicates in right place and followed by unpack.
acl-cqc Sep 29, 2025
28032a9
comment CFGToDFG
acl-cqc Sep 29, 2025
7ebc9f8
comments
acl-cqc Sep 29, 2025
ea4d27f
Avoid error if we process CFGs in wrong order
acl-cqc Sep 29, 2025
33aada6
remove old debug
acl-cqc Sep 29, 2025
317b596
Keep entry block stuff in a DFG
acl-cqc Sep 29, 2025
6e0a897
comments requested in review
acl-cqc Sep 29, 2025
3737f01
allow->expect, fmt
acl-cqc Sep 30, 2025
3050976
Split apart normalize_cfg.rs, taking all tests with it
acl-cqc Sep 30, 2025
c2af7cb
Revert "Split apart normalize_cfg.rs, taking all tests with it"
acl-cqc Sep 30, 2025
9d617b9
Rename module, add deprecated mod merge_bbs with just re-export
acl-cqc Sep 30, 2025
ec0e2f6
fmt
acl-cqc Sep 30, 2025
33086a5
Merge remote-tracking branch 'origin/main' into acl/norm_cfg
acl-cqc Sep 30, 2025
dedd861
common up optype_mut's
acl-cqc Sep 30, 2025
683bcfe
check Entry has no preds even if succ == exit; remove test
acl-cqc Sep 30, 2025
476d276
clippy: lifetimes needless after all?
acl-cqc Sep 30, 2025
4006171
fixup! check Entry
acl-cqc Sep 30, 2025
d92aa25
Report preserved exit_dfg/entry_dfg
acl-cqc Sep 30, 2025
e8582f6
rename module normalize_cfg{=>s}
acl-cqc Sep 30, 2025
c41411c
report num_merged by separating merge_basic_blocks
acl-cqc Sep 30, 2025
2f92e90
docs
acl-cqc Sep 30, 2025
34491eb
Ooops, version number
acl-cqc Sep 30, 2025
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
23 changes: 12 additions & 11 deletions hugr-core/src/hugr/patch/inline_dfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,37 @@
//! and deleting the DFG along with its Input + Output

use super::{PatchHugrMut, PatchVerification};
use crate::core::HugrNode;
use crate::ops::handle::{DfgID, NodeHandle};
use crate::{HugrView, IncomingPort, Node, OutgoingPort, PortIndex};

/// Structure identifying an `InlineDFG` rewrite from the spec
pub struct InlineDFG(pub DfgID);
pub struct InlineDFG<N = Node>(pub DfgID<N>);

/// Errors from an [`InlineDFG`] rewrite.
#[derive(Clone, Debug, PartialEq, Eq, thiserror::Error)]
#[non_exhaustive]
pub enum InlineDFGError {
pub enum InlineDFGError<N = Node> {
/// Node to inline was not a DFG. (E.g. node has been overwritten since the `DfgID` originated.)
#[error("{node} was not a DFG")]
NotDFG {
/// The node we tried to inline
node: Node,
node: N,
},
/// The DFG node is the hugr entrypoint
#[error("Cannot inline the entrypoint node, {node}")]
CantInlineEntrypoint {
/// The node we tried to inline
node: Node,
node: N,
},
}

impl PatchVerification for InlineDFG {
type Error = InlineDFGError;
impl<N: HugrNode> PatchVerification for InlineDFG<N> {
type Error = InlineDFGError<N>;

type Node = Node;
type Node = N;

fn verify(&self, h: &impl crate::HugrView<Node = Node>) -> Result<(), Self::Error> {
fn verify(&self, h: &impl crate::HugrView<Node = N>) -> Result<(), Self::Error> {
let n = self.0.node();
if h.get_optype(n).as_dfg().is_none() {
return Err(InlineDFGError::NotDFG { node: n });
Expand All @@ -51,15 +52,15 @@ impl PatchVerification for InlineDFG {
}
}

impl PatchHugrMut for InlineDFG {
impl<N: HugrNode> PatchHugrMut for InlineDFG<N> {
/// The removed nodes: the DFG, and its Input and Output children.
type Outcome = [Node; 3];
type Outcome = [N; 3];

const UNCHANGED_ON_FAILURE: bool = true;

fn apply_hugr_mut(
self,
h: &mut impl crate::hugr::HugrMut<Node = Node>,
h: &mut impl crate::hugr::HugrMut<Node = N>,
) -> Result<Self::Outcome, Self::Error> {
self.verify(h)?;
let n = self.0.node();
Expand Down
2 changes: 1 addition & 1 deletion hugr-core/src/ops/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::{cmp, fmt::Display};
///
/// Uses a flat representation for all the variants, in contrast to the complex
/// `OpType` structures.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, Default)]
#[non_exhaustive]
pub enum OpTag {
/// All operations allowed.
Expand Down
9 changes: 8 additions & 1 deletion hugr-passes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,17 @@ pub use inline_funcs::inline_acyclic;
pub mod linearize_array;
pub use linearize_array::LinearizeArrayPass;
pub mod lower;
pub mod merge_bbs;
mod monomorphize;
pub mod normalize_cfg;
pub mod untuple;

/// Merge basic blocks. Subset of [normalize_cfg], use the latter.
#[deprecated(note = "Use normalize_cfg", since = "0.15.1")]
pub mod merge_bbs {
#[expect(deprecated)] // remove this
pub use super::normalize_cfg::merge_basic_blocks;
}

pub use monomorphize::{MonomorphizePass, mangle_name, monomorphize};
pub mod replace_types;
pub use replace_types::ReplaceTypes;
Expand Down
Loading
Loading