From 81e14bf5b3b2e9e0791d5f776328280d9eda9b1f Mon Sep 17 00:00:00 2001 From: Sebastien La Duca Date: Thu, 21 Jul 2022 17:02:03 -0400 Subject: [PATCH] fmt --- maybe_rayon/src/lib.rs | 276 +++++++++++----------- plonky2/src/fri/oracle.rs | 2 +- plonky2/src/fri/prover.rs | 2 +- plonky2/src/hash/merkle_tree.rs | 2 +- plonky2/src/plonk/permutation_argument.rs | 2 +- plonky2/src/plonk/proof.rs | 2 +- plonky2/src/plonk/prover.rs | 2 +- 7 files changed, 150 insertions(+), 138 deletions(-) diff --git a/maybe_rayon/src/lib.rs b/maybe_rayon/src/lib.rs index 7c7c685a..1a9bd823 100644 --- a/maybe_rayon/src/lib.rs +++ b/maybe_rayon/src/lib.rs @@ -1,250 +1,262 @@ #[cfg(not(feature = "parallel"))] use std::{ - iter::{IntoIterator, Iterator}, - slice::{Chunks, ChunksExact, ChunksMut, ChunksExactMut}, -}; - -#[cfg(feature = "parallel")] -use rayon::{ - prelude::*, - slice::{Chunks as ParChunks, ChunksMut as ParChunksMut, ChunksExact as ParChunksExact, ChunksExactMut as ParChunksExactMut, ParallelSlice, ParallelSliceMut} + iter::{IntoIterator, Iterator}, + slice::{Chunks, ChunksExact, ChunksExactMut, ChunksMut}, }; #[cfg(feature = "parallel")] pub use rayon::prelude::{ - ParallelIterator, - IndexedParallelIterator, - ParallelExtend, - ParallelDrainFull, - ParallelDrainRange + IndexedParallelIterator, ParallelDrainFull, ParallelDrainRange, ParallelExtend, + ParallelIterator, +}; +#[cfg(feature = "parallel")] +use rayon::{ + prelude::*, + slice::{ + Chunks as ParChunks, ChunksExact as ParChunksExact, ChunksExactMut as ParChunksExactMut, + ChunksMut as ParChunksMut, ParallelSlice, ParallelSliceMut, + }, }; pub trait MaybeParIter<'data> { - #[cfg(feature = "parallel")] - type Item: Send + 'data; + #[cfg(feature = "parallel")] + type Item: Send + 'data; - #[cfg(feature = "parallel")] - type Iter: ParallelIterator; + #[cfg(feature = "parallel")] + type Iter: ParallelIterator; - #[cfg(not(feature = "parallel"))] - type Item; + #[cfg(not(feature = "parallel"))] + type Item; - #[cfg(not(feature = "parallel"))] - type Iter: Iterator; + #[cfg(not(feature = "parallel"))] + type Iter: Iterator; - fn par_iter(&'data self) -> Self::Iter; + fn par_iter(&'data self) -> Self::Iter; } #[cfg(feature = "parallel")] -impl<'data, T> MaybeParIter<'data> for T where T: ?Sized + IntoParallelRefIterator<'data> { - type Item = T::Item; - type Iter = T::Iter; +impl<'data, T> MaybeParIter<'data> for T +where + T: ?Sized + IntoParallelRefIterator<'data>, +{ + type Item = T::Item; + type Iter = T::Iter; - fn par_iter(&'data self) -> Self::Iter { - self.par_iter() - } + fn par_iter(&'data self) -> Self::Iter { + self.par_iter() + } } #[cfg(not(feature = "parallel"))] impl<'data, T: 'data> MaybeParIter<'data> for Vec { - type Item = &'data T; - type Iter = std::slice::Iter<'data, T>; + type Item = &'data T; + type Iter = std::slice::Iter<'data, T>; - fn par_iter(&'data self) -> Self::Iter { - self.iter() - } + fn par_iter(&'data self) -> Self::Iter { + self.iter() + } } #[cfg(not(feature = "parallel"))] impl<'data, T: 'data> MaybeParIter<'data> for [T] { - type Item = &'data T; - type Iter = std::slice::Iter<'data, T>; + type Item = &'data T; + type Iter = std::slice::Iter<'data, T>; - fn par_iter(&'data self) -> Self::Iter { - self.iter() - } + fn par_iter(&'data self) -> Self::Iter { + self.iter() + } } pub trait MaybeParIterMut<'data> { - #[cfg(feature = "parallel")] - type Item: Send + 'data; + #[cfg(feature = "parallel")] + type Item: Send + 'data; - #[cfg(feature = "parallel")] - type Iter: ParallelIterator; + #[cfg(feature = "parallel")] + type Iter: ParallelIterator; - #[cfg(not(feature = "parallel"))] - type Item; + #[cfg(not(feature = "parallel"))] + type Item; - #[cfg(not(feature = "parallel"))] - type Iter: Iterator; + #[cfg(not(feature = "parallel"))] + type Iter: Iterator; - fn par_iter_mut(&'data mut self) -> Self::Iter; + fn par_iter_mut(&'data mut self) -> Self::Iter; } #[cfg(feature = "parallel")] -impl<'data, T> MaybeParIterMut<'data> for T where T: ?Sized + IntoParallelRefMutIterator<'data> { - type Item = T::Item; - type Iter = T::Iter; +impl<'data, T> MaybeParIterMut<'data> for T +where + T: ?Sized + IntoParallelRefMutIterator<'data>, +{ + type Item = T::Item; + type Iter = T::Iter; - fn par_iter_mut(&'data mut self) -> Self::Iter { - self.par_iter_mut() - } + fn par_iter_mut(&'data mut self) -> Self::Iter { + self.par_iter_mut() + } } #[cfg(not(feature = "parallel"))] impl<'data, T: 'data> MaybeParIterMut<'data> for Vec { - type Item = &'data mut T; - type Iter = std::slice::IterMut<'data, T>; + type Item = &'data mut T; + type Iter = std::slice::IterMut<'data, T>; - fn par_iter_mut(&'data mut self) -> Self::Iter { - self.iter_mut() - } + fn par_iter_mut(&'data mut self) -> Self::Iter { + self.iter_mut() + } } #[cfg(not(feature = "parallel"))] impl<'data, T: 'data> MaybeParIterMut<'data> for [T] { - type Item = &'data mut T; - type Iter = std::slice::IterMut<'data, T>; - - fn par_iter_mut(&'data mut self) -> Self::Iter { - self.iter_mut() - } + type Item = &'data mut T; + type Iter = std::slice::IterMut<'data, T>; + + fn par_iter_mut(&'data mut self) -> Self::Iter { + self.iter_mut() + } } pub trait MaybeIntoParIter { - #[cfg(feature = "parallel")] - type Item: Send; + #[cfg(feature = "parallel")] + type Item: Send; - #[cfg(feature = "parallel")] - type Iter: ParallelIterator; + #[cfg(feature = "parallel")] + type Iter: ParallelIterator; - #[cfg(not(feature = "parallel"))] - type Item; + #[cfg(not(feature = "parallel"))] + type Item; - #[cfg(not(feature = "parallel"))] - type Iter: Iterator; + #[cfg(not(feature = "parallel"))] + type Iter: Iterator; - fn into_par_iter(self) -> Self::Iter; + fn into_par_iter(self) -> Self::Iter; } #[cfg(feature = "parallel")] -impl MaybeIntoParIter for T where T: IntoParallelIterator { - type Item = T::Item; - type Iter = T::Iter; +impl MaybeIntoParIter for T +where + T: IntoParallelIterator, +{ + type Item = T::Item; + type Iter = T::Iter; - fn into_par_iter(self) -> Self::Iter { - self.into_par_iter() - } + fn into_par_iter(self) -> Self::Iter { + self.into_par_iter() + } } #[cfg(not(feature = "parallel"))] -impl MaybeIntoParIter for T where T: IntoIterator { - type Item = T::Item; - type Iter = T::IntoIter; +impl MaybeIntoParIter for T +where + T: IntoIterator, +{ + type Item = T::Item; + type Iter = T::IntoIter; - fn into_par_iter(self) -> Self::Iter { - self.into_iter() - } + fn into_par_iter(self) -> Self::Iter { + self.into_iter() + } } #[cfg(feature = "parallel")] pub trait MaybeParChunks { - fn par_chunks(&self, chunk_size: usize) -> ParChunks<'_, T>; - fn par_chunks_exact(&self, chunk_size: usize) -> ParChunksExact<'_, T>; + fn par_chunks(&self, chunk_size: usize) -> ParChunks<'_, T>; + fn par_chunks_exact(&self, chunk_size: usize) -> ParChunksExact<'_, T>; } #[cfg(not(feature = "parallel"))] pub trait MaybeParChunks { - fn par_chunks(&self, chunk_size: usize) -> Chunks<'_, T>; - fn par_chunks_exact(&self, chunk_size: usize) -> ChunksExact<'_, T>; + fn par_chunks(&self, chunk_size: usize) -> Chunks<'_, T>; + fn par_chunks_exact(&self, chunk_size: usize) -> ChunksExact<'_, T>; } #[cfg(feature = "parallel")] impl + ?Sized, U: Sync> MaybeParChunks for T { - fn par_chunks(&self, chunk_size: usize) -> ParChunks<'_, U> { - self.par_chunks(chunk_size) - } - fn par_chunks_exact(&self, chunk_size: usize) -> ParChunksExact<'_, U> { - self.par_chunks_exact(chunk_size) - } + fn par_chunks(&self, chunk_size: usize) -> ParChunks<'_, U> { + self.par_chunks(chunk_size) + } + fn par_chunks_exact(&self, chunk_size: usize) -> ParChunksExact<'_, U> { + self.par_chunks_exact(chunk_size) + } } #[cfg(not(feature = "parallel"))] impl MaybeParChunks for [T] { - fn par_chunks(&self, chunk_size: usize) -> Chunks<'_, T> { - self.chunks(chunk_size) - } + fn par_chunks(&self, chunk_size: usize) -> Chunks<'_, T> { + self.chunks(chunk_size) + } - fn par_chunks_exact(&self, chunk_size: usize) -> ChunksExact<'_, T> { - self.chunks_exact(chunk_size) - } + fn par_chunks_exact(&self, chunk_size: usize) -> ChunksExact<'_, T> { + self.chunks_exact(chunk_size) + } } #[cfg(feature = "parallel")] pub trait MaybeParChunksMut { - fn par_chunks_mut(&mut self, chunk_size: usize) -> ParChunksMut<'_, T>; - fn par_chunks_exact_mut(&mut self, chunk_size: usize) -> ParChunksExactMut<'_, T>; + fn par_chunks_mut(&mut self, chunk_size: usize) -> ParChunksMut<'_, T>; + fn par_chunks_exact_mut(&mut self, chunk_size: usize) -> ParChunksExactMut<'_, T>; } #[cfg(not(feature = "parallel"))] pub trait MaybeParChunksMut { - fn par_chunks_mut(&mut self, chunk_size: usize) -> ChunksMut<'_, T>; - fn par_chunks_exact_mut(&mut self, chunk_size: usize) -> ChunksExactMut<'_, T>; + fn par_chunks_mut(&mut self, chunk_size: usize) -> ChunksMut<'_, T>; + fn par_chunks_exact_mut(&mut self, chunk_size: usize) -> ChunksExactMut<'_, T>; } - #[cfg(feature = "parallel")] impl, U: Send> MaybeParChunksMut for T { - fn par_chunks_mut(&mut self, chunk_size: usize) -> ParChunksMut<'_, U> { - self.par_chunks_mut(chunk_size) - } - fn par_chunks_exact_mut(&mut self, chunk_size: usize) -> ParChunksExactMut<'_, U> { - self.par_chunks_exact_mut(chunk_size) - } + fn par_chunks_mut(&mut self, chunk_size: usize) -> ParChunksMut<'_, U> { + self.par_chunks_mut(chunk_size) + } + fn par_chunks_exact_mut(&mut self, chunk_size: usize) -> ParChunksExactMut<'_, U> { + self.par_chunks_exact_mut(chunk_size) + } } #[cfg(not(feature = "parallel"))] impl MaybeParChunksMut for [T] { - fn par_chunks_mut(&mut self, chunk_size: usize) -> ChunksMut<'_, T> { - self.chunks_mut(chunk_size) - } - fn par_chunks_exact_mut(&mut self, chunk_size: usize) -> ChunksExactMut<'_, T> { - self.chunks_exact_mut(chunk_size) - } + fn par_chunks_mut(&mut self, chunk_size: usize) -> ChunksMut<'_, T> { + self.chunks_mut(chunk_size) + } + fn par_chunks_exact_mut(&mut self, chunk_size: usize) -> ChunksExactMut<'_, T> { + self.chunks_exact_mut(chunk_size) + } } pub trait ParallelIteratorMock { - type Item; - fn find_any

