Skip to content

Commit

Permalink
Merge pull request #13 from o1-labs/rb/wasm-clippify
Browse files Browse the repository at this point in the history
wasm: clippy-suggested fixes
  • Loading branch information
mitschabaude committed Jun 26, 2023
2 parents 5837695 + e31c79a commit 14d97c3
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 35 deletions.
4 changes: 2 additions & 2 deletions kimchi/wasm/src/arkworks/bigint_256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ pub fn caml_bigint_256_of_decimal_string(s: String) -> WasmBigInteger256 {

#[wasm_bindgen]
pub fn caml_bigint_256_num_limbs() -> i32 {
return BIGINT256_NUM_LIMBS.try_into().unwrap();
BIGINT256_NUM_LIMBS
}

#[wasm_bindgen]
pub fn caml_bigint_256_bytes_per_limb() -> i32 {
return BIGINT256_LIMB_BYTES.try_into().unwrap();
BIGINT256_LIMB_BYTES
}

#[wasm_bindgen]
Expand Down
4 changes: 2 additions & 2 deletions kimchi/wasm/src/arkworks/pasta_fp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ pub fn caml_pasta_fp_div(x: WasmPastaFp, y: WasmPastaFp) -> WasmPastaFp {

#[wasm_bindgen]
pub fn caml_pasta_fp_inv(x: WasmPastaFp) -> Option<WasmPastaFp> {
x.0.inverse().map(|x| WasmPastaFp(x))
x.0.inverse().map(WasmPastaFp)
}

#[wasm_bindgen]
Expand All @@ -134,7 +134,7 @@ pub fn caml_pasta_fp_is_square(x: WasmPastaFp) -> bool {

#[wasm_bindgen]
pub fn caml_pasta_fp_sqrt(x: WasmPastaFp) -> Option<WasmPastaFp> {
x.0.sqrt().map(|x| WasmPastaFp(x))
x.0.sqrt().map(WasmPastaFp)
}

#[wasm_bindgen]
Expand Down
4 changes: 2 additions & 2 deletions kimchi/wasm/src/arkworks/pasta_fq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ pub fn caml_pasta_fq_div(x: WasmPastaFq, y: WasmPastaFq) -> WasmPastaFq {

#[wasm_bindgen]
pub fn caml_pasta_fq_inv(x: WasmPastaFq) -> Option<WasmPastaFq> {
x.0.inverse().map(|x| WasmPastaFq(x))
x.0.inverse().map(WasmPastaFq)
}

#[wasm_bindgen]
Expand All @@ -134,7 +134,7 @@ pub fn caml_pasta_fq_is_square(x: WasmPastaFq) -> bool {

#[wasm_bindgen]
pub fn caml_pasta_fq_sqrt(x: WasmPastaFq) -> Option<WasmPastaFq> {
x.0.sqrt().map(|x| WasmPastaFq(x))
x.0.sqrt().map(WasmPastaFq)
}

#[wasm_bindgen]
Expand Down
3 changes: 2 additions & 1 deletion kimchi/wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ extern "C" {

#[wasm_bindgen]
pub fn greet(name: &str) {
alert(&format!("Hello, {}!", name));
alert(&format!("Hello, {name}!"));
}

#[wasm_bindgen]
Expand Down Expand Up @@ -59,6 +59,7 @@ pub fn set_u32_ptr(ptr: *mut u32, arg: u32) {
}
}

#[allow(unreachable_code)]
#[wasm_bindgen]
pub fn wait_until_non_zero(ptr: *const u32) -> u32 {
// The rust docs explicitly forbid using this for cross-thread syncronization. Oh well, we
Expand Down
1 change: 1 addition & 0 deletions kimchi/wasm/src/oracles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ macro_rules! impl_oracles {

#[wasm_bindgen]
impl [<Wasm $field_name:camel RandomOracles>] {
#[allow(clippy::too_many_arguments)]
#[wasm_bindgen(constructor)]
pub fn new(
joint_combiner_chal: Option<$WasmF>,
Expand Down
13 changes: 6 additions & 7 deletions kimchi/wasm/src/pasta_fp_plonk_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,13 @@ pub fn caml_pasta_fp_plonk_index_read(

// optional offset in file
if let Some(offset) = offset {
r.seek(Start(offset as u64)).map_err(|err| {
JsValue::from_str(&format!("caml_pasta_fp_plonk_index_read: {}", err))
})?;
r.seek(Start(offset as u64))
.map_err(|err| JsValue::from_str(&format!("caml_pasta_fp_plonk_index_read: {err}")))?;
}

// deserialize the index
let mut t = ProverIndex::<GAffine>::deserialize(&mut rmp_serde::Deserializer::new(r))
.map_err(|err| JsValue::from_str(&format!("caml_pasta_fp_plonk_index_read: {}", err)))?;
.map_err(|err| JsValue::from_str(&format!("caml_pasta_fp_plonk_index_read: {err}")))?;
t.srs = srs.0.clone();
let (linearization, powers_of_alpha) = expr_linearization(Some(&t.cs.feature_flags), true);
t.linearization = linearization;
Expand All @@ -152,7 +151,7 @@ pub fn caml_pasta_fp_plonk_index_write(
index
.0
.serialize(&mut rmp_serde::Serializer::new(w))
.map_err(|e| JsValue::from_str(&format!("caml_pasta_fp_plonk_index_read: {}", e)))
.map_err(|e| JsValue::from_str(&format!("caml_pasta_fp_plonk_index_read: {e}")))
}

#[wasm_bindgen]
Expand All @@ -165,14 +164,14 @@ pub fn caml_pasta_fp_plonk_index_serialize(index: &WasmPastaFpPlonkIndex) -> Str

fn format_field(f: &Fp) -> String {
// TODO this could be much nicer, should end up as "1", "-1", "0" etc
format!("{}", f)
format!("{f}")
}

pub fn format_circuit_gate(i: usize, gate: &CircuitGate<Fp>) -> String {
let coeffs = gate
.coeffs
.iter()
.map(|coeff: &Fp| format_field(coeff))
.map(format_field)
.collect::<Vec<_>>()
.join("\n");
let wires = gate
Expand Down
9 changes: 4 additions & 5 deletions kimchi/wasm/src/pasta_fq_plonk_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,13 @@ pub fn caml_pasta_fq_plonk_index_read(

// optional offset in file
if let Some(offset) = offset {
r.seek(Start(offset as u64)).map_err(|err| {
JsValue::from_str(&format!("caml_pasta_fq_plonk_index_read: {}", err))
})?;
r.seek(Start(offset as u64))
.map_err(|err| JsValue::from_str(&format!("caml_pasta_fq_plonk_index_read: {err}")))?;
}

// deserialize the index
let mut t = ProverIndex::<GAffine>::deserialize(&mut rmp_serde::Deserializer::new(r))
.map_err(|err| JsValue::from_str(&format!("caml_pasta_fq_plonk_index_read: {}", err)))?;
.map_err(|err| JsValue::from_str(&format!("caml_pasta_fq_plonk_index_read: {err}")))?;
t.srs = srs.0.clone();
let (linearization, powers_of_alpha) = expr_linearization(Some(&t.cs.feature_flags), true);
t.linearization = linearization;
Expand All @@ -153,7 +152,7 @@ pub fn caml_pasta_fq_plonk_index_write(
index
.0
.serialize(&mut rmp_serde::Serializer::new(w))
.map_err(|e| JsValue::from_str(&format!("caml_pasta_fq_plonk_index_read: {}", e)))
.map_err(|e| JsValue::from_str(&format!("caml_pasta_fq_plonk_index_read: {e}")))
}

#[wasm_bindgen]
Expand Down
2 changes: 1 addition & 1 deletion kimchi/wasm/src/urs_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub fn batch_dlog_accumulator_generate<G: CommitmentCurve>(
.into_par_iter()
.chunks(rounds)
.map(|chals| {
let chals: Vec<G::ScalarField> = chals.into_iter().map(|x| *x).collect();
let chals: Vec<G::ScalarField> = chals.into_iter().copied().collect();
let scalars: Vec<_> = b_poly_coefficients(&chals)
.into_iter()
.map(|x| x.into_repr())
Expand Down
2 changes: 1 addition & 1 deletion kimchi/wasm/src/wasm_flat_vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl<'a, T> std::iter::IntoIterator for &'a WasmFlatVector<T> {
type Item = <&'a Vec<T> as std::iter::IntoIterator>::Item;
type IntoIter = <&'a Vec<T> as std::iter::IntoIterator>::IntoIter;
fn into_iter(self) -> Self::IntoIter {
(&self.0).into_iter()
self.0.iter()
}
}

Expand Down
26 changes: 13 additions & 13 deletions kimchi/wasm/src/wasm_ocaml_serde/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl<'de> de::MapAccess<'de> for ObjectAccess {
Some(field) => {
self.next_value = Some(Deserializer::from(self.data.get(self.idx)));
self.idx += 1;
return Ok(Some(seed.deserialize(str_deserializer(field))?));
Ok(Some(seed.deserialize(str_deserializer(field))?))
}
}
}
Expand Down Expand Up @@ -91,11 +91,11 @@ impl Deserializer {
fn as_bytes(&self) -> Option<Vec<u8>> {
if let Some(v) = self.0.dyn_ref::<Uint8Array>() {
Some(v.to_vec())
} else if let Some(v) = self.0.dyn_ref::<ArrayBuffer>() {
/* We can hit this case when the values have come from the non-serde conversions. */
Some(Uint8Array::new(v).to_vec())
} else {
None
/* We can hit this case when the values have come from the non-serde conversions. */
self.0
.dyn_ref::<ArrayBuffer>()
.map(|v| Uint8Array::new(v).to_vec())
}
}
}
Expand Down Expand Up @@ -172,19 +172,19 @@ impl<'de> de::Deserializer<'de> for Deserializer {
visitor.visit_u32(self.0.unchecked_into::<Number>().as_f64().unwrap() as u32)
}

fn deserialize_i64<V: de::Visitor<'de>>(self, visitor: V) -> Result<V::Value> {
fn deserialize_i64<V: de::Visitor<'de>>(self, _visitor: V) -> Result<V::Value> {
Err(Error::custom("Deserializing i64 is not implemented"))
}

fn deserialize_u64<V: de::Visitor<'de>>(self, visitor: V) -> Result<V::Value> {
fn deserialize_u64<V: de::Visitor<'de>>(self, _visitor: V) -> Result<V::Value> {
Err(Error::custom("Deserializing u64 is not implemented"))
}

fn deserialize_i128<V: de::Visitor<'de>>(self, visitor: V) -> Result<V::Value> {
fn deserialize_i128<V: de::Visitor<'de>>(self, _visitor: V) -> Result<V::Value> {
Err(Error::custom("Deserializing i128 is not implemented"))
}

fn deserialize_u128<V: de::Visitor<'de>>(self, visitor: V) -> Result<V::Value> {
fn deserialize_u128<V: de::Visitor<'de>>(self, _visitor: V) -> Result<V::Value> {
Err(Error::custom("Deserializing u128 is not implemented"))
}

Expand All @@ -205,7 +205,7 @@ impl<'de> de::Deserializer<'de> for Deserializer {
fn deserialize_newtype_struct<V: de::Visitor<'de>>(
self,
_name: &'static str,
visitor: V,
_visitor: V,
) -> Result<V::Value> {
Err(Error::custom(
"Deserializing newtype structus is not implemented",
Expand All @@ -226,15 +226,15 @@ impl<'de> de::Deserializer<'de> for Deserializer {
fn deserialize_tuple_struct<V: de::Visitor<'de>>(
self,
_name: &'static str,
len: usize,
visitor: V,
_len: usize,
_visitor: V,
) -> Result<V::Value> {
Err(Error::custom(
"Deserializing tuple structs is not implemented",
))
}

fn deserialize_map<V: de::Visitor<'de>>(self, visitor: V) -> Result<V::Value> {
fn deserialize_map<V: de::Visitor<'de>>(self, _visitor: V) -> Result<V::Value> {
Err(Error::custom("Deserializing maps is not implemented"))
}

Expand Down
2 changes: 1 addition & 1 deletion kimchi/wasm/src/wasm_vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl<'a, T> std::iter::IntoIterator for &'a WasmVector<T> {
type Item = <&'a Vec<T> as std::iter::IntoIterator>::Item;
type IntoIter = <&'a Vec<T> as std::iter::IntoIterator>::IntoIter;
fn into_iter(self) -> Self::IntoIter {
(&self.0).into_iter()
self.0.iter()
}
}

Expand Down

0 comments on commit 14d97c3

Please sign in to comment.