Skip to content

Commit d2074cb

Browse files
committed
Auto merge of #98817 - the8472:dont-optimize-ui-tests, r=Mark-Simulacrum
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
2 parents a3beeaa + f719239 commit d2074cb

File tree

5 files changed

+35
-6
lines changed

5 files changed

+35
-6
lines changed

src/bootstrap/test.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -1363,13 +1363,10 @@ note: if you're sure you want to do this, please open an issue as to why. In the
13631363
if let Some(ref npm) = builder.config.npm {
13641364
cmd.arg("--npm").arg(npm);
13651365
}
1366-
1367-
let mut flags = if is_rustdoc { Vec::new() } else { vec!["-Crpath".to_string()] };
1368-
if !is_rustdoc {
1369-
if builder.config.rust_optimize_tests {
1370-
flags.push("-O".to_string());
1371-
}
1366+
if builder.config.rust_optimize_tests {
1367+
cmd.arg("--optimize-tests");
13721368
}
1369+
let mut flags = if is_rustdoc { Vec::new() } else { vec!["-Crpath".to_string()] };
13731370
flags.push(format!("-Cdebuginfo={}", builder.config.rust_debuginfo_level_tests));
13741371
flags.push(builder.config.cmd.rustc_args().join(" "));
13751372

src/tools/compiletest/src/common.rs

+4
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,10 @@ 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 by default. Individual test-suites and test files may
273+
/// override this setting.
274+
pub optimize_tests: bool,
275+
272276
/// What panic strategy the target is built with. Unwind supports Abort, but
273277
/// not vice versa.
274278
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", "run tests with optimizations 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

+25
Original file line numberDiff line numberDiff line change
@@ -1862,6 +1862,31 @@ impl<'test> TestCx<'test> {
18621862
}
18631863
}
18641864

1865+
if self.config.optimize_tests && !is_rustdoc {
1866+
match self.config.mode {
1867+
Ui => {
1868+
// If optimize-tests is true we still only want to optimize tests that actually get
1869+
// executed and that don't specify their own optimization levels.
1870+
// Note: aux libs don't have a pass-mode, so they won't get optimized
1871+
// unless compile-flags are set in the aux file.
1872+
if self.config.optimize_tests
1873+
&& self.props.pass_mode(&self.config) == Some(PassMode::Run)
1874+
&& !self
1875+
.props
1876+
.compile_flags
1877+
.iter()
1878+
.any(|arg| arg == "-O" || arg.contains("opt-level"))
1879+
{
1880+
rustc.arg("-O");
1881+
}
1882+
}
1883+
DebugInfo => { /* debuginfo tests must be unoptimized */ }
1884+
_ => {
1885+
rustc.arg("-O");
1886+
}
1887+
}
1888+
}
1889+
18651890
match self.config.mode {
18661891
Incremental => {
18671892
// If we are extracting and matching errors in the new

0 commit comments

Comments
 (0)