diff --git a/crates/prover/Cargo.toml b/crates/prover/Cargo.toml index 508c86e18..a9b80e9e4 100644 --- a/crates/prover/Cargo.toml +++ b/crates/prover/Cargo.toml @@ -56,6 +56,9 @@ nonstandard-style = "deny" rust-2018-idioms = "deny" unused = "deny" +[lints.clippy] +missing_const_for_fn = "warn" + [package.metadata.cargo-machete] ignored = ["downcast-rs"] diff --git a/crates/prover/src/core/air/accumulation.rs b/crates/prover/src/core/air/accumulation.rs index 2e7010ae6..f958f2029 100644 --- a/crates/prover/src/core/air/accumulation.rs +++ b/crates/prover/src/core/air/accumulation.rs @@ -39,7 +39,7 @@ impl PointEvaluationAccumulator { self.accumulation = self.accumulation * self.random_coeff + evaluation; } - pub fn finalize(self) -> SecureField { + pub const fn finalize(self) -> SecureField { self.accumulation } } diff --git a/crates/prover/src/core/backend/simd/cm31.rs b/crates/prover/src/core/backend/simd/cm31.rs index 31aba0a44..2155e8ff1 100644 --- a/crates/prover/src/core/backend/simd/cm31.rs +++ b/crates/prover/src/core/backend/simd/cm31.rs @@ -19,12 +19,12 @@ impl PackedCM31 { } /// Returns all `a` values such that each vector element is represented as `a + bi`. - pub fn a(&self) -> PackedM31 { + pub const fn a(&self) -> PackedM31 { self.0[0] } /// Returns all `b` values such that each vector element is represented as `a + bi`. - pub fn b(&self) -> PackedM31 { + pub const fn b(&self) -> PackedM31 { self.0[1] } diff --git a/crates/prover/src/core/backend/simd/column.rs b/crates/prover/src/core/backend/simd/column.rs index 07d7463ee..dd5578c0e 100644 --- a/crates/prover/src/core/backend/simd/column.rs +++ b/crates/prover/src/core/backend/simd/column.rs @@ -463,7 +463,7 @@ impl VeryPackedBaseColumn { /// # Safety /// /// The resulting pointer does not update the underlying `data`'s length. - pub unsafe fn transform_under_ref(value: &BaseColumn) -> &Self { + pub const unsafe fn transform_under_ref(value: &BaseColumn) -> &Self { &*(std::ptr::addr_of!(*value) as *const VeryPackedBaseColumn) } diff --git a/crates/prover/src/core/backend/simd/fft/mod.rs b/crates/prover/src/core/backend/simd/fft/mod.rs index ba091b145..b3ea4d700 100644 --- a/crates/prover/src/core/backend/simd/fft/mod.rs +++ b/crates/prover/src/core/backend/simd/fft/mod.rs @@ -97,7 +97,7 @@ pub fn compute_first_twiddles(twiddle1_dbl: u32x8) -> (u32x16, u32x16) { } #[inline] -unsafe fn load(mem_addr: *const u32) -> u32x16 { +const unsafe fn load(mem_addr: *const u32) -> u32x16 { std::ptr::read(mem_addr as *const u32x16) } diff --git a/crates/prover/src/core/backend/simd/m31.rs b/crates/prover/src/core/backend/simd/m31.rs index f6291626b..dbeec152f 100644 --- a/crates/prover/src/core/backend/simd/m31.rs +++ b/crates/prover/src/core/backend/simd/m31.rs @@ -78,14 +78,14 @@ impl PackedM31 { self + self } - pub fn into_simd(self) -> Simd { + pub const fn into_simd(self) -> Simd { self.0 } /// # Safety /// /// Vector elements must be in the range `[0, P]`. - pub unsafe fn from_simd_unchecked(v: Simd) -> Self { + pub const unsafe fn from_simd_unchecked(v: Simd) -> Self { Self(v) } @@ -93,7 +93,7 @@ impl PackedM31 { /// /// Behavior is undefined if the pointer does not have the same alignment as /// [`PackedM31`]. The loaded `u32` values must be in the range `[0, P]`. - pub unsafe fn load(mem_addr: *const u32) -> Self { + pub const unsafe fn load(mem_addr: *const u32) -> Self { Self(ptr::read(mem_addr as *const u32x16)) } diff --git a/crates/prover/src/core/backend/simd/qm31.rs b/crates/prover/src/core/backend/simd/qm31.rs index 13d03ce39..0876265d1 100644 --- a/crates/prover/src/core/backend/simd/qm31.rs +++ b/crates/prover/src/core/backend/simd/qm31.rs @@ -27,12 +27,12 @@ impl PackedQM31 { } /// Returns all `a` values such that each vector element is represented as `a + bu`. - pub fn a(&self) -> PackedCM31 { + pub const fn a(&self) -> PackedCM31 { self.0[0] } /// Returns all `b` values such that each vector element is represented as `a + bu`. - pub fn b(&self) -> PackedCM31 { + pub const fn b(&self) -> PackedCM31 { self.0[1] } @@ -79,14 +79,14 @@ impl PackedQM31 { /// Returns vectors `a, b, c, d` such that element `i` is represented as /// `QM31(a_i, b_i, c_i, d_i)`. - pub fn into_packed_m31s(self) -> [PackedM31; 4] { + pub const fn into_packed_m31s(self) -> [PackedM31; 4] { let Self([PackedCM31([a, b]), PackedCM31([c, d])]) = self; [a, b, c, d] } /// Creates an instance from vectors `a, b, c, d` such that element `i` /// is represented as `QM31(a_i, b_i, c_i, d_i)`. - pub fn from_packed_m31s([a, b, c, d]: [PackedM31; 4]) -> Self { + pub const fn from_packed_m31s([a, b, c, d]: [PackedM31; 4]) -> Self { Self([PackedCM31([a, b]), PackedCM31([c, d])]) } } diff --git a/crates/prover/src/core/backend/simd/utils.rs b/crates/prover/src/core/backend/simd/utils.rs index b5cb9e986..d5f53a22b 100644 --- a/crates/prover/src/core/backend/simd/utils.rs +++ b/crates/prover/src/core/backend/simd/utils.rs @@ -30,7 +30,7 @@ impl UnsafeMut { /// # Safety /// /// Returns a raw mutable pointer. - pub unsafe fn get(&self) -> *mut T { + pub const unsafe fn get(&self) -> *mut T { self.0 } } @@ -43,7 +43,7 @@ impl UnsafeConst { /// # Safety /// /// Returns a raw constant pointer. - pub unsafe fn get(&self) -> *const T { + pub const unsafe fn get(&self) -> *const T { self.0 } } diff --git a/crates/prover/src/core/channel/blake2s.rs b/crates/prover/src/core/channel/blake2s.rs index 86565658b..160d4754e 100644 --- a/crates/prover/src/core/channel/blake2s.rs +++ b/crates/prover/src/core/channel/blake2s.rs @@ -19,7 +19,7 @@ pub struct Blake2sChannel { } impl Blake2sChannel { - pub fn digest(&self) -> Blake2sHash { + pub const fn digest(&self) -> Blake2sHash { self.digest } pub fn update_digest(&mut self, new_digest: Blake2sHash) { diff --git a/crates/prover/src/core/channel/poseidon252.rs b/crates/prover/src/core/channel/poseidon252.rs index c0960fc3e..a02a82b1d 100644 --- a/crates/prover/src/core/channel/poseidon252.rs +++ b/crates/prover/src/core/channel/poseidon252.rs @@ -19,7 +19,7 @@ pub struct Poseidon252Channel { } impl Poseidon252Channel { - pub fn digest(&self) -> FieldElement252 { + pub const fn digest(&self) -> FieldElement252 { self.digest } pub fn update_digest(&mut self, new_digest: FieldElement252) { diff --git a/crates/prover/src/core/circle.rs b/crates/prover/src/core/circle.rs index 0fbdd64b4..7d77d52ff 100644 --- a/crates/prover/src/core/circle.rs +++ b/crates/prover/src/core/circle.rs @@ -223,15 +223,15 @@ pub const SECURE_FIELD_CIRCLE_ORDER: u128 = P4 - 1; pub struct CirclePointIndex(pub usize); impl CirclePointIndex { - pub fn zero() -> Self { + pub const fn zero() -> Self { Self(0) } - pub fn generator() -> Self { + pub const fn generator() -> Self { Self(1) } - pub fn reduce(self) -> Self { + pub const fn reduce(self) -> Self { Self(self.0 & ((1 << M31_CIRCLE_LOG_ORDER) - 1)) } @@ -343,16 +343,16 @@ impl Coset { } /// Returns the size of the coset. - pub fn size(&self) -> usize { + pub const fn size(&self) -> usize { 1 << self.log_size() } /// Returns the log size of the coset. - pub fn log_size(&self) -> u32 { + pub const fn log_size(&self) -> u32 { self.log_size } - pub fn iter(&self) -> CosetIterator> { + pub const fn iter(&self) -> CosetIterator> { CosetIterator { cur: self.initial, step: self.step, @@ -360,7 +360,7 @@ impl Coset { } } - pub fn iter_indices(&self) -> CosetIterator { + pub const fn iter_indices(&self) -> CosetIterator { CosetIterator { cur: self.initial_index, step: self.step_size, @@ -389,7 +389,7 @@ impl Coset { && *self == other.repeated_double(other.log_size - self.log_size) } - pub fn initial(&self) -> CirclePoint { + pub const fn initial(&self) -> CirclePoint { self.initial } diff --git a/crates/prover/src/core/fields/cm31.rs b/crates/prover/src/core/fields/cm31.rs index 6f1b6c2ef..e7f92dba7 100644 --- a/crates/prover/src/core/fields/cm31.rs +++ b/crates/prover/src/core/fields/cm31.rs @@ -24,7 +24,7 @@ impl CM31 { Self(M31::from_u32_unchecked(a), M31::from_u32_unchecked(b)) } - pub fn from_m31(a: M31, b: M31) -> CM31 { + pub const fn from_m31(a: M31, b: M31) -> CM31 { Self(a, b) } } diff --git a/crates/prover/src/core/fields/m31.rs b/crates/prover/src/core/fields/m31.rs index a7c3c57a2..7c28bf33a 100644 --- a/crates/prover/src/core/fields/m31.rs +++ b/crates/prover/src/core/fields/m31.rs @@ -55,7 +55,7 @@ impl M31 { /// let val = (P as u64).pow(2) - 19; /// assert_eq!(M31::reduce(val), M31::from(P - 19)); /// ``` - pub fn reduce(val: u64) -> Self { + pub const fn reduce(val: u64) -> Self { Self((((((val >> MODULUS_BITS) + val + 1) >> MODULUS_BITS) + val) & (P as u64)) as u32) } @@ -211,15 +211,15 @@ mod tests { use super::{M31, P}; use crate::core::fields::IntoSlice; - fn mul_p(a: u32, b: u32) -> u32 { + const fn mul_p(a: u32, b: u32) -> u32 { ((a as u64 * b as u64) % P as u64) as u32 } - fn add_p(a: u32, b: u32) -> u32 { + const fn add_p(a: u32, b: u32) -> u32 { (a + b) % P } - fn neg_p(a: u32) -> u32 { + const fn neg_p(a: u32) -> u32 { if a == 0 { 0 } else { diff --git a/crates/prover/src/core/fields/qm31.rs b/crates/prover/src/core/fields/qm31.rs index 6da19a3c0..41342ade6 100644 --- a/crates/prover/src/core/fields/qm31.rs +++ b/crates/prover/src/core/fields/qm31.rs @@ -32,15 +32,15 @@ impl QM31 { ) } - pub fn from_m31(a: M31, b: M31, c: M31, d: M31) -> Self { + pub const fn from_m31(a: M31, b: M31, c: M31, d: M31) -> Self { Self(CM31::from_m31(a, b), CM31::from_m31(c, d)) } - pub fn from_m31_array(array: [M31; SECURE_EXTENSION_DEGREE]) -> Self { + pub const fn from_m31_array(array: [M31; SECURE_EXTENSION_DEGREE]) -> Self { Self::from_m31(array[0], array[1], array[2], array[3]) } - pub fn to_m31_array(self) -> [M31; SECURE_EXTENSION_DEGREE] { + pub const fn to_m31_array(self) -> [M31; SECURE_EXTENSION_DEGREE] { [self.0 .0, self.0 .1, self.1 .0, self.1 .1] } diff --git a/crates/prover/src/core/fri.rs b/crates/prover/src/core/fri.rs index ce5d4bddb..9c60498aa 100644 --- a/crates/prover/src/core/fri.rs +++ b/crates/prover/src/core/fri.rs @@ -69,7 +69,7 @@ impl FriConfig { } } - fn last_layer_domain_size(&self) -> usize { + const fn last_layer_domain_size(&self) -> usize { 1 << (self.log_last_layer_degree_bound + self.log_blowup_factor) } } @@ -564,13 +564,13 @@ pub struct CirclePolyDegreeBound { } impl CirclePolyDegreeBound { - pub fn new(log_degree_bound: u32) -> Self { + pub const fn new(log_degree_bound: u32) -> Self { Self { log_degree_bound } } /// Maps a circle polynomial's degree bound to the degree bound of the univariate (line) /// polynomial it gets folded into. - fn fold_to_line(&self) -> LinePolyDegreeBound { + const fn fold_to_line(&self) -> LinePolyDegreeBound { LinePolyDegreeBound { log_degree_bound: self.log_degree_bound - CIRCLE_TO_LINE_FOLD_STEP, } @@ -596,7 +596,7 @@ struct LinePolyDegreeBound { impl LinePolyDegreeBound { /// Returns [None] if the unfolded degree bound is smaller than the folding factor. - fn fold(self, n_folds: u32) -> Option { + const fn fold(self, n_folds: u32) -> Option { if self.log_degree_bound < n_folds { return None; } diff --git a/crates/prover/src/core/lookups/utils.rs b/crates/prover/src/core/lookups/utils.rs index 035579e5f..d31bf8a33 100644 --- a/crates/prover/src/core/lookups/utils.rs +++ b/crates/prover/src/core/lookups/utils.rs @@ -204,7 +204,7 @@ pub struct Fraction { impl Copy for Fraction {} impl Fraction { - pub fn new(numerator: N, denominator: D) -> Self { + pub const fn new(numerator: N, denominator: D) -> Self { Self { numerator, denominator, @@ -260,7 +260,7 @@ pub struct Reciprocal { } impl Reciprocal { - pub fn new(x: T) -> Self { + pub const fn new(x: T) -> Self { Self { x } } } diff --git a/crates/prover/src/core/poly/circle/canonic.rs b/crates/prover/src/core/poly/circle/canonic.rs index 837e648d9..cda0fcc8c 100644 --- a/crates/prover/src/core/poly/circle/canonic.rs +++ b/crates/prover/src/core/poly/circle/canonic.rs @@ -31,7 +31,7 @@ impl CanonicCoset { } /// Gets the full coset represented G_{2n} + . - pub fn coset(&self) -> Coset { + pub const fn coset(&self) -> Coset { self.coset } @@ -46,24 +46,24 @@ impl CanonicCoset { } /// Returns the log size of the coset. - pub fn log_size(&self) -> u32 { + pub const fn log_size(&self) -> u32 { self.coset.log_size } /// Returns the size of the coset. - pub fn size(&self) -> usize { + pub const fn size(&self) -> usize { self.coset.size() } - pub fn initial_index(&self) -> CirclePointIndex { + pub const fn initial_index(&self) -> CirclePointIndex { self.coset.initial_index } - pub fn step_size(&self) -> CirclePointIndex { + pub const fn step_size(&self) -> CirclePointIndex { self.coset.step_size } - pub fn step(&self) -> CirclePoint { + pub const fn step(&self) -> CirclePoint { self.coset.step } diff --git a/crates/prover/src/core/poly/circle/domain.rs b/crates/prover/src/core/poly/circle/domain.rs index fba2bc3fb..2bffac773 100644 --- a/crates/prover/src/core/poly/circle/domain.rs +++ b/crates/prover/src/core/poly/circle/domain.rs @@ -20,7 +20,7 @@ pub struct CircleDomain { impl CircleDomain { /// Given a coset C + , constructs the circle domain +-C + (i.e., /// this coset and its conjugate). - pub fn new(half_coset: Coset) -> Self { + pub const fn new(half_coset: Coset) -> Self { Self { half_coset } } @@ -38,12 +38,12 @@ impl CircleDomain { } /// Returns the size of the domain. - pub fn size(&self) -> usize { + pub const fn size(&self) -> usize { 1 << self.log_size() } /// Returns the log size of the domain. - pub fn log_size(&self) -> u32 { + pub const fn log_size(&self) -> u32 { self.half_coset.log_size + 1 } diff --git a/crates/prover/src/core/poly/circle/poly.rs b/crates/prover/src/core/poly/circle/poly.rs index c10fc5e7a..6744a0c80 100644 --- a/crates/prover/src/core/poly/circle/poly.rs +++ b/crates/prover/src/core/poly/circle/poly.rs @@ -34,7 +34,7 @@ impl CirclePoly { Self { log_size, coeffs } } - pub fn log_size(&self) -> u32 { + pub const fn log_size(&self) -> u32 { self.log_size } diff --git a/crates/prover/src/core/poly/line.rs b/crates/prover/src/core/poly/line.rs index 62b24ac97..71574e4ab 100644 --- a/crates/prover/src/core/poly/line.rs +++ b/crates/prover/src/core/poly/line.rs @@ -58,12 +58,12 @@ impl LineDomain { } /// Returns the size of the domain. - pub fn size(&self) -> usize { + pub const fn size(&self) -> usize { self.coset.size() } /// Returns the log size of the domain. - pub fn log_size(&self) -> u32 { + pub const fn log_size(&self) -> u32 { self.coset.log_size() } @@ -80,7 +80,7 @@ impl LineDomain { } /// Returns the domain's underlying coset. - pub fn coset(&self) -> Coset { + pub const fn coset(&self) -> Coset { self.coset } } @@ -208,11 +208,11 @@ impl> LineEvaluation { /// Returns the number of evaluations. #[allow(clippy::len_without_is_empty)] - pub fn len(&self) -> usize { + pub const fn len(&self) -> usize { 1 << self.domain.log_size() } - pub fn domain(&self) -> LineDomain { + pub const fn domain(&self) -> LineDomain { self.domain } diff --git a/crates/prover/src/core/utils.rs b/crates/prover/src/core/utils.rs index 628679d7c..97632203a 100644 --- a/crates/prover/src/core/utils.rs +++ b/crates/prover/src/core/utils.rs @@ -54,7 +54,7 @@ impl<'a, I: Iterator> PeekableExt<'a, I> for Peekable { } /// Returns the bit reversed index of `i` which is represented by `log_size` bits. -pub fn bit_reverse_index(i: usize, log_size: u32) -> usize { +pub const fn bit_reverse_index(i: usize, log_size: u32) -> usize { if log_size == 0 { return i; } @@ -64,7 +64,7 @@ pub fn bit_reverse_index(i: usize, log_size: u32) -> usize { /// Returns the index of the previous element in a bit reversed /// [super::poly::circle::CircleEvaluation] of log size `eval_log_size` relative to a smaller domain /// of size `domain_log_size`. -pub fn previous_bit_reversed_circle_domain_index( +pub const fn previous_bit_reversed_circle_domain_index( i: usize, domain_log_size: u32, eval_log_size: u32, @@ -75,7 +75,7 @@ pub fn previous_bit_reversed_circle_domain_index( /// Returns the index of the offset element in a bit reversed /// [super::poly::circle::CircleEvaluation] of log size `eval_log_size` relative to a smaller domain /// of size `domain_log_size`. -pub fn offset_bit_reversed_circle_domain_index( +pub const fn offset_bit_reversed_circle_domain_index( i: usize, domain_log_size: u32, eval_log_size: u32, @@ -122,7 +122,7 @@ pub(crate) fn coset_order_to_circle_domain_order(values: &[F]) -> Vec< /// /// [`CircleDomain`]: crate::core::poly::circle::CircleDomain /// [`Coset`]: crate::core::circle::Coset -pub fn coset_index_to_circle_domain_index(coset_index: usize, log_domain_size: u32) -> usize { +pub const fn coset_index_to_circle_domain_index(coset_index: usize, log_domain_size: u32) -> usize { if coset_index % 2 == 0 { coset_index / 2 } else { diff --git a/crates/prover/src/core/vcs/blake2s_ref.rs b/crates/prover/src/core/vcs/blake2s_ref.rs index ab32ea6d9..81679a579 100644 --- a/crates/prover/src/core/vcs/blake2s_ref.rs +++ b/crates/prover/src/core/vcs/blake2s_ref.rs @@ -19,32 +19,32 @@ pub const SIGMA: [[u8; 16]; 10] = [ ]; #[inline(always)] -fn add(a: u32, b: u32) -> u32 { +const fn add(a: u32, b: u32) -> u32 { a.wrapping_add(b) } #[inline(always)] -fn xor(a: u32, b: u32) -> u32 { +const fn xor(a: u32, b: u32) -> u32 { a ^ b } #[inline(always)] -fn rot16(x: u32) -> u32 { +const fn rot16(x: u32) -> u32 { (x >> 16) | (x << (32 - 16)) } #[inline(always)] -fn rot12(x: u32) -> u32 { +const fn rot12(x: u32) -> u32 { (x >> 12) | (x << (32 - 12)) } #[inline(always)] -fn rot8(x: u32) -> u32 { +const fn rot8(x: u32) -> u32 { (x >> 8) | (x << (32 - 8)) } #[inline(always)] -fn rot7(x: u32) -> u32 { +const fn rot7(x: u32) -> u32 { (x >> 7) | (x << (32 - 7)) } diff --git a/crates/prover/src/examples/xor/gkr_lookups/mle_eval.rs b/crates/prover/src/examples/xor/gkr_lookups/mle_eval.rs index 985bfaf51..f4e43dcbb 100644 --- a/crates/prover/src/examples/xor/gkr_lookups/mle_eval.rs +++ b/crates/prover/src/examples/xor/gkr_lookups/mle_eval.rs @@ -1135,7 +1135,7 @@ mod tests { } impl MleCoeffColumnEval { - pub fn new(interaction: usize, n_variables: usize) -> Self { + pub const fn new(interaction: usize, n_variables: usize) -> Self { Self { interaction, n_variables,