Skip to content

Commit a4e8904

Browse files
committed
add way to split mir-opt into panic=abort and panic=unwind
1 parent 6fd0d1b commit a4e8904

File tree

4 files changed

+68
-20
lines changed

4 files changed

+68
-20
lines changed

src/tools/compiletest/src/common.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,15 @@ pub enum PanicStrategy {
131131
Abort,
132132
}
133133

134+
impl PanicStrategy {
135+
pub(crate) fn for_miropt_test_tools(&self) -> miropt_test_tools::PanicStrategy {
136+
match self {
137+
PanicStrategy::Unwind => miropt_test_tools::PanicStrategy::Unwind,
138+
PanicStrategy::Abort => miropt_test_tools::PanicStrategy::Abort,
139+
}
140+
}
141+
}
142+
134143
/// Configuration for compiletest
135144
#[derive(Debug, Default, Clone)]
136145
pub struct Config {
@@ -572,7 +581,7 @@ pub struct TargetCfg {
572581
#[serde(rename = "target-endian", default)]
573582
endian: Endian,
574583
#[serde(rename = "panic-strategy", default)]
575-
panic: PanicStrategy,
584+
pub(crate) panic: PanicStrategy,
576585
}
577586

578587
impl TargetCfg {

src/tools/compiletest/src/runtest.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3565,6 +3565,7 @@ impl<'test> TestCx<'test> {
35653565
let files = miropt_test_tools::files_for_miropt_test(
35663566
&self.testpaths.file,
35673567
self.config.get_pointer_width(),
3568+
self.config.target_cfg().panic.for_miropt_test_tools(),
35683569
);
35693570

35703571
let mut out = Vec::new();
@@ -3582,25 +3583,24 @@ impl<'test> TestCx<'test> {
35823583
}
35833584

35843585
fn check_mir_dump(&self) {
3585-
let test_file_contents = fs::read_to_string(&self.testpaths.file).unwrap();
3586-
35873586
let test_dir = self.testpaths.file.parent().unwrap();
35883587
let test_crate =
35893588
self.testpaths.file.file_stem().unwrap().to_str().unwrap().replace("-", "_");
35903589

3591-
let mut bit_width = String::new();
3592-
if test_file_contents.lines().any(|l| l == "// EMIT_MIR_FOR_EACH_BIT_WIDTH") {
3593-
bit_width = format!(".{}bit", self.config.get_pointer_width());
3594-
}
3590+
let suffix = miropt_test_tools::output_file_suffix(
3591+
&self.testpaths.file,
3592+
self.config.get_pointer_width(),
3593+
self.config.target_cfg().panic.for_miropt_test_tools(),
3594+
);
35953595

35963596
if self.config.bless {
35973597
for e in
3598-
glob(&format!("{}/{}.*{}.mir", test_dir.display(), test_crate, bit_width)).unwrap()
3598+
glob(&format!("{}/{}.*{}.mir", test_dir.display(), test_crate, suffix)).unwrap()
35993599
{
36003600
std::fs::remove_file(e.unwrap()).unwrap();
36013601
}
36023602
for e in
3603-
glob(&format!("{}/{}.*{}.diff", test_dir.display(), test_crate, bit_width)).unwrap()
3603+
glob(&format!("{}/{}.*{}.diff", test_dir.display(), test_crate, suffix)).unwrap()
36043604
{
36053605
std::fs::remove_file(e.unwrap()).unwrap();
36063606
}
@@ -3609,6 +3609,7 @@ impl<'test> TestCx<'test> {
36093609
let files = miropt_test_tools::files_for_miropt_test(
36103610
&self.testpaths.file,
36113611
self.config.get_pointer_width(),
3612+
self.config.target_cfg().panic.for_miropt_test_tools(),
36123613
);
36133614
for miropt_test_tools::MiroptTestFiles { from_file, to_file, expected_file, passes: _ } in
36143615
files

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

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::fs;
2+
use std::path::Path;
23

34
pub struct MiroptTestFiles {
45
pub expected_file: std::path::PathBuf,
@@ -8,18 +9,52 @@ pub struct MiroptTestFiles {
89
pub passes: Vec<String>,
910
}
1011

11-
pub fn files_for_miropt_test(testfile: &std::path::Path, bit_width: u32) -> Vec<MiroptTestFiles> {
12+
pub enum PanicStrategy {
13+
Unwind,
14+
Abort,
15+
}
16+
17+
pub fn output_file_suffix(
18+
testfile: &Path,
19+
bit_width: u32,
20+
panic_strategy: PanicStrategy,
21+
) -> String {
22+
let mut each_bit_width = false;
23+
let mut each_panic_strategy = false;
24+
for line in fs::read_to_string(testfile).unwrap().lines() {
25+
if line == "// EMIT_MIR_FOR_EACH_BIT_WIDTH" {
26+
each_bit_width = true;
27+
}
28+
if line == "// EMIT_MIR_FOR_EACH_PANIC_STRATEGY" {
29+
each_panic_strategy = true;
30+
}
31+
}
32+
33+
let mut suffix = String::new();
34+
if each_bit_width {
35+
suffix.push_str(&format!(".{}bit", bit_width));
36+
}
37+
if each_panic_strategy {
38+
match panic_strategy {
39+
PanicStrategy::Unwind => suffix.push_str(".panic-unwind"),
40+
PanicStrategy::Abort => suffix.push_str(".panic-abort"),
41+
}
42+
}
43+
suffix
44+
}
45+
46+
pub fn files_for_miropt_test(
47+
testfile: &std::path::Path,
48+
bit_width: u32,
49+
panic_strategy: PanicStrategy,
50+
) -> Vec<MiroptTestFiles> {
1251
let mut out = Vec::new();
1352
let test_file_contents = fs::read_to_string(&testfile).unwrap();
1453

1554
let test_dir = testfile.parent().unwrap();
1655
let test_crate = testfile.file_stem().unwrap().to_str().unwrap().replace('-', "_");
1756

18-
let bit_width = if test_file_contents.lines().any(|l| l == "// EMIT_MIR_FOR_EACH_BIT_WIDTH") {
19-
format!(".{}bit", bit_width)
20-
} else {
21-
String::new()
22-
};
57+
let suffix = output_file_suffix(testfile, bit_width, panic_strategy);
2358

2459
for l in test_file_contents.lines() {
2560
if l.starts_with("// EMIT_MIR ") {
@@ -37,7 +72,7 @@ pub fn files_for_miropt_test(testfile: &std::path::Path, bit_width: u32) -> Vec<
3772
passes.push(trimmed.split('.').last().unwrap().to_owned());
3873
let test_against = format!("{}.after.mir", trimmed);
3974
from_file = format!("{}.before.mir", trimmed);
40-
expected_file = format!("{}{}.diff", trimmed, bit_width);
75+
expected_file = format!("{}{}.diff", trimmed, suffix);
4176
assert!(test_names.next().is_none(), "two mir pass names specified for MIR diff");
4277
to_file = Some(test_against);
4378
} else if let Some(first_pass) = test_names.next() {
@@ -51,7 +86,7 @@ pub fn files_for_miropt_test(testfile: &std::path::Path, bit_width: u32) -> Vec<
5186
assert!(test_names.next().is_none(), "three mir pass names specified for MIR diff");
5287

5388
expected_file =
54-
format!("{}{}.{}-{}.diff", test_name, bit_width, first_pass, second_pass);
89+
format!("{}{}.{}-{}.diff", test_name, suffix, first_pass, second_pass);
5590
let second_file = format!("{}.{}.mir", test_name, second_pass);
5691
from_file = format!("{}.{}.mir", test_name, first_pass);
5792
to_file = Some(second_file);
@@ -64,7 +99,7 @@ pub fn files_for_miropt_test(testfile: &std::path::Path, bit_width: u32) -> Vec<
6499
let extension = cap.get(1).unwrap().as_str();
65100

66101
expected_file =
67-
format!("{}{}{}", test_name.trim_end_matches(extension), bit_width, extension,);
102+
format!("{}{}{}", test_name.trim_end_matches(extension), suffix, extension,);
68103
from_file = test_name.to_string();
69104
assert!(test_names.next().is_none(), "two mir pass names specified for MIR dump");
70105
to_file = None;

src/tools/tidy/src/mir_opt_tests.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Tidy check to ensure that mir opt directories do not have stale files or dashes in file names
22
3+
use miropt_test_tools::PanicStrategy;
34
use std::collections::HashSet;
45
use std::path::{Path, PathBuf};
56

@@ -24,8 +25,10 @@ fn check_unused_files(path: &Path, bless: bool, bad: &mut bool) {
2425

2526
for file in rs_files {
2627
for bw in [32, 64] {
27-
for output_file in miropt_test_tools::files_for_miropt_test(&file, bw) {
28-
output_files.remove(&output_file.expected_file);
28+
for ps in [PanicStrategy::Unwind, PanicStrategy::Abort] {
29+
for output_file in miropt_test_tools::files_for_miropt_test(&file, bw, ps) {
30+
output_files.remove(&output_file.expected_file);
31+
}
2932
}
3033
}
3134
}

0 commit comments

Comments
 (0)