(self, predicate: P) -> Option + type Item; + fn find_any

(self, predicate: P) -> Option where P: Fn(&Self::Item) -> bool + Sync + Send; } impl ParallelIteratorMock for T { - type Item = T::Item; + type Item = T::Item; - fn find_any

(mut self, predicate: P) -> Option + fn find_any

(mut self, predicate: P) -> Option where - P: Fn(&Self::Item) -> bool + Sync + Send - { - self.find(predicate) - } + P: Fn(&Self::Item) -> bool + Sync + Send, + { + self.find(predicate) + } } #[cfg(feature = "parallel")] pub fn join(oper_a: A, oper_b: B) -> (RA, RB) - where A: FnOnce() -> RA + Send, - B: FnOnce() -> RB + Send, - RA: Send, - RB: Send +where + A: FnOnce() -> RA + Send, + B: FnOnce() -> RB + Send, + RA: Send, + RB: Send, { rayon::join(oper_a, oper_b) } #[cfg(not(feature = "parallel"))] pub fn join(oper_a: A, oper_b: B) -> (RA, RB) - where A: FnOnce() -> RA, - B: FnOnce() -> RB, +where + A: FnOnce() -> RA, + B: FnOnce() -> RB, { (oper_a(), oper_b()) } diff --git a/plonky2/src/fri/oracle.rs b/plonky2/src/fri/oracle.rs index 47647701..1f5b648f 100644 --- a/plonky2/src/fri/oracle.rs +++ b/plonky2/src/fri/oracle.rs @@ -1,11 +1,11 @@ use itertools::Itertools; +use maybe_rayon::*; use plonky2_field::extension::Extendable; use plonky2_field::fft::FftRootTable; use plonky2_field::packed::PackedField; use plonky2_field::polynomial::{PolynomialCoeffs, PolynomialValues}; use plonky2_field::types::Field; use plonky2_util::{log2_strict, reverse_index_bits_in_place}; -use maybe_rayon::*; use crate::fri::proof::FriProof; use crate::fri::prover::fri_proof; diff --git a/plonky2/src/fri/prover.rs b/plonky2/src/fri/prover.rs index 94389a7e..39e25869 100644 --- a/plonky2/src/fri/prover.rs +++ b/plonky2/src/fri/prover.rs @@ -1,8 +1,8 @@ use itertools::Itertools; +use maybe_rayon::*; use plonky2_field::extension::{flatten, unflatten, Extendable}; use plonky2_field::polynomial::{PolynomialCoeffs, PolynomialValues}; use plonky2_util::reverse_index_bits_in_place; -use maybe_rayon::*; use crate::fri::proof::{FriInitialTreeProof, FriProof, FriQueryRound, FriQueryStep}; use crate::fri::{FriConfig, FriParams}; diff --git a/plonky2/src/hash/merkle_tree.rs b/plonky2/src/hash/merkle_tree.rs index f7b6d4a2..1da66bff 100644 --- a/plonky2/src/hash/merkle_tree.rs +++ b/plonky2/src/hash/merkle_tree.rs @@ -1,10 +1,10 @@ use std::mem::MaybeUninit; use std::slice; +use maybe_rayon::*; use plonky2_util::log2_strict; use serde::{Deserialize, Serialize}; -use maybe_rayon::*; use crate::hash::hash_types::RichField; use crate::hash::merkle_proofs::MerkleProof; use crate::plonk::config::GenericHashOut; diff --git a/plonky2/src/plonk/permutation_argument.rs b/plonky2/src/plonk/permutation_argument.rs index f9b23796..3658a12d 100644 --- a/plonky2/src/plonk/permutation_argument.rs +++ b/plonky2/src/plonk/permutation_argument.rs @@ -1,8 +1,8 @@ use std::collections::HashMap; +use maybe_rayon::*; use plonky2_field::polynomial::PolynomialValues; use plonky2_field::types::Field; -use maybe_rayon::*; use crate::iop::target::Target; use crate::iop::wire::Wire; diff --git a/plonky2/src/plonk/proof.rs b/plonky2/src/plonk/proof.rs index 1cb83b14..922a24bb 100644 --- a/plonky2/src/plonk/proof.rs +++ b/plonky2/src/plonk/proof.rs @@ -1,7 +1,7 @@ use anyhow::ensure; +use maybe_rayon::*; use plonky2_field::extension::Extendable; use serde::{Deserialize, Serialize}; -use maybe_rayon::*; use crate::fri::oracle::PolynomialBatch; use crate::fri::proof::{ diff --git a/plonky2/src/plonk/prover.rs b/plonky2/src/plonk/prover.rs index 9275e241..3e81942b 100644 --- a/plonky2/src/plonk/prover.rs +++ b/plonky2/src/plonk/prover.rs @@ -2,11 +2,11 @@ use std::mem::swap; use anyhow::ensure; use anyhow::Result; +use maybe_rayon::*; use plonky2_field::extension::Extendable; use plonky2_field::polynomial::{PolynomialCoeffs, PolynomialValues}; use plonky2_field::zero_poly_coset::ZeroPolyOnCoset; use plonky2_util::{ceil_div_usize, log2_ceil}; -use maybe_rayon::*; use crate::field::types::Field; use crate::fri::oracle::PolynomialBatch;