diff --git a/.cargo/config b/.cargo/config index 37d5cbf4b7..72acba760b 100644 --- a/.cargo/config +++ b/.cargo/config @@ -6,7 +6,6 @@ xclippy = [ "clippy", "--workspace", "--all-targets", "--", "-Wclippy::all", - "-Wclippy::match_same_arms", "-Wclippy::cast_lossless", "-Wclippy::checked_conversions", "-Wclippy::dbg_macro", @@ -15,16 +14,30 @@ xclippy = [ "-Wclippy::enum_glob_use", "-Wclippy::filter_map_next", "-Wclippy::flat_map_option", + "-Wclippy::from_iter_instead_of_collect", + "-Wclippy::implicit_clone", "-Wclippy::inefficient_to_string", + "-Wclippy::large_stack_arrays", "-Wclippy::large_types_passed_by_value", + "-Wclippy::macro_use_imports", "-Wclippy::manual_assert", "-Wclippy::manual_ok_or", + "-Wclippy::map_err_ignore", "-Wclippy::map_flatten", "-Wclippy::map_unwrap_or", + "-Wclippy::match_same_arms", + "-Wclippy::match_wild_err_arm", "-Wclippy::needless_borrow", + "-Wclippy::needless_continue", + "-Wclippy::needless_for_each", "-Wclippy::needless_pass_by_value", + "-Wclippy::option_option", + "-Wclippy::same_functions_in_if_condition", + "-Wclippy::single_match_else", "-Wclippy::trait_duplication_in_bounds", "-Wclippy::unnecessary_wraps", + "-Wclippy::unnested_or_patterns", + "-Wnonstandard_style", "-Wrust_2018_idioms", "-Wtrivial_numeric_casts", "-Wunused_lifetimes", diff --git a/Cargo.toml b/Cargo.toml index 4fe77aedfd..f46ecc1910 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -44,7 +44,6 @@ num-traits = "0.2.15" once_cell = { workspace = true } pairing = { workspace = true } pasta_curves = { workspace = true, features = ["repr-c", "serde"] } -peekmore = "1.3.0" rand = { workspace = true } rand_core = { version = "0.6.4", default-features = false } rand_xorshift = "0.3.0" diff --git a/benches/justfile b/benches/justfile index d6007c214c..5de3c729d9 100644 --- a/benches/justfile +++ b/benches/justfile @@ -3,7 +3,7 @@ # TODO: Move dotenv-filename into justfile once the feature is available set dotenv-load -commit := `git rev-parse HEAD` +commit := $(git rev-parse HEAD) # Run CPU benchmarks bench +benches: diff --git a/src/cli/config.rs b/src/cli/config.rs index 76f55e463b..e76b70faf0 100644 --- a/src/cli/config.rs +++ b/src/cli/config.rs @@ -89,13 +89,13 @@ impl CliSettings { // Then overwrite with any `LURK` environment variables .add_source(Environment::with_prefix("LURK")) // TODO: Derive config::Source for `cli_settings` and use `add_source` instead - .set_override_option(proofs, cli_settings.and_then(|s| s.get(proofs).map(|v| v.to_owned())))? - .set_override_option(commits, cli_settings.and_then(|s| s.get(commits).map(|v| v.to_owned())))? - .set_override_option(circom, cli_settings.and_then(|s| s.get(circom).map(|v| v.to_owned())))? - .set_override_option(backend, cli_settings.and_then(|s| s.get(backend).map(|v| v.to_owned())))? - .set_override_option(field, cli_settings.and_then(|s| s.get(field).map(|v| v.to_owned())))? - .set_override_option(rc, cli_settings.and_then(|s| s.get(rc).map(|v| v.to_owned())))? - .set_override_option(limit, cli_settings.and_then(|s| s.get(limit).map(|v| v.to_owned())))? + .set_override_option(proofs, cli_settings.and_then(|s| s.get(proofs).cloned()))? + .set_override_option(commits, cli_settings.and_then(|s| s.get(commits).cloned()))? + .set_override_option(circom, cli_settings.and_then(|s| s.get(circom).cloned()))? + .set_override_option(backend, cli_settings.and_then(|s| s.get(backend).cloned()))? + .set_override_option(field, cli_settings.and_then(|s| s.get(field).cloned()))? + .set_override_option(rc, cli_settings.and_then(|s| s.get(rc).cloned()))? + .set_override_option(limit, cli_settings.and_then(|s| s.get(limit).cloned()))? .build() .and_then(|c| c.try_deserialize()) } diff --git a/src/config.rs b/src/config.rs index b1012b0e57..64a7ec24b2 100644 --- a/src/config.rs +++ b/src/config.rs @@ -80,7 +80,7 @@ impl Settings { // Then override with any `LURK` environment variables .add_source(Environment::with_prefix("LURK")) // Optionally override if settings were specified via CLI arg - .set_override_option(public_params, settings.and_then(|s| s.get(public_params).map(|v| v.to_owned())))? + .set_override_option(public_params, settings.and_then(|s| s.get(public_params).cloned()))? .build() .and_then(|c| c.try_deserialize()) } diff --git a/src/coprocessor/trie/mod.rs b/src/coprocessor/trie/mod.rs index 46c6e92c3e..af948aad39 100644 --- a/src/coprocessor/trie/mod.rs +++ b/src/coprocessor/trie/mod.rs @@ -323,9 +323,9 @@ pub fn install(state: &Rc>, lang: &mut Lang( parallel: bool, ) -> Vec>> { let mut slots_data = Vec::with_capacity(frames.len() * num_slots_per_frame); - frames.iter().for_each(|frame| { + for frame in frames.iter() { [ (&frame.hints.hash4, SlotType::Hash4), (&frame.hints.hash6, SlotType::Hash6), @@ -188,7 +188,7 @@ fn generate_slots_witnesses( ] .into_iter() .for_each(|(sd_vec, st)| sd_vec.iter().for_each(|sd| slots_data.push((sd, st)))); - }); + } // precompute these values let hash4_witness_size = compute_witness_size(&SlotType::Hash4, store); let hash6_witness_size = compute_witness_size(&SlotType::Hash6, store); @@ -395,7 +395,7 @@ impl<'a, F: LurkField, C: Coprocessor + 'a> MultiFrameTrait<'a, F, C> for Mul type AllocatedIO = Vec>; fn emitted(_store: &Store, eval_frame: &Self::EvalFrame) -> Vec { - eval_frame.emitted.to_vec() + eval_frame.emitted.clone() } fn io_to_scalar_vector( @@ -536,7 +536,7 @@ impl<'a, F: LurkField, C: Coprocessor + 'a> MultiFrameTrait<'a, F, C> for Mul .last() .expect("chunk must not be empty") .output - .to_vec(); + .clone(); let inner_frames = if chunk.len() < reduction_count { let mut inner_frames = Vec::with_capacity(reduction_count); inner_frames.extend(chunk.to_vec()); @@ -557,7 +557,7 @@ impl<'a, F: LurkField, C: Coprocessor + 'a> MultiFrameTrait<'a, F, C> for Mul store: Some(store), lurk_step: lurk_step.clone(), cprocs: None, - input: Some(chunk[0].input.to_vec()), + input: Some(chunk[0].input.clone()), output: Some(output), frames: Some(inner_frames), cached_witness: OnceCell::new(), @@ -578,7 +578,7 @@ impl<'a, F: LurkField, C: Coprocessor + 'a> MultiFrameTrait<'a, F, C> for Mul let first_frame = &frames[chunk_start_idx]; // Variables occurring in both branches - let input = first_frame.input.to_vec(); + let input = first_frame.input.clone(); let output: Vec<_>; let frames_to_add: Vec<_>; @@ -616,7 +616,7 @@ impl<'a, F: LurkField, C: Coprocessor + 'a> MultiFrameTrait<'a, F, C> for Mul .last() .expect("empty inner_frames") .output - .to_vec(); + .clone(); if inner_frames.len() < reduction_count { pad_frames( @@ -632,7 +632,7 @@ impl<'a, F: LurkField, C: Coprocessor + 'a> MultiFrameTrait<'a, F, C> for Mul frames_to_add = inner_frames; } else { chunk_start_idx += 1; - output = first_frame.output.to_vec(); + output = first_frame.output.clone(); frames_to_add = vec![first_frame.clone()]; num_frames = 1; pc = first_frame.pc; @@ -763,27 +763,24 @@ impl<'a, F: LurkField, C: Coprocessor> Circuit for MultiFrame<'a, F, C> { Ok(()) }; - match self.store { - Some(store) => { - let input = self - .input - .as_ref() - .ok_or_else(|| SynthesisError::AssignmentMissing)?; - let output = self - .output - .as_ref() - .ok_or_else(|| SynthesisError::AssignmentMissing)?; - let frames = self.frames.as_ref().unwrap(); - synth(store, frames, input, output) - } - None => { - assert!(self.frames.is_none()); - let store = Store::default(); - let dummy_io = [store.dummy(); 3]; - let blank_frame = Frame::blank(self.get_func(), self.pc, &store); - let frames = vec![blank_frame; self.num_frames]; - synth(&store, &frames, &dummy_io, &dummy_io) - } + if let Some(store) = self.store { + let input = self + .input + .as_ref() + .ok_or_else(|| SynthesisError::AssignmentMissing)?; + let output = self + .output + .as_ref() + .ok_or_else(|| SynthesisError::AssignmentMissing)?; + let frames = self.frames.as_ref().unwrap(); + synth(store, frames, input, output) + } else { + assert!(self.frames.is_none()); + let store = Store::default(); + let dummy_io = [store.dummy(); 3]; + let blank_frame = Frame::blank(self.get_func(), self.pc, &store); + let frames = vec![blank_frame; self.num_frames]; + synth(&store, &frames, &dummy_io, &dummy_io) } } } @@ -857,23 +854,20 @@ impl<'a, F: LurkField, C: Coprocessor> nova::traits::circuit::StepCircuit )); } - let output_ptrs = match self.frames.as_ref() { - Some(frames) => { - if self.pc != 0 { - assert_eq!(frames.len(), 1); - } - let store = self.store.expect("store missing"); - let g = self.lurk_step.alloc_globals(cs, store)?; - self.synthesize_frames(cs, store, input, frames, &g)? - } - None => { - assert!(self.store.is_none()); - let store = Store::default(); - let blank_frame = Frame::blank(self.get_func(), self.pc, &store); - let frames = vec![blank_frame; self.num_frames]; - let g = self.lurk_step.alloc_globals(cs, &store)?; - self.synthesize_frames(cs, &store, input, &frames, &g)? + let output_ptrs = if let Some(frames) = self.frames.as_ref() { + if self.pc != 0 { + assert_eq!(frames.len(), 1); } + let store = self.store.expect("store missing"); + let g = self.lurk_step.alloc_globals(cs, store)?; + self.synthesize_frames(cs, store, input, frames, &g)? + } else { + assert!(self.store.is_none()); + let store = Store::default(); + let blank_frame = Frame::blank(self.get_func(), self.pc, &store); + let frames = vec![blank_frame; self.num_frames]; + let g = self.lurk_step.alloc_globals(cs, &store)?; + self.synthesize_frames(cs, &store, input, &frames, &g)? }; let mut output = Vec::with_capacity(z.len()); diff --git a/src/lem/store.rs b/src/lem/store.rs index 6d1b8b4ea7..378481f36f 100644 --- a/src/lem/store.rs +++ b/src/lem/store.rs @@ -1417,10 +1417,8 @@ mod tests { Pos::No, crate::UInt::U64(store.expect_f(idx).to_u64_unchecked()), ), - Ptr::Atom(Tag::Expr(ExprTag::Sym), _) - | Ptr::Atom(Tag::Expr(ExprTag::Key), _) - | Ptr::Tuple2(Tag::Expr(ExprTag::Sym), _) - | Ptr::Tuple2(Tag::Expr(ExprTag::Key), _) => { + Ptr::Atom(Tag::Expr(ExprTag::Sym | ExprTag::Key), _) + | Ptr::Tuple2(Tag::Expr(ExprTag::Sym | ExprTag::Key), _) => { Syntax::Symbol(Pos::No, store.fetch_symbol(&ptr).unwrap().into()) } Ptr::Atom(Tag::Expr(ExprTag::Str), _) | Ptr::Tuple2(Tag::Expr(ExprTag::Str), _) => { diff --git a/src/lem/tests/eval_tests.rs b/src/lem/tests/eval_tests.rs index 08dc69b224..84c1c52a16 100644 --- a/src/lem/tests/eval_tests.rs +++ b/src/lem/tests/eval_tests.rs @@ -168,7 +168,7 @@ fn self_evaluating() { let expr_key = ":key"; let expt_key = s.key("key"); - [ + for (expr, expt) in [ (expr_num, expt_num), (expr_u64, expt_u64), (expr_char, expt_char), @@ -178,9 +178,9 @@ fn self_evaluating() { (expr_key, expt_key), ] .into_iter() - .for_each(|(expr, expt)| { + { test_aux::>(s, expr, Some(expt), None, None, None, &expect!["1"], &None); - }); + } let fun = s.intern_fun(s.intern_user_symbol("x"), s.list(vec![expt_nil]), expt_nil); do_test_aux::>(s, &fun, Some(fun), None, None, None, &expect!["1"], &None); diff --git a/src/proof/tests/nova_tests_lem.rs b/src/proof/tests/nova_tests_lem.rs index cd07e17df2..9fa63e514d 100644 --- a/src/proof/tests/nova_tests_lem.rs +++ b/src/proof/tests/nova_tests_lem.rs @@ -40,7 +40,7 @@ fn test_prove_self_evaluating() { let expr_key = ":key"; let expt_key = s.key("key"); - [ + for (expr, expt) in [ (expr_num, expt_num), (expr_u64, expt_u64), (expr_char, expt_char), @@ -50,9 +50,9 @@ fn test_prove_self_evaluating() { (expr_key, expt_key), ] .into_iter() - .for_each(|(expr, expt)| { + { test_aux::<_, _, M1<'_, _>>(s, expr, Some(expt), None, None, None, &expect!["1"], &None); - }); + } let fun = s.intern_fun(s.intern_user_symbol("x"), s.list(vec![expt_nil]), expt_nil); nova_test_full_aux2::<_, _, M1<'_, _>>( diff --git a/src/public_parameters/mod.rs b/src/public_parameters/mod.rs index 5cb84a12bf..899ec9f919 100644 --- a/src/public_parameters/mod.rs +++ b/src/public_parameters/mod.rs @@ -161,35 +161,34 @@ where let maybe_aux_params = supernova_aux_params::(instance_primary); - let pp = match (maybe_circuit_params_vec, maybe_aux_params) { - (Ok(circuit_params_vec), Ok(aux_params)) => { - println!("generating public params"); + let pp = if let (Ok(circuit_params_vec), Ok(aux_params)) = + (maybe_circuit_params_vec, maybe_aux_params) + { + println!("generating public params"); - let pp = - SuperNovaPublicParams::::from_parts_unchecked(circuit_params_vec, aux_params); - let (pk, vk) = CompressedSNARK::setup(&pp).unwrap(); + let pp = + SuperNovaPublicParams::::from_parts_unchecked(circuit_params_vec, aux_params); + let (pk, vk) = CompressedSNARK::setup(&pp).unwrap(); - supernova::PublicParams { pp, pk, vk } - } - _ => { - println!("generating running claim params"); - let pp = default(instance_primary); + supernova::PublicParams { pp, pk, vk } + } else { + println!("generating running claim params"); + let pp = default(instance_primary); - let (circuit_params_vec, aux_params) = pp.pp.into_parts(); + let (circuit_params_vec, aux_params) = pp.pp.into_parts(); - disk_cache.write_abomonated(instance_primary, &aux_params)?; + disk_cache.write_abomonated(instance_primary, &aux_params)?; - for (circuit_index, circuit_params) in circuit_params_vec.iter().enumerate() { - let instance = instance_primary.reindex(circuit_index); - disk_cache.write_abomonated(&instance, circuit_params)?; - } + for (circuit_index, circuit_params) in circuit_params_vec.iter().enumerate() { + let instance = instance_primary.reindex(circuit_index); + disk_cache.write_abomonated(&instance, circuit_params)?; + } - let pp = - SuperNovaPublicParams::::from_parts_unchecked(circuit_params_vec, aux_params); - let (pk, vk) = CompressedSNARK::setup(&pp).unwrap(); + let pp = + SuperNovaPublicParams::::from_parts_unchecked(circuit_params_vec, aux_params); + let (pk, vk) = CompressedSNARK::setup(&pp).unwrap(); - supernova::PublicParams { pp, pk, vk } - } + supernova::PublicParams { pp, pk, vk } }; Ok(pp)