From 6ca85c516e85d74a1266b86afe841760f4ba495e Mon Sep 17 00:00:00 2001 From: incertia Date: Thu, 26 Sep 2024 09:38:12 -0400 Subject: [PATCH 1/3] revert lita-xyz/Plonky3#4 --- air/src/air.rs | 15 +++++---------- air/src/two_row_matrix.rs | 6 +++--- brakedown/benches/encode.rs | 2 +- commit/src/mmcs.rs | 4 ++-- dft/benches/fft.rs | 12 ++++++++---- fri/src/prover.rs | 2 +- keccak-air/src/air.rs | 3 +-- matrix/src/bitrev.rs | 16 ++++++---------- matrix/src/dense.rs | 32 +++++++++++++++----------------- matrix/src/lib.rs | 8 ++++---- matrix/src/stack.rs | 1 - matrix/src/strided.rs | 4 +--- matrix/src/util.rs | 4 ++-- tensor-pcs/src/wrapped_matrix.rs | 5 ++--- uni-stark/src/public.rs | 4 ++-- uni-stark/tests/fib_air.rs | 3 +-- uni-stark/tests/mul_air.rs | 4 +--- 17 files changed, 55 insertions(+), 70 deletions(-) diff --git a/air/src/air.rs b/air/src/air.rs index ecef6bd47..1d3b2af5d 100644 --- a/air/src/air.rs +++ b/air/src/air.rs @@ -1,4 +1,3 @@ -use core::fmt::Debug; use core::ops::{Add, Mul, Sub}; use p3_field::{AbstractExtensionField, AbstractField, ExtensionField, Field}; @@ -6,7 +5,7 @@ use p3_matrix::dense::RowMajorMatrix; use p3_matrix::MatrixRowSlices; /// An AIR (algebraic intermediate representation). -pub trait BaseAir: Sync { +pub trait BaseAir: Sync { /// The number of private columns (a.k.a. registers) in this AIR. fn width(&self) -> usize; @@ -52,8 +51,7 @@ pub trait AirBuilder: Sized { + Sub + Mul + Mul - + Mul - + Debug; + + Mul; type M: MatrixRowSlices; @@ -133,7 +131,7 @@ pub trait ExtensionBuilder: AirBuilder { type ExprEF: AbstractExtensionField; - type VarEF: Into + Copy + Debug; + type VarEF: Into + Copy; fn assert_zero_ext(&mut self, x: I) where @@ -155,10 +153,7 @@ pub trait ExtensionBuilder: AirBuilder { } } -pub trait PermutationAirBuilder: ExtensionBuilder -where - ::VarEF: Debug, -{ +pub trait PermutationAirBuilder: ExtensionBuilder { type MP: MatrixRowSlices; fn permutation(&self) -> Self::MP; @@ -235,7 +230,7 @@ mod tests { #[allow(dead_code)] struct FibonacciAir; - impl BaseAir for FibonacciAir { + impl BaseAir for FibonacciAir { fn width(&self) -> usize { 1 } diff --git a/air/src/two_row_matrix.rs b/air/src/two_row_matrix.rs index 4bc2d351a..f3115e40a 100644 --- a/air/src/two_row_matrix.rs +++ b/air/src/two_row_matrix.rs @@ -3,7 +3,7 @@ use core::slice; use p3_matrix::{Matrix, MatrixRowSlices, MatrixRows}; -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone)] pub struct TwoRowMatrixView<'a, T> { pub local: &'a [T], pub next: &'a [T], @@ -25,7 +25,7 @@ impl<'a, T> Matrix for TwoRowMatrixView<'a, T> { } } -impl MatrixRows for TwoRowMatrixView<'_, T> { +impl MatrixRows for TwoRowMatrixView<'_, T> { type Row<'a> = Cloned> where @@ -42,7 +42,7 @@ impl MatrixRows for TwoRowMatrixView<'_, T> { } } -impl MatrixRowSlices for TwoRowMatrixView<'_, T> { +impl MatrixRowSlices for TwoRowMatrixView<'_, T> { fn row_slice(&self, r: usize) -> &[T] { match r { 0 => self.local, diff --git a/brakedown/benches/encode.rs b/brakedown/benches/encode.rs index 6863ffe8c..905349a05 100644 --- a/brakedown/benches/encode.rs +++ b/brakedown/benches/encode.rs @@ -19,7 +19,7 @@ fn encode(c: &mut Criterion) where Standard: Distribution, { - let mut group = c.benchmark_group(format!("encode::<{}>", type_name::())); + let mut group = c.benchmark_group(&format!("encode::<{}>", type_name::())); group.sample_size(10); let mut rng = thread_rng(); diff --git a/commit/src/mmcs.rs b/commit/src/mmcs.rs index 6b5a2cf91..94210d409 100644 --- a/commit/src/mmcs.rs +++ b/commit/src/mmcs.rs @@ -19,7 +19,7 @@ use serde::Serialize; /// The `DirectMmcs` sub-trait represents an MMS which can be directly constructed from a set of /// matrices. Other MMCSs may be virtual combinations of child MMCSs, or may be constructed in a /// streaming manner. -pub trait Mmcs: Clone { +pub trait Mmcs: Clone { type ProverData; type Commitment: Clone + Serialize + DeserializeOwned; type Proof: Serialize + DeserializeOwned; @@ -72,7 +72,7 @@ pub trait Mmcs: Clone { } /// An MMCS over explicit inputs which are supplied upfront. -pub trait DirectMmcs: Mmcs { +pub trait DirectMmcs: Mmcs { fn commit(&self, inputs: Vec>) -> (Self::Commitment, Self::ProverData); fn commit_matrix(&self, input: RowMajorMatrix) -> (Self::Commitment, Self::ProverData) { diff --git a/dft/benches/fft.rs b/dft/benches/fft.rs index 905c3ea68..2ba4fcce5 100644 --- a/dft/benches/fft.rs +++ b/dft/benches/fft.rs @@ -47,7 +47,7 @@ where Dft: TwoAdicSubgroupDft, Standard: Distribution, { - let mut group = c.benchmark_group(format!( + let mut group = c.benchmark_group(&format!( "fft::<{}, {}, {}>", type_name::(), type_name::(), @@ -75,7 +75,11 @@ where Dft: TwoAdicSubgroupDft>, Standard: Distribution, { - let mut group = c.benchmark_group(format!("m31_fft::<{}, {}>", type_name::(), BATCH_SIZE)); + let mut group = c.benchmark_group(&format!( + "m31_fft::<{}, {}>", + type_name::(), + BATCH_SIZE + )); group.sample_size(10); let mut rng = thread_rng(); @@ -98,7 +102,7 @@ where Dft: TwoAdicSubgroupDft, Standard: Distribution, { - let mut group = c.benchmark_group(format!( + let mut group = c.benchmark_group(&format!( "ifft::<{}, {}, {}>", type_name::(), type_name::(), @@ -127,7 +131,7 @@ where Dft: TwoAdicSubgroupDft, Standard: Distribution, { - let mut group = c.benchmark_group(format!( + let mut group = c.benchmark_group(&format!( "coset_lde::<{}, {}, {}>", type_name::(), type_name::(), diff --git a/fri/src/prover.rs b/fri/src/prover.rs index c893b81ad..b52c9376c 100644 --- a/fri/src/prover.rs +++ b/fri/src/prover.rs @@ -134,7 +134,7 @@ where } } -struct CommitPhaseResult> { +struct CommitPhaseResult> { commits: Vec, data: Vec, final_poly: F, diff --git a/keccak-air/src/air.rs b/keccak-air/src/air.rs index 7e8e0c3c3..f68a3f880 100644 --- a/keccak-air/src/air.rs +++ b/keccak-air/src/air.rs @@ -1,5 +1,4 @@ use core::borrow::Borrow; -use core::fmt::Debug; use p3_air::{Air, AirBuilder, BaseAir}; use p3_field::AbstractField; @@ -14,7 +13,7 @@ use crate::{BITS_PER_LIMB, NUM_ROUNDS, U64_LIMBS}; /// Assumes the field size is at least 16 bits. pub struct KeccakAir {} -impl BaseAir for KeccakAir { +impl BaseAir for KeccakAir { fn width(&self) -> usize { NUM_KECCAK_COLS } diff --git a/matrix/src/bitrev.rs b/matrix/src/bitrev.rs index 60f2fafe2..b9057eb47 100644 --- a/matrix/src/bitrev.rs +++ b/matrix/src/bitrev.rs @@ -9,7 +9,7 @@ use crate::{Matrix, MatrixGet, MatrixRowSlices, MatrixRowSlicesMut, MatrixRows}; /// A matrix that is possibly bit-reversed, and can easily switch /// between orderings. Pretty much just either `RowMajorMatrix` or /// `BitReversedMatrixView`. -pub trait BitReversableMatrix: MatrixRowSlicesMut { +pub trait BitReversableMatrix: MatrixRowSlicesMut { type BitRev: BitReversableMatrix; fn bit_reverse_rows(self) -> Self::BitRev; } @@ -46,7 +46,7 @@ impl> MatrixGet for BitReversedMatrixView { } } -impl> MatrixRows for BitReversedMatrixView { +impl> MatrixRows for BitReversedMatrixView { type Row<'a> = Inner::Row<'a> where @@ -67,31 +67,27 @@ impl> MatrixRows for BitReversedMat } } -impl> MatrixRowSlices - for BitReversedMatrixView -{ +impl> MatrixRowSlices for BitReversedMatrixView { fn row_slice(&self, r: usize) -> &[T] { self.inner.row_slice(reverse_bits_len(r, self.log_height)) } } -impl> MatrixRowSlicesMut - for BitReversedMatrixView -{ +impl> MatrixRowSlicesMut for BitReversedMatrixView { fn row_slice_mut(&mut self, r: usize) -> &mut [T] { self.inner .row_slice_mut(reverse_bits_len(r, self.log_height)) } } -impl BitReversableMatrix for BitReversedMatrixView> { +impl BitReversableMatrix for BitReversedMatrixView> { type BitRev = RowMajorMatrix; fn bit_reverse_rows(self) -> Self::BitRev { self.inner } } -impl BitReversableMatrix for RowMajorMatrix { +impl BitReversableMatrix for RowMajorMatrix { type BitRev = BitReversedMatrixView>; fn bit_reverse_rows(self) -> Self::BitRev { BitReversedMatrixView::new(self) diff --git a/matrix/src/dense.rs b/matrix/src/dense.rs index 9184cd5ba..75fb71ec9 100644 --- a/matrix/src/dense.rs +++ b/matrix/src/dense.rs @@ -1,4 +1,3 @@ -use alloc::fmt::Debug; use alloc::vec; use alloc::vec::Vec; use core::iter::Cloned; @@ -19,13 +18,13 @@ const TRANSPOSE_BLOCK_SIZE: usize = 64; /// A dense matrix stored in row-major form. #[derive(Clone, Debug, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(Deserialize, Serialize))] -pub struct RowMajorMatrix { +pub struct RowMajorMatrix { /// All values, stored in row-major order. pub values: Vec, pub width: usize, } -impl RowMajorMatrix { +impl RowMajorMatrix { #[must_use] pub fn new(values: Vec, width: usize) -> Self { debug_assert!(width == 0 || values.len() % width == 0); @@ -102,7 +101,7 @@ impl RowMajorMatrix { } } - pub fn map U>(&self, f: F) -> RowMajorMatrix + pub fn map U>(&self, f: F) -> RowMajorMatrix where T: Clone, { @@ -182,7 +181,7 @@ impl RowMajorMatrix { } } -impl Matrix for RowMajorMatrix { +impl Matrix for RowMajorMatrix { fn width(&self) -> usize { self.width } @@ -196,14 +195,14 @@ impl Matrix for RowMajorMatrix { } } -impl MatrixGet for RowMajorMatrix { +impl MatrixGet for RowMajorMatrix { #[inline] fn get(&self, r: usize, c: usize) -> T { self.values[r * self.width + c].clone() } } -impl MatrixRows for RowMajorMatrix { +impl MatrixRows for RowMajorMatrix { type Row<'a> = Cloned> where @@ -221,21 +220,21 @@ impl MatrixRows for RowMajorMatrix { } } -impl MatrixRowSlices for RowMajorMatrix { +impl MatrixRowSlices for RowMajorMatrix { fn row_slice(&self, r: usize) -> &[T] { debug_assert!(r < self.height()); &self.values[r * self.width..(r + 1) * self.width] } } -impl MatrixRowSlicesMut for RowMajorMatrix { +impl MatrixRowSlicesMut for RowMajorMatrix { fn row_slice_mut(&mut self, r: usize) -> &mut [T] { debug_assert!(r < self.height()); &mut self.values[r * self.width..(r + 1) * self.width] } } -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone)] pub struct RowMajorMatrixView<'a, T> { pub values: &'a [T], pub width: usize, @@ -289,7 +288,7 @@ impl MatrixGet for RowMajorMatrixView<'_, T> { } } -impl MatrixRows for RowMajorMatrixView<'_, T> { +impl MatrixRows for RowMajorMatrixView<'_, T> { type Row<'a> = Cloned> where @@ -309,14 +308,13 @@ impl MatrixRows for RowMajorMatrixView<'_, T> { } } -impl MatrixRowSlices for RowMajorMatrixView<'_, T> { +impl MatrixRowSlices for RowMajorMatrixView<'_, T> { fn row_slice(&self, r: usize) -> &[T] { debug_assert!(r < self.height()); &self.values[r * self.width..(r + 1) * self.width] } } -#[derive(Debug)] pub struct RowMajorMatrixViewMut<'a, T> { pub values: &'a mut [T], pub width: usize, @@ -429,7 +427,7 @@ impl MatrixGet for RowMajorMatrixViewMut<'_, T> { } } -impl MatrixRows for RowMajorMatrixViewMut<'_, T> { +impl MatrixRows for RowMajorMatrixViewMut<'_, T> { type Row<'a> = Cloned> where @@ -449,14 +447,14 @@ impl MatrixRows for RowMajorMatrixViewMut<'_, T> } } -impl MatrixRowSlices for RowMajorMatrixViewMut<'_, T> { +impl MatrixRowSlices for RowMajorMatrixViewMut<'_, T> { fn row_slice(&self, r: usize) -> &[T] { debug_assert!(r < self.height()); &self.values[r * self.width..(r + 1) * self.width] } } -impl MatrixRowSlicesMut for RowMajorMatrixViewMut<'_, T> { +impl MatrixRowSlicesMut for RowMajorMatrixViewMut<'_, T> { fn row_slice_mut(&mut self, r: usize) -> &mut [T] { debug_assert!(r < self.height()); &mut self.values[r * self.width..(r + 1) * self.width] @@ -465,7 +463,7 @@ impl MatrixRowSlicesMut for RowMajorMatrixViewMu impl MatrixTranspose for RowMajorMatrix where - T: Clone + Default + Send + Sync + Debug, + T: Clone + Default + Send + Sync, { fn transpose(self) -> Self { let block_size = TRANSPOSE_BLOCK_SIZE; diff --git a/matrix/src/lib.rs b/matrix/src/lib.rs index 2f7b765df..1ace9f81e 100644 --- a/matrix/src/lib.rs +++ b/matrix/src/lib.rs @@ -59,7 +59,7 @@ pub trait MatrixGet: Matrix { } /// A `Matrix` that supports randomly accessing particular rows. -pub trait MatrixRows: Matrix { +pub trait MatrixRows: Matrix { type Row<'a>: IntoIterator where Self: 'a; @@ -102,16 +102,16 @@ pub trait MatrixRows: Matrix { } /// A `Matrix` which supports access its rows as slices. -pub trait MatrixRowSlices: MatrixRows + Debug { +pub trait MatrixRowSlices: MatrixRows { fn row_slice(&self, r: usize) -> &[T]; } /// A `Matrix` which supports access its rows as mutable slices. -pub trait MatrixRowSlicesMut: MatrixRowSlices { +pub trait MatrixRowSlicesMut: MatrixRowSlices { fn row_slice_mut(&mut self, r: usize) -> &mut [T]; } /// A `TransposeMatrix` which supports transpose logic for matrices -pub trait MatrixTranspose: MatrixRows { +pub trait MatrixTranspose: MatrixRows { fn transpose(self) -> Self; } diff --git a/matrix/src/stack.rs b/matrix/src/stack.rs index a522a1030..085f8f1fe 100644 --- a/matrix/src/stack.rs +++ b/matrix/src/stack.rs @@ -34,7 +34,6 @@ impl MatrixRows for VerticalPair where First: MatrixRows, Second: MatrixRows, - T: core::fmt::Debug, { type Row<'a> = EitherIterable, Second::Row<'a>> diff --git a/matrix/src/strided.rs b/matrix/src/strided.rs index 79db61d89..fd52c1a15 100644 --- a/matrix/src/strided.rs +++ b/matrix/src/strided.rs @@ -26,9 +26,7 @@ impl> MatrixGet for VerticallyStridedMatrixView } } -impl> MatrixRows - for VerticallyStridedMatrixView -{ +impl> MatrixRows for VerticallyStridedMatrixView { type Row<'a> = Inner::Row<'a> where diff --git a/matrix/src/util.rs b/matrix/src/util.rs index 3758c6116..fe516b631 100644 --- a/matrix/src/util.rs +++ b/matrix/src/util.rs @@ -4,7 +4,7 @@ use p3_util::{log2_strict_usize, reverse_bits_len}; use crate::dense::RowMajorMatrix; use crate::Matrix; -pub fn reverse_matrix_index_bits(mat: &mut RowMajorMatrix) { +pub fn reverse_matrix_index_bits(mat: &mut RowMajorMatrix) { let w = mat.width(); let h = mat.height(); let log_h = log2_strict_usize(h); @@ -20,7 +20,7 @@ pub fn reverse_matrix_index_bits(mat: &mut RowMajorMatrix(mat: &mut RowMajorMatrix, i: usize, j: usize) { +pub fn swap_rows(mat: &mut RowMajorMatrix, i: usize, j: usize) { let w = mat.width(); let (upper, lower) = mat.values.split_at_mut(j * w); let row_i = &mut upper[i * w..(i + 1) * w]; diff --git a/tensor-pcs/src/wrapped_matrix.rs b/tensor-pcs/src/wrapped_matrix.rs index 97cef8459..a4582d6ce 100644 --- a/tensor-pcs/src/wrapped_matrix.rs +++ b/tensor-pcs/src/wrapped_matrix.rs @@ -38,7 +38,6 @@ where impl MatrixRows for WrappedMatrix where M: MatrixRows, - T: core::fmt::Debug, { type Row<'a> = WrappedMatrixRow<'a, T, M> @@ -58,7 +57,7 @@ where pub struct WrappedMatrixRow<'a, T, M> where - T: 'a + core::fmt::Debug, + T: 'a, M: MatrixRows, { wrapped_matrix: &'a WrappedMatrix, @@ -69,7 +68,7 @@ where impl<'a, T, M> Iterator for WrappedMatrixRow<'a, T, M> where - T: 'a + core::fmt::Debug, + T: 'a, M: MatrixRows, { type Item = T; diff --git a/uni-stark/src/public.rs b/uni-stark/src/public.rs index c569e1061..6e90f9f32 100644 --- a/uni-stark/src/public.rs +++ b/uni-stark/src/public.rs @@ -69,7 +69,7 @@ impl Matrix for PublicRow { } } -impl MatrixRows for PublicRow { +impl MatrixRows for PublicRow { type Row<'a> = Cloned> where @@ -81,7 +81,7 @@ impl MatrixRows for PublicRow { } } -impl MatrixRowSlices for PublicRow { +impl MatrixRowSlices for PublicRow { fn row_slice(&self, _r: usize) -> &[T] { self.0.iter().as_slice() } diff --git a/uni-stark/tests/fib_air.rs b/uni-stark/tests/fib_air.rs index 98ac993f0..200d58bf1 100644 --- a/uni-stark/tests/fib_air.rs +++ b/uni-stark/tests/fib_air.rs @@ -1,4 +1,3 @@ -use core::fmt::Debug; use std::borrow::Borrow; use p3_air::{Air, AirBuilder, AirBuilderWithPublicValues, BaseAir}; @@ -21,7 +20,7 @@ use rand::thread_rng; pub struct FibonacciAir {} -impl BaseAir for FibonacciAir { +impl BaseAir for FibonacciAir { fn width(&self) -> usize { NUM_FIBONACCI_COLS } diff --git a/uni-stark/tests/mul_air.rs b/uni-stark/tests/mul_air.rs index cff73d315..2b4db60ff 100644 --- a/uni-stark/tests/mul_air.rs +++ b/uni-stark/tests/mul_air.rs @@ -1,5 +1,3 @@ -use core::fmt::Debug; - use itertools::Itertools; use p3_air::{Air, AirBuilder, BaseAir}; use p3_baby_bear::BabyBear; @@ -28,7 +26,7 @@ const TRACE_WIDTH: usize = REPETITIONS * 3; struct MulAir; -impl BaseAir for MulAir { +impl BaseAir for MulAir { fn width(&self) -> usize { TRACE_WIDTH } From e1995a683fbb073d09549b10fd131b8c24837fcf Mon Sep 17 00:00:00 2001 From: incertia Date: Thu, 26 Sep 2024 09:41:46 -0400 Subject: [PATCH 2/3] derive some more for TwoRowMatrixView --- air/src/two_row_matrix.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/air/src/two_row_matrix.rs b/air/src/two_row_matrix.rs index f3115e40a..c598d6ce4 100644 --- a/air/src/two_row_matrix.rs +++ b/air/src/two_row_matrix.rs @@ -3,7 +3,7 @@ use core::slice; use p3_matrix::{Matrix, MatrixRowSlices, MatrixRows}; -#[derive(Copy, Clone)] +#[derive(Clone, Copy, Debug, Eq, PartialEq)] pub struct TwoRowMatrixView<'a, T> { pub local: &'a [T], pub next: &'a [T], From 9eabb8733aee776524b5806a5f1227030679df20 Mon Sep 17 00:00:00 2001 From: incertia Date: Thu, 26 Sep 2024 09:46:10 -0400 Subject: [PATCH 3/3] fix clippy errors and reformat --- brakedown/benches/encode.rs | 2 +- dft/benches/fft.rs | 12 ++++-------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/brakedown/benches/encode.rs b/brakedown/benches/encode.rs index 905349a05..6863ffe8c 100644 --- a/brakedown/benches/encode.rs +++ b/brakedown/benches/encode.rs @@ -19,7 +19,7 @@ fn encode(c: &mut Criterion) where Standard: Distribution, { - let mut group = c.benchmark_group(&format!("encode::<{}>", type_name::())); + let mut group = c.benchmark_group(format!("encode::<{}>", type_name::())); group.sample_size(10); let mut rng = thread_rng(); diff --git a/dft/benches/fft.rs b/dft/benches/fft.rs index 2ba4fcce5..905c3ea68 100644 --- a/dft/benches/fft.rs +++ b/dft/benches/fft.rs @@ -47,7 +47,7 @@ where Dft: TwoAdicSubgroupDft, Standard: Distribution, { - let mut group = c.benchmark_group(&format!( + let mut group = c.benchmark_group(format!( "fft::<{}, {}, {}>", type_name::(), type_name::(), @@ -75,11 +75,7 @@ where Dft: TwoAdicSubgroupDft>, Standard: Distribution, { - let mut group = c.benchmark_group(&format!( - "m31_fft::<{}, {}>", - type_name::(), - BATCH_SIZE - )); + let mut group = c.benchmark_group(format!("m31_fft::<{}, {}>", type_name::(), BATCH_SIZE)); group.sample_size(10); let mut rng = thread_rng(); @@ -102,7 +98,7 @@ where Dft: TwoAdicSubgroupDft, Standard: Distribution, { - let mut group = c.benchmark_group(&format!( + let mut group = c.benchmark_group(format!( "ifft::<{}, {}, {}>", type_name::(), type_name::(), @@ -131,7 +127,7 @@ where Dft: TwoAdicSubgroupDft, Standard: Distribution, { - let mut group = c.benchmark_group(&format!( + let mut group = c.benchmark_group(format!( "coset_lde::<{}, {}, {}>", type_name::(), type_name::(),