diff --git a/examples/circuit-layout.rs b/examples/circuit-layout.rs index 6020686..93ad054 100644 --- a/examples/circuit-layout.rs +++ b/examples/circuit-layout.rs @@ -8,6 +8,7 @@ use halo2::{ use plotters::prelude::*; use std::marker::PhantomData; +#[allow(clippy::many_single_char_names)] fn main() { /// This represents an advice column at a certain row in the ConstraintSystem #[derive(Copy, Clone, Debug)] @@ -372,7 +373,7 @@ fn main() { } let a = Fp::rand(); - let a_squared = a * &a; + let a_squared = a * a; let aux = Fp::one() + Fp::one(); let lookup_table = vec![aux, a, a, Fp::zero()]; let lookup_table_2 = vec![Fp::zero(), a, a_squared, Fp::zero()]; diff --git a/src/circuit.rs b/src/circuit.rs index 562246f..e9ad299 100644 --- a/src/circuit.rs +++ b/src/circuit.rs @@ -154,9 +154,9 @@ pub trait Layouter { /// region.assign_advice(self.config.a, offset, || { Some(value)}); /// }); /// ``` - fn assign_region(&mut self, name: N, assignment: A) -> Result<(), Error> + fn assign_region(&mut self, name: N, assignment: A) -> Result where - A: FnMut(Region<'_, C>) -> Result<(), Error>, + A: FnMut(Region<'_, C>) -> Result, N: Fn() -> NR, NR: Into; @@ -202,9 +202,9 @@ impl<'a, C: Chip, L: Layouter + 'a> Layouter for NamespacedLayouter<'a, C, self.0.config() } - fn assign_region(&mut self, name: N, assignment: A) -> Result<(), Error> + fn assign_region(&mut self, name: N, assignment: A) -> Result where - A: FnMut(Region<'_, C>) -> Result<(), Error>, + A: FnMut(Region<'_, C>) -> Result, N: Fn() -> NR, NR: Into, { diff --git a/src/circuit/layouter.rs b/src/circuit/layouter.rs index 6f1a348..88ad9cc 100644 --- a/src/circuit/layouter.rs +++ b/src/circuit/layouter.rs @@ -106,9 +106,9 @@ impl<'a, C: Chip, CS: Assignment + 'a> Layouter for SingleChip<'a, &self.config } - fn assign_region(&mut self, name: N, mut assignment: A) -> Result<(), Error> + fn assign_region(&mut self, name: N, mut assignment: A) -> Result where - A: FnMut(Region<'_, C>) -> Result<(), Error>, + A: FnMut(Region<'_, C>) -> Result, N: Fn() -> NR, NR: Into, { @@ -136,13 +136,13 @@ impl<'a, C: Chip, CS: Assignment + 'a> Layouter for SingleChip<'a, self.cs.enter_region(name); let mut region = SingleChipRegion::new(self, region_index); - { + let result = { let region: &mut dyn RegionLayouter = &mut region; - assignment(region.into())?; - } + assignment(region.into()) + }?; self.cs.exit_region(); - Ok(()) + Ok(result) } fn get_root(&mut self) -> &mut Self::Root { diff --git a/src/dev/graph/layout.rs b/src/dev/graph/layout.rs index 7131680..78c8657 100644 --- a/src/dev/graph/layout.rs +++ b/src/dev/graph/layout.rs @@ -107,7 +107,7 @@ pub fn circuit_layout, DB: DrawingBackend> if let Some(offset) = region.offset { // Sort the region's columns according to the defined ordering. let mut columns: Vec<_> = region.columns.into_iter().collect(); - columns.sort_unstable_by(|a, b| column_index(a).cmp(&column_index(b))); + columns.sort_unstable_by_key(|a| column_index(a)); // Render contiguous parts of the same region as a single box. let mut width = None; diff --git a/src/plonk/circuit.rs b/src/plonk/circuit.rs index 21879cb..3e8c71f 100644 --- a/src/plonk/circuit.rs +++ b/src/plonk/circuit.rs @@ -1,7 +1,10 @@ use core::cmp::max; use core::ops::{Add, Mul}; use ff::Field; -use std::convert::TryFrom; +use std::{ + convert::TryFrom, + ops::{Neg, Sub}, +}; use super::{lookup, permutation, Error}; use crate::poly::Rotation; @@ -316,6 +319,13 @@ impl Expression { } } +impl Neg for Expression { + type Output = Expression; + fn neg(self) -> Self::Output { + Expression::Scaled(Box::new(self), -F::one()) + } +} + impl Add for Expression { type Output = Expression; fn add(self, rhs: Expression) -> Expression { @@ -323,6 +333,13 @@ impl Add for Expression { } } +impl Sub for Expression { + type Output = Expression; + fn sub(self, rhs: Expression) -> Expression { + Expression::Sum(Box::new(self), Box::new(-rhs)) + } +} + impl Mul for Expression { type Output = Expression; fn mul(self, rhs: Expression) -> Expression {