Skip to content

Commit

Permalink
chore: fix new clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
mayeul-zama committed Feb 6, 2025
1 parent dda9ee7 commit 1e9d7bc
Show file tree
Hide file tree
Showing 32 changed files with 60 additions and 59 deletions.
3 changes: 1 addition & 2 deletions tfhe/examples/regex_engine/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@ fn build_branches(
build_branches(
content,
&(RegExpr::Seq {
re_xs: std::iter::repeat(*repeat_re.clone())
.take(std::cmp::max(1, at_least))
re_xs: std::iter::repeat_n(*repeat_re.clone(), std::cmp::max(1, at_least))
.collect(),
}),
c_pos,
Expand Down
5 changes: 4 additions & 1 deletion tfhe/examples/sha256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,10 @@ fn encrypt_data<T: AsRef<[u8]>>(input: T, client_key: Option<&ClientKey>) -> Vec
.iter()
.copied()
.chain(iter::once(0x80))
.chain(iter::repeat(0x00).take(if remainder == 0 { 0 } else { 64 - remainder }))
.chain(std::iter::repeat_n(
0x00,
if remainder == 0 { 0 } else { 64 - remainder },
))
.chain(((len * 8) as u64).to_be_bytes());

ArrayChunks::<_, 4>::new(bytes_iter)
Expand Down
2 changes: 1 addition & 1 deletion tfhe/examples/sha256_bool/padding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fn pad_sha256_data(data: &[u8]) -> Vec<bool> {

// Calculate the number of padding zeros required
let padding_zeros = (512 - ((bits.len() + 64) % 512)) % 512;
bits.extend(std::iter::repeat(false).take(padding_zeros));
bits.extend(std::iter::repeat_n(false, padding_zeros));

// Append a 64-bit big-endian representation of the original message length
let data_len_bits = (data.len() as u64) * 8;
Expand Down
22 changes: 10 additions & 12 deletions tfhe/src/boolean/key_switching_key/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,16 @@ impl KeySwitchingKey {
pub fn cast_into(&self, ct: &Ciphertext, ct_dest: &mut Ciphertext) {
match ct {
Ciphertext::Trivial(_) => *ct_dest = ct.clone(),
Ciphertext::Encrypted(ref cipher) => {
match ct_dest {
Ciphertext::Trivial(_) => {
let mut cipher_dest = cipher.clone();
keyswitch_lwe_ciphertext(&self.key_switching_key, cipher, &mut cipher_dest);
*ct_dest = Ciphertext::Encrypted(cipher_dest);
}
Ciphertext::Encrypted(ref mut cipher_dest) => {
keyswitch_lwe_ciphertext(&self.key_switching_key, cipher, cipher_dest);
}
};
}
Ciphertext::Encrypted(ref cipher) => match ct_dest {
Ciphertext::Trivial(_) => {
let mut cipher_dest = cipher.clone();
keyswitch_lwe_ciphertext(&self.key_switching_key, cipher, &mut cipher_dest);
*ct_dest = Ciphertext::Encrypted(cipher_dest);
}
Ciphertext::Encrypted(ref mut cipher_dest) => {
keyswitch_lwe_ciphertext(&self.key_switching_key, cipher, cipher_dest);
}
},
}
}

Expand Down
2 changes: 1 addition & 1 deletion tfhe/src/c_api/high_level_api/zk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ pub unsafe extern "C" fn compact_pke_crs_safe_serialize(
crate::safe_serialization::SerializationConfig::new(serialized_size_limit)
.serialize_into(&wrapper.0, &mut buffer)
.unwrap();
};
}

*result = buffer.into();
})
Expand Down
2 changes: 1 addition & 1 deletion tfhe/src/core_crypto/algorithms/lwe_encryption.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ pub fn fill_lwe_mask_and_body_for_encryption_native_mod_compatible<
*output_body.data = (*output_body.data).wrapping_mul(torus_scaling);
}
CiphertextModulusKind::Other => unreachable!(),
};
}
}

