From 6af5faf7928c989e5b8bb6b006bec293e4376656 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Mon, 21 Feb 2022 13:05:37 -0500 Subject: [PATCH] Soft-disable incremental compilation This disables incremental compilation by default and adds a snippet to the compiler release notes explaining the rationale and encouraging testing. --- RELEASES.md | 15 +++++++++++ compiler/rustc_session/src/config.rs | 7 ++++- src/doc/rustc/src/codegen-options/index.md | 3 +++ src/test/run-make/dep-graph/Makefile | 4 ++- .../incremental-session-fail/Makefile | 1 + src/tools/compiletest/src/runtest.rs | 27 ++++++++++++++++++- 6 files changed, 54 insertions(+), 3 deletions(-) diff --git a/RELEASES.md b/RELEASES.md index 96da1660c0feb..2bf212123d43a 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -18,6 +18,21 @@ Compiler - [Warn when a `#[test]`-like built-in attribute macro is present multiple times.][91172] - [Add support for riscv64gc-unknown-freebsd][91284] - [Stabilize `-Z emit-future-incompat` as `--json future-incompat`][91535] +- [Soft disable incremental compilation][94124] + +This release disables incremental compilation, unless the user has explicitly +opted in via the newly added RUSTC_FORCE_INCREMENTAL=1 environment variable. +This is due to a known and relatively frequently occurring bug in incremental +compilation, which causes builds to issue internal compiler errors. This +particular bug is already fixed on nightly, but that fix has not yet rolled out +to stable and is deemed too risky for a direct stable backport. + +As always, we encourage users to test with nightly and report bugs so that we +can track failures and fix issues earlier. + +See [94124] for more details. + +[94124]: https://github.com/rust-lang/rust/issues/94124 Libraries --------- diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 0659816e82da3..08bcea26ebe12 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -2102,7 +2102,12 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options { check_thread_count(&debugging_opts, error_format); - let incremental = cg.incremental.as_ref().map(PathBuf::from); + let incremental = + if std::env::var_os("RUSTC_FORCE_INCREMENTAL").map(|v| v == "1").unwrap_or(false) { + cg.incremental.as_ref().map(PathBuf::from) + } else { + None + }; let assert_incr_state = parse_assert_incr_state(&debugging_opts.assert_incr_state, error_format); diff --git a/src/doc/rustc/src/codegen-options/index.md b/src/doc/rustc/src/codegen-options/index.md index 0201b88417a8b..ec03d4b82b25e 100644 --- a/src/doc/rustc/src/codegen-options/index.md +++ b/src/doc/rustc/src/codegen-options/index.md @@ -160,6 +160,9 @@ to save information after compiling a crate to be reused when recompiling the crate, improving re-compile times. This takes a path to a directory where incremental files will be stored. +Note that this option currently does not take effect unless +`RUSTC_FORCE_INCREMENTAL=1` in the environment. + ## inline-threshold This option lets you set the default threshold for inlining a function. It diff --git a/src/test/run-make/dep-graph/Makefile b/src/test/run-make/dep-graph/Makefile index 88916022c7c82..2bd6b99c80963 100644 --- a/src/test/run-make/dep-graph/Makefile +++ b/src/test/run-make/dep-graph/Makefile @@ -5,7 +5,9 @@ # Just verify that we successfully run and produce dep graphs when requested. all: - RUST_DEP_GRAPH=$(TMPDIR)/dep-graph $(RUSTC) \ + RUST_DEP_GRAPH=$(TMPDIR)/dep-graph \ + RUSTC_FORCE_INCREMENTAL=1 \ + $(RUSTC) \ -Cincremental=$(TMPDIR)/incr \ -Zquery-dep-graph -Zdump-dep-graph foo.rs test -f $(TMPDIR)/dep-graph.txt diff --git a/src/test/run-make/incremental-session-fail/Makefile b/src/test/run-make/incremental-session-fail/Makefile index 0461bb926e76e..0601e264b95eb 100644 --- a/src/test/run-make/incremental-session-fail/Makefile +++ b/src/test/run-make/incremental-session-fail/Makefile @@ -8,6 +8,7 @@ all: # Make it so that rustc will fail to create a session directory. touch $(SESSION_DIR) # Check exit code is 1 for an error, and not 101 for ICE. + RUSTC_FORCE_INCREMENTAL=1 \ $(RUSTC) foo.rs --crate-type=rlib -C incremental=$(SESSION_DIR) > $(OUTPUT_FILE) 2>&1; [ $$? -eq 1 ] $(CGREP) "Could not create incremental compilation crate directory" < $(OUTPUT_FILE) # -v tests are fragile, hopefully this text won't change diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index f039ba59d231c..8649e6d841e10 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -130,6 +130,15 @@ pub fn run(config: Config, testpaths: &TestPaths, revision: Option<&str>) { } debug!("running {:?}", testpaths.file.display()); let mut props = TestProps::from_file(&testpaths.file, revision, &config); + + // Currently, incremental is soft disabled unless this environment + // variable is set. A bunch of our tests assume it's enabled, though - so + // just enable it for our tests. + // + // This is deemed preferable to ignoring those tests; we still want to test + // incremental somewhat, as users can opt in to it. + props.rustc_env.push((String::from("RUSTC_FORCE_INCREMENTAL"), String::from("1"))); + if props.incremental { props.incremental_dir = Some(incremental_dir(&config, testpaths)); } @@ -146,6 +155,12 @@ pub fn run(config: Config, testpaths: &TestPaths, revision: Option<&str>) { assert!(!props.revisions.is_empty(), "Incremental tests require revisions."); for revision in &props.revisions { let mut revision_props = TestProps::from_file(&testpaths.file, Some(revision), &config); + + // See above - need to enable it explicitly for now. + revision_props + .rustc_env + .push((String::from("RUSTC_FORCE_INCREMENTAL"), String::from("1"))); + revision_props.incremental_dir = props.incremental_dir.clone(); let rev_cx = TestCx { config: &config, @@ -1630,7 +1645,17 @@ impl<'test> TestCx<'test> { /// Returns whether or not it is a dylib. fn build_auxiliary(&self, source_path: &str, aux_dir: &Path) -> bool { let aux_testpaths = self.compute_aux_test_paths(source_path); - let aux_props = self.props.from_aux_file(&aux_testpaths.file, self.revision, self.config); + let mut aux_props = + self.props.from_aux_file(&aux_testpaths.file, self.revision, self.config); + + // Currently, incremental is soft disabled unless this environment + // variable is set. A bunch of our tests assume it's enabled, though - so + // just enable it for our tests. + // + // This is deemed preferable to ignoring those tests; we still want to test + // incremental somewhat, as users can opt in to it. + aux_props.rustc_env.push((String::from("RUSTC_FORCE_INCREMENTAL"), String::from("1"))); + let aux_output = TargetLocation::ThisDirectory(self.aux_output_dir_name()); let aux_cx = TestCx { config: self.config,