Skip to content

Commit

Permalink
Address various clippy warnings/errors in bellman
Browse files Browse the repository at this point in the history
  • Loading branch information
str4d committed Aug 23, 2019
1 parent bb11ef2 commit 08664b1
Show file tree
Hide file tree
Showing 13 changed files with 90 additions and 87 deletions.
22 changes: 13 additions & 9 deletions src/domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,19 @@ pub struct EvaluationDomain<E: ScalarEngine, G: Group<E>> {
minv: E::Fr,
}

impl<E: ScalarEngine, G: Group<E>> EvaluationDomain<E, G> {
pub fn as_ref(&self) -> &[G] {
impl<E: ScalarEngine, G: Group<E>> AsRef<[G]> for EvaluationDomain<E, G> {
fn as_ref(&self) -> &[G] {
&self.coeffs
}
}

pub fn as_mut(&mut self) -> &mut [G] {
impl<E: ScalarEngine, G: Group<E>> AsMut<[G]> for EvaluationDomain<E, G> {
fn as_mut(&mut self) -> &mut [G] {
&mut self.coeffs
}
}

impl<E: ScalarEngine, G: Group<E>> EvaluationDomain<E, G> {
pub fn into_coeffs(self) -> Vec<G> {
self.coeffs
}
Expand Down Expand Up @@ -64,9 +68,9 @@ impl<E: ScalarEngine, G: Group<E>> EvaluationDomain<E, G> {
coeffs.resize(m, G::group_zero());

Ok(EvaluationDomain {
coeffs: coeffs,
exp: exp,
omega: omega,
coeffs,
exp,
omega,
omegainv: omega.inverse().unwrap(),
geninv: E::Fr::multiplicative_generator().inverse().unwrap(),
minv: E::Fr::from_str(&format!("{}", m))
Expand Down Expand Up @@ -291,7 +295,7 @@ fn serial_fft<E: ScalarEngine, T: Group<E>>(a: &mut [T], omega: &E::Fr, log_n: u

let mut m = 1;
for _ in 0..log_n {
let w_m = omega.pow(&[(n / (2 * m)) as u64]);
let w_m = omega.pow(&[u64::from(n / (2 * m))]);

let mut k = 0;
while k < n {
Expand Down Expand Up @@ -337,12 +341,12 @@ fn parallel_fft<E: ScalarEngine, T: Group<E>>(
let omega_step = omega.pow(&[(j as u64) << log_new_n]);

let mut elt = E::Fr::one();
for i in 0..(1 << log_new_n) {
for (i, tmp) in tmp.iter_mut().enumerate() {
for s in 0..num_cpus {
let idx = (i + (s << log_new_n)) % (1 << log_n);
let mut t = a[idx];
t.group_mul_assign(&elt);
tmp[i].group_add_assign(&t);
tmp.group_add_assign(&t);
elt.mul_assign(&omega_step);
}
elt.mul_assign(&omega_j);
Expand Down
4 changes: 2 additions & 2 deletions src/gadgets/blake2s.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ pub fn blake2s<E: Engine, CS: ConstraintSystem<E>>(
blocks.push(this_block);
}

if blocks.len() == 0 {
if blocks.is_empty() {
blocks.push((0..16).map(|_| UInt32::constant(0)).collect());
}

Expand Down Expand Up @@ -433,7 +433,7 @@ mod test {
let expected = hex!("c59f682376d137f3f255e671e207d1f2374ebe504e9314208a52d9f88d69e8c8");

let mut out = out.into_iter();
for b in expected.into_iter() {
for b in expected.iter() {
for i in 0..8 {
let c = out.next().unwrap().get_value().unwrap();

Expand Down
30 changes: 15 additions & 15 deletions src/gadgets/boolean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl AllocatedBit {

Ok(AllocatedBit {
variable: var,
value: value,
value,
})
}

Expand Down Expand Up @@ -93,7 +93,7 @@ impl AllocatedBit {

Ok(AllocatedBit {
variable: var,
value: value,
value,
})
}

Expand Down Expand Up @@ -302,7 +302,7 @@ pub fn field_into_boolean_vec_le<E: Engine, CS: ConstraintSystem<E>, F: PrimeFie
) -> Result<Vec<Boolean>, SynthesisError> {
let v = field_into_allocated_bits_le::<E, CS, F>(cs, value)?;

Ok(v.into_iter().map(|e| Boolean::from(e)).collect())
Ok(v.into_iter().map(Boolean::from).collect())
}

pub fn field_into_allocated_bits_le<E: Engine, CS: ConstraintSystem<E>, F: PrimeField>(
Expand Down Expand Up @@ -412,24 +412,24 @@ impl Boolean {
}

pub fn get_value(&self) -> Option<bool> {
match self {
&Boolean::Constant(c) => Some(c),
&Boolean::Is(ref v) => v.get_value(),
&Boolean::Not(ref v) => v.get_value().map(|b| !b),
match *self {
Boolean::Constant(c) => Some(c),
Boolean::Is(ref v) => v.get_value(),
Boolean::Not(ref v) => v.get_value().map(|b| !b),
}
}

pub fn lc<E: Engine>(&self, one: Variable, coeff: E::Fr) -> LinearCombination<E> {
match self {
&Boolean::Constant(c) => {
match *self {
Boolean::Constant(c) => {
if c {
LinearCombination::<E>::zero() + (coeff, one)
} else {
LinearCombination::<E>::zero()
}
}
&Boolean::Is(ref v) => LinearCombination::<E>::zero() + (coeff, v.get_variable()),
&Boolean::Not(ref v) => {
Boolean::Is(ref v) => LinearCombination::<E>::zero() + (coeff, v.get_variable()),
Boolean::Not(ref v) => {
LinearCombination::<E>::zero() + (coeff, one) - (coeff, v.get_variable())
}
}
Expand All @@ -442,10 +442,10 @@ impl Boolean {

/// Return a negated interpretation of this boolean.
pub fn not(&self) -> Self {
match self {
&Boolean::Constant(c) => Boolean::Constant(!c),
&Boolean::Is(ref v) => Boolean::Not(v.clone()),
&Boolean::Not(ref v) => Boolean::Is(v.clone()),
match *self {
Boolean::Constant(c) => Boolean::Constant(!c),
Boolean::Is(ref v) => Boolean::Not(v.clone()),
Boolean::Not(ref v) => Boolean::Is(v.clone()),
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/gadgets/multieq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct MultiEq<E: Engine, CS: ConstraintSystem<E>> {
impl<E: Engine, CS: ConstraintSystem<E>> MultiEq<E, CS> {
pub fn new(cs: CS) -> Self {
MultiEq {
cs: cs,
cs,
ops: 0,
bits_used: 0,
lhs: LinearCombination::zero(),
Expand Down
12 changes: 6 additions & 6 deletions src/gadgets/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl<E: Engine> AllocatedNum<E> {
E: Engine,
CS: ConstraintSystem<E>,
{
assert!(v.len() > 0);
assert!(!v.is_empty());

// Let's keep this simple for now and just AND them all
// manually
Expand Down Expand Up @@ -132,7 +132,7 @@ impl<E: Engine> AllocatedNum<E> {
current_run.push(a_bit.clone());
result.push(a_bit);
} else {
if current_run.len() > 0 {
if !current_run.is_empty() {
// This is the start of a run of zeros, but we need
// to k-ary AND against `last_run` first.

Expand Down Expand Up @@ -183,7 +183,7 @@ impl<E: Engine> AllocatedNum<E> {
cs.enforce(|| "unpacking constraint", |lc| lc, |lc| lc, |_| lc);

// Convert into booleans, and reverse for little-endian bit order
Ok(result.into_iter().map(|b| Boolean::from(b)).rev().collect())
Ok(result.into_iter().map(Boolean::from).rev().collect())
}

/// Convert the allocated number into its little-endian representation.
Expand All @@ -208,7 +208,7 @@ impl<E: Engine> AllocatedNum<E> {

cs.enforce(|| "unpacking constraint", |lc| lc, |lc| lc, |_| lc);

Ok(bits.into_iter().map(|b| Boolean::from(b)).collect())
Ok(bits.into_iter().map(Boolean::from).collect())
}

pub fn mul<CS>(&self, mut cs: CS, other: &Self) -> Result<Self, SynthesisError>
Expand Down Expand Up @@ -238,7 +238,7 @@ impl<E: Engine> AllocatedNum<E> {
);

Ok(AllocatedNum {
value: value,
value,
variable: var,
})
}
Expand Down Expand Up @@ -270,7 +270,7 @@ impl<E: Engine> AllocatedNum<E> {
);

Ok(AllocatedNum {
value: value,
value,
variable: var,
})
}
Expand Down
6 changes: 4 additions & 2 deletions src/gadgets/sha256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use super::uint32::UInt32;
use crate::{ConstraintSystem, SynthesisError};
use pairing::Engine;

#[allow(clippy::unreadable_literal)]
const ROUND_CONSTANTS: [u32; 64] = [
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
Expand All @@ -15,6 +16,7 @@ const ROUND_CONSTANTS: [u32; 64] = [
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
];

#[allow(clippy::unreadable_literal)]
const IV: [u32; 8] = [
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19,
];
Expand Down Expand Up @@ -130,7 +132,7 @@ where
Ok(match self {
Maybe::Concrete(ref v) => return Ok(v.clone()),
Maybe::Deferred(mut v) => {
v.extend(others.into_iter().cloned());
v.extend(others.iter().cloned());
UInt32::addmany(cs, &v)?
}
})
Expand Down Expand Up @@ -286,7 +288,7 @@ mod test {
let expected = hex!("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855");

let mut out = out_bits.into_iter();
for b in expected.into_iter() {
for b in expected.iter() {
for i in (0..8).rev() {
let c = out.next().unwrap().get_value().unwrap();

Expand Down
6 changes: 3 additions & 3 deletions src/gadgets/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ fn proc_lc<E: Engine>(terms: &[(Variable, E::Fr)]) -> BTreeMap<OrderedVariable,
let mut map = BTreeMap::new();
for &(var, coeff) in terms {
map.entry(OrderedVariable(var))
.or_insert(E::Fr::zero())
.or_insert_with(E::Fr::zero)
.add_assign(&coeff);
}

Expand Down Expand Up @@ -157,7 +157,7 @@ impl<E: Engine> TestConstraintSystem<E> {
};

let powers_of_two = (0..E::Fr::NUM_BITS)
.map(|i| E::Fr::from_str("2").unwrap().pow(&[i as u64]))
.map(|i| E::Fr::from_str("2").unwrap().pow(&[u64::from(i)]))
.collect::<Vec<_>>();

let pp = |s: &mut String, lc: &LinearCombination<E>| {
Expand Down Expand Up @@ -286,7 +286,7 @@ impl<E: Engine> TestConstraintSystem<E> {
}
}

return true;
true
}

pub fn num_inputs(&self) -> usize {
Expand Down
Loading

0 comments on commit 08664b1

Please sign in to comment.