From 125f33aa4c45a6eff14a23d2505455b55a3b0d15 Mon Sep 17 00:00:00 2001 From: The 8472 Date: Sat, 2 Jul 2022 20:50:55 +0200 Subject: [PATCH 1/2] 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 --- src/bootstrap/test.rs | 5 ++++- src/tools/compiletest/src/common.rs | 5 +++++ src/tools/compiletest/src/header.rs | 1 + src/tools/compiletest/src/main.rs | 2 ++ src/tools/compiletest/src/runtest.rs | 12 ++++++++++++ 5 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index 9958306b5765c..65d7a264edd91 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -1365,11 +1365,14 @@ note: if you're sure you want to do this, please open an issue as to why. In the } let mut flags = if is_rustdoc { Vec::new() } else { vec!["-Crpath".to_string()] }; - if !is_rustdoc { + if !is_rustdoc && mode != "ui" { if builder.config.rust_optimize_tests { flags.push("-O".to_string()); } } + if builder.config.rust_optimize_tests { + cmd.arg("--optimize-tests"); + } flags.push(format!("-Cdebuginfo={}", builder.config.rust_debuginfo_level_tests)); flags.push(builder.config.cmd.rustc_args().join(" ")); diff --git a/src/tools/compiletest/src/common.rs b/src/tools/compiletest/src/common.rs index bdf26d040ad14..bd058bcda41f1 100644 --- a/src/tools/compiletest/src/common.rs +++ b/src/tools/compiletest/src/common.rs @@ -269,6 +269,11 @@ pub struct Config { /// Flags to pass to the compiler when building for the target pub target_rustcflags: Option, + /// Whether tests should be optimized. + /// Currently only provides a default for UI-tests that are run-pass. + /// Other tests are controlled by rustcflags or the testfiles themselves. + pub optimize_tests: bool, + /// What panic strategy the target is built with. Unwind supports Abort, but /// not vice versa. pub target_panic: PanicStrategy, diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs index 31e979a574b6e..7cf4a88c47043 100644 --- a/src/tools/compiletest/src/header.rs +++ b/src/tools/compiletest/src/header.rs @@ -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 diff --git a/src/tools/compiletest/src/main.rs b/src/tools/compiletest/src/main.rs index 4e8e5afd4bbe2..28ab3a72ef68b 100644 --- a/src/tools/compiletest/src/main.rs +++ b/src/tools/compiletest/src/main.rs @@ -102,6 +102,7 @@ pub fn parse_config(args: Vec) -> 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", "build UI tests with optimization enabled") .optopt("", "target-panic", "what panic strategy the target supports", "unwind | abort") .optflag("", "verbose", "run tests verbosely, showing all output") .optflag( @@ -253,6 +254,7 @@ pub fn parse_config(args: Vec) -> 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, diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 160b9785d975f..8c98f87c48ca8 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -1875,6 +1875,18 @@ impl<'test> TestCx<'test> { rustc.arg("-Zdeduplicate-diagnostics=no"); } 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 + 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"); + } if !self.props.compile_flags.iter().any(|s| s.starts_with("--error-format")) { rustc.args(&["--error-format", "json"]); rustc.args(&["--json", "future-incompat"]); From f71923942499124357b9005ea3567b20f4f5ab26 Mon Sep 17 00:00:00 2001 From: The 8472 Date: Sat, 2 Jul 2022 22:19:49 +0200 Subject: [PATCH 2/2] move optimize-tests flag handling from bootstrap to compiletest --- src/bootstrap/test.rs | 8 +----- src/tools/compiletest/src/common.rs | 5 ++-- src/tools/compiletest/src/main.rs | 2 +- src/tools/compiletest/src/runtest.rs | 37 +++++++++++++++++++--------- 4 files changed, 29 insertions(+), 23 deletions(-) diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index 65d7a264edd91..f3395507bb08b 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -1363,16 +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 && mode != "ui" { - 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(" ")); diff --git a/src/tools/compiletest/src/common.rs b/src/tools/compiletest/src/common.rs index bd058bcda41f1..be81ff881f3a8 100644 --- a/src/tools/compiletest/src/common.rs +++ b/src/tools/compiletest/src/common.rs @@ -269,9 +269,8 @@ pub struct Config { /// Flags to pass to the compiler when building for the target pub target_rustcflags: Option, - /// Whether tests should be optimized. - /// Currently only provides a default for UI-tests that are run-pass. - /// Other tests are controlled by rustcflags or the testfiles themselves. + /// 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 diff --git a/src/tools/compiletest/src/main.rs b/src/tools/compiletest/src/main.rs index 28ab3a72ef68b..a8a151ca114d2 100644 --- a/src/tools/compiletest/src/main.rs +++ b/src/tools/compiletest/src/main.rs @@ -102,7 +102,7 @@ pub fn parse_config(args: Vec) -> 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", "build UI tests with optimization enabled") + .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( diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 8c98f87c48ca8..35ed4e8c95790 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -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 @@ -1875,18 +1900,6 @@ impl<'test> TestCx<'test> { rustc.arg("-Zdeduplicate-diagnostics=no"); } 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 - 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"); - } if !self.props.compile_flags.iter().any(|s| s.starts_with("--error-format")) { rustc.args(&["--error-format", "json"]); rustc.args(&["--json", "future-incompat"]);