Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(ci): force installation of toolchain for tfhe-lints #2144

Open
wants to merge 2 commits into
base: release/1.0.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ clippy_versionable: install_rs_check_toolchain
.PHONY: clippy_tfhe_lints # Run clippy lints on tfhe-lints
clippy_tfhe_lints: install_cargo_dylint # the toolchain is selected with toolchain.toml
cd utils/tfhe-lints && \
rustup toolchain install && \
cargo clippy --all-targets -- --no-deps -D warnings

.PHONY: clippy_all # Run all clippy targets
Expand All @@ -457,6 +458,7 @@ check_rust_bindings_did_not_change:

.PHONY: tfhe_lints # Run custom tfhe-rs lints
tfhe_lints: install_cargo_dylint
rustup toolchain install && \
RUSTFLAGS="$(RUSTFLAGS)" cargo dylint --all -p tfhe --no-deps -- \
--features=boolean,shortint,integer,strings,zk-pok

Expand Down Expand Up @@ -907,6 +909,7 @@ test_versionable: install_rs_build_toolchain
.PHONY: test_tfhe_lints # Run test on tfhe-lints
test_tfhe_lints: install_cargo_dylint
cd utils/tfhe-lints && \
rustup toolchain install && \
cargo test

# The backward compat data repo holds historical binary data but also rust code to generate and load them.
Expand Down
2 changes: 1 addition & 1 deletion toolchain.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nightly-2025-02-19
nightly-2025-02-20
6 changes: 3 additions & 3 deletions utils/tfhe-lints/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ publish = false
crate-type = ["cdylib"]

[dependencies]
clippy_utils = { git = "https://github.com/rust-lang/rust-clippy", rev = "ff4a26d442bead94a4c96fb1de967374bc4fbd8e" }
clippy_utils = { git = "https://github.com/rust-lang/rust-clippy", rev = "238edf273d195c8e472851ebd60571f77f978ac8" }
dylint_linting = "3.2.1"

[dev-dependencies]
Expand All @@ -21,5 +21,5 @@ tfhe-versionable = "0.4.0"
rustc_private = true

[[example]]
name = "ui"
path = "ui/main.rs"
name = "ui"
path = "ui/main.rs"
3 changes: 2 additions & 1 deletion utils/tfhe-lints/rust-toolchain
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[toolchain]
channel = "nightly-2024-11-28"
channel = "nightly-2025-02-20"
components = ["llvm-tools-preview", "rustc-dev"]
profile = "default"
7 changes: 4 additions & 3 deletions utils/tfhe-lints/src/serialize_without_versionize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ impl SerializeWithoutVersionizeInner {
self.versionize_trait
.get_or_init(|| {
let versionize_trait = cx.tcx.all_traits().find(|def_id| {
cx.match_def_path(*def_id, symbols_list_from_str(&VERSIONIZE_TRAIT).as_slice())
let path = cx.get_def_path(*def_id);
path == symbols_list_from_str(&VERSIONIZE_TRAIT)
});

versionize_trait
Expand Down Expand Up @@ -85,8 +86,8 @@ impl<'tcx> LateLintPass<'tcx> for SerializeWithoutVersionize {

// Check if the implemented trait is `Serialize`
if let Some(def_id) = trait_ref.trait_def_id() {
if cx.match_def_path(def_id, symbols_list_from_str(&SERIALIZE_TRAIT).as_slice())
{
let path = cx.get_def_path(def_id);
if path == symbols_list_from_str(&SERIALIZE_TRAIT) {
// Try to find an implementation of versionize for this type
let mut found_impl = false;
if let Some(versionize_trait) = self.0.versionize_trait(cx) {
Expand Down
16 changes: 10 additions & 6 deletions utils/tfhe-lints/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use rustc_ast::tokenstream::TokenTree;
use rustc_hir::def_id::DefId;
use rustc_hir::AttrArgs;
use rustc_lint::LateContext;
use rustc_middle::ty::{Ty, TyKind};
use rustc_span::Symbol;
Expand All @@ -11,16 +12,19 @@ pub fn symbols_list_from_str(list: &[&str]) -> Vec<Symbol> {

/// Checks if the lint is allowed for the item represented by [`DefId`].
/// This shouldn't be necessary since the lints are declared with the
/// `declare_tool_lint` macro but for a mysterious reason this does not
/// `impl_late_lint` macro but for a mysterious reason this does not
/// work automatically.
pub fn is_allowed_lint(cx: &LateContext<'_>, target: DefId, lint_name: &str) -> bool {
for attr in cx.tcx.get_attrs(target, Symbol::intern("allow")) {
let tokens = attr.get_normal_item().args.inner_tokens();
let mut trees = tokens.trees();
if let AttrArgs::Delimited(args) = &attr.get_normal_item().args {
let len = args.tokens.len();

if let Some(TokenTree::Token(tool_token, _)) = trees.next() {
if tool_token.is_ident_named(Symbol::intern(lint_name)) {
return true;
for id in 0..len {
if let Some(TokenTree::Token(tool_token, _)) = args.tokens.get(id) {
if tool_token.is_ident_named(Symbol::intern(lint_name)) {
return true;
}
}
}
}
}
Expand Down
Loading