Skip to content

Commit 12b5498

Browse files
committed
Auto merge of rust-lang#120023 - klensy:tidy-alloc, r=Mark-Simulacrum
tidy: reduce allocs this reduces allocs in tidy from (dhat output) ``` ==31349== Total: 1,365,199,543 bytes in 4,774,213 blocks ==31349== At t-gmax: 10,975,708 bytes in 66,093 blocks ==31349== At t-end: 2,880,947 bytes in 12,332 blocks ==31349== Reads: 5,210,008,956 bytes ==31349== Writes: 1,280,920,127 bytes ``` to ``` ==66633== Total: 791,565,538 bytes in 3,503,144 blocks ==66633== At t-gmax: 10,914,511 bytes in 65,997 blocks ==66633== At t-end: 395,531 bytes in 941 blocks ==66633== Reads: 4,249,388,949 bytes ==66633== Writes: 814,119,580 bytes ``` <del>by wrapping regex and updating `ignore` (effect probably not only from `ignore`, didn't measured)</del> also moves one more regex into `Lazy` to reduce regex rebuilds.
2 parents eeeb021 + f6fa03b commit 12b5498

File tree

5 files changed

+24
-17
lines changed

5 files changed

+24
-17
lines changed

Cargo.lock

-3
Original file line numberDiff line numberDiff line change
@@ -2541,9 +2541,6 @@ dependencies = [
25412541
[[package]]
25422542
name = "miropt-test-tools"
25432543
version = "0.1.0"
2544-
dependencies = [
2545-
"regex",
2546-
]
25472544

25482545
[[package]]
25492546
name = "native-tls"

src/tools/compiletest/src/header.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::io::BufReader;
66
use std::path::{Path, PathBuf};
77
use std::process::Command;
88

9+
use once_cell::sync::Lazy;
910
use regex::Regex;
1011
use tracing::*;
1112

@@ -829,7 +830,8 @@ fn iter_header_extra(
829830
let mut ln = String::new();
830831
let mut line_number = 0;
831832

832-
let revision_magic_comment = Regex::new("//(\\[.*\\])?~.*").unwrap();
833+
static REVISION_MAGIC_COMMENT_RE: Lazy<Regex> =
834+
Lazy::new(|| Regex::new("//(\\[.*\\])?~.*").unwrap());
833835

834836
loop {
835837
line_number += 1;
@@ -849,7 +851,7 @@ fn iter_header_extra(
849851
// First try to accept `ui_test` style comments
850852
} else if let Some((lncfg, ln)) = line_directive(comment, ln) {
851853
it(lncfg, orig_ln, ln, line_number);
852-
} else if mode == Mode::Ui && suite == "ui" && !revision_magic_comment.is_match(ln) {
854+
} else if mode == Mode::Ui && suite == "ui" && !REVISION_MAGIC_COMMENT_RE.is_match(ln) {
853855
let Some((_, rest)) = line_directive("//", ln) else {
854856
continue;
855857
};

src/tools/miropt-test-tools/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,3 @@ version = "0.1.0"
44
edition = "2021"
55

66
[dependencies]
7-
regex = "1.0"

src/tools/miropt-test-tools/src/lib.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,19 @@ pub fn files_for_miropt_test(
100100
} else {
101101
// Allow-list for file extensions that can be produced by MIR dumps.
102102
// Other extensions can be added here, as needed by new dump flags.
103-
let ext_re = regex::Regex::new(r#"(\.(mir|dot))$"#).unwrap();
104-
let cap = ext_re.captures_iter(test_name).next().unwrap_or_else(|| {
105-
panic!("in {testfile:?}:\nEMIT_MIR has an unrecognized extension: {test_name}")
106-
});
107-
let extension = cap.get(1).unwrap().as_str();
103+
static ALLOWED_EXT: &[&str] = &["mir", "dot"];
104+
let Some((test_name_wo_ext, test_name_ext)) = test_name.rsplit_once('.') else {
105+
panic!(
106+
"in {testfile:?}:\nEMIT_MIR has an unrecognized extension: {test_name}, expected one of {ALLOWED_EXT:?}"
107+
)
108+
};
109+
if !ALLOWED_EXT.contains(&test_name_ext) {
110+
panic!(
111+
"in {testfile:?}:\nEMIT_MIR has an unrecognized extension: {test_name}, expected one of {ALLOWED_EXT:?}"
112+
)
113+
}
108114

109-
expected_file =
110-
format!("{}{}{}", test_name.trim_end_matches(extension), suffix, extension,);
115+
expected_file = format!("{}{}.{}", test_name_wo_ext, suffix, test_name_ext);
111116
from_file = test_name.to_string();
112117
assert!(test_names.next().is_none(), "two mir pass names specified for MIR dump");
113118
to_file = None;

src/tools/tidy/src/style.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -130,16 +130,20 @@ fn should_ignore(line: &str) -> bool {
130130
// Matches test annotations like `//~ ERROR text`.
131131
// This mirrors the regex in src/tools/compiletest/src/runtest.rs, please
132132
// update both if either are changed.
133-
let re = Regex::new("\\s*//(\\[.*\\])?~.*").unwrap();
133+
lazy_static::lazy_static! {
134+
static ref ANNOTATION_RE: Regex = Regex::new("\\s*//(\\[.*\\])?~.*").unwrap();
135+
}
134136
// For `ui_test`-style UI test directives, also ignore
135137
// - `//@[rev] compile-flags`
136138
// - `//@[rev] normalize-stderr-test`
137-
let ui_test_long_directives =
139+
lazy_static::lazy_static! {
140+
static ref UI_TEST_LONG_DIRECTIVES_RE: Regex =
138141
Regex::new("\\s*//@(\\[.*\\]) (compile-flags|normalize-stderr-test|error-pattern).*")
139142
.unwrap();
140-
re.is_match(line)
143+
}
144+
ANNOTATION_RE.is_match(line)
141145
|| ANNOTATIONS_TO_IGNORE.iter().any(|a| line.contains(a))
142-
|| ui_test_long_directives.is_match(line)
146+
|| UI_TEST_LONG_DIRECTIVES_RE.is_match(line)
143147
}
144148

145149
/// Returns `true` if `line` is allowed to be longer than the normal limit.

0 commit comments

Comments
 (0)