pub fn fill_lwe_mask_and_body_for_encryption_other_mod<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,10 @@ impl<Scalar: UnsignedTorus> CompressedModulusSwitchedGlweCiphertext<Scalar> {
.unpack()
// Scaling
.map(|a| a << (Scalar::BITS - log_modulus))
.chain(
std::iter::repeat(Scalar::ZERO).take(self.polynomial_size.0 - self.bodies_count.0),
)
.chain(std::iter::repeat_n(
Scalar::ZERO,
self.polynomial_size.0 - self.bodies_count.0,
))
.collect();

GlweCiphertextOwned::from_container(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ impl<Scalar: UnsignedInteger + CastInto<usize> + CastFrom<usize>>

if let Some(packed_diffs) = &self.packed_diffs {
diffs_two_complement = packed_diffs.unpack().collect()
};
}

let diffs = |a: usize| {
self.packed_diffs.as_ref().map_or(0, |packed_diffs| {
Expand Down
2 changes: 1 addition & 1 deletion tfhe/src/integer/block_decomposition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ where
self.data >>= self.num_bits_in_mask;
} else {
self.data = T::ZERO;
};
}

if self.num_bits_valid < self.num_bits_in_mask {
// This will be the case when self.num_bits_in_mask is not a multiple
Expand Down
2 changes: 1 addition & 1 deletion tfhe/src/integer/client_key/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ impl ClientKey {
// End of T::BITS reached no need to try more
// recomposition
break;
};
}
}

recomposer.value()
Expand Down
4 changes: 2 additions & 2 deletions tfhe/src/integer/gpu/server_key/radix/abs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl CudaServerKey {
d_multibit_bsk.grouping_factor,
);
}
};
}
}
}
pub fn unchecked_abs<T>(&self, ct: &T, streams: &CudaStreams) -> T
Expand Down Expand Up @@ -135,7 +135,7 @@ impl CudaServerKey {
let mut res = unsafe { ct.duplicate_async(streams) };
if !ct.block_carries_are_empty() {
unsafe { self.full_propagate_assign_async(&mut res, streams) };
};
}
if T::IS_SIGNED {
unsafe { self.unchecked_abs_assign_async(&mut res, streams) };
}
Expand Down
2 changes: 1 addition & 1 deletion tfhe/src/integer/gpu/server_key/radix/div_mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl CudaServerKey {
d_multibit_bsk.grouping_factor,
);
}
};
}

quotient.as_mut().info = quotient.as_ref().info.after_div_rem();
remainder.as_mut().info = remainder.as_ref().info.after_div_rem();
Expand Down
12 changes: 6 additions & 6 deletions tfhe/src/integer/gpu/server_key/radix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ impl CudaServerKey {
uses_carry,
);
}
};
}
ciphertext.info.blocks.iter_mut().for_each(|b| {
b.degree = Degree::new(b.message_modulus.0 - 1);
b.noise_level = NoiseLevel::NOMINAL;
Expand Down Expand Up @@ -374,7 +374,7 @@ impl CudaServerKey {
uses_carry,
);
}
};
}
lhs.as_mut().info.blocks.iter_mut().for_each(|b| {
b.degree = Degree::new(b.message_modulus.0 - 1);
b.noise_level = NoiseLevel::NOMINAL;
Expand Down Expand Up @@ -435,7 +435,7 @@ impl CudaServerKey {
d_multibit_bsk.grouping_factor,
);
}
};
}
}
ciphertext.info.blocks.iter_mut().for_each(|b| {
b.degree = Degree::new(b.message_modulus.0 - 1);
Expand Down Expand Up @@ -989,7 +989,7 @@ impl CudaServerKey {
d_multibit_bsk.grouping_factor,
);
}
};
}
}

for (i, info) in output.info.blocks[block_range].iter_mut().enumerate() {
Expand Down Expand Up @@ -1109,7 +1109,7 @@ impl CudaServerKey {
self.message_modulus.0 as u32,
);
}
};
}
}

for (i, info) in output.info.blocks[block_range].iter_mut().enumerate() {
Expand Down Expand Up @@ -1286,7 +1286,7 @@ impl CudaServerKey {
lut.sample_extraction_stride as u32,
);
}
};
}

let mut ciphertexts = Vec::<CudaRadixCiphertext>::with_capacity(function_count);

Expand Down
2 changes: 1 addition & 1 deletion tfhe/src/integer/gpu/server_key/radix/mul.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl CudaServerKey {
d_multibit_bsk.grouping_factor,
);
}
};
}

ct_left.as_mut().info = ct_left.as_ref().info.after_mul();
}
Expand Down
2 changes: 1 addition & 1 deletion tfhe/src/integer/gpu/server_key/radix/scalar_add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ impl CudaServerKey {
{
if !ct.block_carries_are_empty() {
self.full_propagate_assign_async(ct, streams);
};
}

self.unchecked_scalar_add_assign_async(ct, scalar, streams);
let _carry = self.propagate_single_carry_assign_async(ct, streams, None, OutputFlag::None);
Expand Down
4 changes: 2 additions & 2 deletions tfhe/src/integer/gpu/server_key/radix/scalar_mul.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ impl CudaServerKey {
d_multibit_bsk.grouping_factor,
);
}
};
}

ct.as_mut().info = ct.as_ref().info.after_scalar_mul();
}
Expand Down Expand Up @@ -243,7 +243,7 @@ impl CudaServerKey {
{
if !ct.block_carries_are_empty() {
self.full_propagate_assign_async(ct, streams);
};
}

self.unchecked_scalar_mul_assign_async(ct, scalar, streams);
}
Expand Down
2 changes: 1 addition & 1 deletion tfhe/src/integer/gpu/server_key/radix/scalar_sub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ impl CudaServerKey {
{
if !ct.block_carries_are_empty() {
self.full_propagate_assign_async(ct, streams);
};
}

self.unchecked_scalar_sub_assign_async(ct, scalar, streams);
let _carry = self.propagate_single_carry_assign_async(ct, streams, None, OutputFlag::None);
Expand Down
2 changes: 1 addition & 1 deletion tfhe/src/integer/gpu/server_key/radix/sub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ impl CudaServerKey {
uses_input_borrow,
);
}
};
}
ciphertext.info.blocks.iter_mut().for_each(|b| {
b.degree = Degree::new(b.message_modulus.0 - 1);
b.noise_level = NoiseLevel::NOMINAL;
Expand Down
4 changes: 2 additions & 2 deletions tfhe/src/integer/server_key/radix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ impl ServerKey {
} else {
let num_blocks_to_remove = current_num_blocks - target_num_blocks;
self.trim_radix_blocks_msb_assign(&mut ct_as_unsigned_radix, num_blocks_to_remove);
};
}
ct_as_unsigned_radix.blocks
};

