Skip to content

Commit

Permalink
clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
kunxian-xia committed Dec 27, 2023
1 parent 8b1542c commit 2dac615
Show file tree
Hide file tree
Showing 27 changed files with 72 additions and 121 deletions.
5 changes: 3 additions & 2 deletions halo2_proofs/benches/lookups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ fn criterion_benchmark(c: &mut Criterion) {
impl<F: Field> Circuit<F> for MyCircuit<F> {
type Config = MyConfig;
type FloorPlanner = SimpleFloorPlanner;
type Params = ();

fn without_witnesses(&self) -> Self {
Self::default()
Expand All @@ -58,8 +59,8 @@ fn criterion_benchmark(c: &mut Criterion) {

meta.create_gate("degree 6 gate", |meta| {
let dummy_selector = meta.query_selector(dummy_selector);
let constraints = vec![dummy_selector.clone(); 4]
.iter()
let constraints = std::iter::repeat(dummy_selector.clone())
.take(4)
.fold(dummy_selector.clone(), |acc, val| acc * val.clone());
Constraints::with_selector(dummy_selector, Some(constraints))
});
Expand Down
34 changes: 17 additions & 17 deletions halo2_proofs/src/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ pub fn best_multiexp<C: CurveAffine>(coeffs: &[C::Scalar], bases: &[C]) -> C::Cu
pub fn best_fft<Scalar: Field, G: FftGroup<Scalar>>(a: &mut [G], omega: Scalar, log_n: u32) {
let threads = multicore::current_num_threads();
let log_split = log2_floor(threads) as usize;
let n = a.len() as usize;
let n = a.len();
let sub_n = n >> log_split;
let split_m = 1 << log_split;

Expand All @@ -215,7 +215,7 @@ fn serial_fft<Scalar: Field, G: FftGroup<Scalar>>(a: &mut [G], omega: Scalar, lo
for k in 0..n as usize {
let rk = bitreverse(k, log_n as usize);
if k < rk {
a.swap(rk as usize, k as usize);
a.swap(rk, k);
}
}

Expand Down Expand Up @@ -258,7 +258,7 @@ fn serial_split_fft<Scalar: Field, G: FftGroup<Scalar>>(
let high_idx = omega_idx >> SPARSE_TWIDDLE_DEGREE;
let mut w_m = twiddle_lut[low_idx];
if high_idx > 0 {
w_m = w_m * twiddle_lut[(1 << SPARSE_TWIDDLE_DEGREE) + high_idx];
w_m *= twiddle_lut[(1 << SPARSE_TWIDDLE_DEGREE) + high_idx];
}

let mut k = 0;
Expand Down Expand Up @@ -298,28 +298,28 @@ fn split_radix_fft<Scalar: Field, G: FftGroup<Scalar>>(
// used to be: vec![G::identity; split_m];
// let mut t1 = a.clone();
// if unsafe code is allowed, a 10% performance improvement can be achieved
let mut t1: Vec<G> = Vec::with_capacity(split_m as usize);
let mut t1: Vec<G> = Vec::with_capacity(split_m);
unsafe {
t1.set_len(split_m as usize);
t1.set_len(split_m);
}
for i in 0..split_m {
t1[bitreverse(i, log_split)] = a[(i * sub_n + sub_fft_offset)];
t1[bitreverse(i, log_split)] = a[i * sub_n + sub_fft_offset];
}
serial_split_fft(&mut t1, twiddle_lut, sub_n, log_split as u32);

let sparse_degree = SPARSE_TWIDDLE_DEGREE;
let omega_idx = sub_fft_offset as usize;
let omega_idx = sub_fft_offset;
let low_idx = omega_idx % (1 << sparse_degree);
let high_idx = omega_idx >> sparse_degree;
let mut omega = twiddle_lut[low_idx];
if high_idx > 0 {
omega = omega * twiddle_lut[(1 << sparse_degree) + high_idx];
omega *= twiddle_lut[(1 << sparse_degree) + high_idx];
}
let mut w_m = Scalar::ONE;
for i in 0..split_m {
t1[i] *= &w_m;
tmp[i] = t1[i];
w_m = w_m * omega;
w_m *= omega;
}
}

Expand All @@ -339,7 +339,7 @@ pub fn generate_twiddle_lookup_table<F: Field>(
let mut w_n = omega.pow_vartime([start as u64, 0, 0, 0]);
for twiddle_lut in twiddle_lut.iter_mut() {
*twiddle_lut = w_n;
w_n = w_n * omega;
w_n *= omega;
}
});
return twiddle_lut;
Expand All @@ -348,14 +348,14 @@ pub fn generate_twiddle_lookup_table<F: Field>(
// sparse
let low_degree_lut_len = 1 << sparse_degree;
let high_degree_lut_len = 1 << (log_n - sparse_degree - without_last_level as u32);
let mut twiddle_lut = vec![F::ZERO; (low_degree_lut_len + high_degree_lut_len) as usize];
let mut twiddle_lut = vec![F::ZERO; low_degree_lut_len + high_degree_lut_len];
parallelize(
&mut twiddle_lut[..low_degree_lut_len],
|twiddle_lut, start| {
let mut w_n = omega.pow_vartime([start as u64, 0, 0, 0]);
for twiddle_lut in twiddle_lut.iter_mut() {
*twiddle_lut = w_n;
w_n = w_n * omega;
w_n *= omega;
}
},
);
Expand All @@ -366,15 +366,15 @@ pub fn generate_twiddle_lookup_table<F: Field>(
let mut w_n = high_degree_omega.pow_vartime([start as u64, 0, 0, 0]);
for twiddle_lut in twiddle_lut.iter_mut() {
*twiddle_lut = w_n;
w_n = w_n * high_degree_omega;
w_n *= high_degree_omega;
}
},
);
twiddle_lut
}

pub fn parallel_fft<Scalar: Field, G: FftGroup<Scalar>>(a: &mut [G], omega: Scalar, log_n: u32) {
let n = a.len() as usize;
let n = a.len();
assert_eq!(n, 1 << log_n);

let log_split = log2_floor(multicore::current_num_threads()) as usize;
Expand Down Expand Up @@ -580,7 +580,7 @@ pub(crate) fn parallelize_internal<T: Send, F: Fn(&mut [T], usize) + Send + Sync

multicore::scope(|scope| {
// Skip special-case: number of iterations is cleanly divided by number of threads.
let mut chunk_starts = vec![];
let chunk_starts = vec![];
if cutoff_chunk_id != 0 {
for (chunk_id, chunk) in v_hi.chunks_exact_mut(base_chunk_size + 1).enumerate() {
let offset = chunk_id * (base_chunk_size + 1);
Expand Down Expand Up @@ -650,7 +650,7 @@ pub fn lagrange_interpolate<F: Field>(points: &[F], evals: &[F]) -> Vec<F> {
.enumerate()
.filter(|&(k, _)| k != j)
.map(|a| a.1)
.zip(denoms.into_iter())
.zip(denoms)
{
product.resize(tmp.len() + 1, F::ZERO);
for ((a, b), product) in tmp
Expand All @@ -665,7 +665,7 @@ pub fn lagrange_interpolate<F: Field>(points: &[F], evals: &[F]) -> Vec<F> {
}
assert_eq!(tmp.len(), points.len());
assert_eq!(product.len(), points.len() - 1);
for (final_coeff, interpolation_coeff) in final_poly.iter_mut().zip(tmp.into_iter()) {
for (final_coeff, interpolation_coeff) in final_poly.iter_mut().zip(tmp) {
*final_coeff += interpolation_coeff * eval;
}
}
Expand Down
3 changes: 0 additions & 3 deletions halo2_proofs/src/circuit/floor_planner/single_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use std::cmp;
use std::collections::HashMap;
use std::fmt;
use std::marker::PhantomData;
use std::ops::Range;
use std::sync::{Arc, Mutex};
use std::time::Instant;

Check warning on line 5 in halo2_proofs/src/circuit/floor_planner/single_pass.rs

View workflow job for this annotation

GitHub Actions / Build target wasm32-wasi

unused import: `std::time::Instant`

Check warning on line 5 in halo2_proofs/src/circuit/floor_planner/single_pass.rs

View workflow job for this annotation

GitHub Actions / Build target wasm32-unknown-unknown

unused import: `std::time::Instant`

Check warning on line 5 in halo2_proofs/src/circuit/floor_planner/single_pass.rs

View workflow job for this annotation

GitHub Actions / Test on ubuntu-latest with basic features

unused import: `std::time::Instant`

use rayon::prelude::{IndexedParallelIterator, IntoParallelIterator, ParallelIterator};

Check warning on line 7 in halo2_proofs/src/circuit/floor_planner/single_pass.rs

View workflow job for this annotation

GitHub Actions / Build target wasm32-wasi

unused import: `IntoParallelIterator`

Check warning on line 7 in halo2_proofs/src/circuit/floor_planner/single_pass.rs

View workflow job for this annotation

GitHub Actions / Build target wasm32-wasi

unused import: `ParallelIterator`

Check warning on line 7 in halo2_proofs/src/circuit/floor_planner/single_pass.rs

View workflow job for this annotation

GitHub Actions / Build target wasm32-wasi

unused import: `IndexedParallelIterator`

Check warning on line 7 in halo2_proofs/src/circuit/floor_planner/single_pass.rs

View workflow job for this annotation

GitHub Actions / Build target wasm32-unknown-unknown

unused import: `IntoParallelIterator`

Check warning on line 7 in halo2_proofs/src/circuit/floor_planner/single_pass.rs

View workflow job for this annotation

GitHub Actions / Build target wasm32-unknown-unknown

unused import: `ParallelIterator`

Check warning on line 7 in halo2_proofs/src/circuit/floor_planner/single_pass.rs

View workflow job for this annotation

GitHub Actions / Build target wasm32-unknown-unknown

unused import: `IndexedParallelIterator`

Check warning on line 7 in halo2_proofs/src/circuit/floor_planner/single_pass.rs

View workflow job for this annotation

GitHub Actions / Test on ubuntu-latest with basic features

unused import: `IntoParallelIterator`

Check warning on line 7 in halo2_proofs/src/circuit/floor_planner/single_pass.rs

View workflow job for this annotation

GitHub Actions / Test on ubuntu-latest with basic features

unused import: `ParallelIterator`

Check warning on line 7 in halo2_proofs/src/circuit/floor_planner/single_pass.rs

View workflow job for this annotation

GitHub Actions / Test on ubuntu-latest with basic features

unused import: `IndexedParallelIterator`
Expand All @@ -18,7 +16,6 @@ use crate::{
table_layouter::{compute_table_lengths, SimpleTableLayouter},
Cell, Layouter, Region, RegionIndex, RegionStart, Table, Value,
},
multicore,
plonk::{
Advice, Any, Assigned, Assignment, Challenge, Circuit, Column, Error, Fixed, FloorPlanner,
Instance, Selector, TableColumn,
Expand Down
3 changes: 1 addition & 2 deletions halo2_proofs/src/circuit/floor_planner/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,7 @@ impl FloorPlanner for V1 {
if constant_positions().count() < plan.constants.len() {
return Err(Error::NotEnoughColumnsForConstants);
}
for ((fixed_column, fixed_row), (value, advice)) in
constant_positions().zip(plan.constants.into_iter())
for ((fixed_column, fixed_row), (value, advice)) in constant_positions().zip(plan.constants)
{
plan.cs.assign_fixed(
|| format!("Constant({:?})", value.evaluate()),
Expand Down
19 changes: 8 additions & 11 deletions halo2_proofs/src/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ use std::collections::HashSet;
use std::iter;
use std::ops::{Add, Mul, Neg, Range};
use std::sync::Arc;
use std::time::Instant;

use blake2b_simd::blake2b;
use ff::Field;
use ff::FromUniformBytes;
use group::Group;

use crate::plonk::permutation::keygen::Assembly;
use crate::{
Expand All @@ -25,8 +23,6 @@ use crate::{
use crate::{plonk::sealed::SealedPhase, plonk::FirstPhase, plonk::Phase};
#[cfg(feature = "multiphase-mock-prover")]
use ff::BatchInvert;
#[cfg(feature = "multiphase-mock-prover")]
use group::Group;

#[cfg(feature = "multicore")]
use crate::multicore::{
Expand Down Expand Up @@ -875,11 +871,13 @@ impl<'a, F: Field> Assignment<F> for MockProver<'a, F> {
}

#[cfg(not(feature = "multiphase-mock-prover"))]
*self
.advice
.get_mut(column.index())
.and_then(|v| v.get_mut(row - self.rw_rows.start))
.ok_or(Error::BoundsFailure)? = assigned;
{
*self
.advice
.get_mut(column.index())
.and_then(|v| v.get_mut(row - self.rw_rows.start))
.ok_or(Error::BoundsFailure)? = assigned;
}

#[cfg(feature = "phase-check")]
// if false && self.current_phase.0 > column.column_type().phase.0 {
Expand Down Expand Up @@ -1091,7 +1089,6 @@ impl<'a, F: FromUniformBytes<64> + Ord> MockProver<'a, F> {
#[cfg(not(feature = "circuit-params"))]
let config = ConcreteCircuit::configure(&mut cs);
let cs = cs.chunk_lookups();
let cs = cs;

assert!(
n >= cs.minimum_rows(),
Expand Down Expand Up @@ -1300,7 +1297,7 @@ impl<'a, F: FromUniformBytes<64> + Ord> MockProver<'a, F> {
debug_assert_eq!(Arc::strong_count(&prover.fixed_vec), 1);

#[cfg(feature = "thread-safe-region")]
prover.permutation.build_ordered_mapping();
prover.permutation.as_mut().unwrap().build_ordered_mapping();

Ok(prover)
}
Expand Down
7 changes: 0 additions & 7 deletions halo2_proofs/src/dev/graph/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,10 +321,3 @@ impl CircuitLayout {
Ok(())
}
}
fn query_advice(&self, _column: Column<Advice>, _row: usize) -> Result<F, Error> {
Ok(F::ZERO)
}

fn query_fixed(&self, _column: Column<Fixed>, _row: usize) -> Result<F, Error> {
Ok(F::ZERO)
}
1 change: 0 additions & 1 deletion halo2_proofs/src/helpers.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::plonk::{Any, Column};
use crate::poly::Polynomial;
use ff::Field;
use ff::{FromUniformBytes, PrimeField};
use halo2curves::{serde::SerdeObject, CurveAffine};
use num_bigint::BigUint;
Expand Down
3 changes: 2 additions & 1 deletion halo2_proofs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
#![feature(stmt_expr_attributes)]
// #![deny(missing_docs)]
// #![deny(unsafe_code)]
#![allow(clippy::uninit_vec)]
#![allow(clippy::too_many_arguments)]

#[cfg(feature = "counter")]
#[macro_use]
extern crate lazy_static;

#[cfg(feature = "counter")]
Expand Down
6 changes: 2 additions & 4 deletions halo2_proofs/src/plonk/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@ use core::cmp::max;
use core::ops::{Add, Mul};
use ff::Field;
use sealed::SealedPhase;
use std::collections::{BTreeMap, HashMap};
use std::collections::BTreeMap;
use std::fmt::Debug;
//use std::fmt::Debug;
use std::hash::Hasher;
use std::iter::{Product, Sum};
use std::marker::PhantomData;
use std::ops::Range;
use std::{
convert::TryFrom,
Expand Down Expand Up @@ -1890,7 +1888,7 @@ impl<F: Field> ConstraintSystem<F> {
pub fn lookup_any<S: AsRef<str>>(
&mut self,
// FIXME use name in debug messages
name: &'static str,
_name: S,
table_map: impl FnOnce(&mut VirtualCells<'_, F>) -> Vec<(Expression<F>, Expression<F>)>,
) {
let mut cells = VirtualCells::new(self);
Expand Down
12 changes: 3 additions & 9 deletions halo2_proofs/src/plonk/evaluation.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
use crate::multicore;
use crate::plonk::{
mv_lookup, permutation, AdviceQuery, Any, FixedQuery, InstanceQuery, ProvingKey,
};
use crate::plonk::{mv_lookup, permutation, Any, ProvingKey};
use crate::poly::Basis;
use crate::{
arithmetic::{eval_polynomial, parallelize, CurveAffine},
arithmetic::{parallelize, CurveAffine},
poly::{Coeff, ExtendedLagrangeCoeff, LagrangeCoeff, Polynomial, Rotation},
};
use group::ff::{BatchInvert, Field, PrimeField, WithSmallOrderMulGroup};
use rayon::prelude::IntoParallelIterator;
use rayon::prelude::ParallelIterator;
use std::process::exit;
use std::sync::atomic::fence;
use group::ff::{Field, PrimeField, WithSmallOrderMulGroup};

use super::{shuffle, ConstraintSystem, Expression};

Expand Down
7 changes: 2 additions & 5 deletions halo2_proofs/src/plonk/mv_lookup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,8 @@ impl<F: Field> Argument<F> {
input_degree
};

let inputs_expressions_degree: usize = self
.inputs_expressions
.iter()
.map(|input_expressions| expr_degree(input_expressions))
.sum();
let inputs_expressions_degree: usize =
self.inputs_expressions.iter().map(expr_degree).sum();

let table_degree = expr_degree(&self.table_expressions);

Expand Down
Loading

0 comments on commit 2dac615

Please sign in to comment.