Skip to content

Commit

Permalink
chore: clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
huitseeker committed Sep 20, 2023
1 parent cd96d73 commit f2e247d
Show file tree
Hide file tree
Showing 23 changed files with 46 additions and 90 deletions.
1 change: 1 addition & 0 deletions .cargo/config
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions benches/end2end.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
})
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion benches/fibonacci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ fn fibo_prove<M: measurement::Measurement>(
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,
Expand Down
6 changes: 3 additions & 3 deletions clutch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,14 +510,14 @@ impl ClutchState<F, Coproc<F>> {
println!();
Ok(None)
}
fn proof_claim(&self, store: &mut Store<F>, rest: Ptr<F>) -> Result<Option<Ptr<F>>> {
fn proof_claim(&self, store: &Store<F>, rest: Ptr<F>) -> Result<Option<Ptr<F>>> {
let proof = self.get_proof(store, rest)?;

println!("{0:#?}", proof.claim);
Ok(None)
}

fn get_proof(&self, store: &mut Store<F>, rest: Ptr<F>) -> Result<Proof<'_, F>> {
fn get_proof(&self, store: &Store<F>, rest: Ptr<F>) -> Result<Proof<'_, F>> {
let (proof_cid, _rest1) = store.car_cdr(&rest)?;
let zptr_string = store
.fetch_string(&proof_cid)
Expand Down Expand Up @@ -579,7 +579,7 @@ impl ClutchState<F, Coproc<F>> {
bail!("verification of new proof failed");
}
}
fn verify(&mut self, store: &mut Store<F>, rest: Ptr<F>) -> Result<Option<Ptr<F>>> {
fn verify(&mut self, store: &Store<F>, rest: Ptr<F>) -> Result<Option<Ptr<F>>> {
let (proof_cid, _) = store.car_cdr(&rest)?;

let zptr_string = store
Expand Down
10 changes: 5 additions & 5 deletions fcomm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ impl<F: LurkField> Eq for LurkPtr<F> {}
#[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<F: LurkField + Serialize> {
pub struct CommittedExpression<F: LurkField> {
pub expr: LurkPtr<F>,
#[cfg_attr(
not(target_arch = "wasm32"),
Expand Down Expand Up @@ -405,7 +405,7 @@ impl ReductionCount {

impl Evaluation {
fn new<F: LurkField>(
s: &mut Store<F>,
s: &Store<F>,
input: IO<F>,
output: IO<F>,
iterations: Option<usize>, // This might be padded, so is not quite 'iterations' in the sense of number of actual reduction steps required
Expand Down Expand Up @@ -491,7 +491,7 @@ impl<F: LurkField + Serialize + DeserializeOwned> PtrEvaluation<F> {
}

impl<F: LurkField + Serialize + DeserializeOwned> Commitment<F> {
pub fn from_comm(s: &mut Store<F>, ptr: &Ptr<F>) -> Result<Self, Error> {
pub fn from_comm(s: &Store<F>, ptr: &Ptr<F>) -> Result<Self, Error> {
assert_eq!(ExprTag::Comm, ptr.tag);

let digest = *s
Expand Down Expand Up @@ -589,7 +589,7 @@ impl<F: LurkField + Serialize + DeserializeOwned> LurkPtr<F> {
}
}

pub fn from_ptr(s: &mut Store<F>, ptr: &Ptr<F>) -> Self {
pub fn from_ptr(s: &Store<F>, ptr: &Ptr<F>) -> 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 })
Expand All @@ -599,7 +599,7 @@ impl<F: LurkField + Serialize + DeserializeOwned> LurkPtr<F> {
impl LurkCont {
pub fn cont_ptr<F: LurkField + Serialize + DeserializeOwned>(
&self,
s: &mut Store<F>,
s: &Store<F>,
) -> ContPtr<F> {
match self {
Self::Outermost => s.get_cont_outermost(),
Expand Down
2 changes: 1 addition & 1 deletion src/circuit/circuit_frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ impl<'a, F: LurkField, C: Coprocessor<F>> 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();
Expand Down
15 changes: 3 additions & 12 deletions src/circuit/gadgets/constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,10 +377,7 @@ pub(crate) fn pick<F: PrimeField, CS: ConstraintSystem<F>>(
condition: &Boolean,
a: &AllocatedNum<F>,
b: &AllocatedNum<F>,
) -> Result<AllocatedNum<F>, SynthesisError>
where
CS: ConstraintSystem<F>,
{
) -> Result<AllocatedNum<F>, SynthesisError> {
let c = AllocatedNum::alloc(cs.namespace(|| "pick result"), || {
if condition
.get_value()
Expand Down Expand Up @@ -410,10 +407,7 @@ pub(crate) fn pick_const<F: PrimeField, CS: ConstraintSystem<F>>(
condition: &Boolean,
a: F,
b: F,
) -> Result<AllocatedNum<F>, SynthesisError>
where
CS: ConstraintSystem<F>,
{
) -> Result<AllocatedNum<F>, SynthesisError> {
let c = AllocatedNum::alloc(cs.namespace(|| "pick result"), || {
if condition
.get_value()
Expand Down Expand Up @@ -441,10 +435,7 @@ where
pub(crate) fn boolean_to_num<F: PrimeField, CS: ConstraintSystem<F>>(
mut cs: CS,
bit: &Boolean,
) -> Result<AllocatedNum<F>, SynthesisError>
where
CS: ConstraintSystem<F>,
{
) -> Result<AllocatedNum<F>, SynthesisError> {
let num = AllocatedNum::alloc(cs.namespace(|| "Allocate num"), || {
if bit.get_value().ok_or(SynthesisError::AssignmentMissing)? {
Ok(F::ONE)
Expand Down
4 changes: 2 additions & 2 deletions src/circuit/gadgets/hashes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ impl<'a, F: LurkField> HashConst<'a, F> {
#[allow(dead_code)]
fn cache_hash_witness<CS: ConstraintSystem<F>>(
&self,
cs: &mut CS,
cs: &CS,
preimage: Vec<F>,
hash_circuit_witness_cache: &mut HashCircuitWitnessCache<F>,
) {
Expand Down Expand Up @@ -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: ConstraintSystem<F>>(
cs: &mut CS,
cs: &CS,
names_and_ptrs: &[(ContName, (Option<ContPtr<F>>, Option<Vec<F>>))],
hash_constants: HashConst<'_, F>,
) -> Option<HashCircuitWitnessCache<F>> {
Expand Down
2 changes: 1 addition & 1 deletion src/cli/repl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ impl Repl<F> {

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));
Expand Down
3 changes: 1 addition & 2 deletions src/eval/reduction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1150,8 +1150,7 @@ fn apply_continuation<F: LurkField>(
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)
Expand Down
2 changes: 1 addition & 1 deletion src/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ impl<F: LurkField> Hash for FWrap<F> {

impl<F: LurkField> PartialOrd for FWrap<F> {
fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
(self.0.to_repr().as_ref()).partial_cmp(other.0.to_repr().as_ref())
Some(self.cmp(other))
}
}

Expand Down
38 changes: 4 additions & 34 deletions src/hash_witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,28 +296,6 @@ impl<F: LurkField> ConsStub<F> {
}
}

pub fn car_cdr_mut(
&mut self,
s: &mut Store<F>,
cons: &Ptr<F>,
) -> Result<(Ptr<F>, Ptr<F>), 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<F>, car: Ptr<F>, cdr: Ptr<F>) -> Ptr<F> {
match self {
Self::Dummy => {
Expand Down Expand Up @@ -572,10 +550,10 @@ impl<F: LurkField> ConsWitness<F> {
pub fn car_cdr_mut_named(
&mut self,
name: ConsName,
store: &mut Store<F>,
store: &Store<F>,
cons: &Ptr<F>,
) -> Result<(Ptr<F>, Ptr<F>), 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(
Expand Down Expand Up @@ -610,17 +588,13 @@ impl<F: LurkField> Cons<F> {
fn get_car_cdr(s: &Store<F>, cons: &Ptr<F>) -> Result<(Ptr<F>, Ptr<F>), store::Error> {
s.car_cdr(cons)
}

fn get_car_cdr_mut(s: &mut Store<F>, cons: &Ptr<F>) -> Result<(Ptr<F>, Ptr<F>), store::Error> {
s.car_cdr(cons)
}
}

impl<F: LurkField> ContWitness<F> {
pub fn fetch_named_cont(
&mut self,
name: ContName,
store: &mut Store<F>,
store: &Store<F>,
cont: &ContPtr<F>,
) -> Option<Continuation<F>> {
self.get_assigned_slot(name).fetch_cont(store, cont)
Expand All @@ -638,11 +612,7 @@ impl<F: LurkField> ContWitness<F> {
}

impl<F: LurkField> ContStub<F> {
pub fn fetch_cont(
&mut self,
store: &mut Store<F>,
cont: &ContPtr<F>,
) -> Option<Continuation<F>> {
pub fn fetch_cont(&mut self, store: &Store<F>, cont: &ContPtr<F>) -> Option<Continuation<F>> {
match self {
Self::Dummy => {
let continuation = store.fetch_cont(cont)?;
Expand Down
2 changes: 1 addition & 1 deletion src/lem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ mod tests {
let log_fmt = |_: usize, _: &[Ptr<Fr>], _: &[Ptr<Fr>], _: &Store<Fr>| 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)
Expand Down
2 changes: 1 addition & 1 deletion src/parser/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/proof/groth16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ impl<C: Coprocessor<Scalar>> Groth16Prover<Bls12, C, Scalar> {
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();

Expand Down
2 changes: 1 addition & 1 deletion src/proof/nova.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ where
&'a self,
pp: &'a PublicParams<'_, F, C>,
frames: &[Frame<IO<F>, Witness<F>, F, C>],
store: &'a mut Store<F>,
store: &'a Store<F>,
lang: Arc<Lang<F, C>>,
) -> Result<(Proof<'_, F, C>, Vec<F>, Vec<F>, usize), ProofError> {
let z0 = frames[0].input.to_vector(store)?;
Expand Down
2 changes: 0 additions & 2 deletions src/proof/supernova.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ where
<<G1<F> as Group>::Scalar as PrimeField>::Repr: Abomonation,
<<G2<F> as Group>::Scalar as PrimeField>::Repr: Abomonation,
<F as PrimeField>::Repr: Abomonation,
C: Coprocessor<F>,
F: CurveCycleEquipped + LurkField,
<<<F as CurveCycleEquipped>::G2 as Group>::Scalar as PrimeField>::Repr: Abomonation,
{
/// Proves the computation recursively, generating a recursive SNARK proof.
Expand Down
2 changes: 1 addition & 1 deletion src/public_parameters/mem_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl PublicParamMemCache {
// retrieve the per-Coproc public param table
let entry = mem_cache.entry::<PublicParamMap<F, C>>();
// 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) => {
Expand Down
4 changes: 1 addition & 3 deletions src/repl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ pub trait ReplTrait<F: LurkField, C: Coprocessor<F>> {
state: Rc<RefCell<State>>,
file_path: P,
) -> Result<()> {
let file_path = file_path;

let input = read_to_string(file_path)?;
eprintln!(
"Read from {}: {}",
Expand Down Expand Up @@ -324,7 +322,7 @@ pub fn run_repl<P: AsRef<Path>, F: LurkField, T: ReplTrait<F, C>, C: Coprocessor
}

impl<F: LurkField, C: Coprocessor<F>> ReplState<F, C> {
pub fn new(s: &mut Store<F>, limit: usize, command: Option<Command>, lang: Lang<F, C>) -> Self {
pub fn new(s: &Store<F>, limit: usize, command: Option<Command>, lang: Lang<F, C>) -> Self {
Self {
env: empty_sym_env(s),
limit,
Expand Down
8 changes: 4 additions & 4 deletions src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down
2 changes: 1 addition & 1 deletion src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ impl<F: LurkField> Store<F> {
// fetch a symbol cons or keyword cons
pub fn fetch_symcons(&self, ptr: &Ptr<F>) -> Option<(Ptr<F>, Ptr<F>)> {
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))
}
Expand Down
2 changes: 1 addition & 1 deletion src/z_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Loading

0 comments on commit f2e247d

Please sign in to comment.