Skip to content

Commit

Permalink
Soft-disable incremental compilation
Browse files Browse the repository at this point in the history
This disables incremental compilation by default and adds a snippet to the
compiler release notes explaining the rationale and encouraging testing.
  • Loading branch information
Mark-Simulacrum committed Feb 22, 2022
1 parent a92566a commit 6af5faf
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 3 deletions.
15 changes: 15 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
---------
Expand Down
7 changes: 6 additions & 1 deletion compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions src/doc/rustc/src/codegen-options/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/test/run-make/dep-graph/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/test/run-make/incremental-session-fail/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 26 additions & 1 deletion src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 6af5faf

Please sign in to comment.