Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions crates/fhe-math/benches/ntt.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// Allow indexing in benchmarks for convenience
#![allow(clippy::indexing_slicing)]
#![allow(missing_docs)]

#![expect(missing_docs, reason = "examples/benches/tests omit docs by design")]
use criterion::{BenchmarkId, Criterion, criterion_group, criterion_main};
use fhe_math::{ntt::NttOperator, zq::Modulus};
use rand::rng;
Expand Down
5 changes: 1 addition & 4 deletions crates/fhe-math/benches/rns.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// Allow indexing in benchmarks for convenience
#![allow(clippy::indexing_slicing)]
#![allow(missing_docs)]

#![expect(missing_docs, reason = "examples/benches/tests omit docs by design")]
use criterion::{BenchmarkId, Criterion, criterion_group, criterion_main};
use fhe_math::rns::{RnsContext, RnsScaler, ScalingFactor};
use num_bigint::BigUint;
Expand Down
9 changes: 5 additions & 4 deletions crates/fhe-math/benches/rq.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Allow indexing in benchmarks for convenience
#![allow(clippy::indexing_slicing)]
#![allow(missing_docs)]

#![expect(missing_docs, reason = "examples/benches/tests omit docs by design")]
#![expect(
clippy::indexing_slicing,
reason = "performance or example code relies on validated indices"
)]
use criterion::measurement::WallTime;
use criterion::{BenchmarkGroup, BenchmarkId, Criterion, criterion_group, criterion_main};
use fhe_math::rq::*;
Expand Down
9 changes: 5 additions & 4 deletions crates/fhe-math/benches/zq.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Allow indexing in benchmarks for convenience
#![allow(clippy::indexing_slicing)]
#![allow(missing_docs)]

#![expect(missing_docs, reason = "examples/benches/tests omit docs by design")]
#![expect(
clippy::indexing_slicing,
reason = "performance or example code relies on validated indices"
)]
use criterion::{BenchmarkId, Criterion, criterion_group, criterion_main};
use fhe_math::zq::Modulus;
use rand::rng;
Expand Down
7 changes: 5 additions & 2 deletions crates/fhe-math/src/ntt/native.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Allow indexing in this performance-critical NTT implementation.
// Expect indexing in this performance-critical NTT implementation.
// The unsafe blocks already indicate this is performance-sensitive code.
#![allow(clippy::indexing_slicing)]
#![expect(
clippy::indexing_slicing,
reason = "performance or example code relies on validated indices"
)]

use crate::zq::Modulus;
use itertools::Itertools;
Expand Down
2 changes: 0 additions & 2 deletions crates/fhe-math/src/proto/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
//! Protobuf for the `fhe-math` crate.

#![allow(missing_docs)]

/// Protobuf for polynomials.
pub mod rq;
7 changes: 4 additions & 3 deletions crates/fhe-math/src/proto/rq.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![allow(missing_docs)]

#[allow(clippy::derive_partial_eq_without_eq)]
#[expect(
clippy::derive_partial_eq_without_eq,
reason = "prost-generated types do not need Eq"
)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Rq {
#[prost(enumeration = "Representation", tag = "1")]
Expand Down
12 changes: 9 additions & 3 deletions crates/fhe-math/src/rns/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#![warn(missing_docs, unused_imports)]
// Allow indexing in this performance-critical RNS implementation
#![allow(clippy::indexing_slicing)]
// Expect indexing in this performance-critical RNS implementation
#![expect(
clippy::indexing_slicing,
reason = "performance or example code relies on validated indices"
)]

//! Residue-Number System operations.

Expand Down Expand Up @@ -69,7 +72,10 @@ impl RnsContext {
product_dig *= &BigUintDig::from(moduli_u64[i]);
}

#[allow(clippy::type_complexity)]
#[expect(
clippy::type_complexity,
reason = "complex tuple is produced by multiunzip"
)]
let (moduli, q_tilde, q_tilde_shoup, q_star, garner): (
Vec<Modulus>,
Vec<u64>,
Expand Down
7 changes: 5 additions & 2 deletions crates/fhe-math/src/rns/scaler.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#![warn(missing_docs, unused_imports)]
// Allow indexing in this performance-critical RNS scaler implementation
#![allow(clippy::indexing_slicing)]
// Expect indexing in this performance-critical RNS scaler implementation
#![expect(
clippy::indexing_slicing,
reason = "performance or example code relies on validated indices"
)]

//! RNS scaler inspired from Remark 3.2 of <https://eprint.iacr.org/2021/204.pdf>.

