From 6bbaf54026cceb158807b4ed4967d7c3e0f9c329 Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 10 Dec 2024 21:27:14 +0000 Subject: [PATCH] Use rc. --- .../src/witgen/jit/symbolic_expression.rs | 37 ++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/executor/src/witgen/jit/symbolic_expression.rs b/executor/src/witgen/jit/symbolic_expression.rs index 55a44fecf3..4989ae5273 100644 --- a/executor/src/witgen/jit/symbolic_expression.rs +++ b/executor/src/witgen/jit/symbolic_expression.rs @@ -1,6 +1,7 @@ use std::{ fmt::{self, Display, Formatter}, ops::{Add, BitAnd, BitOr, Mul, Neg}, + rc::Rc, }; use powdr_number::FieldElement; @@ -17,12 +18,12 @@ pub enum SymbolicExpression { /// A symbolic value known at run-time, referencing either a cell or a local variable. Variable(V, Option>), BinaryOperation( - Box, + Rc, BinaryOperator, - Box, + Rc, Option>, ), - UnaryOperation(UnaryOperator, Box, Option>), + UnaryOperation(UnaryOperator, Rc, Option>), } #[derive(Debug, Clone)] @@ -141,9 +142,9 @@ impl Add for &SymbolicExpression { SymbolicExpression::Concrete(*a + *b) } _ => SymbolicExpression::BinaryOperation( - Box::new(self.clone()), + Rc::new(self.clone()), BinaryOperator::Add, - Box::new(rhs.clone()), + Rc::new(rhs.clone()), self.range_constraint() .zip(rhs.range_constraint()) .map(|(a, b)| a.combine_sum(&b)), @@ -165,10 +166,12 @@ impl Neg for &SymbolicExpression { fn neg(self) -> Self::Output { match self { SymbolicExpression::Concrete(n) => SymbolicExpression::Concrete(-*n), - SymbolicExpression::UnaryOperation(UnaryOperator::Neg, expr, _) => *expr.clone(), + SymbolicExpression::UnaryOperation(UnaryOperator::Neg, expr, _) => { + expr.as_ref().clone() + } _ => SymbolicExpression::UnaryOperation( UnaryOperator::Neg, - Box::new(self.clone()), + Rc::new(self.clone()), self.range_constraint().map(|rc| rc.multiple(-T::from(1))), ), } @@ -200,9 +203,9 @@ impl Mul for &SymbolicExpression { -self } else { SymbolicExpression::BinaryOperation( - Box::new(self.clone()), + Rc::new(self.clone()), BinaryOperator::Mul, - Box::new(rhs.clone()), + Rc::new(rhs.clone()), None, ) } @@ -232,9 +235,9 @@ impl SymbolicExpression { } else { // TODO other simplifications like `-x / -y => x / y`, `-x / concrete => x / -concrete`, etc. SymbolicExpression::BinaryOperation( - Box::new(self.clone()), + Rc::new(self.clone()), BinaryOperator::Div, - Box::new(rhs.clone()), + Rc::new(rhs.clone()), None, ) } @@ -246,9 +249,9 @@ impl SymbolicExpression { self.clone() } else { SymbolicExpression::BinaryOperation( - Box::new(self.clone()), + Rc::new(self.clone()), BinaryOperator::IntegerDiv, - Box::new(rhs.clone()), + Rc::new(rhs.clone()), None, ) } @@ -265,9 +268,9 @@ impl BitAnd for &SymbolicExpression { SymbolicExpression::Concrete(T::from(0)) } else { SymbolicExpression::BinaryOperation( - Box::new(self.clone()), + Rc::new(self.clone()), BinaryOperator::BitAnd, - Box::new(rhs.clone()), + Rc::new(rhs.clone()), self.range_constraint() .zip(rhs.range_constraint()) .map(|(a, b)| a.conjunction(&b)), @@ -294,9 +297,9 @@ impl BitOr for &SymbolicExpression { SymbolicExpression::Concrete(T::from(v)) } else { SymbolicExpression::BinaryOperation( - Box::new(self.clone()), + Rc::new(self.clone()), BinaryOperator::BitOr, - Box::new(rhs.clone()), + Rc::new(rhs.clone()), None, ) }