From edb435bd46a02111bd072b0a8247f010939df6de Mon Sep 17 00:00:00 2001 From: Nicolas Sarlin Date: Tue, 18 Nov 2025 14:27:28 +0100 Subject: [PATCH] chore: update msrv to 1.91.1 --- Cargo.toml | 2 +- Makefile | 20 +++++++++----- .../src/fw/fw_impl/ilp_div.rs | 1 + tfhe-fft/src/fft_simd.rs | 2 +- tfhe-fft/src/lib.rs | 2 -- tfhe-ntt/src/prime.rs | 26 +++++++++---------- tfhe-ntt/src/product.rs | 2 +- tfhe-ntt/src/roots.rs | 2 +- tfhe-zk-pok/src/four_squares.rs | 2 +- tfhe/examples/sha256_bool/padding.rs | 2 +- tfhe/src/c_api/utils.rs | 2 +- tfhe/src/conformance.rs | 2 +- .../algorithms/polynomial_algorithms.rs | 14 +++++----- .../lwe_multi_bit_bootstrap_key_generation.rs | 2 +- .../traits/contiguous_entity_container.rs | 8 +++--- .../core_crypto/entities/ggsw_ciphertext.rs | 4 ++- .../entities/ggsw_ciphertext_list.rs | 6 ++--- .../core_crypto/entities/glwe_ciphertext.rs | 4 +-- .../entities/glwe_ciphertext_list.rs | 4 ++- .../entities/glwe_keyswitch_key.rs | 6 ++--- .../core_crypto/entities/glwe_secret_key.rs | 2 +- .../core_crypto/entities/lwe_ciphertext.rs | 2 +- .../entities/lwe_ciphertext_list.rs | 2 +- .../entities/lwe_compact_ciphertext_list.rs | 2 +- .../core_crypto/entities/lwe_keyswitch_key.rs | 6 ++--- .../entities/lwe_keyswitch_key_chunk.rs | 6 ++--- .../fft64_lwe_multi_bit_bootstrap_key.rs | 4 +-- .../lwe_multi_bit_bootstrap_key/mod.rs | 2 +- .../standard_lwe_multi_bit_bootstrap_key.rs | 6 +++-- .../entities/lwe_packing_keyswitch_key.rs | 6 ++--- ...rivate_functional_packing_keyswitch_key.rs | 8 +++--- ...e_functional_packing_keyswitch_key_list.rs | 14 +++++----- .../entities/ntt_ggsw_ciphertext_list.rs | 8 +++--- .../core_crypto/entities/polynomial_list.rs | 2 +- .../entities/seeded_ggsw_ciphertext.rs | 4 ++- .../entities/seeded_ggsw_ciphertext_list.rs | 11 +++++--- .../entities/seeded_lwe_keyswitch_key.rs | 4 ++- .../seeded_lwe_keyswitch_key_chunk.rs | 4 ++- .../seeded_lwe_multi_bit_bootstrap_key.rs | 6 +++-- .../seeded_lwe_packing_keyswitch_key.rs | 4 ++- .../entities/pseudo_ggsw_ciphertext.rs | 6 ++--- .../fft_impl/fft128_u128/crypto/bootstrap.rs | 4 +-- .../fft_impl/fft64/math/fft/mod.rs | 7 ++--- tfhe/src/high_level_api/compact_list.rs | 2 +- tfhe/src/high_level_api/global_state.rs | 9 ++----- tfhe/src/integer/ciphertext/compact_list.rs | 2 +- .../server_key/radix_parallel/div_mod.rs | 4 +-- .../modulus_switch_compression.rs | 2 +- tfhe/src/shortint/oprf.rs | 4 +-- tfhe/src/strings/ciphertext.rs | 2 +- .../web_wasm_parallel_tests/package-lock.json | 12 ++++----- toolchain.txt | 2 +- utils/param_dedup/src/main.rs | 2 +- utils/tfhe-lints/Cargo.toml | 2 +- utils/tfhe-lints/README.md | 10 +++++++ utils/tfhe-lints/rust-toolchain | 2 +- .../src/serialize_without_versionize.rs | 9 +++---- 57 files changed, 164 insertions(+), 133 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b686ce395..35d48aeff 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,7 @@ exclude = [ ] [workspace.package] -rust-version = "1.85" +rust-version = "1.91.1" [workspace.dependencies] aligned-vec = { version = "0.6", default-features = false } diff --git a/Makefile b/Makefile index 0b9d60840..6d9cff50f 100644 --- a/Makefile +++ b/Makefile @@ -427,10 +427,10 @@ clippy_rustdoc: install_rs_check_toolchain echo "WARNING: skipped clippy_rustdoc, unsupported OS $(OS)"; \ exit 0; \ fi && \ - CARGO_TERM_QUIET=true CLIPPYFLAGS="-D warnings" RUSTDOCFLAGS="--no-run --nocapture --test-builder ./scripts/clippy_driver.sh -Z unstable-options" \ + CARGO_TERM_QUIET=true CLIPPYFLAGS="-D warnings" RUSTDOCFLAGS="--no-run --test-builder ./scripts/clippy_driver.sh -Z unstable-options" \ cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" test --doc \ --features=boolean,shortint,integer,zk-pok,pbs-stats,strings,experimental \ - -p tfhe + -p tfhe -- --nocapture .PHONY: clippy_rustdoc_gpu # Run clippy lints on doctests enabling the boolean, shortint, integer and zk-pok clippy_rustdoc_gpu: install_rs_check_toolchain @@ -438,10 +438,10 @@ clippy_rustdoc_gpu: install_rs_check_toolchain echo "WARNING: skipped clippy_rustdoc_gpu, unsupported OS $(OS)"; \ exit 0; \ fi && \ - CARGO_TERM_QUIET=true CLIPPYFLAGS="-D warnings" RUSTDOCFLAGS="--no-run --nocapture --test-builder ./scripts/clippy_driver.sh -Z unstable-options" \ + CARGO_TERM_QUIET=true CLIPPYFLAGS="-D warnings" RUSTDOCFLAGS="--no-run --test-builder ./scripts/clippy_driver.sh -Z unstable-options" \ cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" test --doc \ --features=boolean,shortint,integer,zk-pok,pbs-stats,strings,experimental,gpu \ - -p tfhe + -p tfhe -- --nocapture .PHONY: clippy_c_api # Run clippy lints enabling the boolean, shortint and the C API clippy_c_api: install_rs_check_toolchain @@ -649,11 +649,19 @@ build_web_js_api: install_rs_build_toolchain install_wasm_pack -- --features=boolean-client-js-wasm-api,shortint-client-js-wasm-api,integer-client-js-wasm-api,zk-pok,extended-types .PHONY: build_web_js_api_parallel # Build the js API targeting the web browser with parallelism support +# parallel wasm requires specific build options, see https://github.com/rust-lang/rust/pull/147225 build_web_js_api_parallel: install_rs_check_toolchain install_wasm_pack cd tfhe && \ rustup component add rust-src --toolchain $(RS_CHECK_TOOLCHAIN) && \ - RUSTFLAGS="$(WASM_RUSTFLAGS) -C target-feature=+atomics,+bulk-memory" rustup run $(RS_CHECK_TOOLCHAIN) \ - wasm-pack build --release --target=web \ + RUSTFLAGS="$(WASM_RUSTFLAGS) -C target-feature=+atomics,+bulk-memory \ + -Clink-arg=--shared-memory \ + -Clink-arg=--max-memory=1073741824 \ + -Clink-arg=--import-memory \ + -Clink-arg=--export=__wasm_init_tls \ + -Clink-arg=--export=__tls_size \ + -Clink-arg=--export=__tls_align \ + -Clink-arg=--export=__tls_base" \ + rustup run $(RS_CHECK_TOOLCHAIN) wasm-pack build --release --target=web \ -- --features=boolean-client-js-wasm-api,shortint-client-js-wasm-api,integer-client-js-wasm-api,parallel-wasm-api,zk-pok,extended-types \ -Z build-std=panic_abort,std && \ find pkg/snippets -type f -iname workerHelpers.js -exec sed -i "s|const pkg = await import('..\/..\/..');|const pkg = await import('..\/..\/..\/tfhe.js');|" {} \; diff --git a/backends/tfhe-hpu-backend/src/fw/fw_impl/ilp_div.rs b/backends/tfhe-hpu-backend/src/fw/fw_impl/ilp_div.rs index 58547e33e..351ef9c63 100644 --- a/backends/tfhe-hpu-backend/src/fw/fw_impl/ilp_div.rs +++ b/backends/tfhe-hpu-backend/src/fw/fw_impl/ilp_div.rs @@ -659,6 +659,7 @@ pub fn iop_div_corev( } remain_a = Vec::new(); + #[allow(clippy::needless_range_loop)] for i in 0..block_nb { remain_tmp_v[0][i] = &remain_tmp_v[0][i] + &remain_tmp_v[1][i]; remain_tmp_v[2][i] = &remain_tmp_v[2][i] + &remain_tmp_v[3][i]; diff --git a/tfhe-fft/src/fft_simd.rs b/tfhe-fft/src/fft_simd.rs index bba470d07..550697cb2 100644 --- a/tfhe-fft/src/fft_simd.rs +++ b/tfhe-fft/src/fft_simd.rs @@ -54,7 +54,7 @@ pub const H1Y: f64 = -0.38268343236508984f64; struct AssertC64Vec(PhantomData); impl AssertC64Vec { pub const VALID: () = { - assert!(core::mem::size_of::() % core::mem::size_of::() == 0); + assert!(core::mem::size_of::().is_multiple_of(core::mem::size_of::())); }; } diff --git a/tfhe-fft/src/lib.rs b/tfhe-fft/src/lib.rs index 1bfdf1a24..337383b0e 100644 --- a/tfhe-fft/src/lib.rs +++ b/tfhe-fft/src/lib.rs @@ -73,8 +73,6 @@ clippy::too_many_arguments, non_camel_case_types )] -// Should be removed when we raise MSRV above 1.87 -#![allow(clippy::manual_is_multiple_of)] #![cfg_attr(docsrs, feature(doc_cfg))] #![warn(rustdoc::broken_intra_doc_links)] diff --git a/tfhe-ntt/src/prime.rs b/tfhe-ntt/src/prime.rs index a050d0cc1..29157a375 100644 --- a/tfhe-ntt/src/prime.rs +++ b/tfhe-ntt/src/prime.rs @@ -83,18 +83,18 @@ pub const fn is_prime64(n: u64) -> bool { // hand-unrolled for the compiler to optimize divisions #[rustfmt::skip] { - if n % 2 == 0 { return n == 2; } - if n % 3 == 0 { return n == 3; } - if n % 5 == 0 { return n == 5; } - if n % 7 == 0 { return n == 7; } - if n % 11 == 0 { return n == 11; } - if n % 13 == 0 { return n == 13; } - if n % 17 == 0 { return n == 17; } - if n % 19 == 0 { return n == 19; } - if n % 23 == 0 { return n == 23; } - if n % 29 == 0 { return n == 29; } - if n % 31 == 0 { return n == 31; } - if n % 37 == 0 { return n == 37; } + if n.is_multiple_of(2) { return n == 2; } + if n.is_multiple_of(3) { return n == 3; } + if n.is_multiple_of(5) { return n == 5; } + if n.is_multiple_of(7) { return n == 7; } + if n.is_multiple_of(11) { return n == 11; } + if n.is_multiple_of(13) { return n == 13; } + if n.is_multiple_of(17) { return n == 17; } + if n.is_multiple_of(19) { return n == 19; } + if n.is_multiple_of(23) { return n == 23; } + if n.is_multiple_of(29) { return n == 29; } + if n.is_multiple_of(31) { return n == 31; } + if n.is_multiple_of(37) { return n == 37; } }; // deterministic miller rabin test, works for any n < 2^64 @@ -104,7 +104,7 @@ pub const fn is_prime64(n: u64) -> bool { let mut s = 0; let mut d = n - 1; - while d % 2 == 0 { + while d.is_multiple_of(2) { s += 1; d /= 2; } diff --git a/tfhe-ntt/src/product.rs b/tfhe-ntt/src/product.rs index bed2eac55..18904b87d 100644 --- a/tfhe-ntt/src/product.rs +++ b/tfhe-ntt/src/product.rs @@ -156,7 +156,7 @@ impl Plan { factors: impl AsRef<[u64]>, ) -> Option { fn try_new_impl(polynomial_size: usize, modulus: u64, primes: &mut [u64]) -> Option { - if polynomial_size % 2 != 0 { + if !polynomial_size.is_multiple_of(2) { return None; } diff --git a/tfhe-ntt/src/roots.rs b/tfhe-ntt/src/roots.rs index e9cf58641..9c9ddd29d 100644 --- a/tfhe-ntt/src/roots.rs +++ b/tfhe-ntt/src/roots.rs @@ -7,7 +7,7 @@ pub const fn get_q_s64(p: Div64) -> (u64, u64) { let p = p.divisor(); let mut q = p - 1; let mut s = 0; - while q % 2 == 0 { + while q.is_multiple_of(2) { q /= 2; s += 1; } diff --git a/tfhe-zk-pok/src/four_squares.rs b/tfhe-zk-pok/src/four_squares.rs index 0d5872ef4..76d68391e 100644 --- a/tfhe-zk-pok/src/four_squares.rs +++ b/tfhe-zk-pok/src/four_squares.rs @@ -226,7 +226,7 @@ pub fn four_squares(v: u128, sanity_check_mode: ProofSanityCheckMode) -> [u64; 4 let mut d = p - 1; let mut s = 0u32; - while d % 2 == 0 { + while d.is_multiple_of(2) { d /= 2; s += 1; } diff --git a/tfhe/examples/sha256_bool/padding.rs b/tfhe/examples/sha256_bool/padding.rs index 4b5c1f1b5..4e951cd5f 100644 --- a/tfhe/examples/sha256_bool/padding.rs +++ b/tfhe/examples/sha256_bool/padding.rs @@ -8,7 +8,7 @@ pub fn pad_sha256_input(input: &str) -> Vec { let bytes = if input.starts_with("0x") && is_valid_hex(&input[2..]) { let no_prefix = &input[2..]; - let hex_input = if no_prefix.len() % 2 == 0 { + let hex_input = if no_prefix.len().is_multiple_of(2) { // hex value can be converted to bytes no_prefix.to_string() } else { diff --git a/tfhe/src/c_api/utils.rs b/tfhe/src/c_api/utils.rs index 8c0966ed6..091fe9c84 100644 --- a/tfhe/src/c_api/utils.rs +++ b/tfhe/src/c_api/utils.rs @@ -18,7 +18,7 @@ pub fn check_ptr_is_non_null_and_aligned(ptr: *const T) -> Result<(), String> return Err(format!("pointer is null, got: {ptr:p}")); } let expected_alignment = std::mem::align_of::(); - if ptr as usize % expected_alignment != 0 { + if !(ptr as usize).is_multiple_of(expected_alignment) { return Err(format!( "pointer is misaligned, expected {expected_alignment} bytes alignment, got pointer: \ {ptr:p}. You May have mixed some pointers in your function call. If that's not the \ diff --git a/tfhe/src/conformance.rs b/tfhe/src/conformance.rs index 55a03f18f..627aa06a2 100644 --- a/tfhe/src/conformance.rs +++ b/tfhe/src/conformance.rs @@ -67,7 +67,7 @@ impl ListSizeConstraint { if self.group_size == 0 { size == 0 } else { - size % self.group_size == 0 + size.is_multiple_of(self.group_size) && size >= self.min_inclusive_group_count * self.group_size && size <= self.max_inclusive_group_count * self.group_size } diff --git a/tfhe/src/core_crypto/algorithms/polynomial_algorithms.rs b/tfhe/src/core_crypto/algorithms/polynomial_algorithms.rs index 024824307..3b8e9431b 100644 --- a/tfhe/src/core_crypto/algorithms/polynomial_algorithms.rs +++ b/tfhe/src/core_crypto/algorithms/polynomial_algorithms.rs @@ -400,7 +400,7 @@ pub fn polynomial_wrapping_monic_monomial_div_assign( OutputCont: ContainerMut, { let full_cycles_count = monomial_degree.0 / output.as_ref().container_len(); - if full_cycles_count % 2 != 0 { + if !full_cycles_count.is_multiple_of(2) { output .as_mut() .iter_mut() @@ -425,7 +425,7 @@ pub fn polynomial_wrapping_monic_monomial_div_assign_custom_mod, { let full_cycles_count = monomial_degree.0 / output.as_ref().container_len(); - if full_cycles_count % 2 != 0 { + if !full_cycles_count.is_multiple_of(2) { output .as_mut() .iter_mut() @@ -467,7 +467,7 @@ pub fn polynomial_wrapping_monic_monomial_mul_assign( OutputCont: ContainerMut, { let full_cycles_count = monomial_degree.0 / output.as_ref().container_len(); - if full_cycles_count % 2 != 0 { + if !full_cycles_count.is_multiple_of(2) { output .as_mut() .iter_mut() @@ -491,7 +491,7 @@ pub fn polynomial_wrapping_monic_monomial_mul_assign_custom_mod, { let full_cycles_count = monomial_degree.0 / output.as_ref().container_len(); - if full_cycles_count % 2 != 0 { + if !full_cycles_count.is_multiple_of(2) { output .as_mut() .iter_mut() @@ -561,7 +561,7 @@ pub fn polynomial_wrapping_monic_monomial_div( let remaining_degree = monomial_degree.0 % polynomial_size; let full_cycles_count = monomial_degree.0 / polynomial_size; - if full_cycles_count % 2 == 0 { + if full_cycles_count.is_multiple_of(2) { copy_without_neg( &mut output[..polynomial_size - remaining_degree], &input[remaining_degree..], @@ -625,7 +625,7 @@ pub fn polynomial_wrapping_monic_monomial_mul( let remaining_degree = monomial_degree.0 % polynomial_size; let full_cycles_count = monomial_degree.0 / polynomial_size; - if full_cycles_count % 2 == 0 { + if full_cycles_count.is_multiple_of(2) { copy_with_neg( &mut output[..remaining_degree], &input[polynomial_size - remaining_degree..], @@ -701,7 +701,7 @@ pub(crate) fn polynomial_wrapping_monic_monomial_mul_and_subtract { ) -> ChunksExactWrappingLendingIterator<'_, Self::Element, Self::SelfView<'_>> { let entity_count = self.entity_count(); assert!( - entity_count % chunk_size == 0, + entity_count.is_multiple_of(chunk_size), "The current container has {entity_count} entities, which is not dividable by the \ requested chunk_size: {chunk_size}, preventing chunks_exact from returning an iterator." ); @@ -297,7 +297,7 @@ pub trait ContiguousEntityContainer: AsRef<[Self::Element]> { { let entity_count = self.entity_count(); assert!( - entity_count % chunk_size == 0, + entity_count.is_multiple_of(chunk_size), "The current container has {entity_count} entities, which is not dividable by the \ requested chunk_size: {chunk_size}, preventing chunks_exact from returning an iterator." ); @@ -435,7 +435,7 @@ pub trait ContiguousEntityContainerMut: ContiguousEntityContainer + AsMut<[Self: ) -> ChunksExactWrappingLendingIteratorMut<'_, Self::Element, Self::SelfMutView<'_>> { let entity_count = self.entity_count(); assert!( - entity_count % chunk_size == 0, + entity_count.is_multiple_of(chunk_size), "The current container has {entity_count} entities, which is not dividable by the \ requested chunk_size: {chunk_size}, preventing chunks_exact_mut from returning an \ iterator." @@ -515,7 +515,7 @@ pub trait ContiguousEntityContainerMut: ContiguousEntityContainer + AsMut<[Self: { let entity_count = self.entity_count(); assert!( - entity_count % chunk_size == 0, + entity_count.is_multiple_of(chunk_size), "The current container has {entity_count} entities, which is not dividable by the \ requested chunk_size: {chunk_size}, preventing chunks_exact from returning an iterator." ); diff --git a/tfhe/src/core_crypto/entities/ggsw_ciphertext.rs b/tfhe/src/core_crypto/entities/ggsw_ciphertext.rs index dabce3733..350019900 100644 --- a/tfhe/src/core_crypto/entities/ggsw_ciphertext.rs +++ b/tfhe/src/core_crypto/entities/ggsw_ciphertext.rs @@ -406,7 +406,9 @@ impl> GgswCiphertext "Got an empty container to create a GgswCiphertext" ); assert!( - container.container_len() % (glwe_size.0 * glwe_size.0 * polynomial_size.0) == 0, + container + .container_len() + .is_multiple_of(glwe_size.0 * glwe_size.0 * polynomial_size.0), "The provided container length is not valid. \ It needs to be dividable by glwe_size * glwe_size * polynomial_size: {}. \ Got container length: {} and glwe_size: {glwe_size:?}, \ diff --git a/tfhe/src/core_crypto/entities/ggsw_ciphertext_list.rs b/tfhe/src/core_crypto/entities/ggsw_ciphertext_list.rs index 93ee8f016..4b0cac98a 100644 --- a/tfhe/src/core_crypto/entities/ggsw_ciphertext_list.rs +++ b/tfhe/src/core_crypto/entities/ggsw_ciphertext_list.rs @@ -173,9 +173,9 @@ impl> GgswCiphertextList ciphertext_modulus: CiphertextModulus, ) -> Self { assert!( - container.container_len() - % (decomp_level_count.0 * glwe_size.0 * glwe_size.0 * polynomial_size.0) - == 0, + container.container_len().is_multiple_of( + decomp_level_count.0 * glwe_size.0 * glwe_size.0 * polynomial_size.0 + ), "The provided container length is not valid. \ It needs to be dividable by decomp_level_count * glwe_size * glwe_size * polynomial_size: \ {}.Got container length: {} and decomp_level_count: {decomp_level_count:?}, \ diff --git a/tfhe/src/core_crypto/entities/glwe_ciphertext.rs b/tfhe/src/core_crypto/entities/glwe_ciphertext.rs index b160c5ac1..ae4d1deaf 100644 --- a/tfhe/src/core_crypto/entities/glwe_ciphertext.rs +++ b/tfhe/src/core_crypto/entities/glwe_ciphertext.rs @@ -141,7 +141,7 @@ impl> GlweMask { ciphertext_modulus: CiphertextModulus, ) -> Self { assert!( - container.container_len() % polynomial_size.0 == 0, + container.container_len().is_multiple_of(polynomial_size.0), "The provided container length is not valid. \ It needs to be dividable by polynomial_size. \ Got container length: {} and polynomial_size: {polynomial_size:?}.", @@ -414,7 +414,7 @@ impl> GlweCiphertext "Got an empty container to create a GlweCiphertext" ); assert!( - container.container_len() % polynomial_size.0 == 0, + container.container_len().is_multiple_of(polynomial_size.0), "The provided container length is not valid. \ It needs to be dividable by polynomial_size. \ Got container length: {} and polynomial_size: {polynomial_size:?}.", diff --git a/tfhe/src/core_crypto/entities/glwe_ciphertext_list.rs b/tfhe/src/core_crypto/entities/glwe_ciphertext_list.rs index d7fdad9b2..f4f4e3228 100644 --- a/tfhe/src/core_crypto/entities/glwe_ciphertext_list.rs +++ b/tfhe/src/core_crypto/entities/glwe_ciphertext_list.rs @@ -126,7 +126,9 @@ impl> GlweCiphertextList ciphertext_modulus: CiphertextModulus, ) -> Self { assert!( - container.container_len() % glwe_ciphertext_size(glwe_size, polynomial_size) == 0, + container + .container_len() + .is_multiple_of(glwe_ciphertext_size(glwe_size, polynomial_size)), "The provided container length is not valid. \ It needs to be dividable by glwe_size * polynomial_size. \ Got container length: {}, glwe_size: {glwe_size:?}, polynomial_size: {polynomial_size:?}.", diff --git a/tfhe/src/core_crypto/entities/glwe_keyswitch_key.rs b/tfhe/src/core_crypto/entities/glwe_keyswitch_key.rs index 059c0e662..0c2ea8b7b 100644 --- a/tfhe/src/core_crypto/entities/glwe_keyswitch_key.rs +++ b/tfhe/src/core_crypto/entities/glwe_keyswitch_key.rs @@ -195,13 +195,13 @@ impl> GlweKeyswitchKey> GlweSecretKey { "Got an empty container to create a GlweSecretKey" ); assert!( - container.container_len() % polynomial_size.0 == 0, + container.container_len().is_multiple_of(polynomial_size.0), "The provided container length is not valid. \ It needs to be dividable by polynomial_size. \ Got container length: {} and polynomial_size: {polynomial_size:?}", diff --git a/tfhe/src/core_crypto/entities/lwe_ciphertext.rs b/tfhe/src/core_crypto/entities/lwe_ciphertext.rs index 52339870f..168e6848a 100644 --- a/tfhe/src/core_crypto/entities/lwe_ciphertext.rs +++ b/tfhe/src/core_crypto/entities/lwe_ciphertext.rs @@ -382,7 +382,7 @@ impl> LweMaskList { ciphertext_modulus: CiphertextModulus, ) -> Self { assert!( - container.container_len() % lwe_dimension.0 == 0, + container.container_len().is_multiple_of(lwe_dimension.0), "The provided container length is not valid. \ It needs to be dividable by lwe_dimension. \ Got container length: {} and lwe_dimension: {lwe_dimension:?}.", diff --git a/tfhe/src/core_crypto/entities/lwe_ciphertext_list.rs b/tfhe/src/core_crypto/entities/lwe_ciphertext_list.rs index a4eb727bc..3c13bb185 100644 --- a/tfhe/src/core_crypto/entities/lwe_ciphertext_list.rs +++ b/tfhe/src/core_crypto/entities/lwe_ciphertext_list.rs @@ -144,7 +144,7 @@ impl> LweCiphertextList< ciphertext_modulus: CiphertextModulus, ) -> Self { assert!( - container.container_len() % lwe_size.0 == 0, + container.container_len().is_multiple_of(lwe_size.0), "The provided container length is not valid. \ It needs to be dividable by lwe_size. \ Got container length: {} and lwe_size: {lwe_size:?}.", diff --git a/tfhe/src/core_crypto/entities/lwe_compact_ciphertext_list.rs b/tfhe/src/core_crypto/entities/lwe_compact_ciphertext_list.rs index af20a3e9d..bcda1e4c8 100644 --- a/tfhe/src/core_crypto/entities/lwe_compact_ciphertext_list.rs +++ b/tfhe/src/core_crypto/entities/lwe_compact_ciphertext_list.rs @@ -48,7 +48,7 @@ pub fn lwe_compact_ciphertext_list_mask_count( ) -> LweMaskCount { LweMaskCount( lwe_ciphertext_count.0 / lwe_dimension.0 - + if lwe_ciphertext_count.0 % lwe_dimension.0 == 0 { + + if lwe_ciphertext_count.0.is_multiple_of(lwe_dimension.0) { 0 } else { 1 diff --git a/tfhe/src/core_crypto/entities/lwe_keyswitch_key.rs b/tfhe/src/core_crypto/entities/lwe_keyswitch_key.rs index 7f973eb4c..89b93f3ec 100644 --- a/tfhe/src/core_crypto/entities/lwe_keyswitch_key.rs +++ b/tfhe/src/core_crypto/entities/lwe_keyswitch_key.rs @@ -188,12 +188,12 @@ impl> LweKeyswitchKey "Got an empty container to create an LweKeyswitchKey" ); assert!( - container.container_len() - % lwe_keyswitch_key_input_key_element_encrypted_size( + container.container_len().is_multiple_of( + lwe_keyswitch_key_input_key_element_encrypted_size( decomp_level_count, output_lwe_size ) - == 0, + ), "The provided container length is not valid. \ It needs to be dividable by decomp_level_count * output_lwe_size: {}. \ Got container length: {} and decomp_level_count: {decomp_level_count:?}, \ diff --git a/tfhe/src/core_crypto/entities/lwe_keyswitch_key_chunk.rs b/tfhe/src/core_crypto/entities/lwe_keyswitch_key_chunk.rs index 163dc58b5..d7bc46bf7 100644 --- a/tfhe/src/core_crypto/entities/lwe_keyswitch_key_chunk.rs +++ b/tfhe/src/core_crypto/entities/lwe_keyswitch_key_chunk.rs @@ -122,12 +122,12 @@ impl> LweKeyswitchKeyChu "Got an empty container to create an LweKeyswitchKeyChunk" ); assert!( - container.container_len() - % lwe_keyswitch_key_input_key_element_encrypted_size( + container.container_len().is_multiple_of( + lwe_keyswitch_key_input_key_element_encrypted_size( decomp_level_count, output_lwe_size ) - == 0, + ), "The provided container length is not valid. \ It needs to be dividable by decomp_level_count * output_lwe_size: {}. \ Got container length: {} and decomp_level_count: {decomp_level_count:?}, \ diff --git a/tfhe/src/core_crypto/entities/lwe_multi_bit_bootstrap_key/fft64_lwe_multi_bit_bootstrap_key.rs b/tfhe/src/core_crypto/entities/lwe_multi_bit_bootstrap_key/fft64_lwe_multi_bit_bootstrap_key.rs index 41e983a2c..8a459c21d 100644 --- a/tfhe/src/core_crypto/entities/lwe_multi_bit_bootstrap_key/fft64_lwe_multi_bit_bootstrap_key.rs +++ b/tfhe/src/core_crypto/entities/lwe_multi_bit_bootstrap_key/fft64_lwe_multi_bit_bootstrap_key.rs @@ -37,7 +37,7 @@ impl> FourierLweMultiBitBootstrapKey { grouping_factor: LweBskGroupingFactor, ) -> Self { assert!( - input_lwe_dimension.0 % grouping_factor.0 == 0, + input_lwe_dimension.0.is_multiple_of(grouping_factor.0), "Multi Bit BSK requires input LWE dimension to be a multiple of {}", grouping_factor.0 ); @@ -182,7 +182,7 @@ impl FourierLweMultiBitBootstrapKeyOwned { grouping_factor: LweBskGroupingFactor, ) -> Self { assert!( - input_lwe_dimension.0 % grouping_factor.0 == 0, + input_lwe_dimension.0.is_multiple_of(grouping_factor.0), "Multi Bit BSK requires input LWE dimension ({}) to be a multiple of {}", input_lwe_dimension.0, grouping_factor.0 diff --git a/tfhe/src/core_crypto/entities/lwe_multi_bit_bootstrap_key/mod.rs b/tfhe/src/core_crypto/entities/lwe_multi_bit_bootstrap_key/mod.rs index aa09f5e94..da2251e2b 100644 --- a/tfhe/src/core_crypto/entities/lwe_multi_bit_bootstrap_key/mod.rs +++ b/tfhe/src/core_crypto/entities/lwe_multi_bit_bootstrap_key/mod.rs @@ -26,7 +26,7 @@ pub fn equivalent_multi_bit_lwe_dimension( input_lwe_dimension: LweDimension, grouping_factor: LweBskGroupingFactor, ) -> Result { - if input_lwe_dimension.0 % grouping_factor.0 != 0 { + if !input_lwe_dimension.0.is_multiple_of(grouping_factor.0) { return Err("equivalent_multi_bit_lwe_dimension error: \ input_lwe_dimension is required to be a multiple of grouping_factor"); } diff --git a/tfhe/src/core_crypto/entities/lwe_multi_bit_bootstrap_key/standard_lwe_multi_bit_bootstrap_key.rs b/tfhe/src/core_crypto/entities/lwe_multi_bit_bootstrap_key/standard_lwe_multi_bit_bootstrap_key.rs index bee44157a..540069b41 100644 --- a/tfhe/src/core_crypto/entities/lwe_multi_bit_bootstrap_key/standard_lwe_multi_bit_bootstrap_key.rs +++ b/tfhe/src/core_crypto/entities/lwe_multi_bit_bootstrap_key/standard_lwe_multi_bit_bootstrap_key.rs @@ -196,7 +196,9 @@ impl> LweMultiBitBootstr grouping_factor, }; assert!( - bsk.input_lwe_dimension().0 % grouping_factor.0 == 0, + bsk.input_lwe_dimension() + .0 + .is_multiple_of(grouping_factor.0), "Input LWE dimension ({}) of the bootstrap key needs to be a multiple of {}", bsk.input_lwe_dimension().0, grouping_factor.0, @@ -333,7 +335,7 @@ impl LweMultiBitBootstrapKeyOwned { ciphertext_modulus: CiphertextModulus, ) -> Self { assert!( - input_lwe_dimension.0 % grouping_factor.0 == 0, + input_lwe_dimension.0.is_multiple_of(grouping_factor.0), "Multi Bit BSK requires input LWE dimension ({}) to be a multiple of {}", input_lwe_dimension.0, grouping_factor.0 diff --git a/tfhe/src/core_crypto/entities/lwe_packing_keyswitch_key.rs b/tfhe/src/core_crypto/entities/lwe_packing_keyswitch_key.rs index 88d938bee..eca09c0b3 100644 --- a/tfhe/src/core_crypto/entities/lwe_packing_keyswitch_key.rs +++ b/tfhe/src/core_crypto/entities/lwe_packing_keyswitch_key.rs @@ -144,13 +144,13 @@ impl> LwePackingKeyswitc "Got an empty container to create an LwePackingKeyswitchKey" ); assert!( - container.container_len() - % lwe_packing_keyswitch_key_input_key_element_encrypted_size( + container.container_len().is_multiple_of( + lwe_packing_keyswitch_key_input_key_element_encrypted_size( decomp_level_count, output_glwe_size, output_polynomial_size ) - == 0, + ), "The provided container length is not valid. \ It needs to be dividable by: {}. Got container length: {} and decomp_level_count: \ {decomp_level_count:?}, output_glwe_size: {output_glwe_size:?}, output_polynomial_size: \ diff --git a/tfhe/src/core_crypto/entities/lwe_private_functional_packing_keyswitch_key.rs b/tfhe/src/core_crypto/entities/lwe_private_functional_packing_keyswitch_key.rs index 2f6d1e516..076b83af2 100644 --- a/tfhe/src/core_crypto/entities/lwe_private_functional_packing_keyswitch_key.rs +++ b/tfhe/src/core_crypto/entities/lwe_private_functional_packing_keyswitch_key.rs @@ -211,13 +211,13 @@ impl> "Got an empty container to create an LweKeyswitchKey" ); assert!( - container.container_len() - % lwe_pfpksk_input_key_element_encrypted_size( + container + .container_len() + .is_multiple_of(lwe_pfpksk_input_key_element_encrypted_size( decomp_level_count, output_glwe_size, output_polynomial_size - ) - == 0, + )), "The provided container length is not valid. \ It needs to be dividable by decomp_level_count * output_glwe_size * output_polynomial_size:\ {}. Got container length: {} and decomp_level_count: {decomp_level_count:?}, \ diff --git a/tfhe/src/core_crypto/entities/lwe_private_functional_packing_keyswitch_key_list.rs b/tfhe/src/core_crypto/entities/lwe_private_functional_packing_keyswitch_key_list.rs index e3d7ce0c4..64c593c65 100644 --- a/tfhe/src/core_crypto/entities/lwe_private_functional_packing_keyswitch_key_list.rs +++ b/tfhe/src/core_crypto/entities/lwe_private_functional_packing_keyswitch_key_list.rs @@ -144,14 +144,12 @@ impl> ciphertext_modulus: CiphertextModulus, ) -> Self { assert!( - container.container_len() - % lwe_pfpksk_size( - input_lwe_size, - decomp_level_count, - output_glwe_size, - output_polynomial_size - ) - == 0, + container.container_len().is_multiple_of(lwe_pfpksk_size( + input_lwe_size, + decomp_level_count, + output_glwe_size, + output_polynomial_size + )), "The provided container length is not valid. \ It needs to be dividable by input_lwe_size * decomp_level_count * output_glwe_size * \ output_polynomial_size: {}. Got container length: {} and input_lwe_size: {input_lwe_size:?}\ diff --git a/tfhe/src/core_crypto/entities/ntt_ggsw_ciphertext_list.rs b/tfhe/src/core_crypto/entities/ntt_ggsw_ciphertext_list.rs index 9cc94f7c1..e4334b2b6 100644 --- a/tfhe/src/core_crypto/entities/ntt_ggsw_ciphertext_list.rs +++ b/tfhe/src/core_crypto/entities/ntt_ggsw_ciphertext_list.rs @@ -109,9 +109,11 @@ impl> NttGgswCiphertextL ciphertext_modulus: CiphertextModulus, ) -> Self { assert!( - data.container_len() - % ggsw_ciphertext_size(glwe_size, polynomial_size, decomposition_level_count) - == 0, + data.container_len().is_multiple_of(ggsw_ciphertext_size( + glwe_size, + polynomial_size, + decomposition_level_count + )), "The provided container length is not valid. \ It needs to be dividable by the size of a GGSW ciphertext: {}. \ Got container length: {}.", diff --git a/tfhe/src/core_crypto/entities/polynomial_list.rs b/tfhe/src/core_crypto/entities/polynomial_list.rs index d5e8f4441..9baedc8d0 100644 --- a/tfhe/src/core_crypto/entities/polynomial_list.rs +++ b/tfhe/src/core_crypto/entities/polynomial_list.rs @@ -63,7 +63,7 @@ impl> PolynomialList { /// ``` pub fn from_container(container: C, polynomial_size: PolynomialSize) -> Self { assert!( - container.container_len() % polynomial_size.0 == 0, + container.container_len().is_multiple_of(polynomial_size.0), "The provided container length is not valid. \ It needs to be dividable by polynomial_size. \ Got container length: {} and polynomial_size: {polynomial_size:?}.", diff --git a/tfhe/src/core_crypto/entities/seeded_ggsw_ciphertext.rs b/tfhe/src/core_crypto/entities/seeded_ggsw_ciphertext.rs index ba33106c8..1e7e95185 100644 --- a/tfhe/src/core_crypto/entities/seeded_ggsw_ciphertext.rs +++ b/tfhe/src/core_crypto/entities/seeded_ggsw_ciphertext.rs @@ -165,7 +165,9 @@ impl> SeededGgswCipherte "Got an empty container to create a SeededGgswCiphertext" ); assert!( - container.container_len() % (glwe_size.0 * polynomial_size.0) == 0, + container + .container_len() + .is_multiple_of(glwe_size.0 * polynomial_size.0), "The provided container length is not valid. \ It needs to be dividable by glwe_size * polynomial_size: {}. \ Got container length: {} and glwe_size: {glwe_size:?}, \ diff --git a/tfhe/src/core_crypto/entities/seeded_ggsw_ciphertext_list.rs b/tfhe/src/core_crypto/entities/seeded_ggsw_ciphertext_list.rs index 071fbf1cd..257a7941d 100644 --- a/tfhe/src/core_crypto/entities/seeded_ggsw_ciphertext_list.rs +++ b/tfhe/src/core_crypto/entities/seeded_ggsw_ciphertext_list.rs @@ -142,8 +142,9 @@ impl> SeededGgswCipherte ); assert!( - container.container_len() % (decomp_level_count.0 * glwe_size.0 * polynomial_size.0) - == 0, + container + .container_len() + .is_multiple_of(decomp_level_count.0 * glwe_size.0 * polynomial_size.0), "The provided container length is not valid. \ It needs to be dividable by decomp_level_count * glwe_size * polynomial_size: \ {}.Got container length: {} and decomp_level_count: {decomp_level_count:?}, \ @@ -487,7 +488,11 @@ impl TryFrom<&MultiBitBootstrapKeyConformanceParams) -> Result { - if value.input_lwe_dimension.0 % value.grouping_factor.0 != 0 { + if !value + .input_lwe_dimension + .0 + .is_multiple_of(value.grouping_factor.0) + { return Err(()); } diff --git a/tfhe/src/core_crypto/entities/seeded_lwe_keyswitch_key.rs b/tfhe/src/core_crypto/entities/seeded_lwe_keyswitch_key.rs index 16c21efa4..1a063ad70 100644 --- a/tfhe/src/core_crypto/entities/seeded_lwe_keyswitch_key.rs +++ b/tfhe/src/core_crypto/entities/seeded_lwe_keyswitch_key.rs @@ -149,7 +149,9 @@ impl> SeededLweKeyswitch "Got an empty container to create an SeededLweKeyswitchKey" ); assert!( - container.container_len() % (decomp_level_count.0) == 0, + container + .container_len() + .is_multiple_of(decomp_level_count.0), "The provided container length is not valid. \ It needs to be dividable by decomp_level_count: {}. \ Got container length: {} and decomp_level_count: {decomp_level_count:?}.", diff --git a/tfhe/src/core_crypto/entities/seeded_lwe_keyswitch_key_chunk.rs b/tfhe/src/core_crypto/entities/seeded_lwe_keyswitch_key_chunk.rs index eac185737..41318363e 100644 --- a/tfhe/src/core_crypto/entities/seeded_lwe_keyswitch_key_chunk.rs +++ b/tfhe/src/core_crypto/entities/seeded_lwe_keyswitch_key_chunk.rs @@ -142,7 +142,9 @@ impl> SeededLweKeyswitch "Got an empty container to create a SeededLweKeyswitchKeyChunk" ); assert!( - container.container_len() % (decomp_level_count.0) == 0, + container + .container_len() + .is_multiple_of(decomp_level_count.0), "The provided container length is not valid. \ It needs to be dividable by decomp_level_count: {}. \ Got container length: {} and decomp_level_count: {decomp_level_count:?}.", diff --git a/tfhe/src/core_crypto/entities/seeded_lwe_multi_bit_bootstrap_key.rs b/tfhe/src/core_crypto/entities/seeded_lwe_multi_bit_bootstrap_key.rs index 3dbb009ff..bf799660b 100644 --- a/tfhe/src/core_crypto/entities/seeded_lwe_multi_bit_bootstrap_key.rs +++ b/tfhe/src/core_crypto/entities/seeded_lwe_multi_bit_bootstrap_key.rs @@ -203,7 +203,9 @@ impl> SeededLweMultiBitB }; assert!( - bsk.input_lwe_dimension().0 % grouping_factor.0 == 0, + bsk.input_lwe_dimension() + .0 + .is_multiple_of(grouping_factor.0), "Input LWE dimension ({}) of the bootstrap key needs to be a multiple of {}", bsk.input_lwe_dimension().0, grouping_factor.0, @@ -421,7 +423,7 @@ impl SeededLweMultiBitBootstrapKeyOwned { ciphertext_modulus: CiphertextModulus, ) -> Self { assert!( - input_lwe_dimension.0 % grouping_factor.0 == 0, + input_lwe_dimension.0.is_multiple_of(grouping_factor.0), "Multi Bit BSK requires input LWE dimension ({}) to be a multiple of {}", input_lwe_dimension.0, grouping_factor.0 diff --git a/tfhe/src/core_crypto/entities/seeded_lwe_packing_keyswitch_key.rs b/tfhe/src/core_crypto/entities/seeded_lwe_packing_keyswitch_key.rs index a58af1353..f98af45f4 100644 --- a/tfhe/src/core_crypto/entities/seeded_lwe_packing_keyswitch_key.rs +++ b/tfhe/src/core_crypto/entities/seeded_lwe_packing_keyswitch_key.rs @@ -174,7 +174,9 @@ impl> SeededLwePackingKe "Got an empty container to create an SeededLwePackingKeyswitchKey" ); assert!( - container.container_len() % (decomp_level_count.0 * output_polynomial_size.0) == 0, + container + .container_len() + .is_multiple_of(decomp_level_count.0 * output_polynomial_size.0), "The provided container length is not valid. \ It needs to be dividable by decomp_level_count * output_polynomial_size: {}. \ Got container length: {} decomp_level_count: {decomp_level_count:?} \ diff --git a/tfhe/src/core_crypto/experimental/entities/pseudo_ggsw_ciphertext.rs b/tfhe/src/core_crypto/experimental/entities/pseudo_ggsw_ciphertext.rs index 64cdc9a2a..b02a95ecb 100644 --- a/tfhe/src/core_crypto/experimental/entities/pseudo_ggsw_ciphertext.rs +++ b/tfhe/src/core_crypto/experimental/entities/pseudo_ggsw_ciphertext.rs @@ -270,9 +270,9 @@ impl> PseudoGgswCipherte "Got an empty container to create a PseudoGgswCiphertext" ); assert!( - container.container_len() - % (input_glwe_size.to_glwe_dimension().0 * output_glwe_size.0 * polynomial_size.0) - == 0, + container.container_len().is_multiple_of( + input_glwe_size.to_glwe_dimension().0 * output_glwe_size.0 * polynomial_size.0 + ), "The provided container length is not valid. \ It needs to be dividable by glwe_dimension_in * output_glwe_size * polynomial_size: {}. \ Got container length: {} and glwe_dimension_in: {:?}, output_glwe_size: \ diff --git a/tfhe/src/core_crypto/fft_impl/fft128_u128/crypto/bootstrap.rs b/tfhe/src/core_crypto/fft_impl/fft128_u128/crypto/bootstrap.rs index cae17f901..60a2b925b 100644 --- a/tfhe/src/core_crypto/fft_impl/fft128_u128/crypto/bootstrap.rs +++ b/tfhe/src/core_crypto/fft_impl/fft128_u128/crypto/bootstrap.rs @@ -20,7 +20,7 @@ pub fn polynomial_wrapping_monic_monomial_mul_assign_split( let output_lo = output_lo.into_container(); let output_hi = output_hi.into_container(); let full_cycles_count = monomial_degree.0 / output_lo.container_len(); - if full_cycles_count % 2 != 0 { + if !full_cycles_count.is_multiple_of(2) { izip_eq!(&mut *output_lo, &mut *output_hi) .for_each(|(lo, hi)| (*lo, *hi) = wrapping_neg((*lo, *hi))); } @@ -40,7 +40,7 @@ pub fn polynomial_wrapping_monic_monomial_div_assign_split( let output_lo = output_lo.into_container(); let output_hi = output_hi.into_container(); let full_cycles_count = monomial_degree.0 / output_lo.container_len(); - if full_cycles_count % 2 != 0 { + if !full_cycles_count.is_multiple_of(2) { izip_eq!(&mut *output_lo, &mut *output_hi) .for_each(|(lo, hi)| (*lo, *hi) = wrapping_neg((*lo, *hi))); } diff --git a/tfhe/src/core_crypto/fft_impl/fft64/math/fft/mod.rs b/tfhe/src/core_crypto/fft_impl/fft64/math/fft/mod.rs index 1039f5d04..2cb864c98 100644 --- a/tfhe/src/core_crypto/fft_impl/fft64/math/fft/mod.rs +++ b/tfhe/src/core_crypto/fft_impl/fft64/math/fft/mod.rs @@ -585,9 +585,10 @@ impl> FourierPolynomialList { pub fn iter_mut( &mut self, ) -> impl DoubleEndedIterator> { - assert!( - self.data.container_len() % self.polynomial_size.to_fourier_polynomial_size().0 == 0 - ); + assert!(self + .data + .container_len() + .is_multiple_of(self.polynomial_size.to_fourier_polynomial_size().0)); self.data .as_mut() .chunks_exact_mut(self.polynomial_size.to_fourier_polynomial_size().0) diff --git a/tfhe/src/high_level_api/compact_list.rs b/tfhe/src/high_level_api/compact_list.rs index f820d6f59..cafd707c4 100644 --- a/tfhe/src/high_level_api/compact_list.rs +++ b/tfhe/src/high_level_api/compact_list.rs @@ -964,7 +964,7 @@ fn num_bits_to_strict_num_blocks( message_modulus: MessageModulus, ) -> crate::Result { let bits_per_block = message_modulus.0.ilog2(); - if num_bits as u32 % bits_per_block != 0 { + if !(num_bits as u32).is_multiple_of(bits_per_block) { let message = format!("Number of bits must be a multiple of the parameter's MessageModulus.ilog2 ({bits_per_block} here)"); return Err(crate::Error::new(message)); } diff --git a/tfhe/src/high_level_api/global_state.rs b/tfhe/src/high_level_api/global_state.rs index b48aa5b6f..f2a042620 100644 --- a/tfhe/src/high_level_api/global_state.rs +++ b/tfhe/src/high_level_api/global_state.rs @@ -261,9 +261,10 @@ mod gpu { } } - #[derive(Clone)] + #[derive(Clone, Default)] pub enum CudaGpuChoice { Single(GpuIndex), + #[default] Multi, Custom(CustomMultiGpuIndexes), } @@ -295,12 +296,6 @@ mod gpu { } } } - - impl Default for CudaGpuChoice { - fn default() -> Self { - Self::Multi - } - } } #[cfg(feature = "hpu")] diff --git a/tfhe/src/integer/ciphertext/compact_list.rs b/tfhe/src/integer/ciphertext/compact_list.rs index 232b685c1..cdd4ec4bc 100644 --- a/tfhe/src/integer/ciphertext/compact_list.rs +++ b/tfhe/src/integer/ciphertext/compact_list.rs @@ -65,7 +65,7 @@ fn unpack_and_sanitize( unpacked.push(block.clone()); unpacked.push(block); } - if block_count % 2 == 0 { + if block_count.is_multiple_of(2) { unpacked.push(packed_blocks[0].clone()); } unpacked.push(packed_blocks.pop().unwrap()); diff --git a/tfhe/src/integer/server_key/radix_parallel/div_mod.rs b/tfhe/src/integer/server_key/radix_parallel/div_mod.rs index 9c5712b73..1c5644ab0 100644 --- a/tfhe/src/integer/server_key/radix_parallel/div_mod.rs +++ b/tfhe/src/integer/server_key/radix_parallel/div_mod.rs @@ -412,7 +412,7 @@ impl ServerKey { // to trim out bits which should not be there let mut trim_last_interesting_divisor_bits = || { - if ((msb_bit_set + 1) % num_bits_in_message as usize) == 0 { + if (msb_bit_set + 1).is_multiple_of(num_bits_in_message as usize) { return; } // The last block of the interesting part of the remainder @@ -441,7 +441,7 @@ impl ServerKey { let mut trim_first_divisor_ms_bits = || { if divisor_ms_blocks.blocks.is_empty() - || ((msb_bit_set + 1) % num_bits_in_message as usize) == 0 + || (msb_bit_set + 1).is_multiple_of(num_bits_in_message as usize) { return; } diff --git a/tfhe/src/integer/server_key/radix_parallel/modulus_switch_compression.rs b/tfhe/src/integer/server_key/radix_parallel/modulus_switch_compression.rs index 79772f6ff..da0dd049c 100644 --- a/tfhe/src/integer/server_key/radix_parallel/modulus_switch_compression.rs +++ b/tfhe/src/integer/server_key/radix_parallel/modulus_switch_compression.rs @@ -76,7 +76,7 @@ impl ServerKey { let len = blocks.len(); - if len % 2 == 0 { + if len.is_multiple_of(2) { paired_blocks = blocks; last_block = None; } else { diff --git a/tfhe/src/shortint/oprf.rs b/tfhe/src/shortint/oprf.rs index 1c4b36a5e..4ec8774ba 100644 --- a/tfhe/src/shortint/oprf.rs +++ b/tfhe/src/shortint/oprf.rs @@ -393,8 +393,8 @@ pub(crate) mod test { }; let prf = |x| { - let a = (negacyclic_part(x) + p_prime - 1) % (2 * output_p); - assert!(a % 2 == 0); + let a: u64 = (negacyclic_part(x) + p_prime - 1) % (2 * output_p); + assert!(a.is_multiple_of(2)); a / 2 }; diff --git a/tfhe/src/strings/ciphertext.rs b/tfhe/src/strings/ciphertext.rs index b99fb5145..e8dc93c40 100644 --- a/tfhe/src/strings/ciphertext.rs +++ b/tfhe/src/strings/ciphertext.rs @@ -69,7 +69,7 @@ impl Compactable for &ClearString { if let Some(n) = num_blocks { assert!( - n as u32 % blocks_per_char == 0, + (n as u32).is_multiple_of(blocks_per_char), "Inconsistent num block would split the string inside a a character" ); } diff --git a/tfhe/web_wasm_parallel_tests/package-lock.json b/tfhe/web_wasm_parallel_tests/package-lock.json index 8c44979c8..eeead65b0 100644 --- a/tfhe/web_wasm_parallel_tests/package-lock.json +++ b/tfhe/web_wasm_parallel_tests/package-lock.json @@ -26,7 +26,6 @@ "integrity": "sha512-30iZtAPgz+LTIYoeivqYo853f02jBYSd5uGnGpkFV0M3xOt9aN73erkgYAmZU43x4VfqcnLxW9Kpg3R5LC4YYw==", "dev": true, "license": "Apache-2.0", - "peer": true, "dependencies": { "@jridgewell/gen-mapping": "^0.3.5", "@jridgewell/trace-mapping": "^0.3.24" @@ -393,7 +392,6 @@ "integrity": "sha512-Xg0tn4HcfTijTwfDwYlvVCl43V6h4KyVVX2aEm4qdO/PC6L2YvzLHFdmxhoeSA3eslcE6+ZVXHgWwopXYLNq4Q==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@babel/template": "^7.25.0", "@babel/types": "^7.25.6" @@ -2133,6 +2131,7 @@ "integrity": "sha512-tcpGyI9zbizT9JbV6oYE477V6mTlXvvi0T0G3SNIYE2apm/G5huBa1+K89VGeovbg+jycCrfhl3ADxErOuO6Jg==", "dev": true, "license": "MIT", + "peer": true, "bin": { "acorn": "bin/acorn" }, @@ -2392,6 +2391,7 @@ } ], "license": "MIT", + "peer": true, "dependencies": { "caniuse-lite": "^1.0.30001646", "electron-to-chromium": "^1.5.4", @@ -2714,8 +2714,7 @@ "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-2.0.0.tgz", "integrity": "sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==", "dev": true, - "license": "MIT", - "peer": true + "license": "MIT" }, "node_modules/core-js-compat": { "version": "3.38.1", @@ -3004,7 +3003,6 @@ "integrity": "sha512-3hN7NaskYvMDLQY55gnW3NQ+mesEAepTqlg+VEbj7zzqEMBVNhzcGYYeqFo/TlYz6eQiFcp1HcsCZO+nGgS8zg==", "dev": true, "license": "MIT", - "peer": true, "engines": { "node": ">=6.9.0" } @@ -3308,7 +3306,6 @@ "integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==", "dev": true, "license": "MIT", - "peer": true, "bin": { "json5": "lib/cli.js" }, @@ -3882,6 +3879,7 @@ "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "fast-deep-equal": "^3.1.1", "fast-json-stable-stringify": "^2.0.0", @@ -4401,6 +4399,7 @@ "integrity": "sha512-KcsGn50VT+06JH/iunZJedYGUJS5FGjow8wb9c0v5n1Om8O1g4L6LjtfxwlXIATopoQu+vOXXa7gYisWxCoPyg==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@types/estree": "^1.0.5", "@webassemblyjs/ast": "^1.12.1", @@ -4448,6 +4447,7 @@ "integrity": "sha512-pIDJHIEI9LR0yxHXQ+Qh95k2EvXpWzZ5l+d+jIo+RdSm9MiHfzazIxwwni/p7+x4eJZuvG1AJwgC4TNQ7NRgsg==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@discoveryjs/json-ext": "^0.5.0", "@webpack-cli/configtest": "^2.1.1", diff --git a/toolchain.txt b/toolchain.txt index 48809f95b..7e0087567 100644 --- a/toolchain.txt +++ b/toolchain.txt @@ -1 +1 @@ -nightly-2025-08-26 +nightly-2025-11-19 diff --git a/utils/param_dedup/src/main.rs b/utils/param_dedup/src/main.rs index e0a2cedef..9c14c1464 100644 --- a/utils/param_dedup/src/main.rs +++ b/utils/param_dedup/src/main.rs @@ -382,7 +382,7 @@ fn main() { "crate::shortint::parameters::{old_param_dir_name}::{old_param_prefix}{current_normalized_param_ident_str}" )).unwrap(); - param.expr = Box::new(old_param_path_expr); + *param.expr = old_param_path_expr; modified_item_count += 1; } diff --git a/utils/tfhe-lints/Cargo.toml b/utils/tfhe-lints/Cargo.toml index bd52b31d2..7fdec9dde 100644 --- a/utils/tfhe-lints/Cargo.toml +++ b/utils/tfhe-lints/Cargo.toml @@ -9,7 +9,7 @@ publish = false crate-type = ["cdylib"] [dependencies] -clippy_utils = { git = "https://github.com/rust-lang/rust-clippy", rev = "334fb906aef13d20050987b13448f37391bb97a2" } +clippy_utils = { git = "https://github.com/rust-lang/rust-clippy", rev = "c936595d17413c1f08e162e117e504fb4ed126e4" } dylint_linting = "4.1.0" [dev-dependencies] diff --git a/utils/tfhe-lints/README.md b/utils/tfhe-lints/README.md index 73364f22f..c2ae33383 100644 --- a/utils/tfhe-lints/README.md +++ b/utils/tfhe-lints/README.md @@ -27,3 +27,13 @@ Use instead: #[versionize(MyStructVersions)] pub struct MyStruct {} ``` + +## Updating to new toolchains +The dylint library is frequently updated to support new toolchains. To update the tool to the +latest supported toolchain, simply run the following command in this folder: +``` +cargo dylint upgrade +``` + +Since the tool uses the Rust compiler API, which is unstable, manual adjustments to the code may be +necessary. diff --git a/utils/tfhe-lints/rust-toolchain b/utils/tfhe-lints/rust-toolchain index 913b3a19a..f7243dd21 100644 --- a/utils/tfhe-lints/rust-toolchain +++ b/utils/tfhe-lints/rust-toolchain @@ -1,4 +1,4 @@ [toolchain] -channel = "nightly-2025-08-07" +channel = "nightly-2025-10-31" components = ["llvm-tools-preview", "rustc-dev"] profile = "default" diff --git a/utils/tfhe-lints/src/serialize_without_versionize.rs b/utils/tfhe-lints/src/serialize_without_versionize.rs index a720fba16..1668f8835 100644 --- a/utils/tfhe-lints/src/serialize_without_versionize.rs +++ b/utils/tfhe-lints/src/serialize_without_versionize.rs @@ -66,7 +66,7 @@ impl<'tcx> LateLintPass<'tcx> for SerializeWithoutVersionize { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { // If the currently checked item is a trait impl if let ItemKind::Impl(Impl { - of_trait: Some(ref trait_ref), + of_trait: Some(trait_ref), .. }) = item.kind { @@ -86,7 +86,7 @@ impl<'tcx> LateLintPass<'tcx> for SerializeWithoutVersionize { } // Check if the implemented trait is `Serialize` - if let Some(def_id) = trait_ref.trait_def_id() { + if let Some(def_id) = trait_ref.trait_ref.trait_def_id() { let path = cx.get_def_path(def_id); if path == symbols_list_from_str(&SERIALIZE_TRAIT) || path == symbols_list_from_str(&SERIALIZE_TRAIT_LEGACY) @@ -97,10 +97,7 @@ impl<'tcx> LateLintPass<'tcx> for SerializeWithoutVersionize { cx.tcx .for_each_relevant_impl(versionize_trait, ty, |impl_id| { if !found_impl { - let trait_ref = cx - .tcx - .impl_trait_ref(impl_id) - .expect("must be a trait implementation"); + let trait_ref = cx.tcx.impl_trait_ref(impl_id); if trait_ref.instantiate_identity().args.type_at(0) == ty { found_impl = true;