Expand Down
2 changes: 1 addition & 1 deletion crates/fhe-math/src/rq/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ impl From<&Poly> for Vec<BigUint> {

#[cfg(test)]
mod tests {
#![allow(clippy::expect_used)]
#![expect(clippy::expect_used, reason = "bounds are validated before use")]

use crate::{
Error as CrateError,
Expand Down
7 changes: 5 additions & 2 deletions crates/fhe-math/src/rq/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#![warn(missing_docs, unused_imports)]
// Allow indexing/slicing in this performance-critical polynomial arithmetic module.
// Expect indexing/slicing in this performance-critical polynomial arithmetic module.
// This code heavily uses RNS representation and requires fast array access.
#![allow(clippy::indexing_slicing)]
#![expect(
clippy::indexing_slicing,
reason = "performance or example code relies on validated indices"
)]

//! Polynomials in R_q\[x\] = (ZZ_q1 x ... x ZZ_qn)\[x\] where the qi's are
//! prime moduli in zq.
Expand Down
2 changes: 1 addition & 1 deletion crates/fhe-math/src/rq/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ impl Sub<&Poly> for &Poly {
}

impl MulAssign<&Poly> for Poly {
#[allow(clippy::panic)]
#[expect(clippy::panic, reason = "panic indicates violated internal invariant")]
fn mul_assign(&mut self, p: &Poly) {
assert!(!p.has_lazy_coefficients);
assert_ne!(
Expand Down
1 change: 0 additions & 1 deletion crates/fhe-math/src/zq/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1118,7 +1118,6 @@ mod tests {
let ntests = 100;
let mut rng = rand::rng();

#[allow(clippy::single_element_loop)]
for p in [4611686018326724609] {
let q = Modulus::new(p).unwrap();
assert!(primes::supports_opt(p));
Expand Down
22 changes: 17 additions & 5 deletions crates/fhe-util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub fn sample_vec_cbd<R: RngCore + CryptoRng>(

/// Transcodes a vector of u64 of `nbits`-bit numbers into a vector of bytes.
#[must_use]
#[allow(clippy::expect_used)]
#[expect(clippy::expect_used, reason = "bounds are validated before use")]
pub fn transcode_to_bytes(a: &[u64], nbits: usize) -> Vec<u8> {
assert!(0 < nbits && nbits <= 64);

Expand Down Expand Up @@ -96,7 +96,7 @@ pub fn transcode_to_bytes(a: &[u64], nbits: usize) -> Vec<u8> {

/// Transcodes a vector of u8 into a vector of u64 of `nbits`-bit numbers.
#[must_use]
#[allow(clippy::expect_used)]
#[expect(clippy::expect_used, reason = "bounds are validated before use")]
pub fn transcode_from_bytes(b: &[u8], nbits: usize) -> Vec<u64> {
assert!(0 < nbits && nbits <= 64);
let mask = (u64::MAX >> (64 - nbits)) as u128;
Expand Down Expand Up @@ -135,7 +135,7 @@ pub fn transcode_from_bytes(b: &[u8], nbits: usize) -> Vec<u64> {
/// Transcodes a vector of u64 of `input_nbits`-bit numbers into a vector of u64
/// of `output_nbits`-bit numbers.
#[must_use]
#[allow(clippy::expect_used)]
#[expect(clippy::expect_used, reason = "bounds are validated before use")]
pub fn transcode_bidirectional(a: &[u64], input_nbits: usize, output_nbits: usize) -> Vec<u64> {
assert!(0 < input_nbits && input_nbits <= 64);
assert!(0 < output_nbits && output_nbits <= 64);
Expand Down Expand Up @@ -196,8 +196,11 @@ pub fn variance<T: PrimInt>(values: &[T]) -> f64 {

#[cfg(test)]
mod tests {
// Allow indexing in tests for convenience
#![allow(clippy::indexing_slicing)]
// Expect indexing in tests for convenience
#![expect(
clippy::indexing_slicing,
reason = "performance or example code relies on validated indices"
)]

use itertools::Itertools;
use rand::RngCore;
Expand Down Expand Up @@ -291,6 +294,15 @@ mod tests {
assert_eq!(&decoded[..input.len()], input);
}

#[test]
fn transcode_empty_roundtrip() {
let input: Vec<u64> = Vec::new();
let bytes = transcode_to_bytes(&input, 8);
assert!(bytes.is_empty());
let decoded = transcode_from_bytes(&bytes, 8);
assert!(decoded.is_empty());
}

#[test]
fn inv_kats() {
// KATs for inversion generated in Sage using the following code.
Expand Down
9 changes: 6 additions & 3 deletions crates/fhe/benches/bfv.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Allow indexing in benchmarks for convenience
#![allow(clippy::indexing_slicing)]
#![allow(missing_docs)]
// Expect indexing in benchmarks for convenience
#![expect(missing_docs, reason = "examples/benches/tests omit docs by design")]
#![expect(
clippy::indexing_slicing,
reason = "performance or example code relies on validated indices"
)]

use criterion::{BenchmarkId, Criterion, criterion_group, criterion_main};
use fhe::bfv::{
Expand Down
5 changes: 2 additions & 3 deletions crates/fhe/benches/bfv_optimized_ops.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Allow indexing in benchmarks for convenience
#![allow(clippy::indexing_slicing)]
#![allow(missing_docs)]
// Expect indexing in benchmarks for convenience
#![expect(missing_docs, reason = "examples/benches/tests omit docs by design")]

use criterion::{BenchmarkId, Criterion, criterion_group, criterion_main};
use fhe::bfv::{BfvParameters, Ciphertext, Encoding, Plaintext, SecretKey, dot_product_scalar};
Expand Down
5 changes: 2 additions & 3 deletions crates/fhe/benches/bfv_rgsw.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Allow indexing in benchmarks for convenience
#![allow(clippy::indexing_slicing)]
#![allow(missing_docs)]
// Expect indexing in benchmarks for convenience
#![expect(missing_docs, reason = "examples/benches/tests omit docs by design")]

use criterion::{BenchmarkId, Criterion, criterion_group, criterion_main};
use fhe::bfv::{BfvParameters, Ciphertext, Encoding, Plaintext, RGSWCiphertext, SecretKey};
Expand Down
9 changes: 6 additions & 3 deletions crates/fhe/examples/bfv_basic.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Allow indexing in examples for simplicity
#![allow(clippy::indexing_slicing)]
#![allow(missing_docs)]
// Expect indexing in examples for simplicity
#![expect(missing_docs, reason = "examples/benches/tests omit docs by design")]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Drop missing_docs expect for non-public example

This example crate has no public items, so missing_docs never fires. With #![expect(missing_docs)] the compiler emits an unfulfilled-lint-expectations warning, and the required cargo clippy --all-targets -- -D warnings will fail for this target. Consider removing the expect here or adding a documented public item if you really want a missing_docs expectation.

Useful? React with 👍 / 👎.

#![expect(
clippy::indexing_slicing,
reason = "performance or example code relies on validated indices"
)]

use std::error::Error;

Expand Down
9 changes: 6 additions & 3 deletions crates/fhe/examples/bfv_ops.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Allow indexing in examples for simplicity
#![allow(clippy::indexing_slicing)]
#![allow(missing_docs)]
// Expect indexing in examples for simplicity
#![expect(missing_docs, reason = "examples/benches/tests omit docs by design")]
#![expect(
clippy::indexing_slicing,
reason = "performance or example code relies on validated indices"
)]

mod util;

Expand Down
9 changes: 6 additions & 3 deletions crates/fhe/examples/mulpir.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Allow indexing in examples for simplicity
#![allow(clippy::indexing_slicing)]
#![allow(missing_docs)]
// Expect indexing in examples for simplicity
#![expect(missing_docs, reason = "examples/benches/tests omit docs by design")]
#![expect(
clippy::indexing_slicing,
reason = "performance or example code relies on validated indices"
)]

// Implementation of MulPIR using the `fhe` crate.
//
Expand Down
8 changes: 5 additions & 3 deletions crates/fhe/examples/pir.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
// Allow indexing in examples for simplicity
#![allow(clippy::indexing_slicing)]
#![allow(missing_docs)]
//! CLI configuration for PIR example runs.
// Expect indexing in examples for simplicity

use clap::Parser;

/// Command-line arguments for configuring a PIR example run.
#[derive(Parser)]
pub struct Cli {
#[arg(
long,
help = "The number of elements in the database",
default_value = "65536"
)]
/// Number of elements in the database.
pub database_size: usize,

#[arg(
long,
help = "The size of each database element",
default_value = "1024"
)]
/// Size in bytes of each database element.
pub element_size: usize,
}

Expand Down
9 changes: 6 additions & 3 deletions crates/fhe/examples/rgsw.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Allow indexing in examples for simplicity
#![allow(clippy::indexing_slicing)]
#![allow(missing_docs)]
// Expect indexing in examples for simplicity
#![expect(missing_docs, reason = "examples/benches/tests omit docs by design")]
#![expect(
clippy::indexing_slicing,
reason = "performance or example code relies on validated indices"
)]

use std::error::Error;

Expand Down
9 changes: 6 additions & 3 deletions crates/fhe/examples/sealpir.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Allow indexing in examples for simplicity
#![allow(clippy::indexing_slicing)]
#![allow(missing_docs)]
// Expect indexing in examples for simplicity
#![expect(missing_docs, reason = "examples/benches/tests omit docs by design")]
#![expect(
clippy::indexing_slicing,
reason = "performance or example code relies on validated indices"
)]

// Implementation of SealPIR using the `fhe` crate.
//
Expand Down
Loading
Loading