Skip to content

Commit

Permalink
chore(ci): update toolchain, fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
sarah el kazdadi authored and tmontaigu committed Feb 23, 2024
1 parent 83239e6 commit c59434f
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 34 deletions.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tasks/src/format_latex_doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<CommentContent>,
full_doc_comment_content: &[CommentContent],
part_start_idx: usize,
) -> (usize, usize) {
let mut next_line_idx = part_start_idx + 1;
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions tfhe/benches/integer/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 = || {
Expand Down Expand Up @@ -2140,7 +2141,7 @@ fn bench_server_key_cast_function<F>(
.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::<Vec<_>>();
let param_name = param.name();

Expand Down
3 changes: 2 additions & 1 deletion tfhe/benches/integer/signed_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1126,7 +1127,7 @@ fn bench_server_key_signed_cast_function<F>(
.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::<Vec<_>>();
let param_name = param.name();

Expand Down
19 changes: 11 additions & 8 deletions tfhe/examples/sha256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,16 +442,19 @@ fn sha256_fhe_parallel(input: Vec<FheUint32>) -> [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)
);

Expand Down
20 changes: 10 additions & 10 deletions tfhe/src/core_crypto/fft_impl/fft128_u128/crypto/ggsw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand All @@ -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),
),
);
Expand All @@ -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);
Expand All @@ -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),
);
Expand Down Expand Up @@ -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!(
Expand All @@ -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),
),
);
Expand All @@ -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);
Expand All @@ -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),
);
Expand Down
2 changes: 1 addition & 1 deletion tfhe/src/high_level_api/global_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Option<InternalServerKey>> = RefCell::new(None);
static INTERNAL_KEYS: RefCell<Option<InternalServerKey>> = const { RefCell::new(None) };
}

/// The function used to initialize internal keys.
Expand Down
6 changes: 2 additions & 4 deletions tfhe/src/js_on_wasm_api/js_high_level_api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ pub(crate) fn catch_panic_result<F, R>(closure: F) -> Result<R, JsError>
where
F: FnOnce() -> Result<R, JsError>,
{
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<F, R>(closure: F) -> Result<R, JsError>
Expand Down
2 changes: 1 addition & 1 deletion tfhe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
Expand Down
8 changes: 4 additions & 4 deletions tfhe/src/shortint/server_key/tests/noise_level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion toolchain.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nightly-2023-11-30
nightly-2024-02-13

0 comments on commit c59434f

Please sign in to comment.