From ce14a4909dbaa1c266796cebad7ccbd4faab3563 Mon Sep 17 00:00:00 2001 From: "Mayeul@Zama" <69792125+mayeul-zama@users.noreply.github.com> Date: Wed, 15 Jan 2025 10:02:49 +0100 Subject: [PATCH] chore: fix new lints --- tfhe-ntt/src/product.rs | 14 +++++++------- .../core_crypto/fft_impl/fft128/math/fft/mod.rs | 6 +++--- .../fft_impl/fft128_u128/math/fft/mod.rs | 8 ++++---- tfhe/src/integer/gpu/server_key/radix/mod.rs | 2 +- tfhe/src/integer/server_key/radix/mod.rs | 2 +- tfhe/src/integer/server_key/radix/slice.rs | 2 +- .../server_key/radix_parallel/comparison.rs | 2 +- .../server_key/radix_parallel/scalar_comparison.rs | 2 +- .../server_key/radix_parallel/scalar_shift.rs | 4 ++-- tfhe/src/shortint/client_key/mod.rs | 2 +- utils/tfhe-versionable-derive/src/lib.rs | 2 +- 11 files changed, 23 insertions(+), 23 deletions(-) diff --git a/tfhe-ntt/src/product.rs b/tfhe-ntt/src/product.rs index 31f8fe0ddf..bed2eac55c 100644 --- a/tfhe-ntt/src/product.rs +++ b/tfhe-ntt/src/product.rs @@ -278,12 +278,12 @@ impl Plan { let ntt_32: &mut [u32] = bytemuck::cast_slice_mut(ntt_32); // optimize common cases(?): u64x1, u32x1 - if self.plan_32.len() == 0 && self.plan_64.len() == 1 { + if self.plan_32.is_empty() && self.plan_64.len() == 1 { ntt_64.copy_from_slice(standard); self.plan_64[0].fwd(ntt_64); return; } - if self.plan_32.len() == 1 && self.plan_64.len() == 0 { + if self.plan_32.len() == 1 && self.plan_64.is_empty() { for (ntt, &standard) in ntt_32.iter_mut().zip(standard) { *ntt = standard as u32; } @@ -291,7 +291,7 @@ impl Plan { return; } - if self.plan_32.len() == 2 && self.plan_64.len() == 0 { + if self.plan_32.len() == 2 && self.plan_64.is_empty() { let (ntt0, ntt1) = ntt_32.split_at_mut(self.ntt_size()); let p0_div = self.plan_32[0].p_div(); let p1_div = self.plan_32[1].p_div(); @@ -375,7 +375,7 @@ impl Plan { let ntt_64 = &*ntt_64; // optimize common cases(?): u64x1, u32x1, u32x2 - if self.plan_32.len() == 0 && self.plan_64.len() == 0 { + if self.plan_32.is_empty() && self.plan_64.is_empty() { match mode { InvMode::Replace => standard.fill(0), InvMode::Accumulate => {} @@ -383,7 +383,7 @@ impl Plan { return; } - if self.plan_32.len() == 0 && self.plan_64.len() == 1 { + if self.plan_32.is_empty() && self.plan_64.len() == 1 { match mode { InvMode::Replace => standard.copy_from_slice(ntt_64), InvMode::Accumulate => { @@ -396,7 +396,7 @@ impl Plan { } return; } - if self.plan_32.len() == 1 && self.plan_64.len() == 0 { + if self.plan_32.len() == 1 && self.plan_64.is_empty() { match mode { InvMode::Replace => { for (standard, &ntt) in standard.iter_mut().zip(ntt_32) { @@ -416,7 +416,7 @@ impl Plan { // implements the algorithms from "the art of computer programming (Donald E. Knuth)" 4.3.2 // for finding solutions of the chinese remainder theorem - if self.plan_32.len() == 2 && self.plan_64.len() == 0 { + if self.plan_32.len() == 2 && self.plan_64.is_empty() { let (ntt0, ntt1) = ntt_32.split_at(self.ntt_size()); let p0 = self.plan_32[0].modulus(); let p1 = self.plan_32[1].modulus(); diff --git a/tfhe/src/core_crypto/fft_impl/fft128/math/fft/mod.rs b/tfhe/src/core_crypto/fft_impl/fft128/math/fft/mod.rs index 8ec1926983..7b5169d551 100644 --- a/tfhe/src/core_crypto/fft_impl/fft128/math/fft/mod.rs +++ b/tfhe/src/core_crypto/fft_impl/fft128/math/fft/mod.rs @@ -166,7 +166,7 @@ pub fn f64_to_u128(f: f64) -> u128 { 0 } else { // >= 1, < max - let m = 1 << 127 | (f as u128) << 75; // Mantissa and the implicit 1-bit. + let m = (1 << 127) | ((f as u128) << 75); // Mantissa and the implicit 1-bit. let s = 1150 - (f >> 52); // Shift based on the exponent and bias. if s >= 128 { 0 @@ -180,13 +180,13 @@ pub fn f64_to_u128(f: f64) -> u128 { pub fn f64_to_i128(f: f64) -> i128 { let f = f.to_bits(); - let a = f & !0 >> 1; // Remove sign bit. + let a = f & (!0 >> 1); // Remove sign bit. if a < 1023 << 52 { // >= 0, < 1 0 } else { // >= 1, < max - let m = 1 << 127 | (a as u128) << 75; // Mantissa and the implicit 1-bit. + let m = (1 << 127) | ((a as u128) << 75); // Mantissa and the implicit 1-bit. let s = 1150 - (a >> 52); // Shift based on the exponent and bias. let u = (m >> s) as i128; // Unsigned result. if (f as i64) < 0 { diff --git a/tfhe/src/core_crypto/fft_impl/fft128_u128/math/fft/mod.rs b/tfhe/src/core_crypto/fft_impl/fft128_u128/math/fft/mod.rs index b9915e6f5d..52fdb790cd 100644 --- a/tfhe/src/core_crypto/fft_impl/fft128_u128/math/fft/mod.rs +++ b/tfhe/src/core_crypto/fft_impl/fft128_u128/math/fft/mod.rs @@ -33,7 +33,7 @@ pub fn u128_to_f64((lo, hi): (u64, u64)) -> f64 { const C: f64 = (1u128 << 76) as f64; const D: f64 = u128::MAX as f64; if hi < 1 << 40 { - let l = f64::from_bits(A.to_bits() | (lo << 12) >> 12) - A; + let l = f64::from_bits(A.to_bits() | ((lo << 12) >> 12)) - A; let h = f64::from_bits(B.to_bits() | ((lo >> 52) | (hi << 12))) - B; l + h } else { @@ -306,7 +306,7 @@ pub fn f64_to_u128(f: f64) -> (u64, u64) { (0u64, 0u64) } else { // >= 1, < max - let hi = 1 << 63 | f << 11; + let hi = (1 << 63) | (f << 11); let s = 1150 - (f >> 52); // Shift based on the exponent and bias. if s >= 128 { (0u64, 0u64) @@ -322,13 +322,13 @@ pub fn f64_to_u128(f: f64) -> (u64, u64) { pub fn f64_to_i128(f: f64) -> (u64, u64) { let f = f.to_bits(); - let a = f & !0 >> 1; // Remove sign bit. + let a = f & (!0 >> 1); // Remove sign bit. if a < 1023 << 52 { // >= 0, < 1 (0, 0) } else { // >= 1, < max - let hi = 1 << 63 | a << 11; + let hi = (1 << 63) | (a << 11); let s = 1150 - (a >> 52); // Shift based on the exponent and bias. let u = if s >= 128 { (0, 0) diff --git a/tfhe/src/integer/gpu/server_key/radix/mod.rs b/tfhe/src/integer/gpu/server_key/radix/mod.rs index af2a02cc48..ccb49e3dfc 100644 --- a/tfhe/src/integer/gpu/server_key/radix/mod.rs +++ b/tfhe/src/integer/gpu/server_key/radix/mod.rs @@ -1160,7 +1160,7 @@ impl CudaServerKey { let num_bits_in_block = message_modulus.ilog2(); let padding_block_creator_lut = self.generate_lookup_table(|x| { let x = x % message_modulus; - let x_sign_bit = x >> (num_bits_in_block - 1) & 1; + let x_sign_bit = (x >> (num_bits_in_block - 1)) & 1; // padding is a message full of 1 if sign bit is one // else padding is a zero message (message_modulus - 1) * x_sign_bit diff --git a/tfhe/src/integer/server_key/radix/mod.rs b/tfhe/src/integer/server_key/radix/mod.rs index 4ad4bcf36b..6623505f26 100644 --- a/tfhe/src/integer/server_key/radix/mod.rs +++ b/tfhe/src/integer/server_key/radix/mod.rs @@ -501,7 +501,7 @@ impl ServerKey { let num_bits_in_block = message_modulus.ilog2(); let padding_block_creator_lut = self.key.generate_lookup_table(|x| { let x = x % message_modulus; - let x_sign_bit = x >> (num_bits_in_block - 1) & 1; + let x_sign_bit = (x >> (num_bits_in_block - 1)) & 1; // padding is a message full of 1 if sign bit is one // else padding is a zero message (message_modulus - 1) * x_sign_bit diff --git a/tfhe/src/integer/server_key/radix/slice.rs b/tfhe/src/integer/server_key/radix/slice.rs index c04846754c..0df05f854e 100644 --- a/tfhe/src/integer/server_key/radix/slice.rs +++ b/tfhe/src/integer/server_key/radix/slice.rs @@ -45,7 +45,7 @@ pub(in crate::integer) fn slice_oneblock_clear_unaligned( offset: usize, block_size: usize, ) -> u64 { - cur_block >> (offset) | ((next_block << (block_size - offset)) % (1 << block_size)) + (cur_block >> (offset)) | ((next_block << (block_size - offset)) % (1 << block_size)) } impl ServerKey { diff --git a/tfhe/src/integer/server_key/radix_parallel/comparison.rs b/tfhe/src/integer/server_key/radix_parallel/comparison.rs index 9f08371741..2392ec5a17 100644 --- a/tfhe/src/integer/server_key/radix_parallel/comparison.rs +++ b/tfhe/src/integer/server_key/radix_parallel/comparison.rs @@ -311,7 +311,7 @@ impl ServerKey { is_x_less_than_y_given_input_borrow(x, y, 0, self.message_modulus()); let b1 = is_x_less_than_y_given_input_borrow(x, y, 1, self.message_modulus()); - (b1 << 1 | b0) << 2 + ((b1 << 1) | b0) << 2 }); Some(PreparedSignedCheck::Unified( diff --git a/tfhe/src/integer/server_key/radix_parallel/scalar_comparison.rs b/tfhe/src/integer/server_key/radix_parallel/scalar_comparison.rs index f6eb10e94d..8635cc92f7 100644 --- a/tfhe/src/integer/server_key/radix_parallel/scalar_comparison.rs +++ b/tfhe/src/integer/server_key/radix_parallel/scalar_comparison.rs @@ -969,7 +969,7 @@ impl ServerKey { }; let b0 = is_x_less_than_y_given_input_borrow(x, y, 0, modulus); let b1 = is_x_less_than_y_given_input_borrow(x, y, 1, modulus); - (b1 << 1 | b0) << 2 + ((b1 << 1) | b0) << 2 }); Some(PreparedSignedCheck::Unified( diff --git a/tfhe/src/integer/server_key/radix_parallel/scalar_shift.rs b/tfhe/src/integer/server_key/radix_parallel/scalar_shift.rs index f93af2375e..77a2da1f31 100644 --- a/tfhe/src/integer/server_key/radix_parallel/scalar_shift.rs +++ b/tfhe/src/integer/server_key/radix_parallel/scalar_shift.rs @@ -176,7 +176,7 @@ impl ServerKey { let shift_last_block = || { let last_block_lut = self.key.generate_lookup_table(|x| { let x = x % message_modulus; - let x_sign_bit = x >> (num_bits_in_block - 1) & 1; + let x_sign_bit = (x >> (num_bits_in_block - 1)) & 1; let shifted = x >> shift_within_block; // padding is a message full of 1 if sign bit is one // else padding is a zero message @@ -193,7 +193,7 @@ impl ServerKey { let pad_block_creator_lut = self.key.generate_lookup_table(|x| { let x = x % message_modulus; - let x_sign_bit = x >> (num_bits_in_block - 1) & 1; + let x_sign_bit = (x >> (num_bits_in_block - 1)) & 1; // padding is a message full of 1 if sign bit is one // else padding is a zero message (message_modulus - 1) * x_sign_bit diff --git a/tfhe/src/shortint/client_key/mod.rs b/tfhe/src/shortint/client_key/mod.rs index 26d9aca041..4a727b3460 100644 --- a/tfhe/src/shortint/client_key/mod.rs +++ b/tfhe/src/shortint/client_key/mod.rs @@ -798,7 +798,7 @@ impl ClientKey { let decrypted_u64: u64 = self.decrypt_no_decode(ct); let mut result = decrypted_u64 as u128 * basis as u128; - result = result.wrapping_add((result & 1 << 63) << 1) / (1 << 64); + result = result.wrapping_add((result & (1 << 63)) << 1) / (1 << 64); result as u64 % basis } diff --git a/utils/tfhe-versionable-derive/src/lib.rs b/utils/tfhe-versionable-derive/src/lib.rs index 3d521294a2..0a5683f7f2 100644 --- a/utils/tfhe-versionable-derive/src/lib.rs +++ b/utils/tfhe-versionable-derive/src/lib.rs @@ -514,7 +514,7 @@ fn remove_unsized_bound( .filter(|bound| match bound { TypeParamBound::Trait(trait_bound) => { if !matches!(trait_bound.modifier, TraitBoundModifier::None) { - if let Some(segment) = trait_bound.path.segments.iter().last() { + if let Some(segment) = trait_bound.path.segments.iter().next_back() { if segment.ident == "Sized" { return false; }