From cfc7cf31e2b88c4d907ce3c280a9586be9498922 Mon Sep 17 00:00:00 2001 From: chriseth Date: Mon, 1 Sep 2025 19:11:46 +0200 Subject: [PATCH] Derive clone for ConstraintRef (#3241) Derives `Clone` (and some other traits) for `ConstraintRef`. Since it is a reference, it should implement Clone. Note that `Clone` for `AlgebraicConstraint` is only auto-derived if `V` is `Clone`, which is the case if `V` is a reference. --- autoprecompiles/src/constraint_optimizer.rs | 2 +- constraint-solver/src/algebraic_constraint/mod.rs | 2 +- constraint-solver/src/constraint_system.rs | 1 + constraint-solver/src/solver/base.rs | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/autoprecompiles/src/constraint_optimizer.rs b/autoprecompiles/src/constraint_optimizer.rs index 6336bd90e..1c0f6768c 100644 --- a/autoprecompiles/src/constraint_optimizer.rs +++ b/autoprecompiles/src/constraint_optimizer.rs @@ -222,7 +222,7 @@ fn remove_free_variables( .filter(|(variable, constraint)| match constraint { // Remove the algebraic constraint if we can solve for the variable. ConstraintRef::AlgebraicConstraint(constr) => { - can_always_be_satisfied_via_free_variable(constr.clone(), variable) + can_always_be_satisfied_via_free_variable(*constr, variable) } ConstraintRef::BusInteraction(bus_interaction) => { let bus_id = bus_interaction.bus_id.try_to_number().unwrap(); diff --git a/constraint-solver/src/algebraic_constraint/mod.rs b/constraint-solver/src/algebraic_constraint/mod.rs index 4d328834e..aeb1835a7 100644 --- a/constraint-solver/src/algebraic_constraint/mod.rs +++ b/constraint-solver/src/algebraic_constraint/mod.rs @@ -10,7 +10,7 @@ use num_traits::{One, Zero}; pub mod solve; /// An algebraic constraint -#[derive(Clone, Debug, Hash, Eq, PartialEq)] +#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] pub struct AlgebraicConstraint { /// The expression representing the constraint, which must evaluate to 0 for the constraint to be satisfied. pub expression: V, diff --git a/constraint-solver/src/constraint_system.rs b/constraint-solver/src/constraint_system.rs index 256757d7c..a974ef9a3 100644 --- a/constraint-solver/src/constraint_system.rs +++ b/constraint-solver/src/constraint_system.rs @@ -267,6 +267,7 @@ impl BusInteractionHandler for DefaultBusInteractionHandler< } } +#[derive(Clone, Copy, Debug, Hash, Eq, PartialEq)] pub enum ConstraintRef<'a, T, V> { AlgebraicConstraint(AlgebraicConstraint<&'a GroupedExpression>), BusInteraction(&'a BusInteraction>), diff --git a/constraint-solver/src/solver/base.rs b/constraint-solver/src/solver/base.rs index dd91ca484..00301dbbf 100644 --- a/constraint-solver/src/solver/base.rs +++ b/constraint-solver/src/solver/base.rs @@ -364,7 +364,7 @@ where while let Some(item) = self.constraint_system.pop_front() { let effects = match item { ConstraintRef::AlgebraicConstraint(c) => { - if let Some((v1, expr)) = try_to_simple_equivalence(c.clone()) { + if let Some((v1, expr)) = try_to_simple_equivalence(c) { self.apply_assignment(&v1, &expr); continue; }