Skip to content

Commit

Permalink
Nightly rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeyBF committed Feb 10, 2024
1 parent f3829e9 commit ac2d8cc
Show file tree
Hide file tree
Showing 12 changed files with 84 additions and 85 deletions.
3 changes: 1 addition & 2 deletions ext/crates/fp/src/field/fp.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::{constants::BITS_PER_LIMB, limb::Limb, prime::Prime};

use super::{limb::LimbMethods, Field, FieldElement};
use crate::{constants::BITS_PER_LIMB, limb::Limb, prime::Prime};

/// A prime field. This is just a wrapper around a prime.
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
Expand Down
3 changes: 1 addition & 2 deletions ext/crates/fp/src/field/limb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@

use std::ops::Range;

use super::FieldElement;
use crate::{
constants::BITS_PER_LIMB,
limb::{Limb, LimbBitIndexPair},
};

use super::FieldElement;

/// Methods that lets us interact with the underlying `Limb` type.
///
/// In practice this is an extension trait of a `Field`, so we treat it as such. We can't make it a
Expand Down
6 changes: 2 additions & 4 deletions ext/crates/fp/src/field/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::prime::Prime;

use self::limb::LimbMethods;
use crate::prime::Prime;

pub(crate) mod limb;

Expand Down Expand Up @@ -54,9 +53,8 @@ pub trait Field: LimbMethods + Sized {
// TODO: Figure out better tests
#[cfg(test)]
mod test {
use crate::prime::{P2, P3};

use super::{Field, SmallFq};
use crate::prime::{P2, P3};

#[test]
fn test_f_4() {
Expand Down
3 changes: 1 addition & 2 deletions ext/crates/fp/src/field/smallfq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::sync::Arc;
use dashmap::DashMap as HashMap;
use once_cell::sync::Lazy;

use super::{limb::LimbMethods, Field, FieldElement, Fp};
use crate::{
constants::BITS_PER_LIMB,
limb::Limb,
Expand All @@ -11,8 +12,6 @@ use crate::{
PRIME_TO_INDEX_MAP,
};

use super::{limb::LimbMethods, Field, FieldElement, Fp};

static SMALL_CONWAY_POLYS: [[[u32; 17]; 15]; 54] = include!("small_conway_polys.txt");

type ZechTable = HashMap<SmallFqElement, SmallFqElement>;
Expand Down
1 change: 0 additions & 1 deletion ext/crates/fp/src/limb.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
pub(crate) use crate::constants::Limb;

use crate::constants::BITS_PER_LIMB;

/// A struct containing the information required to access a specific entry in an array of `Limb`s.
Expand Down
17 changes: 9 additions & 8 deletions ext/crates/fp/src/matrix/m4ri.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use crate::constants::BITS_PER_LIMB;
use crate::field::limb::LimbMethods;
use crate::field::Fp;
use crate::limb::Limb;
use crate::matrix::Matrix;
use crate::prime::P2;
use crate::simd;

use itertools::Itertools;

use crate::{
constants::BITS_PER_LIMB,
field::{limb::LimbMethods, Fp},
limb::Limb,
matrix::Matrix,
prime::P2,
simd,
};

#[derive(Debug, Default)]
/// M4RI works as follows --- first row reduce k rows using the naive algorithm. We then construct
/// a table of all 2^k linear combinations of these rows. This can be done in O(2^k) time. We then
Expand Down
3 changes: 1 addition & 2 deletions ext/crates/fp/src/vector/impl_slicemutp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ use std::cmp::Ordering;

use itertools::Itertools;

use super::inner::{FqVectorP, SliceMutP, SliceP};
use crate::{
constants,
field::{Field, FieldElement},
limb::Limb,
prime::{Prime, ValidPrime},
};

use super::inner::{FqVectorP, SliceMutP, SliceP};

impl<'a, F: Field> SliceMutP<'a, F> {
pub fn prime(&self) -> ValidPrime {
self.fq.characteristic().to_dyn()
Expand Down
10 changes: 5 additions & 5 deletions ext/crates/fp/src/vector/impl_slicep.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
use super::{
inner::{FqVectorP, SliceP},
iter::{FpVectorIteratorP, FpVectorNonZeroIteratorP},
};
use crate::{
constants,
field::Field,
limb::Limb,
prime::{Prime, ValidPrime},
};

use super::{
inner::{FqVectorP, SliceP},
iter::{FpVectorIteratorP, FpVectorNonZeroIteratorP},
};

// Public methods

impl<'a, F: Field> SliceP<'a, F> {
Expand Down Expand Up @@ -68,6 +67,7 @@ impl<'a, F: Field> SliceP<'a, F> {
}
true
}

#[must_use]
pub fn slice(self, start: usize, end: usize) -> SliceP<'a, F> {
assert!(start <= end && end <= self.len());
Expand Down
3 changes: 1 addition & 2 deletions ext/crates/fp/src/vector/iter.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::{field::Field, limb::Limb};

use super::inner::SliceP;
use crate::{field::Field, limb::Limb};

pub struct FpVectorIteratorP<'a, F> {
fq: F,
Expand Down
12 changes: 7 additions & 5 deletions ext/crates/fp/src/vector/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ mod test {
use rstest::rstest;

use super::{inner::FqVectorP, *};
use crate::field::limb::LimbMethods;
use crate::field::Fp;
use crate::limb;
use crate::prime::{Prime, ValidPrime, P2};
use crate::{
field::{limb::LimbMethods, Fp},
limb,
prime::{Prime, ValidPrime, P2},
};

pub struct VectorDiffEntry {
pub index: usize,
Expand Down Expand Up @@ -1064,7 +1065,8 @@ mod test {
.iter()
.format_with("\n", |(tuple, popcnts, res, test_res), f| {
f(&format_args!(
" Inputs: {tuple:x?}\n expected {res:?}, got {test_res:?}. popcnts: {popcnts:?}"
" Inputs: {tuple:x?}\n expected {res:?}, got {test_res:?}. \
popcnts: {popcnts:?}"
))
});
panic!("\nFailed test cases:\n {formatter}");
Expand Down
19 changes: 10 additions & 9 deletions ext/crates/fp/src/vector/vector_2.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
//! This module replaces `vector` when `odd-primes` is disabled. Instead of producing enum
//! wrappers, it simply rexports `FooP<2>` as `Foo`.
use std::io::{Read, Write};
use std::mem::size_of;
use std::{
io::{Read, Write},
mem::size_of,
};

use itertools::Itertools;

use serde::{Deserialize, Deserializer, Serialize, Serializer};

use crate::field::limb::LimbMethods;
use crate::field::Fp;
use crate::limb::Limb;
use crate::prime::{Prime, ValidPrime, P2};
use crate::vector::inner::{FqVectorP, SliceMutP, SliceP};

use super::iter::{FpVectorIteratorP, FpVectorNonZeroIteratorP};
use crate::{
field::{limb::LimbMethods, Fp},
limb::Limb,
prime::{Prime, ValidPrime, P2},
vector::inner::{FqVectorP, SliceMutP, SliceP},
};

static F2: Fp<P2> = Fp(P2);

Expand Down
89 changes: 46 additions & 43 deletions ext/crates/fp/src/vector/vector_generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,22 @@
//!
//! This module is only used when the `odd-primes` feature is enabled.
use std::convert::TryInto;
use std::io::{Read, Write};
use std::mem::size_of;
use std::{
convert::TryInto,
io::{Read, Write},
mem::size_of,
};

use itertools::Itertools;

use serde::{Deserialize, Deserializer, Serialize, Serializer};

use crate::field::{limb::LimbMethods, Fp};
use crate::limb::Limb;
use crate::prime::{primes::*, Prime, ValidPrime};
use crate::vector::inner::{FqVectorP, SliceMutP, SliceP};

use super::iter::{FpVectorIteratorP, FpVectorNonZeroIteratorP};
use crate::{
field::{limb::LimbMethods, Fp},
limb::Limb,
prime::{primes::*, Prime, ValidPrime},
vector::inner::{FqVectorP, SliceMutP, SliceP},
};

macro_rules! dispatch_vector_inner {
// other is a type, but marking it as a :ty instead of :tt means we cannot use it to access its
Expand Down Expand Up @@ -210,6 +212,40 @@ pub enum FpVectorNonZeroIterator<'a> {
}

impl FpVector {
dispatch_vector! {
pub fn prime(&self) -> ValidPrime;
pub fn len(&self) -> usize;
pub fn is_empty(&self) -> bool;
pub fn scale(&mut self, c: u32);
pub fn set_to_zero(&mut self);
pub fn entry(&self, index: usize) -> u32;
pub fn set_entry(&mut self, index: usize, value: u32);
pub fn assign(&mut self, other: &Self);
pub fn assign_partial(&mut self, other: &Self);
pub fn add(&mut self, other: &Self, c: u32);
pub fn add_offset(&mut self, other: &Self, c: u32, offset: usize);
pub fn slice(&self, start: usize, end: usize) -> (dispatch Slice);
pub fn as_slice(&self) -> (dispatch Slice);
pub fn slice_mut(&mut self, start: usize, end: usize) -> (dispatch SliceMut);
pub fn as_slice_mut(&mut self) -> (dispatch SliceMut);
pub fn is_zero(&self) -> bool;
pub fn iter(&self) -> (dispatch FpVectorIterator);
pub fn iter_nonzero(&self) -> (dispatch FpVectorNonZeroIterator);
pub fn extend_len(&mut self, dim: usize);
pub fn set_scratch_vector_size(&mut self, dim: usize);
pub fn add_basis_element(&mut self, index: usize, value: u32);
pub fn copy_from_slice(&mut self, slice: &[u32]);
pub(crate) fn trim_start(&mut self, n: usize);
pub fn add_truncate(&mut self, other: &Self, c: u32) -> (Option<()>);
pub fn sign_rule(&self, other: &Self) -> bool;
pub fn add_carry(&mut self, other: &Self, c: u32, rest: &mut [FpVector]) -> bool;
pub fn first_nonzero(&self) -> (Option<(usize, u32)>);
pub fn density(&self) -> f32;

pub(crate) fn limbs(&self) -> (&[Limb]);
pub(crate) fn limbs_mut(&mut self) -> (&mut [Limb]);
}

pub fn new<P: Prime>(p: P, len: usize) -> FpVector {
match p.as_u32() {
2 => FpVector::_2(FqVectorP::new(Fp(P2), len)),
Expand Down Expand Up @@ -244,6 +280,7 @@ impl FpVector {
let entries_per_limb = Fp(p).entries_per_limb();
(len + entries_per_limb - 1) / entries_per_limb
}

pub(crate) fn padded_len(p: ValidPrime, len: usize) -> usize {
Self::num_limbs(p, len) * Fp(p).entries_per_limb()
}
Expand Down Expand Up @@ -294,40 +331,6 @@ impl FpVector {
}
Ok(())
}

dispatch_vector! {
pub fn prime(&self) -> ValidPrime;
pub fn len(&self) -> usize;
pub fn is_empty(&self) -> bool;
pub fn scale(&mut self, c: u32);
pub fn set_to_zero(&mut self);
pub fn entry(&self, index: usize) -> u32;
pub fn set_entry(&mut self, index: usize, value: u32);
pub fn assign(&mut self, other: &Self);
pub fn assign_partial(&mut self, other: &Self);
pub fn add(&mut self, other: &Self, c: u32);
pub fn add_offset(&mut self, other: &Self, c: u32, offset: usize);
pub fn slice(&self, start: usize, end: usize) -> (dispatch Slice);
pub fn as_slice(&self) -> (dispatch Slice);
pub fn slice_mut(&mut self, start: usize, end: usize) -> (dispatch SliceMut);
pub fn as_slice_mut(&mut self) -> (dispatch SliceMut);
pub fn is_zero(&self) -> bool;
pub fn iter(&self) -> (dispatch FpVectorIterator);
pub fn iter_nonzero(&self) -> (dispatch FpVectorNonZeroIterator);
pub fn extend_len(&mut self, dim: usize);
pub fn set_scratch_vector_size(&mut self, dim: usize);
pub fn add_basis_element(&mut self, index: usize, value: u32);
pub fn copy_from_slice(&mut self, slice: &[u32]);
pub(crate) fn trim_start(&mut self, n: usize);
pub fn add_truncate(&mut self, other: &Self, c: u32) -> (Option<()>);
pub fn sign_rule(&self, other: &Self) -> bool;
pub fn add_carry(&mut self, other: &Self, c: u32, rest: &mut [FpVector]) -> bool;
pub fn first_nonzero(&self) -> (Option<(usize, u32)>);
pub fn density(&self) -> f32;

pub(crate) fn limbs(&self) -> (&[Limb]);
pub(crate) fn limbs_mut(&mut self) -> (&mut [Limb]);
}
}

impl<'a> Slice<'a> {
Expand Down

0 comments on commit ac2d8cc

Please sign in to comment.