Skip to content

Commit

Permalink
Auto merge of #98817 - the8472:dont-optimize-ui-tests, r=Mark-Simulacrum
Browse files Browse the repository at this point in the history
Only obey optimize-tests flag on UI tests that are run-pass

stage1 UI tests walltime on my machine:

```
optimize-tests = false, master
25.98s

optimize-tests = true, master
34.69s

optimize-tests = true, patched
28.79s
```

Effects:

- faster UI tests
- llvm asserts get exercised less on build-pass tests
- the difference between opt and nopt builds shrinks a bit
- aux libs don't get optimized since they don't have a pass mode and almost never have explicit compile flags
  • Loading branch information
bors committed Jul 4, 2022
2 parents a3beeaa + f719239 commit d2074cb
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/bootstrap/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1363,13 +1363,10 @@ note: if you're sure you want to do this, please open an issue as to why. In the
if let Some(ref npm) = builder.config.npm {
cmd.arg("--npm").arg(npm);
}

let mut flags = if is_rustdoc { Vec::new() } else { vec!["-Crpath".to_string()] };
if !is_rustdoc {
if builder.config.rust_optimize_tests {
flags.push("-O".to_string());
}
if builder.config.rust_optimize_tests {
cmd.arg("--optimize-tests");
}
let mut flags = if is_rustdoc { Vec::new() } else { vec!["-Crpath".to_string()] };
flags.push(format!("-Cdebuginfo={}", builder.config.rust_debuginfo_level_tests));
flags.push(builder.config.cmd.rustc_args().join(" "));

Expand Down
4 changes: 4 additions & 0 deletions src/tools/compiletest/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,10 @@ pub struct Config {
/// Flags to pass to the compiler when building for the target
pub target_rustcflags: Option<String>,

/// Whether tests should be optimized by default. Individual test-suites and test files may
/// override this setting.
pub optimize_tests: bool,

/// What panic strategy the target is built with. Unwind supports Abort, but
/// not vice versa.
pub target_panic: PanicStrategy,
Expand Down
1 change: 1 addition & 0 deletions src/tools/compiletest/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ impl TestProps {

// copy over select properties to the aux build:
props.incremental_dir = self.incremental_dir.clone();
props.ignore_pass = true;
props.load_from(testfile, cfg, config);

props
Expand Down
2 changes: 2 additions & 0 deletions src/tools/compiletest/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ pub fn parse_config(args: Vec<String>) -> Config {
)
.optmulti("", "host-rustcflags", "flags to pass to rustc for host", "FLAGS")
.optmulti("", "target-rustcflags", "flags to pass to rustc for target", "FLAGS")
.optflag("", "optimize-tests", "run tests with optimizations enabled")
.optopt("", "target-panic", "what panic strategy the target supports", "unwind | abort")
.optflag("", "verbose", "run tests verbosely, showing all output")
.optflag(
Expand Down Expand Up @@ -253,6 +254,7 @@ pub fn parse_config(args: Vec<String>) -> Config {
runtool: matches.opt_str("runtool"),
host_rustcflags: Some(matches.opt_strs("host-rustcflags").join(" ")),
target_rustcflags: Some(matches.opt_strs("target-rustcflags").join(" ")),
optimize_tests: matches.opt_present("optimize-tests"),
target_panic: match matches.opt_str("target-panic").as_deref() {
Some("unwind") | None => PanicStrategy::Unwind,
Some("abort") => PanicStrategy::Abort,
Expand Down
25 changes: 25 additions & 0 deletions src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1862,6 +1862,31 @@ impl<'test> TestCx<'test> {
}
}

if self.config.optimize_tests && !is_rustdoc {
match self.config.mode {
Ui => {
// If optimize-tests is true we still only want to optimize tests that actually get
// executed and that don't specify their own optimization levels.
// Note: aux libs don't have a pass-mode, so they won't get optimized
// unless compile-flags are set in the aux file.
if self.config.optimize_tests
&& self.props.pass_mode(&self.config) == Some(PassMode::Run)
&& !self
.props
.compile_flags
.iter()
.any(|arg| arg == "-O" || arg.contains("opt-level"))
{
rustc.arg("-O");
}
}
DebugInfo => { /* debuginfo tests must be unoptimized */ }
_ => {
rustc.arg("-O");
}
}
}

match self.config.mode {
Incremental => {
// If we are extracting and matching errors in the new
Expand Down

0 comments on commit d2074cb

Please sign in to comment.