Skip to content

Commit

Permalink
tidy: wrap regexes with lazy_static
Browse files Browse the repository at this point in the history
yes, once_cell better, but ...

this reduces from

==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

==47796== Total:     821,467,407 bytes in 3,955,595 blocks
==47796== At t-gmax: 10,976,209 bytes in 66,100 blocks
==47796== At t-end:  2,944,016 bytes in 12,490 blocks
==47796== Reads:     4,788,959,023 bytes
==47796== Writes:    975,493,639 bytes

miropt-test-tools: remove regex usage

this removes regex usage and slightly refactors ext stripping in one case
  • Loading branch information
klensy committed Feb 12, 2024
1 parent 98aa362 commit 60457aa
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
3 changes: 0 additions & 3 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2490,9 +2490,6 @@ dependencies = [
[[package]]
name = "miropt-test-tools"
version = "0.1.0"
dependencies = [
"regex",
]

[[package]]
name = "native-tls"
Expand Down
1 change: 0 additions & 1 deletion src/tools/miropt-test-tools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ version = "0.1.0"
edition = "2021"

[dependencies]
regex = "1.0"
19 changes: 12 additions & 7 deletions src/tools/miropt-test-tools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,19 @@ pub fn files_for_miropt_test(
} else {
// Allow-list for file extensions that can be produced by MIR dumps.
// Other extensions can be added here, as needed by new dump flags.
let ext_re = regex::Regex::new(r#"(\.(mir|dot))$"#).unwrap();
let cap = ext_re.captures_iter(test_name).next().unwrap_or_else(|| {
panic!("in {testfile:?}:\nEMIT_MIR has an unrecognized extension: {test_name}")
});
let extension = cap.get(1).unwrap().as_str();
static ALLOWED_EXT: &[&str] = &["mir", "dot"];
let Some((test_name_wo_ext, test_name_ext)) = test_name.rsplit_once('.') else {
panic!(
"in {testfile:?}:\nEMIT_MIR has an unrecognized extension: {test_name}, expected one of {ALLOWED_EXT:?}"
)
};
if !ALLOWED_EXT.contains(&test_name_ext) {
panic!(
"in {testfile:?}:\nEMIT_MIR has an unrecognized extension: {test_name}, expected one of {ALLOWED_EXT:?}"
)
}

expected_file =
format!("{}{}{}", test_name.trim_end_matches(extension), suffix, extension,);
expected_file = format!("{}{}.{}", test_name_wo_ext, suffix, test_name_ext);
from_file = test_name.to_string();
assert!(test_names.next().is_none(), "two mir pass names specified for MIR dump");
to_file = None;
Expand Down
6 changes: 4 additions & 2 deletions src/tools/tidy/src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,10 @@ fn should_ignore(line: &str) -> bool {
// Matches test annotations like `//~ ERROR text`.
// This mirrors the regex in src/tools/compiletest/src/runtest.rs, please
// update both if either are changed.
let re = Regex::new("\\s*//(\\[.*\\])?~.*").unwrap();
re.is_match(line) || ANNOTATIONS_TO_IGNORE.iter().any(|a| line.contains(a))
lazy_static::lazy_static! {
static ref ANNOTATION_RE: Regex = Regex::new("\\s*//(\\[.*\\])?~.*").unwrap();
}
ANNOTATION_RE.is_match(line) || ANNOTATIONS_TO_IGNORE.iter().any(|a| line.contains(a))
}

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

0 comments on commit 60457aa

Please sign in to comment.