From 5363f350887b1e5b5dd21a86f88c8af9d7fea6da Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:18:25 +0200 Subject: Merging upstream version 1.67.1+dfsg1. Signed-off-by: Daniel Baumann --- src/tools/tidy/Cargo.toml | 2 + src/tools/tidy/src/deps.rs | 48 +++++++++++++++++------- src/tools/tidy/src/lib.rs | 1 + src/tools/tidy/src/main.rs | 2 + src/tools/tidy/src/mir_opt_tests.rs | 74 +++++++++++++++++++++++++++++++++++++ src/tools/tidy/src/style.rs | 2 +- src/tools/tidy/src/ui_tests.rs | 63 +++++++++++++++++-------------- 7 files changed, 150 insertions(+), 42 deletions(-) create mode 100644 src/tools/tidy/src/mir_opt_tests.rs (limited to 'src/tools/tidy') diff --git a/src/tools/tidy/Cargo.toml b/src/tools/tidy/Cargo.toml index 471d78a29..97d038da7 100644 --- a/src/tools/tidy/Cargo.toml +++ b/src/tools/tidy/Cargo.toml @@ -7,8 +7,10 @@ autobins = false [dependencies] cargo_metadata = "0.14" regex = "1" +miropt-test-tools = { path = "../miropt-test-tools" } lazy_static = "1" walkdir = "2" +ignore = "0.4.18" [[bin]] name = "rust-tidy" diff --git a/src/tools/tidy/src/deps.rs b/src/tools/tidy/src/deps.rs index 8a0239ece..296db9dfb 100644 --- a/src/tools/tidy/src/deps.rs +++ b/src/tools/tidy/src/deps.rs @@ -23,6 +23,7 @@ const LICENSES: &[&str] = &[ "MIT OR Apache-2.0 OR Zlib", // tinyvec_macros "MIT OR Zlib OR Apache-2.0", // miniz_oxide "(MIT OR Apache-2.0) AND Unicode-DFS-2016", // unicode_ident + "Unicode-DFS-2016", // tinystr and icu4x ]; /// These are exceptions to Rust's permissive licensing policy, and @@ -30,23 +31,26 @@ const LICENSES: &[&str] = &[ /// tooling. It is _crucial_ that no exception crates be dependencies /// of the Rust runtime (std/test). const EXCEPTIONS: &[(&str, &str)] = &[ - ("mdbook", "MPL-2.0"), // mdbook - ("openssl", "Apache-2.0"), // cargo, mdbook - ("colored", "MPL-2.0"), // rustfmt - ("ryu", "Apache-2.0 OR BSL-1.0"), // cargo/... (because of serde) - ("bytesize", "Apache-2.0"), // cargo - ("im-rc", "MPL-2.0+"), // cargo - ("sized-chunks", "MPL-2.0+"), // cargo via im-rc - ("bitmaps", "MPL-2.0+"), // cargo via im-rc - ("instant", "BSD-3-Clause"), // rustc_driver/tracing-subscriber/parking_lot - ("snap", "BSD-3-Clause"), // rustc + ("ar_archive_writer", "Apache-2.0 WITH LLVM-exception"), // rustc + ("mdbook", "MPL-2.0"), // mdbook + ("openssl", "Apache-2.0"), // cargo, mdbook + ("colored", "MPL-2.0"), // rustfmt + ("ryu", "Apache-2.0 OR BSL-1.0"), // cargo/... (because of serde) + ("bytesize", "Apache-2.0"), // cargo + ("im-rc", "MPL-2.0+"), // cargo + ("sized-chunks", "MPL-2.0+"), // cargo via im-rc + ("bitmaps", "MPL-2.0+"), // cargo via im-rc + ("instant", "BSD-3-Clause"), // rustc_driver/tracing-subscriber/parking_lot + ("snap", "BSD-3-Clause"), // rustc ("fluent-langneg", "Apache-2.0"), // rustc (fluent translations) - ("self_cell", "Apache-2.0"), // rustc (fluent translations) + ("self_cell", "Apache-2.0"), // rustc (fluent translations) // FIXME: this dependency violates the documentation comment above: ("fortanix-sgx-abi", "MPL-2.0"), // libstd but only for `sgx` target ("dunce", "CC0-1.0"), // cargo (dev dependency) ("similar", "Apache-2.0"), // cargo (dev dependency) ("normalize-line-endings", "Apache-2.0"), // cargo (dev dependency) + ("dissimilar", "Apache-2.0"), // rustdoc, rustc_lexer (few tests) via expect-test, (dev deps) + ("subtle", "BSD-3-Clause"), // cargo ]; const EXCEPTIONS_CRANELIFT: &[(&str, &str)] = &[ @@ -85,6 +89,7 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[ "aho-corasick", "annotate-snippets", "ansi_term", + "ar_archive_writer", "arrayvec", "atty", "autocfg", @@ -97,6 +102,7 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[ "chalk-ir", "chalk-solve", "chrono", + "convert_case", // dependency of derive_more "compiler_builtins", "cpufeatures", "crc32fast", @@ -107,14 +113,17 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[ "crypto-common", "cstr", "datafrog", - "difference", + "derive_more", "digest", + "displaydoc", + "dissimilar", "dlmalloc", "either", "ena", "env_logger", "expect-test", "fallible-iterator", // dependency of `thorin` + "fastrand", "filetime", "fixedbitset", "flate2", @@ -130,6 +139,11 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[ "hashbrown", "hermit-abi", "humantime", + "icu_list", + "icu_locid", + "icu_provider", + "icu_provider_adapters", + "icu_provider_macros", "if_chain", "indexmap", "instant", @@ -142,6 +156,7 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[ "libc", "libloading", "libz-sys", + "litemap", "lock_api", "log", "matchers", @@ -205,6 +220,7 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[ "snap", "stable_deref_trait", "stacker", + "subtle", "syn", "synstructure", "tempfile", @@ -250,15 +266,21 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[ "winapi-i686-pc-windows-gnu", "winapi-util", "winapi-x86_64-pc-windows-gnu", + "writeable", // this is a false-positive: it's only used by rustfmt, but because it's enabled through a // feature, tidy thinks it's used by rustc as well. "yansi-term", + "yoke", + "yoke-derive", + "zerofrom", + "zerofrom-derive", + "zerovec", + "zerovec-derive", ]; const PERMITTED_CRANELIFT_DEPENDENCIES: &[&str] = &[ "ahash", "anyhow", - "ar", "arrayvec", "autocfg", "bumpalo", diff --git a/src/tools/tidy/src/lib.rs b/src/tools/tidy/src/lib.rs index fc0bce585..698e4850b 100644 --- a/src/tools/tidy/src/lib.rs +++ b/src/tools/tidy/src/lib.rs @@ -47,6 +47,7 @@ pub mod error_codes_check; pub mod errors; pub mod extdeps; pub mod features; +pub mod mir_opt_tests; pub mod pal; pub mod primitive_docs; pub mod style; diff --git a/src/tools/tidy/src/main.rs b/src/tools/tidy/src/main.rs index ca785042a..b0b11cafc 100644 --- a/src/tools/tidy/src/main.rs +++ b/src/tools/tidy/src/main.rs @@ -31,6 +31,7 @@ fn main() { let args: Vec = env::args().skip(1).collect(); let verbose = args.iter().any(|s| *s == "--verbose"); + let bless = args.iter().any(|s| *s == "--bless"); let bad = std::sync::Arc::new(AtomicBool::new(false)); @@ -64,6 +65,7 @@ fn main() { // Checks over tests. check!(debug_artifacts, &src_path); check!(ui_tests, &src_path); + check!(mir_opt_tests, &src_path, bless); // Checks that only make sense for the compiler. check!(errors, &compiler_path); diff --git a/src/tools/tidy/src/mir_opt_tests.rs b/src/tools/tidy/src/mir_opt_tests.rs new file mode 100644 index 000000000..018573284 --- /dev/null +++ b/src/tools/tidy/src/mir_opt_tests.rs @@ -0,0 +1,74 @@ +//! Tidy check to ensure that mir opt directories do not have stale files or dashes in file names + +use std::collections::HashSet; +use std::path::{Path, PathBuf}; + +fn check_unused_files(path: &Path, bless: bool, bad: &mut bool) { + let mut rs_files = Vec::::new(); + let mut output_files = HashSet::::new(); + let files = walkdir::WalkDir::new(&path.join("test/mir-opt")).into_iter(); + + for file in files.filter_map(Result::ok).filter(|e| e.file_type().is_file()) { + let filepath = file.path(); + if filepath.extension() == Some("rs".as_ref()) { + rs_files.push(filepath.to_owned()); + } else { + output_files.insert(filepath.to_owned()); + } + } + + for file in rs_files { + for bw in [32, 64] { + for output_file in miropt_test_tools::files_for_miropt_test(&file, bw) { + output_files.remove(&output_file.expected_file); + } + } + } + + for extra in output_files { + if extra.file_name() != Some("README.md".as_ref()) { + if !bless { + tidy_error!( + bad, + "the following output file is not associated with any mir-opt test, you can remove it: {}", + extra.display() + ); + } else { + let _ = std::fs::remove_file(extra); + } + } + } +} + +fn check_dash_files(path: &Path, bless: bool, bad: &mut bool) { + for file in walkdir::WalkDir::new(&path.join("test/mir-opt")) + .into_iter() + .filter_map(Result::ok) + .filter(|e| e.file_type().is_file()) + { + let path = file.path(); + if path.extension() == Some("rs".as_ref()) { + if let Some(name) = path.file_name().and_then(|s| s.to_str()) { + if name.contains('-') { + if !bless { + tidy_error!( + bad, + "mir-opt test files should not have dashes in them: {}", + path.display() + ); + } else { + let new_name = name.replace('-', "_"); + let mut new_path = path.to_owned(); + new_path.set_file_name(new_name); + let _ = std::fs::rename(path, new_path); + } + } + } + } + } +} + +pub fn check(path: &Path, bless: bool, bad: &mut bool) { + check_unused_files(path, bless, bad); + check_dash_files(path, bless, bad); +} diff --git a/src/tools/tidy/src/style.rs b/src/tools/tidy/src/style.rs index 541380ceb..e3a094caf 100644 --- a/src/tools/tidy/src/style.rs +++ b/src/tools/tidy/src/style.rs @@ -60,7 +60,7 @@ const ANNOTATIONS_TO_IGNORE: &[&str] = &[ // Intentionally written in decimal rather than hex const PROBLEMATIC_CONSTS: &[u32] = &[ 184594741, 2880289470, 2881141438, 2965027518, 2976579765, 3203381950, 3405691582, 3405697037, - 3735927486, 4027431614, 4276992702, + 3735927486, 3735932941, 4027431614, 4276992702, ]; /// Parser states for `line_is_url`. diff --git a/src/tools/tidy/src/ui_tests.rs b/src/tools/tidy/src/ui_tests.rs index c600f99c2..ee326e190 100644 --- a/src/tools/tidy/src/ui_tests.rs +++ b/src/tools/tidy/src/ui_tests.rs @@ -2,43 +2,50 @@ //! - the number of entries in each directory must be less than `ENTRY_LIMIT` //! - there are no stray `.stderr` files +use ignore::Walk; +use ignore::WalkBuilder; use std::fs; use std::path::Path; const ENTRY_LIMIT: usize = 1000; // FIXME: The following limits should be reduced eventually. -const ROOT_ENTRY_LIMIT: usize = 948; -const ISSUES_ENTRY_LIMIT: usize = 2117; +const ROOT_ENTRY_LIMIT: usize = 939; +const ISSUES_ENTRY_LIMIT: usize = 2070; fn check_entries(path: &Path, bad: &mut bool) { - let dirs = walkdir::WalkDir::new(&path.join("test/ui")) - .into_iter() - .filter_entry(|e| e.file_type().is_dir()); - for dir in dirs { - if let Ok(dir) = dir { - let dir_path = dir.path(); + for dir in Walk::new(&path.join("test/ui")) { + if let Ok(entry) = dir { + if entry.file_type().map(|ft| ft.is_dir()).unwrap_or(false) { + let dir_path = entry.path(); + // Use special values for these dirs. + let is_root = path.join("test/ui") == dir_path; + let is_issues_dir = path.join("test/ui/issues") == dir_path; + let limit = if is_root { + ROOT_ENTRY_LIMIT + } else if is_issues_dir { + ISSUES_ENTRY_LIMIT + } else { + ENTRY_LIMIT + }; - // Use special values for these dirs. - let is_root = path.join("test/ui") == dir_path; - let is_issues_dir = path.join("test/ui/issues") == dir_path; - let limit = if is_root { - ROOT_ENTRY_LIMIT - } else if is_issues_dir { - ISSUES_ENTRY_LIMIT - } else { - ENTRY_LIMIT - }; + let count = WalkBuilder::new(&dir_path) + .max_depth(Some(1)) + .build() + .into_iter() + .collect::>() + .len() + - 1; // remove the dir itself - let count = std::fs::read_dir(dir_path).unwrap().count(); - if count > limit { - tidy_error!( - bad, - "following path contains more than {} entries, \ - you should move the test to some relevant subdirectory (current: {}): {}", - limit, - count, - dir_path.display() - ); + if count > limit { + tidy_error!( + bad, + "following path contains more than {} entries, \ + you should move the test to some relevant subdirectory (current: {}): {}", + limit, + count, + dir_path.display() + ); + } } } } -- cgit v1.2.3