Skip to content

Commit

Permalink
feat: Do not require &mut ConvexCheckers
Browse files Browse the repository at this point in the history
  • Loading branch information
aborgna-q committed Oct 20, 2023
1 parent 0001bf8 commit 59f73d0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/passes/chunks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl Chunk {
pub(self) fn extract<'h, H: HugrView>(
circ: &'h H,
nodes: impl IntoIterator<Item = Node>,
checker: &mut ConvexChecker<'h, H>,
checker: &ConvexChecker<'h, H>,
) -> Self {
let subgraph = SiblingSubgraph::try_from_nodes_with_checker(
nodes.into_iter().collect_vec(),
Expand Down Expand Up @@ -289,7 +289,7 @@ impl CircuitChunks {
.collect();

let mut chunks = Vec::new();
let mut convex_checker = ConvexChecker::new(circ);
let convex_checker = ConvexChecker::new(circ);
let mut running_cost = C::default();
let mut current_group = 0;
for (_, commands) in &circ.commands().map(|cmd| cmd.node()).group_by(|&node| {
Expand All @@ -302,7 +302,7 @@ impl CircuitChunks {
}
current_group
}) {
chunks.push(Chunk::extract(circ, commands, &mut convex_checker));
chunks.push(Chunk::extract(circ, commands, &convex_checker));
}
Self {
signature,
Expand Down
18 changes: 9 additions & 9 deletions src/portmatching/matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ impl PatternMatch {
circ: &impl Circuit,
matcher: &PatternMatcher,
) -> Result<Self, InvalidPatternMatch> {
let mut checker = ConvexChecker::new(circ);
Self::try_from_root_match_with_checker(root, pattern, circ, matcher, &mut checker)
let checker = ConvexChecker::new(circ);
Self::try_from_root_match_with_checker(root, pattern, circ, matcher, &checker)
}

/// Create a pattern match from the image of a pattern root with a checker.
Expand All @@ -117,7 +117,7 @@ impl PatternMatch {
pattern: PatternID,
circ: &'c C,
matcher: &PatternMatcher,
checker: &mut ConvexChecker<'c, C>,
checker: &ConvexChecker<'c, C>,
) -> Result<Self, InvalidPatternMatch> {
let pattern_ref = matcher
.get_pattern(pattern)
Expand Down Expand Up @@ -156,8 +156,8 @@ impl PatternMatch {
inputs: Vec<Vec<(Node, Port)>>,
outputs: Vec<(Node, Port)>,
) -> Result<Self, InvalidPatternMatch> {
let mut checker = ConvexChecker::new(circ);
Self::try_from_io_with_checker(root, pattern, circ, inputs, outputs, &mut checker)
let checker = ConvexChecker::new(circ);
Self::try_from_io_with_checker(root, pattern, circ, inputs, outputs, &checker)
}

/// Create a pattern match from the subcircuit boundaries.
Expand All @@ -174,7 +174,7 @@ impl PatternMatch {
circ: &'c C,
inputs: Vec<Vec<(Node, Port)>>,
outputs: Vec<(Node, Port)>,
checker: &mut ConvexChecker<'c, C>,
checker: &ConvexChecker<'c, C>,
) -> Result<Self, InvalidPatternMatch> {
let subgraph = SiblingSubgraph::try_new_with_checker(inputs, outputs, circ, checker)?;
Ok(Self {
Expand Down Expand Up @@ -248,10 +248,10 @@ impl PatternMatcher {
&'a self,
circuit: &'c C,
) -> impl Iterator<Item = PatternMatch> + 'a {
let mut checker = ConvexChecker::new(circuit);
let checker = ConvexChecker::new(circuit);
circuit
.commands()
.flat_map(move |cmd| self.find_rooted_matches(circuit, cmd.node(), &mut checker))
.flat_map(move |cmd| self.find_rooted_matches(circuit, cmd.node(), &checker))
}

/// Find all convex pattern matches in a circuit.and collect in to a vector
Expand All @@ -264,7 +264,7 @@ impl PatternMatcher {
&self,
circ: &'c C,
root: Node,
checker: &mut ConvexChecker<'c, C>,
checker: &ConvexChecker<'c, C>,
) -> Vec<PatternMatch> {
self.automaton
.run(
Expand Down

0 comments on commit 59f73d0

Please sign in to comment.