Skip to content

Commit 125f33a

Browse files
committed
Only obey optimize-tests flag on UI tests that are run-pass
``` 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
1 parent 4118ad2 commit 125f33a

File tree

5 files changed

+24
-1
lines changed

5 files changed

+24
-1
lines changed

src/bootstrap/test.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1365,11 +1365,14 @@ note: if you're sure you want to do this, please open an issue as to why. In the
13651365
}
13661366

13671367
let mut flags = if is_rustdoc { Vec::new() } else { vec!["-Crpath".to_string()] };
1368-
if !is_rustdoc {
1368+
if !is_rustdoc && mode != "ui" {
13691369
if builder.config.rust_optimize_tests {
13701370
flags.push("-O".to_string());
13711371
}
13721372
}
1373+
if builder.config.rust_optimize_tests {
1374+
cmd.arg("--optimize-tests");
1375+
}
13731376
flags.push(format!("-Cdebuginfo={}", builder.config.rust_debuginfo_level_tests));
13741377
flags.push(builder.config.cmd.rustc_args().join(" "));
13751378

src/tools/compiletest/src/common.rs

+5
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,11 @@ pub struct Config {
269269
/// Flags to pass to the compiler when building for the target
270270
pub target_rustcflags: Option<String>,
271271

272+
/// Whether tests should be optimized.
273+
/// Currently only provides a default for UI-tests that are run-pass.
274+
/// Other tests are controlled by rustcflags or the testfiles themselves.
275+
pub optimize_tests: bool,
276+
272277
/// What panic strategy the target is built with. Unwind supports Abort, but
273278
/// not vice versa.
274279
pub target_panic: PanicStrategy,

src/tools/compiletest/src/header.rs

+1
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ impl TestProps {
244244

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

249250
props

src/tools/compiletest/src/main.rs

+2
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ pub fn parse_config(args: Vec<String>) -> Config {
102102
)
103103
.optmulti("", "host-rustcflags", "flags to pass to rustc for host", "FLAGS")
104104
.optmulti("", "target-rustcflags", "flags to pass to rustc for target", "FLAGS")
105+
.optflag("", "optimize-tests", "build UI tests with optimization enabled")
105106
.optopt("", "target-panic", "what panic strategy the target supports", "unwind | abort")
106107
.optflag("", "verbose", "run tests verbosely, showing all output")
107108
.optflag(
@@ -253,6 +254,7 @@ pub fn parse_config(args: Vec<String>) -> Config {
253254
runtool: matches.opt_str("runtool"),
254255
host_rustcflags: Some(matches.opt_strs("host-rustcflags").join(" ")),
255256
target_rustcflags: Some(matches.opt_strs("target-rustcflags").join(" ")),
257+
optimize_tests: matches.opt_present("optimize-tests"),
256258
target_panic: match matches.opt_str("target-panic").as_deref() {
257259
Some("unwind") | None => PanicStrategy::Unwind,
258260
Some("abort") => PanicStrategy::Abort,

src/tools/compiletest/src/runtest.rs

+12
Original file line numberDiff line numberDiff line change
@@ -1875,6 +1875,18 @@ impl<'test> TestCx<'test> {
18751875
rustc.arg("-Zdeduplicate-diagnostics=no");
18761876
}
18771877
Ui => {
1878+
// If optimize-tests is true we still only want to optimize tests that actually get
1879+
// executed and that don't specify their own optimization levels
1880+
if self.config.optimize_tests
1881+
&& self.props.pass_mode(&self.config) == Some(PassMode::Run)
1882+
&& !self
1883+
.props
1884+
.compile_flags
1885+
.iter()
1886+
.any(|arg| arg == "-O" || arg.contains("opt-level"))
1887+
{
1888+
rustc.arg("-O");
1889+
}
18781890
if !self.props.compile_flags.iter().any(|s| s.starts_with("--error-format")) {
18791891
rustc.args(&["--error-format", "json"]);
18801892
rustc.args(&["--json", "future-incompat"]);

0 commit comments

Comments
 (0)