Skip to content

Commit 1aa8ed5

Browse files
authored
rm more useless generics (#878)
* rm more useless generics * rm useless code
1 parent 93fc31e commit 1aa8ed5

File tree

18 files changed

+38
-46
lines changed

18 files changed

+38
-46
lines changed

curves/curve-constraint-tests/src/lib.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ pub mod fields {
205205
AllocationMode::Constant,
206206
];
207207
for &mode in &modes {
208-
let cs = ConstraintSystem::<ConstraintF>::new_ref();
208+
let cs = ConstraintSystem::new_ref();
209209
let mut rng = test_rng();
210210
for i in 0..=maxpower {
211211
let mut a = F::rand(&mut rng);
@@ -246,7 +246,7 @@ pub mod curves {
246246
AllocationMode::Constant,
247247
];
248248
for &mode in &modes {
249-
let cs = ConstraintSystem::<ConstraintF>::new_ref();
249+
let cs = ConstraintSystem::new_ref();
250250

251251
let mut rng = test_rng();
252252
let a_native = C::rand(&mut rng);
@@ -539,8 +539,6 @@ pub mod pairing {
539539
use ark_relations::r1cs::{ConstraintSystem, SynthesisError};
540540
use ark_std::{test_rng, vec::*, UniformRand};
541541

542-
type BasePrimeField<P> = <<P as Pairing>::BaseField as Field>::BasePrimeField;
543-
544542
#[allow(dead_code)]
545543
pub fn bilinearity_test<E: Pairing, P: PairingVar<E>>() -> Result<(), SynthesisError>
546544
where
@@ -554,7 +552,7 @@ pub mod pairing {
554552
AllocationMode::Constant,
555553
];
556554
for &mode in &modes {
557-
let cs = ConstraintSystem::<BasePrimeField<E>>::new_ref();
555+
let cs = ConstraintSystem::new_ref();
558556

559557
let mut rng = test_rng();
560558
let a = E::G1::rand(&mut rng);

curves/mnt6_298/src/curves/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ pub type MNT6_298 = MNT6<Config>;
2222
pub struct Config;
2323

2424
impl MNT6Config for Config {
25-
const TWIST: Fp3<Self::Fp3Config> = Fp3::<Self::Fp3Config>::new(Fq::ZERO, Fq::ONE, Fq::ZERO);
26-
const TWIST_COEFF_A: Fp3<Self::Fp3Config> =
27-
Fp3::<Self::Fp3Config>::new(Fq::ZERO, Fq::ZERO, g1::Config::COEFF_A);
25+
const TWIST: Fp3<Self::Fp3Config> = Fp3::new(Fq::ZERO, Fq::ONE, Fq::ZERO);
26+
const TWIST_COEFF_A: Fp3<Self::Fp3Config> = Fp3::new(Fq::ZERO, Fq::ZERO, g1::Config::COEFF_A);
2827

2928
// https://github.com/o1-labs/snarky/blob/9c21ab2bb23874604640740d646a932e813432c3/snarkette/mnt6_80.ml#L118
3029
const ATE_LOOP_COUNT: &'static [i8] = &[

ec/src/hashing/curve_maps/elligator2.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ mod test {
226226
const COEFF_D: F101 = MontFp!("12");
227227

228228
const GENERATOR: Affine<TestElligator2MapToCurveConfig> =
229-
Affine::<TestElligator2MapToCurveConfig>::new_unchecked(MontFp!("23"), MontFp!("24"));
229+
Affine::new_unchecked(MontFp!("23"), MontFp!("24"));
230230

231231
type MontCurveConfig = TestElligator2MapToCurveConfig;
232232
}
@@ -286,10 +286,7 @@ mod test {
286286
// map is not constant on that set.
287287
for current_field_element in 0..101 {
288288
map_range.push(
289-
Elligator2Map::<TestElligator2MapToCurveConfig>::map_to_curve(F101::from(
290-
current_field_element as u64,
291-
))
292-
.unwrap(),
289+
Elligator2Map::map_to_curve(F101::from(current_field_element as u64)).unwrap(),
293290
);
294291
}
295292

ec/src/hashing/curve_maps/swu.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ mod test {
270270
let mut map_range: Vec<Affine<TestSWUMapToCurveConfig>> = vec![];
271271
for current_field_element in 0..127 {
272272
let element = F127::from(current_field_element as u64);
273-
map_range.push(SWUMap::<TestSWUMapToCurveConfig>::map_to_curve(element).unwrap());
273+
map_range.push(SWUMap::map_to_curve(element).unwrap());
274274
}
275275

276276
let mut counts =

ec/src/hashing/curve_maps/wb.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ impl<P: WBConfig> MapToCurve<Projective<P>> for WBMap<P> {
105105
element: <Affine<P> as AffineRepr>::BaseField,
106106
) -> Result<Affine<P>, HashToCurveError> {
107107
// first we need to map the field point to the isogenous curve
108-
let point_on_isogenious_curve = SWUMap::<P::IsogenousCurve>::map_to_curve(element).unwrap();
108+
let point_on_isogenious_curve = SWUMap::map_to_curve(element).unwrap();
109109
P::ISOGENY_MAP.apply(point_on_isogenious_curve)
110110
}
111111
}

ec/src/models/mnt4/g2.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ impl<P: MNT4Config> From<G2Affine<P>> for G2Prepared<P> {
5252

5353
let neg_g = -g;
5454
for bit in P::ATE_LOOP_COUNT.iter().skip(1) {
55-
let (r2, coeff) = MNT4::<P>::doubling_for_flipped_miller_loop(&r);
55+
let (r2, coeff) = MNT4::doubling_for_flipped_miller_loop(&r);
5656
g_prep.double_coefficients.push(coeff);
5757
r = r2;
5858

5959
let (r_temp, add_coeff) = match bit {
60-
1 => MNT4::<P>::mixed_addition_for_flipped_miller_loop(&g.x, &g.y, &r),
61-
-1 => MNT4::<P>::mixed_addition_for_flipped_miller_loop(&neg_g.x, &neg_g.y, &r),
60+
1 => MNT4::mixed_addition_for_flipped_miller_loop(&g.x, &g.y, &r),
61+
-1 => MNT4::mixed_addition_for_flipped_miller_loop(&neg_g.x, &neg_g.y, &r),
6262
0 => continue,
6363
_ => unreachable!(),
6464
};
@@ -74,7 +74,7 @@ impl<P: MNT4Config> From<G2Affine<P>> for G2Prepared<P> {
7474
let minus_r_affine_x = r.x * &rz2_inv;
7575
let minus_r_affine_y = -r.y * &rz3_inv;
7676

77-
let add_result = MNT4::<P>::mixed_addition_for_flipped_miller_loop(
77+
let add_result = MNT4::mixed_addition_for_flipped_miller_loop(
7878
&minus_r_affine_x,
7979
&minus_r_affine_y,
8080
&r,

ec/src/models/mnt4/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub trait MNT4Config: 'static + Sized {
5454
.map(|(a, b)| (a.into(), b.into()))
5555
.collect::<Vec<_>>();
5656
let result = ark_std::cfg_into_iter!(pairs)
57-
.map(|(a, b)| MNT4::<Self>::ate_miller_loop(&a, &b))
57+
.map(|(a, b)| MNT4::ate_miller_loop(&a, &b))
5858
.product();
5959
MillerLoopOutput(result)
6060
}

ec/src/models/mnt6/g2.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ impl<P: MNT6Config> From<G2Affine<P>> for G2Prepared<P> {
5252

5353
let neg_g = -g;
5454
for bit in P::ATE_LOOP_COUNT.iter().skip(1) {
55-
let (r2, coeff) = MNT6::<P>::doubling_for_flipped_miller_loop(&r);
55+
let (r2, coeff) = MNT6::doubling_for_flipped_miller_loop(&r);
5656
g_prep.double_coefficients.push(coeff);
5757
r = r2;
5858

5959
let (r_temp, add_coeff) = match bit {
60-
1 => MNT6::<P>::mixed_addition_for_flipper_miller_loop(&g.x, &g.y, &r),
61-
-1 => MNT6::<P>::mixed_addition_for_flipper_miller_loop(&neg_g.x, &neg_g.y, &r),
60+
1 => MNT6::mixed_addition_for_flipper_miller_loop(&g.x, &g.y, &r),
61+
-1 => MNT6::mixed_addition_for_flipper_miller_loop(&neg_g.x, &neg_g.y, &r),
6262
0 => continue,
6363
_ => unreachable!(),
6464
};
@@ -75,7 +75,7 @@ impl<P: MNT6Config> From<G2Affine<P>> for G2Prepared<P> {
7575
let minus_r_y = -r.y * &rz3_inv;
7676

7777
let add_result =
78-
MNT6::<P>::mixed_addition_for_flipper_miller_loop(&minus_r_x, &minus_r_y, &r);
78+
MNT6::mixed_addition_for_flipper_miller_loop(&minus_r_x, &minus_r_y, &r);
7979
g_prep.addition_coefficients.push(add_result.1);
8080
}
8181

ec/src/models/mnt6/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub trait MNT6Config: 'static + Sized {
5555
.map(|(a, b)| (a.into(), b.into()))
5656
.collect::<Vec<_>>();
5757
let result = ark_std::cfg_into_iter!(pairs)
58-
.map(|(a, b)| MNT6::<Self>::ate_miller_loop(&a, &b))
58+
.map(|(a, b)| MNT6::ate_miller_loop(&a, &b))
5959
.product();
6060
MillerLoopOutput(result)
6161
}

ec/src/scalar_mul/variable_base/stream_pippenger.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ impl<G: VariableBaseMSM> HashMapPippenger<G> {
7878
Self {
7979
buffer: HashMap::with_capacity_and_hasher(
8080
max_msm_buffer,
81-
core::hash::BuildHasherDefault::<DefaultHasher>::default(),
81+
core::hash::BuildHasherDefault::default(),
8282
),
8383
result: G::zero(),
8484
buf_size: max_msm_buffer,

ff/src/biginteger/mod.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl<const N: usize> CanonicalDeserialize for BigInt<N> {
6565
compress: Compress,
6666
validate: Validate,
6767
) -> Result<Self, SerializationError> {
68-
Ok(BigInt::<N>(<[u64; N]>::deserialize_with_mode(
68+
Ok(BigInt(<[u64; N]>::deserialize_with_mode(
6969
reader, compress, validate,
7070
)?))
7171
}
@@ -279,15 +279,14 @@ impl<const N: usize> BigInt<N> {
279279
/// Computes the Montgomery R constant modulo `self`.
280280
#[doc(hidden)]
281281
pub const fn montgomery_r(&self) -> Self {
282-
let two_pow_n_times_64 = crate::const_helpers::RBuffer::<N>([0u64; N], 1);
282+
let two_pow_n_times_64 = crate::const_helpers::RBuffer([0u64; N], 1);
283283
const_modulo!(two_pow_n_times_64, self)
284284
}
285285

286286
/// Computes the Montgomery R2 constant modulo `self`.
287287
#[doc(hidden)]
288288
pub const fn montgomery_r2(&self) -> Self {
289-
let two_pow_n_times_64_square =
290-
crate::const_helpers::R2Buffer::<N>([0u64; N], [0u64; N], 1);
289+
let two_pow_n_times_64_square = crate::const_helpers::R2Buffer([0u64; N], [0u64; N], 1);
291290
const_modulo!(two_pow_n_times_64_square, self)
292291
}
293292
}
@@ -386,7 +385,7 @@ impl<const N: usize> BigInteger for BigInt<N> {
386385
return (zero, zero);
387386
}
388387

389-
let mut r = crate::const_helpers::MulBuffer::<N>::zeroed();
388+
let mut r = crate::const_helpers::MulBuffer::zeroed();
390389

391390
let mut carry = 0;
392391

@@ -1231,7 +1230,7 @@ pub trait BigInteger:
12311230
/// assert_eq!(arr, vec);
12321231
/// ```
12331232
fn to_bits_be(&self) -> Vec<bool> {
1234-
BitIteratorBE::new(self).collect::<Vec<_>>()
1233+
BitIteratorBE::new(self).collect()
12351234
}
12361235

12371236
/// Returns the bit representation in a little endian boolean array,
@@ -1248,7 +1247,7 @@ pub trait BigInteger:
12481247
/// assert_eq!(arr, vec);
12491248
/// ```
12501249
fn to_bits_le(&self) -> Vec<bool> {
1251-
BitIteratorLE::new(self).collect::<Vec<_>>()
1250+
BitIteratorLE::new(self).collect()
12521251
}
12531252

12541253
/// Returns the byte representation in a big endian byte array,

ff/src/fields/field_hashers/expander/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub struct TestExpander {
3434
#[test]
3535
fn expander() {
3636
let args = Arguments::from_args();
37-
let mut tests = Vec::<Trial>::new();
37+
let mut tests = Vec::new();
3838

3939
for filename in read_dir("./src/fields/field_hashers/expander/testdata").unwrap() {
4040
let ff = filename.unwrap();

ff/src/fields/field_hashers/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ impl<F: Field, H: FixedOutputReset + Default + Clone, const SEC_PARAM: usize> Ha
8080
};
8181
F::from_base_prime_field_elems((0..m).map(base_prime_field_elem)).unwrap()
8282
};
83-
ark_std::array::from_fn::<F, N, _>(cb)
83+
ark_std::array::from_fn(cb)
8484
}
8585
}
8686

ff/src/fields/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,15 +450,15 @@ mod no_std_tests {
450450

451451
#[test]
452452
fn test_batch_inversion() {
453-
let mut random_coeffs = Vec::<Fr>::new();
453+
let mut random_coeffs = Vec::new();
454454
let vec_size = 1000;
455455

456456
for _ in 0..=vec_size {
457457
random_coeffs.push(Fr::rand(&mut test_rng()));
458458
}
459459

460460
let mut random_coeffs_inv = random_coeffs.clone();
461-
batch_inversion::<Fr>(&mut random_coeffs_inv);
461+
batch_inversion(&mut random_coeffs_inv);
462462
for i in 0..=vec_size {
463463
assert_eq!(random_coeffs_inv[i] * random_coeffs[i], Fr::one());
464464
}

ff/src/fields/models/cubic_extension.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ mod cube_ext_tests {
701701
if d == ext_degree {
702702
continue;
703703
}
704-
let mut random_coeffs = Vec::<Fq>::new();
704+
let mut random_coeffs = Vec::new();
705705
for _ in 0..d {
706706
random_coeffs.push(Fq::rand(&mut test_rng()));
707707
}
@@ -712,7 +712,7 @@ mod cube_ext_tests {
712712
// We test consistency against Fq2::new
713713
let number_of_tests = 10;
714714
for _ in 0..number_of_tests {
715-
let mut random_coeffs = Vec::<Fq>::new();
715+
let mut random_coeffs = Vec::new();
716716
for _ in 0..ext_degree {
717717
random_coeffs.push(Fq::rand(&mut test_rng()));
718718
}

ff/src/fields/models/fp/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,7 @@ impl<P: FpConfig<N>, const N: usize> zeroize::Zeroize for Fp<P, N> {
990990
impl<P: FpConfig<N>, const N: usize> From<num_bigint::BigUint> for Fp<P, N> {
991991
#[inline]
992992
fn from(val: num_bigint::BigUint) -> Fp<P, N> {
993-
Fp::<P, N>::from_le_bytes_mod_order(&val.to_bytes_le())
993+
Fp::from_le_bytes_mod_order(&val.to_bytes_le())
994994
}
995995
}
996996

ff/src/fields/models/fp/montgomery_backend.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,14 @@ pub trait MontConfig<const N: usize>: 'static + Sync + Send + Sized {
7575
/// Precomputed material for use when computing square roots.
7676
/// The default is to use the standard Tonelli-Shanks algorithm.
7777
const SQRT_PRECOMP: Option<SqrtPrecomputation<Fp<MontBackend<Self, N>, N>>> =
78-
sqrt_precomputation::<N, Self>();
78+
sqrt_precomputation();
7979

8080
/// (MODULUS + 1) / 4 when MODULUS % 4 == 3. Used for square root precomputations.
8181
#[doc(hidden)]
8282
const MODULUS_PLUS_ONE_DIV_FOUR: Option<BigInt<N>> = {
8383
match Self::MODULUS.mod_4() == 3 {
8484
true => {
85-
let (modulus_plus_one, carry) =
86-
Self::MODULUS.const_add_with_carry(&BigInt::<N>::one());
85+
let (modulus_plus_one, carry) = Self::MODULUS.const_add_with_carry(&BigInt::one());
8786
let mut result = modulus_plus_one.divide_by_2_round_down();
8887
// Since modulus_plus_one is even, dividing by 2 results in a MSB of 0.
8988
// Thus we can set MSB to `carry` to get the correct result of (MODULUS + 1) // 2:
@@ -727,7 +726,7 @@ impl<T: MontConfig<N>, const N: usize> Fp<MontBackend<T, N>, N> {
727726
/// of this method
728727
#[doc(hidden)]
729728
pub const fn from_sign_and_limbs(is_positive: bool, limbs: &[u64]) -> Self {
730-
let mut repr = BigInt::<N>([0; N]);
729+
let mut repr = BigInt([0; N]);
731730
assert!(limbs.len() <= N);
732731
crate::const_for!((i in 0..(limbs.len())) {
733732
repr.0[i] = limbs[i];

ff/src/fields/models/quadratic_extension.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ mod quad_ext_tests {
786786
if d == ext_degree {
787787
continue;
788788
}
789-
let mut random_coeffs = Vec::<Fq>::new();
789+
let mut random_coeffs = Vec::new();
790790
for _ in 0..d {
791791
random_coeffs.push(Fq::rand(&mut test_rng()));
792792
}
@@ -797,7 +797,7 @@ mod quad_ext_tests {
797797
// We test consistency against Fq2::new
798798
let number_of_tests = 10;
799799
for _ in 0..number_of_tests {
800-
let mut random_coeffs = Vec::<Fq>::new();
800+
let mut random_coeffs = Vec::new();
801801
for _ in 0..ext_degree {
802802
random_coeffs.push(Fq::rand(&mut test_rng()));
803803
}

0 commit comments

Comments
 (0)