Skip to content

Commit

Permalink
clippy: apply missing_const_for_fn rule
Browse files Browse the repository at this point in the history
  • Loading branch information
tcoratger committed Nov 7, 2024
1 parent 4aa5a22 commit b49fce5
Show file tree
Hide file tree
Showing 23 changed files with 67 additions and 64 deletions.
3 changes: 3 additions & 0 deletions crates/prover/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
2 changes: 1 addition & 1 deletion crates/prover/src/core/air/accumulation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/prover/src/core/backend/simd/cm31.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}

Expand Down
2 changes: 1 addition & 1 deletion crates/prover/src/core/backend/simd/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion crates/prover/src/core/backend/simd/fft/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
6 changes: 3 additions & 3 deletions crates/prover/src/core/backend/simd/m31.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,22 +78,22 @@ impl PackedM31 {
self + self
}

pub fn into_simd(self) -> Simd<u32, N_LANES> {
pub const fn into_simd(self) -> Simd<u32, N_LANES> {
self.0
}

/// # Safety
///
/// Vector elements must be in the range `[0, P]`.
pub unsafe fn from_simd_unchecked(v: Simd<u32, N_LANES>) -> Self {
pub const unsafe fn from_simd_unchecked(v: Simd<u32, N_LANES>) -> Self {
Self(v)
}

/// # Safety
///
/// 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))
}

Expand Down
8 changes: 4 additions & 4 deletions crates/prover/src/core/backend/simd/qm31.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}

Expand Down Expand Up @@ -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])])
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/prover/src/core/backend/simd/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl<T: ?Sized> UnsafeMut<T> {
/// # Safety
///
/// Returns a raw mutable pointer.
pub unsafe fn get(&self) -> *mut T {
pub const unsafe fn get(&self) -> *mut T {
self.0
}
}
Expand All @@ -43,7 +43,7 @@ impl<T> UnsafeConst<T> {
/// # Safety
///
/// Returns a raw constant pointer.
pub unsafe fn get(&self) -> *const T {
pub const unsafe fn get(&self) -> *const T {
self.0
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/prover/src/core/channel/blake2s.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion crates/prover/src/core/channel/poseidon252.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
16 changes: 8 additions & 8 deletions crates/prover/src/core/circle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand Down Expand Up @@ -343,24 +343,24 @@ 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<CirclePoint<M31>> {
pub const fn iter(&self) -> CosetIterator<CirclePoint<M31>> {
CosetIterator {
cur: self.initial,
step: self.step,
remaining: self.size(),
}
}

pub fn iter_indices(&self) -> CosetIterator<CirclePointIndex> {
pub const fn iter_indices(&self) -> CosetIterator<CirclePointIndex> {
CosetIterator {
cur: self.initial_index,
step: self.step_size,
Expand Down Expand Up @@ -389,7 +389,7 @@ impl Coset {
&& *self == other.repeated_double(other.log_size - self.log_size)
}

pub fn initial(&self) -> CirclePoint<M31> {
pub const fn initial(&self) -> CirclePoint<M31> {
self.initial
}

Expand Down
2 changes: 1 addition & 1 deletion crates/prover/src/core/fields/cm31.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
8 changes: 4 additions & 4 deletions crates/prover/src/core/fields/m31.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions crates/prover/src/core/fields/qm31.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}

Expand Down
8 changes: 4 additions & 4 deletions crates/prover/src/core/fri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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,
}
Expand All @@ -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<Self> {
const fn fold(self, n_folds: u32) -> Option<Self> {
if self.log_degree_bound < n_folds {
return None;
}
Expand Down
4 changes: 2 additions & 2 deletions crates/prover/src/core/lookups/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ pub struct Fraction<N, D> {
impl<N: Copy, D: Copy> Copy for Fraction<N, D> {}

impl<N, D> Fraction<N, D> {
pub fn new(numerator: N, denominator: D) -> Self {
pub const fn new(numerator: N, denominator: D) -> Self {
Self {
numerator,
denominator,
Expand Down Expand Up @@ -260,7 +260,7 @@ pub struct Reciprocal<T> {
}

impl<T> Reciprocal<T> {
pub fn new(x: T) -> Self {
pub const fn new(x: T) -> Self {
Self { x }
}
}
Expand Down
12 changes: 6 additions & 6 deletions crates/prover/src/core/poly/circle/canonic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl CanonicCoset {
}

/// Gets the full coset represented G_{2n} + <G_n>.
pub fn coset(&self) -> Coset {
pub const fn coset(&self) -> Coset {
self.coset
}

Expand All @@ -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<BaseField> {
pub const fn step(&self) -> CirclePoint<BaseField> {
self.coset.step
}

Expand Down
6 changes: 3 additions & 3 deletions crates/prover/src/core/poly/circle/domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub struct CircleDomain {
impl CircleDomain {
/// Given a coset C + <G_n>, constructs the circle domain +-C + <G_n> (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 }
}

Expand All @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion crates/prover/src/core/poly/circle/poly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl<B: PolyOps> CirclePoly<B> {
Self { log_size, coeffs }
}

pub fn log_size(&self) -> u32 {
pub const fn log_size(&self) -> u32 {
self.log_size
}

Expand Down
Loading

0 comments on commit b49fce5

Please sign in to comment.