-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Speed up tidy #105829
Speed up tidy #105829
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ | |
//! `// ignore-tidy-CHECK-NAME`. | ||
|
||
use crate::walk::{filter_dirs, walk}; | ||
use regex::Regex; | ||
use regex::{Regex, RegexSet}; | ||
use std::path::Path; | ||
|
||
/// Error code markdown is restricted to 80 columns because they can be | ||
|
@@ -225,6 +225,7 @@ pub fn check(path: &Path, bad: &mut bool) { | |
.chain(PROBLEMATIC_CONSTS.iter().map(|v| format!("{:x}", v))) | ||
.chain(PROBLEMATIC_CONSTS.iter().map(|v| format!("{:X}", v))) | ||
.collect(); | ||
let problematic_regex = RegexSet::new(problematic_consts_strings.as_slice()).unwrap(); | ||
walk(path, &mut skip, &mut |entry, contents| { | ||
let file = entry.path(); | ||
let filename = file.file_name().unwrap().to_string_lossy(); | ||
|
@@ -281,7 +282,27 @@ pub fn check(path: &Path, bad: &mut bool) { | |
let mut trailing_new_lines = 0; | ||
let mut lines = 0; | ||
let mut last_safety_comment = false; | ||
let is_test = file.components().any(|c| c.as_os_str() == "tests"); | ||
// scanning the whole file for multiple needles at once is more efficient than | ||
// executing lines times needles separate searches. | ||
let any_problematic_line = problematic_regex.is_match(contents); | ||
for (i, line) in contents.split('\n').enumerate() { | ||
if line.is_empty() { | ||
if i == 0 { | ||
leading_new_lines = true; | ||
} | ||
trailing_new_lines += 1; | ||
continue; | ||
} else { | ||
trailing_new_lines = 0; | ||
} | ||
|
||
let trimmed = line.trim(); | ||
|
||
if !trimmed.starts_with("//") { | ||
lines += 1; | ||
} | ||
Comment on lines
+290
to
+304
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did this move? I don't see There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So we can |
||
|
||
let mut err = |msg: &str| { | ||
tidy_error!(bad, "{}:{}: {}", file.display(), i + 1, msg); | ||
}; | ||
|
@@ -308,36 +329,38 @@ pub fn check(path: &Path, bad: &mut bool) { | |
suppressible_tidy_err!(err, skip_cr, "CR character"); | ||
} | ||
if filename != "style.rs" { | ||
if line.contains("TODO") { | ||
if trimmed.contains("TODO") { | ||
err("TODO is deprecated; use FIXME") | ||
} | ||
if line.contains("//") && line.contains(" XXX") { | ||
if trimmed.contains("//") && trimmed.contains(" XXX") { | ||
err("XXX is deprecated; use FIXME") | ||
} | ||
for s in problematic_consts_strings.iter() { | ||
if line.contains(s) { | ||
err("Don't use magic numbers that spell things (consider 0x12345678)"); | ||
if any_problematic_line { | ||
for s in problematic_consts_strings.iter() { | ||
if trimmed.contains(s) { | ||
err("Don't use magic numbers that spell things (consider 0x12345678)"); | ||
} | ||
} | ||
} | ||
} | ||
let is_test = || file.components().any(|c| c.as_os_str() == "tests"); | ||
// for now we just check libcore | ||
if line.contains("unsafe {") && !line.trim().starts_with("//") && !last_safety_comment { | ||
if file.components().any(|c| c.as_os_str() == "core") && !is_test() { | ||
if trimmed.contains("unsafe {") && !trimmed.starts_with("//") && !last_safety_comment { | ||
if file.components().any(|c| c.as_os_str() == "core") && !is_test { | ||
suppressible_tidy_err!(err, skip_undocumented_unsafe, "undocumented unsafe"); | ||
} | ||
} | ||
if line.contains("// SAFETY:") { | ||
if trimmed.contains("// SAFETY:") { | ||
last_safety_comment = true; | ||
} else if line.trim().starts_with("//") || line.trim().is_empty() { | ||
} else if trimmed.starts_with("//") || trimmed.is_empty() { | ||
// keep previous value | ||
} else { | ||
last_safety_comment = false; | ||
} | ||
if (line.starts_with("// Copyright") | ||
|| line.starts_with("# Copyright") | ||
|| line.starts_with("Copyright")) | ||
&& (line.contains("Rust Developers") || line.contains("Rust Project Developers")) | ||
&& (trimmed.contains("Rust Developers") | ||
|| trimmed.contains("Rust Project Developers")) | ||
{ | ||
suppressible_tidy_err!( | ||
err, | ||
|
@@ -351,18 +374,6 @@ pub fn check(path: &Path, bad: &mut bool) { | |
if filename.ends_with(".cpp") && line.contains("llvm_unreachable") { | ||
err(LLVM_UNREACHABLE_INFO); | ||
} | ||
if line.is_empty() { | ||
if i == 0 { | ||
leading_new_lines = true; | ||
} | ||
trailing_new_lines += 1; | ||
} else { | ||
trailing_new_lines = 0; | ||
} | ||
|
||
if !line.trim().starts_with("//") { | ||
lines += 1; | ||
} | ||
} | ||
if leading_new_lines { | ||
let mut err = |_| { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this useful? Does it run any faster or is it just releasing the resources earlier?
Oh, I guess removing a handle means you have more space in the queue to add more jobs? I'm a little confused why you would only run this once instead of putting it in the loop below ... maybe we should use
rayon::ParallelIterator
instead so we always join the first job to finish? All the custom concurrency code is a little hard to maintain in general.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is called every time in the
check
macro when a task is added to make room for the next task.When I originally wrote this code (before
is_finished
existed) I think I wanted to add rayon but someone said it's better to keep the number of dependencies low so it's faster when one doesn't have tidy compiled.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, the only place I see rayon mentioned in the original PR is #81833 (comment) - do you remember why you made that change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, looks like #81833 (comment). Ok, we don't need to revisit that here.