Expand Down Expand Up @@ -702,7 +702,7 @@ impl ServerKey {
} else {
let num_blocks_to_remove = current_num_blocks - target_num_blocks;
self.trim_radix_blocks_msb_assign(&mut ct_as_unsigned_radix, num_blocks_to_remove);
};
}
ct_as_unsigned_radix.blocks
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ impl<'a> BitExtractor<'a> {
} else {
let iterator = blocks[..num_blocks_to_process].iter().cloned();
self.buffer.extend(iterator);
};
}

// We have to advance our internal iterator
self.input_blocks = blocks[num_blocks_to_process..].iter();
Expand Down
8 changes: 4 additions & 4 deletions tfhe/src/integer/server_key/radix_parallel/block_shift.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ impl ServerKey {
{
if !ct.block_carries_are_empty() {
self.full_propagate_parallelized(ct);
};
}
self.block_barrel_shifter(ct, amount, BarrelShifterOperation::RightRotate)
}

Expand All @@ -324,7 +324,7 @@ impl ServerKey {
{
if !ct.block_carries_are_empty() {
self.full_propagate_parallelized(ct);
};
}
self.block_barrel_shifter(ct, amount, BarrelShifterOperation::LeftRotate)
}

Expand All @@ -334,7 +334,7 @@ impl ServerKey {
{
if !ct.block_carries_are_empty() {
self.full_propagate_parallelized(ct);
};
}
self.block_barrel_shifter(ct, amount, BarrelShifterOperation::RightShift)
}

Expand All @@ -344,7 +344,7 @@ impl ServerKey {
{
if !ct.block_carries_are_empty() {
self.full_propagate_parallelized(ct);
};
}
self.block_barrel_shifter(ct, amount, BarrelShifterOperation::LeftShift)
}

Expand Down
2 changes: 1 addition & 1 deletion tfhe/src/integer/server_key/radix_parallel/comparison.rs
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ impl ServerKey {
};
self.key.unchecked_scalar_add_assign(&mut result, corrector);
result.degree = crate::shortint::ciphertext::Degree::new(3);
};
}

result
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl ServerKey {
{
if !ct.block_carries_are_empty() {
self.full_propagate_parallelized(ct);
};
}

self.unchecked_count_bits_parallelized(ct, kind)
}
Expand Down
2 changes: 1 addition & 1 deletion tfhe/src/integer/server_key/radix_parallel/scalar_add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ impl ServerKey {
{
if !ct.block_carries_are_empty() {
self.full_propagate_parallelized(ct);
};
}

let scalar_blocks = BlockDecomposer::new(scalar, self.message_modulus().0.ilog2())
.iter_as::<u8>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,7 @@ mod tests {

// signed usage example
let chosen = choose_multiplier(3u64, 31, 32);
assert_eq!(chosen.multiplier, ((1u128 << 32) + 2) / 3);
assert_eq!(chosen.multiplier, (1u128 << 32).div_ceil(3));
assert_eq!(chosen.shift_post, 0);
}
}
2 changes: 1 addition & 1 deletion tfhe/src/integer/server_key/radix_parallel/scalar_sub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl ServerKey {
{
if !ct.block_carries_are_empty() {
self.full_propagate_parallelized(ct);
};
}

if Scalar::ZERO == scalar {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ fn draw_unique_randoms(
special_value,
modulus,
);
};
}

let mut numbers = unique_numbers.into_iter().collect::<Vec<u64>>();
for _ in 0..occurrence_count.saturating_sub(1) {
Expand Down
6 changes: 3 additions & 3 deletions tfhe/src/safe_serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ impl SerializationConfig {
SerializationVersioningMode::Unversioned { .. } => {
options.serialize_into(&mut writer, &object)?
}
};
}
} else {
let options = options.with_no_limit();

Expand All @@ -267,8 +267,8 @@ impl SerializationConfig {
SerializationVersioningMode::Unversioned { .. } => {
options.serialize_into(&mut writer, &object)?
}
};
};
}
}

Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion tfhe/src/shortint/ciphertext/zk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ impl ParameterSetConformant for ProvenCompactCiphertextList {
} else {
expected_len = remaining_len;
remaining_len = 0;
};
}

let params = CiphertextListConformanceParams {
ct_list_params: LweCiphertextListParameters {
Expand Down
Loading

0 comments on commit 1e9d7bc

Please sign in to comment.