From 3f3544600029faa9938578e134dc4c1b698463bf Mon Sep 17 00:00:00 2001 From: Rute Figueiredo Date: Tue, 9 Jul 2024 17:03:30 +0200 Subject: [PATCH] formatting --- src/compiler/compiler.rs | 5 ++++- src/compiler/cse.rs | 8 ++++---- src/compiler/mod.rs | 2 +- src/frontend/dsl/cb.rs | 6 +++++- src/frontend/python/mod.rs | 3 ++- src/poly/mod.rs | 37 ++++++++++++++++++++++++++----------- src/sbpir/mod.rs | 33 +++++++++++++++++++++++++++------ 7 files changed, 69 insertions(+), 25 deletions(-) diff --git a/src/compiler/compiler.rs b/src/compiler/compiler.rs index bb2404ff..5def7a7b 100644 --- a/src/compiler/compiler.rs +++ b/src/compiler/compiler.rs @@ -20,7 +20,10 @@ use crate::{ }; use super::{ - cse::cse, semantic::{SymTable, SymbolCategory}, setup_inter::{interpret, Setup}, Config, Message, Messages + cse::cse, + semantic::{SymTable, SymbolCategory}, + setup_inter::{interpret, Setup}, + Config, Message, Messages, }; /// Contains the result of a compilation. diff --git a/src/compiler/cse.rs b/src/compiler/cse.rs index 51d2c6fb..1989f4b9 100644 --- a/src/compiler/cse.rs +++ b/src/compiler/cse.rs @@ -73,9 +73,8 @@ impl CSE { self.identify_common_subexpressions(); let mut signal_factory = SignalFactory::default(); - hashed_step.decomp_constraints(|expr| { - replace_expr(expr, &self.common_exprs, &mut signal_factory) - }); + hashed_step + .decomp_constraints(|expr| replace_expr(expr, &self.common_exprs, &mut signal_factory)); // Convert back to StepType and update the original step *step = hashed_step.without_meta(); @@ -143,7 +142,8 @@ impl CSE { if self.count_map.get(&hash).copied().unwrap_or(0) >= self.config.min_occurrences.unwrap_or(2) as u32 && expr.degree() >= self.config.min_degree.unwrap_or(2) - && !matches!(expr, Expr::MI(_, _)) // Exclude MI expressions + && !matches!(expr, Expr::MI(_, _)) + // Exclude MI expressions { Some(expr.clone()) } else { diff --git a/src/compiler/mod.rs b/src/compiler/mod.rs index 31bf6099..d94dbc46 100644 --- a/src/compiler/mod.rs +++ b/src/compiler/mod.rs @@ -13,9 +13,9 @@ use crate::{ pub mod abepi; #[allow(clippy::module_inception)] pub mod compiler; +mod cse; pub mod semantic; mod setup_inter; -mod cse; #[derive(Default)] pub struct Config { diff --git a/src/frontend/dsl/cb.rs b/src/frontend/dsl/cb.rs index a408b7be..ed42f496 100644 --- a/src/frontend/dsl/cb.rs +++ b/src/frontend/dsl/cb.rs @@ -372,7 +372,11 @@ pub fn next_step_must_not_be, ST: Into>( /// Takes a string annotation and an expression, and returns a new constraint with the given /// annotation and expression. -pub fn annotate>>(annotation: String, expr: E, typing: Typing) -> Constraint { +pub fn annotate>>( + annotation: String, + expr: E, + typing: Typing, +) -> Constraint { Constraint { annotation, expr: expr.into(), diff --git a/src/frontend/python/mod.rs b/src/frontend/python/mod.rs index 16d37038..4e04fa87 100644 --- a/src/frontend/python/mod.rs +++ b/src/frontend/python/mod.rs @@ -1763,7 +1763,8 @@ mod tests { }"#; let constraint: Constraint = serde_json::from_str(json).unwrap(); println!("{:?}", constraint); - let transition_constraint: TransitionConstraint = serde_json::from_str(json).unwrap(); + let transition_constraint: TransitionConstraint = + serde_json::from_str(json).unwrap(); println!("{:?}", transition_constraint); } diff --git a/src/poly/mod.rs b/src/poly/mod.rs index f66d2a20..3aa68c27 100644 --- a/src/poly/mod.rs +++ b/src/poly/mod.rs @@ -25,7 +25,7 @@ pub trait ToField { pub trait Meta: Clone + Default + Debug + Hash { fn from_expr( expr: &Expr, - assignments: &VarAssignments + assignments: &VarAssignments, ) -> Self; } @@ -44,7 +44,7 @@ pub enum Expr { impl Meta for () { fn from_expr( _expr: &Expr, - _assignments: &VarAssignments + _assignments: &VarAssignments, ) -> Self { () } @@ -53,7 +53,7 @@ impl Meta for () { impl Meta for HashResult { fn from_expr( expr: &Expr, - assignments: &VarAssignments + assignments: &VarAssignments, ) -> Self { let hashed_expr = expr.hash(assignments); hashed_expr.meta().clone() @@ -76,7 +76,8 @@ impl Expr { Expr::Pow(se, exp, _) => se.degree() * (*exp as usize), Expr::Query(_, _) => 1, Expr::Halo2Expr(_, _) => panic!("not implemented"), - Expr::MI(se, _) => se.degree(), // Treat MI as not changing the degree of the inner expression + Expr::MI(se, _) => se.degree(), /* Treat MI as not changing the degree of the inner + * expression */ } } @@ -93,8 +94,6 @@ impl Expr { } } - - pub fn map_meta N>(&self, f: Func) -> Expr { match self { Expr::Const(v, m) => Expr::Const(v.clone(), f(m)), @@ -115,8 +114,14 @@ impl Expr { let new_meta = N::from_expr(&expr_without_meta, assignments); match self { Expr::Const(v, _) => Expr::Const(v.clone(), new_meta), - Expr::Sum(ses, _) => Expr::Sum(ses.iter().map(|e| e.with_meta(assignments)).collect(), new_meta), - Expr::Mul(ses, _) => Expr::Mul(ses.iter().map(|e| e.with_meta(assignments)).collect(), new_meta), + Expr::Sum(ses, _) => Expr::Sum( + ses.iter().map(|e| e.with_meta(assignments)).collect(), + new_meta, + ), + Expr::Mul(ses, _) => Expr::Mul( + ses.iter().map(|e| e.with_meta(assignments)).collect(), + new_meta, + ), Expr::Neg(se, _) => Expr::Neg(Box::new(se.with_meta(assignments)), new_meta), Expr::Pow(se, exp, _) => Expr::Pow(Box::new(se.with_meta(assignments)), *exp, new_meta), Expr::Query(v, _) => Expr::Query(v.clone(), new_meta), @@ -413,7 +418,10 @@ pub struct ConstrDecomp { } impl ConstrDecomp { - pub fn get_auto_signal + Copy>(&self, annotation: S) -> Option<(&V, &Expr)> { + pub fn get_auto_signal + Copy>( + &self, + annotation: S, + ) -> Option<(&V, &Expr)> { self.auto_signals.iter().find_map(|(s, e)| { if format!("{:#?}", s) == annotation.into() { Some((s, e)) @@ -438,7 +446,10 @@ impl ConstrDecomp self.constrs.push(Expr::Sum( vec![ expr.clone(), - Expr::Neg(Box::new(Expr::Query(signal.clone(), M::default())), M::default()), + Expr::Neg( + Box::new(Expr::Query(signal.clone(), M::default())), + M::default(), + ), ], M::default(), )); @@ -451,7 +462,11 @@ impl ConstrDecomp { pub fn without_meta(&self) -> ConstrDecomp { ConstrDecomp { constrs: self.constrs.iter().map(|c| c.without_meta()).collect(), - auto_signals: self.auto_signals.iter().map(|(k, v)| (k.clone(), v.without_meta())).collect(), + auto_signals: self + .auto_signals + .iter() + .map(|(k, v)| (k.clone(), v.without_meta())) + .collect(), } } } diff --git a/src/sbpir/mod.rs b/src/sbpir/mod.rs index 0b2733be..ed2e0934 100644 --- a/src/sbpir/mod.rs +++ b/src/sbpir/mod.rs @@ -261,7 +261,11 @@ impl + Clone, M: Meta> SBPIR { impl + Clone, M: Meta> SBPIR { pub fn without_meta(&self) -> SBPIR { SBPIR { - step_types: self.step_types.iter().map(|(k, v)| (*k, v.without_meta())).collect(), + step_types: self + .step_types + .iter() + .map(|(k, v)| (*k, v.without_meta())) + .collect(), forward_signals: self.forward_signals.clone(), shared_signals: self.shared_signals.clone(), fixed_signals: self.fixed_signals.clone(), @@ -442,9 +446,17 @@ impl StepType { name: self.name.clone(), signals: self.signals.clone(), constraints: self.constraints.iter().map(|c| c.without_meta()).collect(), - transition_constraints: self.transition_constraints.iter().map(|c| c.without_meta()).collect(), + transition_constraints: self + .transition_constraints + .iter() + .map(|c| c.without_meta()) + .collect(), lookups: self.lookups.iter().map(|l| l.without_meta()).collect(), - auto_signals: self.auto_signals.iter().map(|(k, v)| (*k, v.without_meta())).collect(), + auto_signals: self + .auto_signals + .iter() + .map(|(k, v)| (*k, v.without_meta())) + .collect(), annotations: self.annotations.clone(), } } @@ -534,7 +546,10 @@ pub struct Constraint { } impl Constraint { - pub fn with_meta(&self, assignments: &VarAssignments>) -> Constraint { + pub fn with_meta( + &self, + assignments: &VarAssignments>, + ) -> Constraint { Constraint { annotation: self.annotation.clone(), expr: self.expr.with_meta(assignments), @@ -559,7 +574,10 @@ pub struct TransitionConstraint { } impl TransitionConstraint { - pub fn with_meta(&self, assignments: &VarAssignments>) -> TransitionConstraint { + pub fn with_meta( + &self, + assignments: &VarAssignments>, + ) -> TransitionConstraint { TransitionConstraint { annotation: self.annotation.clone(), expr: self.expr.with_meta(assignments), @@ -659,7 +677,10 @@ impl Lookup { } impl Lookup { - pub fn with_meta(&self, assignments: &VarAssignments>) -> Lookup { + pub fn with_meta( + &self, + assignments: &VarAssignments>, + ) -> Lookup { Lookup { annotation: self.annotation.clone(), exprs: self