From f2e247dc6e81914b932665584d8bd085eb16663e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Garillot?= Date: Wed, 20 Sep 2023 03:33:38 -0400 Subject: [PATCH] chore: clippy --- .cargo/config | 1 + benches/end2end.rs | 8 +++---- benches/fibonacci.rs | 2 +- clutch/src/lib.rs | 6 ++--- fcomm/src/lib.rs | 10 ++++---- src/circuit/circuit_frame.rs | 2 +- src/circuit/gadgets/constraints.rs | 15 +++--------- src/circuit/gadgets/hashes.rs | 4 ++-- src/cli/repl.rs | 2 +- src/eval/reduction.rs | 3 +-- src/field.rs | 2 +- src/hash_witness.rs | 38 ++++-------------------------- src/lem/mod.rs | 2 +- src/parser/syntax.rs | 2 +- src/proof/groth16.rs | 2 +- src/proof/nova.rs | 2 +- src/proof/supernova.rs | 2 -- src/public_parameters/mem_cache.rs | 2 +- src/repl.rs | 4 +--- src/state.rs | 8 +++---- src/store.rs | 2 +- src/z_data.rs | 2 +- src/z_data/z_ptr.rs | 15 ++++++------ 23 files changed, 46 insertions(+), 90 deletions(-) diff --git a/.cargo/config b/.cargo/config index 1ff1a4771b..2cb7d14d05 100644 --- a/.cargo/config +++ b/.cargo/config @@ -22,6 +22,7 @@ xclippy = [ "-Wclippy::map_unwrap_or", "-Wclippy::needless_borrow", "-Wclippy::checked_conversions", + "-Wclippy::trait_duplication_in_bounds", "-Wrust_2018_idioms", "-Wtrivial_numeric_casts", "-Wunused_lifetimes", diff --git a/benches/end2end.rs b/benches/end2end.rs index 1ba9fcb4ea..eb8572b06c 100644 --- a/benches/end2end.rs +++ b/benches/end2end.rs @@ -309,7 +309,7 @@ fn prove_benchmark(c: &mut Criterion) { b.iter(|| { let result = prover - .prove(&pp, &frames, &mut store, lang_pallas_rc.clone()) + .prove(&pp, &frames, &store, lang_pallas_rc.clone()) .unwrap(); black_box(result); }) @@ -362,7 +362,7 @@ fn prove_compressed_benchmark(c: &mut Criterion) { b.iter(|| { let (proof, _, _, _) = prover - .prove(&pp, &frames, &mut store, lang_pallas_rc.clone()) + .prove(&pp, &frames, &store, lang_pallas_rc.clone()) .unwrap(); let compressed_result = proof.compress(&pp).unwrap(); @@ -412,7 +412,7 @@ fn verify_benchmark(c: &mut Criterion) { ) .unwrap(); let (proof, z0, zi, num_steps) = prover - .prove(&pp, &frames, &mut store, lang_pallas_rc.clone()) + .prove(&pp, &frames, &store, lang_pallas_rc.clone()) .unwrap(); b.iter_batched( @@ -470,7 +470,7 @@ fn verify_compressed_benchmark(c: &mut Criterion) { ) .unwrap(); let (proof, z0, zi, num_steps) = prover - .prove(&pp, &frames, &mut store, lang_pallas_rc.clone()) + .prove(&pp, &frames, &store, lang_pallas_rc.clone()) .unwrap(); let compressed_proof = proof.compress(&pp).unwrap(); diff --git a/benches/fibonacci.rs b/benches/fibonacci.rs index b1c607bfcd..dcbd4b24cf 100644 --- a/benches/fibonacci.rs +++ b/benches/fibonacci.rs @@ -104,7 +104,7 @@ fn fibo_prove( b.iter_batched( || (frames, lang_rc.clone()), |(frames, lang_rc)| { - let result = prover.prove(&pp, frames, &mut store, lang_rc); + let result = prover.prove(&pp, frames, &store, lang_rc); let _ = black_box(result); }, BatchSize::LargeInput, diff --git a/clutch/src/lib.rs b/clutch/src/lib.rs index e1a1329b2d..37b5a31e9a 100644 --- a/clutch/src/lib.rs +++ b/clutch/src/lib.rs @@ -510,14 +510,14 @@ impl ClutchState> { println!(); Ok(None) } - fn proof_claim(&self, store: &mut Store, rest: Ptr) -> Result>> { + fn proof_claim(&self, store: &Store, rest: Ptr) -> Result>> { let proof = self.get_proof(store, rest)?; println!("{0:#?}", proof.claim); Ok(None) } - fn get_proof(&self, store: &mut Store, rest: Ptr) -> Result> { + fn get_proof(&self, store: &Store, rest: Ptr) -> Result> { let (proof_cid, _rest1) = store.car_cdr(&rest)?; let zptr_string = store .fetch_string(&proof_cid) @@ -579,7 +579,7 @@ impl ClutchState> { bail!("verification of new proof failed"); } } - fn verify(&mut self, store: &mut Store, rest: Ptr) -> Result>> { + fn verify(&mut self, store: &Store, rest: Ptr) -> Result>> { let (proof_cid, _) = store.car_cdr(&rest)?; let zptr_string = store diff --git a/fcomm/src/lib.rs b/fcomm/src/lib.rs index e61cf8d973..f301445c29 100644 --- a/fcomm/src/lib.rs +++ b/fcomm/src/lib.rs @@ -264,7 +264,7 @@ impl Eq for LurkPtr {} #[cfg_attr(not(target_arch = "wasm32"), proptest(no_bound))] #[cfg_attr(not(target_arch = "wasm32"), serde_test(types(S1), zdata(true)))] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] -pub struct CommittedExpression { +pub struct CommittedExpression { pub expr: LurkPtr, #[cfg_attr( not(target_arch = "wasm32"), @@ -405,7 +405,7 @@ impl ReductionCount { impl Evaluation { fn new( - s: &mut Store, + s: &Store, input: IO, output: IO, iterations: Option, // This might be padded, so is not quite 'iterations' in the sense of number of actual reduction steps required @@ -491,7 +491,7 @@ impl PtrEvaluation { } impl Commitment { - pub fn from_comm(s: &mut Store, ptr: &Ptr) -> Result { + pub fn from_comm(s: &Store, ptr: &Ptr) -> Result { assert_eq!(ExprTag::Comm, ptr.tag); let digest = *s @@ -589,7 +589,7 @@ impl LurkPtr { } } - pub fn from_ptr(s: &mut Store, ptr: &Ptr) -> Self { + pub fn from_ptr(s: &Store, ptr: &Ptr) -> Self { let (z_store, z_ptr) = ZStore::new_with_expr(s, ptr); let z_ptr = z_ptr.unwrap(); Self::ZStorePtr(ZStorePtr { z_store, z_ptr }) @@ -599,7 +599,7 @@ impl LurkPtr { impl LurkCont { pub fn cont_ptr( &self, - s: &mut Store, + s: &Store, ) -> ContPtr { match self { Self::Outermost => s.get_cont_outermost(), diff --git a/src/circuit/circuit_frame.rs b/src/circuit/circuit_frame.rs index db60121a99..aeb113cddd 100644 --- a/src/circuit/circuit_frame.rs +++ b/src/circuit/circuit_frame.rs @@ -413,7 +413,7 @@ impl<'a, F: LurkField, C: Coprocessor> MultiFrame<'a, F, C> { let mut final_output = None; - for (frames_cs, output) in css.into_iter() { + for (frames_cs, output) in css { final_output = Some(output); let aux = frames_cs.aux_slice(); diff --git a/src/circuit/gadgets/constraints.rs b/src/circuit/gadgets/constraints.rs index 2aab017a12..571b3dc8c4 100644 --- a/src/circuit/gadgets/constraints.rs +++ b/src/circuit/gadgets/constraints.rs @@ -377,10 +377,7 @@ pub(crate) fn pick>( condition: &Boolean, a: &AllocatedNum, b: &AllocatedNum, -) -> Result, SynthesisError> -where - CS: ConstraintSystem, -{ +) -> Result, SynthesisError> { let c = AllocatedNum::alloc(cs.namespace(|| "pick result"), || { if condition .get_value() @@ -410,10 +407,7 @@ pub(crate) fn pick_const>( condition: &Boolean, a: F, b: F, -) -> Result, SynthesisError> -where - CS: ConstraintSystem, -{ +) -> Result, SynthesisError> { let c = AllocatedNum::alloc(cs.namespace(|| "pick result"), || { if condition .get_value() @@ -441,10 +435,7 @@ where pub(crate) fn boolean_to_num>( mut cs: CS, bit: &Boolean, -) -> Result, SynthesisError> -where - CS: ConstraintSystem, -{ +) -> Result, SynthesisError> { let num = AllocatedNum::alloc(cs.namespace(|| "Allocate num"), || { if bit.get_value().ok_or(SynthesisError::AssignmentMissing)? { Ok(F::ONE) diff --git a/src/circuit/gadgets/hashes.rs b/src/circuit/gadgets/hashes.rs index 6d3bdeb8b1..ebb638974f 100644 --- a/src/circuit/gadgets/hashes.rs +++ b/src/circuit/gadgets/hashes.rs @@ -173,7 +173,7 @@ impl<'a, F: LurkField> HashConst<'a, F> { #[allow(dead_code)] fn cache_hash_witness>( &self, - cs: &mut CS, + cs: &CS, preimage: Vec, hash_circuit_witness_cache: &mut HashCircuitWitnessCache, ) { @@ -364,7 +364,7 @@ impl<'a, F: LurkField> AllocatedContWitness<'a, F> { // Currently unused, but not necessarily useless. #[allow(dead_code)] fn make_hash_cache>( - cs: &mut CS, + cs: &CS, names_and_ptrs: &[(ContName, (Option>, Option>))], hash_constants: HashConst<'_, F>, ) -> Option> { diff --git a/src/cli/repl.rs b/src/cli/repl.rs index e6a08853d2..fa442cd5b3 100644 --- a/src/cli/repl.rs +++ b/src/cli/repl.rs @@ -237,7 +237,7 @@ impl Repl { info!("Proving"); let (proof, public_inputs, public_outputs, num_steps) = - prover.prove(&pp, frames, &mut self.store, self.lang.clone())?; + prover.prove(&pp, frames, &self.store, self.lang.clone())?; info!("Compressing proof"); let proof = proof.compress(&pp)?; assert_eq!(self.rc * num_steps, pad(n_frames, self.rc)); diff --git a/src/eval/reduction.rs b/src/eval/reduction.rs index 29deab253f..4dbe9b1a33 100644 --- a/src/eval/reduction.rs +++ b/src/eval/reduction.rs @@ -1150,8 +1150,7 @@ fn apply_continuation( Err(control) => return Ok(control), } } - (Expression::Char(_), Expression::EmptyStr) - | (Expression::Char(_), Expression::Str(..)) + (Expression::Char(_), Expression::EmptyStr | Expression::Str(..)) if matches!(operator, Op2::StrCons) => { cons_witness.strcons_named(ConsName::TheCons, store, evaled_arg, arg2) diff --git a/src/field.rs b/src/field.rs index 0640583e01..f9f26a7bab 100644 --- a/src/field.rs +++ b/src/field.rs @@ -309,7 +309,7 @@ impl Hash for FWrap { impl PartialOrd for FWrap { fn partial_cmp(&self, other: &Self) -> Option { - (self.0.to_repr().as_ref()).partial_cmp(other.0.to_repr().as_ref()) + Some(self.cmp(other)) } } diff --git a/src/hash_witness.rs b/src/hash_witness.rs index 191953839a..65e705ecf3 100644 --- a/src/hash_witness.rs +++ b/src/hash_witness.rs @@ -296,28 +296,6 @@ impl ConsStub { } } - pub fn car_cdr_mut( - &mut self, - s: &mut Store, - cons: &Ptr, - ) -> Result<(Ptr, Ptr), store::Error> { - match self { - Self::Dummy => { - let (car, cdr) = Cons::get_car_cdr_mut(s, cons)?; - - *self = Self::Value(Cons { - car, - cdr, - cons: *cons, - }); - - Ok((car, cdr)) - } - Self::Blank => unreachable!("Blank ConsStub should be used only in blank circuits."), - Self::Value(h) => Ok(h.car_cdr(cons)), - } - } - pub fn cons(&mut self, store: &mut Store, car: Ptr, cdr: Ptr) -> Ptr { match self { Self::Dummy => { @@ -572,10 +550,10 @@ impl ConsWitness { pub fn car_cdr_mut_named( &mut self, name: ConsName, - store: &mut Store, + store: &Store, cons: &Ptr, ) -> Result<(Ptr, Ptr), store::Error> { - self.get_assigned_slot(name).car_cdr_mut(store, cons) + self.get_assigned_slot(name).car_cdr(store, cons) } pub fn extend_named( @@ -610,17 +588,13 @@ impl Cons { fn get_car_cdr(s: &Store, cons: &Ptr) -> Result<(Ptr, Ptr), store::Error> { s.car_cdr(cons) } - - fn get_car_cdr_mut(s: &mut Store, cons: &Ptr) -> Result<(Ptr, Ptr), store::Error> { - s.car_cdr(cons) - } } impl ContWitness { pub fn fetch_named_cont( &mut self, name: ContName, - store: &mut Store, + store: &Store, cont: &ContPtr, ) -> Option> { self.get_assigned_slot(name).fetch_cont(store, cont) @@ -638,11 +612,7 @@ impl ContWitness { } impl ContStub { - pub fn fetch_cont( - &mut self, - store: &mut Store, - cont: &ContPtr, - ) -> Option> { + pub fn fetch_cont(&mut self, store: &Store, cont: &ContPtr) -> Option> { match self { Self::Dummy => { let continuation = store.fetch_cont(cont)?; diff --git a/src/lem/mod.rs b/src/lem/mod.rs index 961d9770c5..5f429ac256 100644 --- a/src/lem/mod.rs +++ b/src/lem/mod.rs @@ -821,7 +821,7 @@ mod tests { let log_fmt = |_: usize, _: &[Ptr], _: &[Ptr], _: &Store| String::default(); let mut cs_prev = None; - for input in inputs.into_iter() { + for input in inputs { let input = [input, nil, outermost]; let (frames, ..) = func .call_until(&input, store, stop_cond, 10, log_fmt) diff --git a/src/parser/syntax.rs b/src/parser/syntax.rs index d39ce1660b..fb0fbd4d15 100644 --- a/src/parser/syntax.rs +++ b/src/parser/syntax.rs @@ -451,7 +451,7 @@ pub mod tests { { match (expected, p.parse(Span::<'a>::new(i))) { (Some(expected), Ok((_, x))) if x == expected => true, - (Some(_), Ok(..)) | (Some(..), Err(_)) | (None, Ok(..)) => { + (Some(_) | None, Ok(..)) | (Some(..), Err(_)) => { // println!("input: {:?}", i); // println!("expected parse error"); // println!("detected: {:?}", x); diff --git a/src/proof/groth16.rs b/src/proof/groth16.rs index a8003855c3..c5dbb34a25 100644 --- a/src/proof/groth16.rs +++ b/src/proof/groth16.rs @@ -156,7 +156,7 @@ impl> Groth16Prover { let mut multiframe_proofs = Vec::with_capacity(multiframes_count); let last_multiframe = multiframes.last().unwrap().clone(); - for multiframe in multiframes.into_iter() { + for multiframe in multiframes { statements.push(multiframe.public_inputs()); let proof = self.prove(multiframe.clone(), params, &mut rng).unwrap(); diff --git a/src/proof/nova.rs b/src/proof/nova.rs index 58cb6afbf1..08ab382ecb 100644 --- a/src/proof/nova.rs +++ b/src/proof/nova.rs @@ -260,7 +260,7 @@ where &'a self, pp: &'a PublicParams<'_, F, C>, frames: &[Frame, Witness, F, C>], - store: &'a mut Store, + store: &'a Store, lang: Arc>, ) -> Result<(Proof<'_, F, C>, Vec, Vec, usize), ProofError> { let z0 = frames[0].input.to_vector(store)?; diff --git a/src/proof/supernova.rs b/src/proof/supernova.rs index 619ce8eb59..7c8a19ee47 100644 --- a/src/proof/supernova.rs +++ b/src/proof/supernova.rs @@ -97,8 +97,6 @@ where < as Group>::Scalar as PrimeField>::Repr: Abomonation, < as Group>::Scalar as PrimeField>::Repr: Abomonation, ::Repr: Abomonation, - C: Coprocessor, - F: CurveCycleEquipped + LurkField, <<::G2 as Group>::Scalar as PrimeField>::Repr: Abomonation, { /// Proves the computation recursively, generating a recursive SNARK proof. diff --git a/src/public_parameters/mem_cache.rs b/src/public_parameters/mem_cache.rs index 1b2a0de7d7..3c93794dff 100644 --- a/src/public_parameters/mem_cache.rs +++ b/src/public_parameters/mem_cache.rs @@ -126,7 +126,7 @@ impl PublicParamMemCache { // retrieve the per-Coproc public param table let entry = mem_cache.entry::>(); // deduce the map and populate it if needed - let param_entry = entry.or_insert_with(HashMap::new); + let param_entry = entry.or_default(); match param_entry.entry((rc, abomonated)) { Entry::Occupied(o) => Ok(o.into_mut()), Entry::Vacant(v) => { diff --git a/src/repl.rs b/src/repl.rs index e313bf5f88..95b7b44f9f 100644 --- a/src/repl.rs +++ b/src/repl.rs @@ -106,8 +106,6 @@ pub trait ReplTrait> { state: Rc>, file_path: P, ) -> Result<()> { - let file_path = file_path; - let input = read_to_string(file_path)?; eprintln!( "Read from {}: {}", @@ -324,7 +322,7 @@ pub fn run_repl, F: LurkField, T: ReplTrait, C: Coprocessor } impl> ReplState { - pub fn new(s: &mut Store, limit: usize, command: Option, lang: Lang) -> Self { + pub fn new(s: &Store, limit: usize, command: Option, lang: Lang) -> Self { Self { env: empty_sym_env(s), limit, diff --git a/src/state.rs b/src/state.rs index fcf0f294d7..cc9a93dfc6 100644 --- a/src/state.rs +++ b/src/state.rs @@ -151,15 +151,15 @@ impl State { // bootstrap the lurk package let mut lurk_package = Package::new(root_package.intern(LURK_PACKAGE_SYMBOL_NAME.into())); - LURK_PACKAGE_SYMBOLS_NAMES.iter().for_each(|symbol_name| { + for symbol_name in LURK_PACKAGE_SYMBOLS_NAMES.iter() { lurk_package.intern((*symbol_name).to_string()); - }); + } // bootstrap the meta package let mut meta_package = Package::new(lurk_package.intern(META_PACKAGE_SYMBOL_NAME.into())); - META_PACKAGE_SYMBOLS_NAMES.iter().for_each(|symbol_name| { + for symbol_name in META_PACKAGE_SYMBOLS_NAMES.iter() { meta_package.intern((*symbol_name).to_string()); - }); + } // bootstrap the user package let mut user_package = Package::new(lurk_package.intern(USER_PACKAGE_SYMBOL_NAME.into())); diff --git a/src/store.rs b/src/store.rs index b6ecbcaa7b..0d5ccd87f8 100644 --- a/src/store.rs +++ b/src/store.rs @@ -625,7 +625,7 @@ impl Store { // fetch a symbol cons or keyword cons pub fn fetch_symcons(&self, ptr: &Ptr) -> Option<(Ptr, Ptr)> { match (ptr.tag, ptr.raw) { - (ExprTag::Sym, RawPtr::Index(x)) | (ExprTag::Key, RawPtr::Index(x)) => { + (ExprTag::Sym | ExprTag::Key, RawPtr::Index(x)) => { let (car, cdr) = self.sym_store.get_index(x)?; Some((*car, *cdr)) } diff --git a/src/z_data.rs b/src/z_data.rs index d073c8ad96..6aa8447744 100644 --- a/src/z_data.rs +++ b/src/z_data.rs @@ -200,7 +200,7 @@ impl ZData { (i, ZData::Atom(data.to_vec())) } else { let (i, xs) = count(ZData::from_bytes_aux, size)(i)?; - (i, ZData::Cell(xs.to_vec())) + (i, ZData::Cell(xs)) }; Ok((i, res)) diff --git a/src/z_data/z_ptr.rs b/src/z_data/z_ptr.rs index 00856c8eab..fa40144a58 100644 --- a/src/z_data/z_ptr.rs +++ b/src/z_data/z_ptr.rs @@ -54,24 +54,23 @@ impl Display for ZPtr { impl PartialOrd for ZPtr { fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} + +impl Ord for ZPtr { + fn cmp(&self, other: &Self) -> core::cmp::Ordering { ( self.0.to_field_bytes::().as_ref(), self.1.to_repr().as_ref(), ) - .partial_cmp(&( + .cmp(&( other.0.to_field_bytes::().as_ref(), other.1.to_repr().as_ref(), )) } } -impl Ord for ZPtr { - fn cmp(&self, other: &Self) -> core::cmp::Ordering { - self.partial_cmp(other) - .expect("ZPtr::cmp: partial_cmp domain invariant violation") - } -} - #[allow(clippy::derived_hash_with_manual_eq)] impl Hash for ZPtr { fn hash(&self, state: &mut H) {