diff --git a/Makefile b/Makefile index a8e0c6f67b..8c06fd597a 100644 --- a/Makefile +++ b/Makefile @@ -179,6 +179,12 @@ clippy_core: install_rs_check_toolchain RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy \ --features=$(TARGET_ARCH_FEATURE),experimental \ -p $(TFHE_SPEC) -- --no-deps -D warnings + RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy \ + --features=$(TARGET_ARCH_FEATURE),nightly-avx512 \ + -p $(TFHE_SPEC) -- --no-deps -D warnings + RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy \ + --features=$(TARGET_ARCH_FEATURE),experimental,nightly-avx512 \ + -p $(TFHE_SPEC) -- --no-deps -D warnings .PHONY: clippy_boolean # Run clippy lints enabling the boolean features clippy_boolean: install_rs_check_toolchain diff --git a/tasks/src/format_latex_doc.rs b/tasks/src/format_latex_doc.rs index 6504c79ef1..253b2490a1 100644 --- a/tasks/src/format_latex_doc.rs +++ b/tasks/src/format_latex_doc.rs @@ -196,7 +196,7 @@ fn find_contiguous_doc_test<'a>( fn find_contiguous_part_in_doc_test_or_comment( part_is_code_block: bool, - full_doc_comment_content: &Vec, + full_doc_comment_content: &[CommentContent], part_start_idx: usize, ) -> (usize, usize) { let mut next_line_idx = part_start_idx + 1; @@ -348,7 +348,7 @@ fn process_doc_lines_until_impossible<'a>( } fn process_non_doc_lines_until_impossible( - lines: &Vec<&str>, + lines: &[&str], rewritten_content: &mut String, mut line_idx: usize, ) -> usize { diff --git a/tfhe/benches/integer/bench.rs b/tfhe/benches/integer/bench.rs index 3eadd9a815..f6a7c909a4 100644 --- a/tfhe/benches/integer/bench.rs +++ b/tfhe/benches/integer/bench.rs @@ -11,6 +11,7 @@ use itertools::iproduct; use rand::prelude::*; use rand::Rng; use std::vec::IntoIter; +use tfhe::core_crypto::algorithms::misc::divide_ceil; use tfhe::integer::keycache::KEY_CACHE; use tfhe::integer::{IntegerKeyKind, RadixCiphertext, RadixClientKey, ServerKey}; use tfhe::keycache::NamedParam; @@ -560,7 +561,7 @@ fn ciphertexts_sum_parallelized(c: &mut Criterion) { bench_group.bench_function(&bench_id, |b| { let (cks, sks) = KEY_CACHE.get_from_params(param, IntegerKeyKind::Radix); - let nb_ctxt = bit_size.div_ceil(param.message_modulus().0.ilog2() as usize); + let nb_ctxt = divide_ceil(bit_size, param.message_modulus().0.ilog2() as usize); let cks = RadixClientKey::from((cks, nb_ctxt)); let encrypt_values = || { @@ -2140,7 +2141,7 @@ fn bench_server_key_cast_function( .bit_sizes() .iter() .copied() - .map(|bit| bit.div_ceil(param.message_modulus().0.ilog2() as usize)) + .map(|bit| divide_ceil(bit, param.message_modulus().0.ilog2() as usize)) .collect::>(); let param_name = param.name(); diff --git a/tfhe/benches/integer/signed_bench.rs b/tfhe/benches/integer/signed_bench.rs index 78c3d4b880..e5abf4fbcc 100644 --- a/tfhe/benches/integer/signed_bench.rs +++ b/tfhe/benches/integer/signed_bench.rs @@ -9,6 +9,7 @@ use itertools::iproduct; use rand::prelude::*; use rand::Rng; use std::vec::IntoIter; +use tfhe::core_crypto::algorithms::misc::divide_ceil; use tfhe::integer::keycache::KEY_CACHE; use tfhe::integer::{IntegerKeyKind, RadixCiphertext, ServerKey, SignedRadixCiphertext, I256}; use tfhe::keycache::NamedParam; @@ -1126,7 +1127,7 @@ fn bench_server_key_signed_cast_function( .bit_sizes() .iter() .copied() - .map(|bit| bit.div_ceil(param.message_modulus().0.ilog2() as usize)) + .map(|bit| divide_ceil(bit, param.message_modulus().0.ilog2() as usize)) .collect::>(); let param_name = param.name(); diff --git a/tfhe/examples/sha256.rs b/tfhe/examples/sha256.rs index 976df54380..cdae69dafd 100644 --- a/tfhe/examples/sha256.rs +++ b/tfhe/examples/sha256.rs @@ -442,16 +442,19 @@ fn sha256_fhe_parallel(input: Vec) -> [FheUint32; 8] { let mut h = hash[7].clone(); for i in 0..64 { + // Please clippy + let e_rotations = || { + let rotations = par_rotr(&e, [6u32, 11, 25]); + &rotations[0] ^ &rotations[1] ^ &rotations[2] + }; + let a_rotations = || { + let rotations = par_rotr(&a, [2u32, 13, 22]); + &rotations[0] ^ &rotations[1] ^ &rotations[2] + }; let (s1, ch, s0, maj) = join!( - || { - let rotations = par_rotr(&e, [6u32, 11, 25]); - &rotations[0] ^ &rotations[1] ^ &rotations[2] - }, + e_rotations, || (&e & &f) ^ ((&e ^ &all_ones) & &g), - || { - let rotations = par_rotr(&a, [2u32, 13, 22]); - &rotations[0] ^ &rotations[1] ^ &rotations[2] - }, + a_rotations, || (&a & &b) ^ (&a & &c) ^ (&b & &c) ); diff --git a/tfhe/src/core_crypto/fft_impl/fft128_u128/crypto/ggsw.rs b/tfhe/src/core_crypto/fft_impl/fft128_u128/crypto/ggsw.rs index 30b6e0ca53..9e6edd1ade 100644 --- a/tfhe/src/core_crypto/fft_impl/fft128_u128/crypto/ggsw.rs +++ b/tfhe/src/core_crypto/fft_impl/fft128_u128/crypto/ggsw.rs @@ -299,10 +299,10 @@ fn collect_next_term_split_avx512( let mod_b_mask_hi = simd.splat_u64x8(mod_b_mask_hi); let shift_minus_64 = simd.splat_u64x8(shift.wrapping_sub(64)); - let _64_minus_shift = simd.splat_u64x8(64u64.wrapping_sub(shift)); + let shift_complement = simd.splat_u64x8(64u64.wrapping_sub(shift)); let shift = simd.splat_u64x8(shift); let base_log_minus_64 = simd.splat_u64x8(base_log.wrapping_sub(64)); - let _64_minus_base_log = simd.splat_u64x8(64u64.wrapping_sub(base_log)); + let base_log_complement = simd.splat_u64x8(64u64.wrapping_sub(base_log)); let base_log = simd.splat_u64x8(base_log); for (out_lo, out_hi, state_lo, state_hi) in izip!( @@ -320,7 +320,7 @@ fn collect_next_term_split_avx512( vstate_lo = simd.or_u64x8( simd.shr_dyn_u64x8(vstate_hi, base_log_minus_64), simd.or_u64x8( - simd.shl_dyn_u64x8(vstate_hi, _64_minus_base_log), + simd.shl_dyn_u64x8(vstate_hi, base_log_complement), simd.shr_dyn_u64x8(vstate_lo, base_log), ), ); @@ -338,7 +338,7 @@ fn collect_next_term_split_avx512( simd.shr_dyn_u64x8(carry_hi, shift_minus_64), simd.or_u64x8( simd.shr_dyn_u64x8(carry_lo, shift), - simd.shr_dyn_u64x8(carry_hi, _64_minus_shift), + simd.shr_dyn_u64x8(carry_hi, shift_complement), ), ); carry_hi = simd.shr_dyn_u64x8(carry_hi, shift); @@ -351,7 +351,7 @@ fn collect_next_term_split_avx512( carry_hi = simd.or_u64x8( simd.or_u64x8( simd.shl_dyn_u64x8(carry_hi, base_log), - simd.shr_dyn_u64x8(carry_lo, _64_minus_base_log), + simd.shr_dyn_u64x8(carry_lo, base_log_complement), ), simd.shl_dyn_u64x8(carry_lo, base_log_minus_64), ); @@ -433,10 +433,10 @@ fn collect_next_term_split_avx2( let mod_b_mask_hi = simd.splat_u64x4(mod_b_mask_hi); let shift_minus_64 = simd.splat_u64x4(shift.wrapping_sub(64)); - let _64_minus_shift = simd.splat_u64x4(64u64.wrapping_sub(shift)); + let shift_complement = simd.splat_u64x4(64u64.wrapping_sub(shift)); let shift = simd.splat_u64x4(shift); let base_log_minus_64 = simd.splat_u64x4(base_log.wrapping_sub(64)); - let _64_minus_base_log = simd.splat_u64x4(64u64.wrapping_sub(base_log)); + let base_log_complement = simd.splat_u64x4(64u64.wrapping_sub(base_log)); let base_log = simd.splat_u64x4(base_log); for (out_lo, out_hi, state_lo, state_hi) in izip!( @@ -454,7 +454,7 @@ fn collect_next_term_split_avx2( vstate_lo = simd.or_u64x4( simd.shr_dyn_u64x4(vstate_hi, base_log_minus_64), simd.or_u64x4( - simd.shl_dyn_u64x4(vstate_hi, _64_minus_base_log), + simd.shl_dyn_u64x4(vstate_hi, base_log_complement), simd.shr_dyn_u64x4(vstate_lo, base_log), ), ); @@ -471,7 +471,7 @@ fn collect_next_term_split_avx2( simd.shr_dyn_u64x4(carry_hi, shift_minus_64), simd.or_u64x4( simd.shr_dyn_u64x4(carry_lo, shift), - simd.shr_dyn_u64x4(carry_hi, _64_minus_shift), + simd.shr_dyn_u64x4(carry_hi, shift_complement), ), ); carry_hi = simd.shr_dyn_u64x4(carry_hi, shift); @@ -484,7 +484,7 @@ fn collect_next_term_split_avx2( carry_hi = simd.or_u64x4( simd.or_u64x4( simd.shl_dyn_u64x4(carry_hi, base_log), - simd.shr_dyn_u64x4(carry_lo, _64_minus_base_log), + simd.shr_dyn_u64x4(carry_lo, base_log_complement), ), simd.shl_dyn_u64x4(carry_lo, base_log_minus_64), ); diff --git a/tfhe/src/high_level_api/global_state.rs b/tfhe/src/high_level_api/global_state.rs index 5e516c9d4b..0e1b6e7885 100644 --- a/tfhe/src/high_level_api/global_state.rs +++ b/tfhe/src/high_level_api/global_state.rs @@ -11,7 +11,7 @@ use std::cell::RefCell; /// (eg a web server that processes multiple requests in multiple threads). /// The user however, has to initialize the internal keys each time it starts a thread. thread_local! { - static INTERNAL_KEYS: RefCell> = RefCell::new(None); + static INTERNAL_KEYS: RefCell> = const { RefCell::new(None) }; } /// The function used to initialize internal keys. diff --git a/tfhe/src/js_on_wasm_api/js_high_level_api/mod.rs b/tfhe/src/js_on_wasm_api/js_high_level_api/mod.rs index 69c3bb9893..5f1106d110 100644 --- a/tfhe/src/js_on_wasm_api/js_high_level_api/mod.rs +++ b/tfhe/src/js_on_wasm_api/js_high_level_api/mod.rs @@ -14,10 +14,8 @@ pub(crate) fn catch_panic_result(closure: F) -> Result where F: FnOnce() -> Result, { - std::panic::catch_unwind(std::panic::AssertUnwindSafe(closure)).map_or_else( - |_| Err(JsError::new("Operation Failed")), - |inner_result| inner_result, - ) + std::panic::catch_unwind(std::panic::AssertUnwindSafe(closure)) + .unwrap_or_else(|_| Err(JsError::new("Operation Failed"))) } pub(crate) fn catch_panic(closure: F) -> Result diff --git a/tfhe/src/lib.rs b/tfhe/src/lib.rs index 4055eb6e15..1a68e5eef1 100644 --- a/tfhe/src/lib.rs +++ b/tfhe/src/lib.rs @@ -62,7 +62,7 @@ any(target_arch = "x86", target_arch = "x86_64"), feature = "nightly-avx512" ), - feature(avx512_target_feature) + feature(avx512_target_feature, stdarch_x86_avx512) )] #![cfg_attr(all(doc, not(doctest)), feature(doc_auto_cfg))] #![cfg_attr(all(doc, not(doctest)), feature(doc_cfg))] diff --git a/tfhe/src/shortint/server_key/tests/noise_level.rs b/tfhe/src/shortint/server_key/tests/noise_level.rs index d812760304..1c61626b00 100644 --- a/tfhe/src/shortint/server_key/tests/noise_level.rs +++ b/tfhe/src/shortint/server_key/tests/noise_level.rs @@ -339,10 +339,10 @@ fn test_noise_level_propagation_ci_run_filter() { test_ct_unary_op_assign_noise_level_propagation(sk, ct); } - for ct1 in [&trivial0, &trivial, &ct1, &ct2] { - for ct2 in [&trivial0, &trivial, &ct1, &ct2] { - test_ct_binary_op_noise_level_propagation(sk, ct1, ct2); - test_ct_binary_op_assign_noise_level_propagation(sk, ct1, ct2); + for ct_left in [&trivial0, &trivial, &ct1, &ct2] { + for ct_right in [&trivial0, &trivial, &ct1, &ct2] { + test_ct_binary_op_noise_level_propagation(sk, ct_left, ct_right); + test_ct_binary_op_assign_noise_level_propagation(sk, ct_left, ct_right); } } diff --git a/toolchain.txt b/toolchain.txt index 96e41fde93..32a59aa422 100644 --- a/toolchain.txt +++ b/toolchain.txt @@ -1 +1 @@ -nightly-2023-11-30 +nightly-2024-02-13