Skip to content

Commit

Permalink
chore: clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
huitseeker committed Sep 19, 2023
1 parent bb644a8 commit 075e89e
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 63 deletions.
8 changes: 4 additions & 4 deletions benches/end2end.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,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 @@ -350,7 +350,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 @@ -394,7 +394,7 @@ fn verify_benchmark(c: &mut Criterion) {
.get_evaluation_frames(ptr, empty_sym_env(&store), &mut store, limit, &lang_pallas)
.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 @@ -446,7 +446,7 @@ fn verify_compressed_benchmark(c: &mut Criterion) {
.get_evaluation_frames(ptr, empty_sym_env(&store), &mut store, limit, &lang_pallas)
.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
8 changes: 4 additions & 4 deletions fcomm/src/lib.rs
Original file line number Diff line number Diff line change
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
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
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/proof/nova.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ where
&'a self,
pp: &'a PublicParams<'_, F, C>,
frames: &[Frame<IO<F>, Witness<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: 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
15 changes: 7 additions & 8 deletions src/z_data/z_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,24 +54,23 @@ impl<E: Tag + Display, F: LurkField> Display for ZPtr<E, F> {

impl<E: Tag, F: LurkField> PartialOrd for ZPtr<E, F> {
fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
Some(self.cmp(other))
}
}

impl<E: Tag, F: LurkField> Ord for ZPtr<E, F> {
fn cmp(&self, other: &Self) -> core::cmp::Ordering {
(
self.0.to_field_bytes::<F>().as_ref(),
self.1.to_repr().as_ref(),
)
.partial_cmp(&(
.cmp(&(
other.0.to_field_bytes::<F>().as_ref(),
other.1.to_repr().as_ref(),
))
}
}

impl<E: Tag, F: LurkField> Ord for ZPtr<E, F> {
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<E: Tag, F: LurkField> Hash for ZPtr<E, F> {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
Expand Down

0 comments on commit 075e89e

Please sign in to comment.