Skip to content

Commit db4235c

Browse files
committed
Auto merge of #49293 - memoryleak47:add-compiletest-nll-compare-mode, r=pnkfelix
Add compiletest `--compare-mode nll` option Before implementing the tidy stuff, I'd appreciate if someone reviews the changes so far. This is my first non-trivial pull request, so I could really use some feedback. :) closes #48879. r? @nikomatsakis
2 parents 48fa6f9 + 03e1509 commit db4235c

File tree

3 files changed

+82
-22
lines changed

3 files changed

+82
-22
lines changed

src/tools/compiletest/src/common.rs

+35-5
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,26 @@ impl fmt::Display for Mode {
9595
}
9696
}
9797

98+
#[derive(Clone)]
99+
pub enum CompareMode {
100+
Nll
101+
}
102+
103+
impl CompareMode {
104+
fn to_str(&self) -> &'static str {
105+
match *self {
106+
CompareMode::Nll => "nll"
107+
}
108+
}
109+
110+
pub fn parse(s: String) -> CompareMode {
111+
match s.as_str() {
112+
"nll" => CompareMode::Nll,
113+
x => panic!("unknown --compare-mode option: {}", x),
114+
}
115+
}
116+
}
117+
98118
#[derive(Clone)]
99119
pub struct Config {
100120
/// The library paths required for running the compiler
@@ -210,6 +230,9 @@ pub struct Config {
210230
/// where to find the remote test client process, if we're using it
211231
pub remote_test_client: Option<PathBuf>,
212232

233+
/// mode describing what file the actual ui output will be compared to
234+
pub compare_mode: Option<CompareMode>,
235+
213236
// Configuration for various run-make tests frobbing things like C compilers
214237
// or querying about various LLVM component information.
215238
pub cc: String,
@@ -230,12 +253,19 @@ pub struct TestPaths {
230253
}
231254

232255
/// Used by `ui` tests to generate things like `foo.stderr` from `foo.rs`.
233-
pub fn expected_output_path(testpaths: &TestPaths, revision: Option<&str>, kind: &str) -> PathBuf {
256+
pub fn expected_output_path(testpaths: &TestPaths,
257+
revision: Option<&str>,
258+
compare_mode: &Option<CompareMode>,
259+
kind: &str) -> PathBuf {
260+
234261
assert!(UI_EXTENSIONS.contains(&kind));
235-
let extension = match revision {
236-
Some(r) => format!("{}.{}", r, kind),
237-
None => kind.to_string(),
238-
};
262+
let mut parts = Vec::new();
263+
264+
if let Some(x) = revision { parts.push(x); }
265+
if let Some(ref x) = *compare_mode { parts.push(x.to_str()); }
266+
parts.push(kind);
267+
268+
let extension = parts.join(".");
239269
testpaths.file.with_extension(extension)
240270
}
241271

src/tools/compiletest/src/main.rs

+15-3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ use getopts::Options;
3838
use common::{Config, TestPaths};
3939
use common::{DebugInfoGdb, DebugInfoLldb, Mode, Pretty};
4040
use common::{expected_output_path, UI_EXTENSIONS};
41+
use common::CompareMode;
4142
use test::ColorConfig;
4243
use util::logv;
4344

@@ -227,6 +228,12 @@ pub fn parse_config(args: Vec<String>) -> Config {
227228
"path to the remote test client",
228229
"PATH",
229230
)
231+
.optopt(
232+
"",
233+
"compare-mode",
234+
"mode describing what file the actual ui output will be compared to",
235+
"COMPARE MODE"
236+
)
230237
.optflag("h", "help", "show this message");
231238

232239
let (argv0, args_) = args.split_first().unwrap();
@@ -320,6 +327,7 @@ pub fn parse_config(args: Vec<String>) -> Config {
320327
quiet: matches.opt_present("quiet"),
321328
color,
322329
remote_test_client: matches.opt_str("remote-test-client").map(PathBuf::from),
330+
compare_mode: matches.opt_str("compare-mode").map(CompareMode::parse),
323331

324332
cc: matches.opt_str("cc").unwrap(),
325333
cxx: matches.opt_str("cxx").unwrap(),
@@ -615,7 +623,8 @@ pub fn make_test(config: &Config, testpaths: &TestPaths) -> test::TestDescAndFn
615623
};
616624

617625
// Debugging emscripten code doesn't make sense today
618-
let ignore = early_props.ignore || !up_to_date(config, testpaths, &early_props)
626+
let ignore = early_props.ignore
627+
|| (!up_to_date(config, testpaths, &early_props) && config.compare_mode.is_none())
619628
|| (config.mode == DebugInfoGdb || config.mode == DebugInfoLldb)
620629
&& config.target.contains("emscripten");
621630

@@ -688,12 +697,15 @@ fn up_to_date(config: &Config, testpaths: &TestPaths, props: &EarlyProps) -> boo
688697
// UI test files.
689698
for extension in UI_EXTENSIONS {
690699
for revision in &props.revisions {
691-
let path = &expected_output_path(testpaths, Some(revision), extension);
700+
let path = &expected_output_path(testpaths,
701+
Some(revision),
702+
&config.compare_mode,
703+
extension);
692704
inputs.push(mtime(path));
693705
}
694706

695707
if props.revisions.is_empty() {
696-
let path = &expected_output_path(testpaths, None, extension);
708+
let path = &expected_output_path(testpaths, None, &config.compare_mode, extension);
697709
inputs.push(mtime(path));
698710
}
699711
}

src/tools/compiletest/src/runtest.rs

+32-14
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use common::{CompileFail, ParseFail, Pretty, RunFail, RunPass, RunPassValgrind};
1313
use common::{Codegen, CodegenUnits, DebugInfoGdb, DebugInfoLldb, Rustdoc};
1414
use common::{Incremental, MirOpt, RunMake, Ui};
1515
use common::{expected_output_path, UI_STDERR, UI_STDOUT};
16+
use common::CompareMode;
1617
use diff;
1718
use errors::{self, Error, ErrorKind};
1819
use filetime::FileTime;
@@ -1683,6 +1684,13 @@ impl<'test> TestCx<'test> {
16831684
}
16841685
}
16851686

1687+
match self.config.compare_mode {
1688+
Some(CompareMode::Nll) => {
1689+
rustc.args(&["-Znll", "-Zborrowck=mir", "-Ztwo-phase-borrows"]);
1690+
},
1691+
None => {},
1692+
}
1693+
16861694
if self.props.force_host {
16871695
rustc.args(self.split_maybe_args(&self.config.host_rustcflags));
16881696
} else {
@@ -2505,11 +2513,8 @@ impl<'test> TestCx<'test> {
25052513
let proc_res = self.compile_test();
25062514
self.check_if_test_should_compile(&proc_res);
25072515

2508-
let expected_stderr_path = self.expected_output_path(UI_STDERR);
2509-
let expected_stderr = self.load_expected_output(&expected_stderr_path);
2510-
2511-
let expected_stdout_path = self.expected_output_path(UI_STDOUT);
2512-
let expected_stdout = self.load_expected_output(&expected_stdout_path);
2516+
let expected_stderr = self.load_expected_output(UI_STDERR);
2517+
let expected_stdout = self.load_expected_output(UI_STDOUT);
25132518

25142519
let normalized_stdout =
25152520
self.normalize_output(&proc_res.stdout, &self.props.normalize_stdout);
@@ -2552,7 +2557,7 @@ impl<'test> TestCx<'test> {
25522557
self.fatal_proc_rec("test run failed!", &proc_res);
25532558
}
25542559
}
2555-
if !explicit {
2560+
if !explicit && self.config.compare_mode.is_none() {
25562561
if !expected_errors.is_empty() || !proc_res.status.success() {
25572562
// "// error-pattern" comments
25582563
self.check_expected_errors(expected_errors, &proc_res);
@@ -2795,19 +2800,32 @@ impl<'test> TestCx<'test> {
27952800
normalized
27962801
}
27972802

2798-
fn expected_output_path(&self, kind: &str) -> PathBuf {
2799-
expected_output_path(&self.testpaths, self.revision, kind)
2800-
}
2803+
fn load_expected_output(&self, kind: &str) -> String {
2804+
let mut path = expected_output_path(&self.testpaths,
2805+
self.revision,
2806+
&self.config.compare_mode,
2807+
kind);
28012808

2802-
fn load_expected_output(&self, path: &Path) -> String {
2803-
if !path.exists() {
2804-
return String::new();
2809+
if !path.exists() && self.config.compare_mode.is_some() {
2810+
// fallback!
2811+
path = expected_output_path(&self.testpaths, self.revision, &None, kind);
28052812
}
28062813

2814+
if path.exists() {
2815+
match self.load_expected_output_from_path(&path) {
2816+
Ok(x) => x,
2817+
Err(x) => self.fatal(&x),
2818+
}
2819+
} else {
2820+
String::new()
2821+
}
2822+
}
2823+
2824+
fn load_expected_output_from_path(&self, path: &Path) -> Result<String, String> {
28072825
let mut result = String::new();
28082826
match File::open(path).and_then(|mut f| f.read_to_string(&mut result)) {
2809-
Ok(_) => result,
2810-
Err(e) => self.fatal(&format!(
2827+
Ok(_) => Ok(result),
2828+
Err(e) => Err(format!(
28112829
"failed to load expected output from `{}`: {}",
28122830
path.display(),
28132831
e

0 commit comments

Comments
 (0)