Skip to content

Commit

Permalink
Cleanup before patch release (#984)
Browse files Browse the repository at this point in the history
* chore: remove peekmore

- Removed `peekmore` dependency from the project

* refactor: (automated) Refactor of code for readability and style improvements

- Modified the project-level lints in `.cargo/config`, added more lints enhance  maintainability.
- corrected the code in function, mostly through clippy.
  • Loading branch information
huitseeker authored Dec 20, 2023
1 parent 3ab302f commit e5e3e01
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 90 deletions.
15 changes: 14 additions & 1 deletion .cargo/config
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
xclippy = [
"clippy", "--workspace", "--all-targets", "--",
"-Wclippy::all",
"-Wclippy::match_same_arms",
"-Wclippy::cast_lossless",
"-Wclippy::checked_conversions",
"-Wclippy::dbg_macro",
Expand All @@ -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",
Expand Down
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion benches/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 7 additions & 7 deletions src/cli/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down
4 changes: 2 additions & 2 deletions src/coprocessor/trie/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,9 @@ pub fn install<F: LurkField>(state: &Rc<RefCell<State>>, lang: &mut Lang<F, Trie

let trie_package_name: Symbol = ".lurk.trie".into();
let mut package = Package::new(trie_package_name.into());
["new", "lookup", "insert"].into_iter().for_each(|name| {
for name in ["new", "lookup", "insert"].into_iter() {
package.intern(name);
});
}
state.borrow_mut().add_package(package);
}

Expand Down
84 changes: 39 additions & 45 deletions src/lem/multiframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ fn generate_slots_witnesses<F: LurkField>(
parallel: bool,
) -> Vec<Arc<SlotWitness<F>>> {
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),
Expand All @@ -188,7 +188,7 @@ fn generate_slots_witnesses<F: LurkField>(
]
.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);
Expand Down Expand Up @@ -395,7 +395,7 @@ impl<'a, F: LurkField, C: Coprocessor<F> + 'a> MultiFrameTrait<'a, F, C> for Mul
type AllocatedIO = Vec<AllocatedPtr<F>>;

fn emitted(_store: &Store<F>, eval_frame: &Self::EvalFrame) -> Vec<Ptr> {
eval_frame.emitted.to_vec()
eval_frame.emitted.clone()
}

fn io_to_scalar_vector(
Expand Down Expand Up @@ -536,7 +536,7 @@ impl<'a, F: LurkField, C: Coprocessor<F> + '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());
Expand All @@ -557,7 +557,7 @@ impl<'a, F: LurkField, C: Coprocessor<F> + '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(),
Expand All @@ -578,7 +578,7 @@ impl<'a, F: LurkField, C: Coprocessor<F> + '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<_>;

Expand Down Expand Up @@ -616,7 +616,7 @@ impl<'a, F: LurkField, C: Coprocessor<F> + 'a> MultiFrameTrait<'a, F, C> for Mul
.last()
.expect("empty inner_frames")
.output
.to_vec();
.clone();

if inner_frames.len() < reduction_count {
pad_frames(
Expand All @@ -632,7 +632,7 @@ impl<'a, F: LurkField, C: Coprocessor<F> + '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;
Expand Down Expand Up @@ -763,27 +763,24 @@ impl<'a, F: LurkField, C: Coprocessor<F>> Circuit<F> 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)
}
}
}
Expand Down Expand Up @@ -857,23 +854,20 @@ impl<'a, F: LurkField, C: Coprocessor<F>> nova::traits::circuit::StepCircuit<F>
));
}

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());
Expand Down
6 changes: 2 additions & 4 deletions src/lem/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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), _) => {
Expand Down
6 changes: 3 additions & 3 deletions src/lem/tests/eval_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -178,9 +178,9 @@ fn self_evaluating() {
(expr_key, expt_key),
]
.into_iter()
.for_each(|(expr, expt)| {
{
test_aux::<Coproc<Fr>>(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::<Coproc<Fr>>(s, &fun, Some(fun), None, None, None, &expect!["1"], &None);
Expand Down
6 changes: 3 additions & 3 deletions src/proof/tests/nova_tests_lem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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<'_, _>>(
Expand Down
43 changes: 21 additions & 22 deletions src/public_parameters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,35 +161,34 @@ where

let maybe_aux_params = supernova_aux_params::<F, C, M>(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::<F, M>::from_parts_unchecked(circuit_params_vec, aux_params);
let (pk, vk) = CompressedSNARK::setup(&pp).unwrap();
let pp =
SuperNovaPublicParams::<F, M>::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::<F, M>::from_parts_unchecked(circuit_params_vec, aux_params);
let (pk, vk) = CompressedSNARK::setup(&pp).unwrap();
let pp =
SuperNovaPublicParams::<F, M>::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)
Expand Down

0 comments on commit e5e3e01

Please sign in to comment.