Skip to content

Commit 7979dd6

Browse files
committed
Auto merge of #32016 - nikomatsakis:incr-comp-save, r=mw
Save/load incremental compilation dep graph Contains the code to serialize/deserialize the dep graph to disk between executions. We also hash the item contents and compare to the new hashes. Also includes a unit test harness. There are definitely some known limitations, such as #32014 and #32015, but I am leaving those for follow-up work. Note that this PR builds on #32007, so the overlapping commits can be excluded from review. r? @michaelwoerister
2 parents 470ca1c + 9eaae92 commit 7979dd6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+2053
-712
lines changed

mk/crates.mk

+5-3
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ RUSTC_CRATES := rustc rustc_typeck rustc_mir rustc_borrowck rustc_resolve rustc_
5858
rustc_trans rustc_back rustc_llvm rustc_privacy rustc_lint \
5959
rustc_data_structures rustc_platform_intrinsics \
6060
rustc_plugin rustc_metadata rustc_passes rustc_save_analysis \
61-
rustc_const_eval rustc_const_math
61+
rustc_const_eval rustc_const_math rustc_incremental
6262
HOST_CRATES := syntax syntax_ext $(RUSTC_CRATES) rustdoc fmt_macros \
6363
flate arena graphviz rbml log serialize
6464
TOOLS := compiletest rustdoc rustc rustbook error_index_generator
@@ -105,7 +105,8 @@ DEPS_rustc_data_structures := std log serialize
105105
DEPS_rustc_driver := arena flate getopts graphviz libc rustc rustc_back rustc_borrowck \
106106
rustc_typeck rustc_mir rustc_resolve log syntax serialize rustc_llvm \
107107
rustc_trans rustc_privacy rustc_lint rustc_plugin \
108-
rustc_metadata syntax_ext rustc_passes rustc_save_analysis rustc_const_eval
108+
rustc_metadata syntax_ext rustc_passes rustc_save_analysis rustc_const_eval \
109+
rustc_incremental
109110
DEPS_rustc_lint := rustc log syntax rustc_const_eval
110111
DEPS_rustc_llvm := native:rustllvm libc std rustc_bitflags
111112
DEPS_rustc_metadata := rustc syntax rbml rustc_const_math
@@ -117,7 +118,8 @@ DEPS_rustc_plugin := rustc rustc_metadata syntax rustc_mir
117118
DEPS_rustc_privacy := rustc log syntax
118119
DEPS_rustc_trans := arena flate getopts graphviz libc rustc rustc_back rustc_mir \
119120
log syntax serialize rustc_llvm rustc_platform_intrinsics \
120-
rustc_const_math rustc_const_eval
121+
rustc_const_math rustc_const_eval rustc_incremental
122+
DEPS_rustc_incremental := rbml rustc serialize rustc_data_structures
121123
DEPS_rustc_save_analysis := rustc log syntax
122124
DEPS_rustc_typeck := rustc syntax rustc_platform_intrinsics rustc_const_math \
123125
rustc_const_eval

mk/tests.mk

+11-1
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ check-stage$(1)-T-$(2)-H-$(3)-exec: \
305305
check-stage$(1)-T-$(2)-H-$(3)-doc-crates-exec \
306306
check-stage$(1)-T-$(2)-H-$(3)-debuginfo-gdb-exec \
307307
check-stage$(1)-T-$(2)-H-$(3)-debuginfo-lldb-exec \
308+
check-stage$(1)-T-$(2)-H-$(3)-incremental-exec \
308309
check-stage$(1)-T-$(2)-H-$(3)-doc-exec \
309310
check-stage$(1)-T-$(2)-H-$(3)-pretty-exec
310311

@@ -481,6 +482,7 @@ DEBUGINFO_LLDB_RS := $(call rwildcard,$(S)src/test/debuginfo/,*.rs)
481482
CODEGEN_RS := $(call rwildcard,$(S)src/test/codegen/,*.rs)
482483
CODEGEN_CC := $(call rwildcard,$(S)src/test/codegen/,*.cc)
483484
CODEGEN_UNITS_RS := $(call rwildcard,$(S)src/test/codegen-units/,*.rs)
485+
INCREMENTAL_RS := $(call rwildcard,$(S)src/test/incremental/,*.rs)
484486
RUSTDOCCK_RS := $(call rwildcard,$(S)src/test/rustdoc/,*.rs)
485487

486488
RPASS_TESTS := $(RPASS_RS)
@@ -496,6 +498,7 @@ DEBUGINFO_GDB_TESTS := $(DEBUGINFO_GDB_RS)
496498
DEBUGINFO_LLDB_TESTS := $(DEBUGINFO_LLDB_RS)
497499
CODEGEN_TESTS := $(CODEGEN_RS) $(CODEGEN_CC)
498500
CODEGEN_UNITS_TESTS := $(CODEGEN_UNITS_RS)
501+
INCREMENTAL_TESTS := $(INCREMENTAL_RS)
499502
RUSTDOCCK_TESTS := $(RUSTDOCCK_RS)
500503

501504
CTEST_SRC_BASE_rpass = run-pass
@@ -558,6 +561,11 @@ CTEST_BUILD_BASE_codegen-units = codegen-units
558561
CTEST_MODE_codegen-units = codegen-units
559562
CTEST_RUNTOOL_codegen-units = $(CTEST_RUNTOOL)
560563

564+
CTEST_SRC_BASE_incremental = incremental
565+
CTEST_BUILD_BASE_incremental = incremental
566+
CTEST_MODE_incremental = incremental
567+
CTEST_RUNTOOL_incremental = $(CTEST_RUNTOOL)
568+
561569
CTEST_SRC_BASE_rustdocck = rustdoc
562570
CTEST_BUILD_BASE_rustdocck = rustdoc
563571
CTEST_MODE_rustdocck = rustdoc
@@ -681,6 +689,7 @@ CTEST_DEPS_debuginfo-lldb_$(1)-T-$(2)-H-$(3) = $$(DEBUGINFO_LLDB_TESTS) \
681689
$(S)src/etc/lldb_rust_formatters.py
682690
CTEST_DEPS_codegen_$(1)-T-$(2)-H-$(3) = $$(CODEGEN_TESTS)
683691
CTEST_DEPS_codegen-units_$(1)-T-$(2)-H-$(3) = $$(CODEGEN_UNITS_TESTS)
692+
CTEST_DEPS_incremental_$(1)-T-$(2)-H-$(3) = $$(INCREMENTAL_TESTS)
684693
CTEST_DEPS_rustdocck_$(1)-T-$(2)-H-$(3) = $$(RUSTDOCCK_TESTS) \
685694
$$(HBIN$(1)_H_$(3))/rustdoc$$(X_$(3)) \
686695
$(S)src/etc/htmldocck.py
@@ -747,7 +756,7 @@ endif
747756
endef
748757

749758
CTEST_NAMES = rpass rpass-valgrind rpass-full rfail-full cfail-full rfail cfail pfail \
750-
debuginfo-gdb debuginfo-lldb codegen codegen-units rustdocck
759+
debuginfo-gdb debuginfo-lldb codegen codegen-units rustdocck incremental
751760

752761
$(foreach host,$(CFG_HOST), \
753762
$(eval $(foreach target,$(CFG_TARGET), \
@@ -945,6 +954,7 @@ TEST_GROUPS = \
945954
debuginfo-lldb \
946955
codegen \
947956
codegen-units \
957+
incremental \
948958
doc \
949959
$(foreach docname,$(DOC_NAMES),doc-$(docname)) \
950960
pretty \

src/compiletest/common.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ pub enum Mode {
2525
DebugInfoLldb,
2626
Codegen,
2727
Rustdoc,
28-
CodegenUnits
28+
CodegenUnits,
29+
Incremental,
2930
}
3031

3132
impl FromStr for Mode {
@@ -43,6 +44,7 @@ impl FromStr for Mode {
4344
"codegen" => Ok(Codegen),
4445
"rustdoc" => Ok(Rustdoc),
4546
"codegen-units" => Ok(CodegenUnits),
47+
"incremental" => Ok(Incremental),
4648
_ => Err(()),
4749
}
4850
}
@@ -62,6 +64,7 @@ impl fmt::Display for Mode {
6264
Codegen => "codegen",
6365
Rustdoc => "rustdoc",
6466
CodegenUnits => "codegen-units",
67+
Incremental => "incremental",
6568
}, f)
6669
}
6770
}

src/compiletest/compiletest.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ pub fn parse_config(args: Vec<String> ) -> Config {
7171
reqopt("", "aux-base", "directory to find auxiliary test files", "PATH"),
7272
reqopt("", "stage-id", "the target-stage identifier", "stageN-TARGET"),
7373
reqopt("", "mode", "which sort of compile tests to run",
74-
"(compile-fail|parse-fail|run-fail|run-pass|run-pass-valgrind|pretty|debug-info)"),
74+
"(compile-fail|parse-fail|run-fail|run-pass|\
75+
run-pass-valgrind|pretty|debug-info|incremental)"),
7576
optflag("", "ignored", "run tests marked as ignored"),
7677
optopt("", "runtool", "supervisor program to run tests under \
7778
(eg. emulator, valgrind)", "PROGRAM"),

src/compiletest/runtest.rs

+66
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use common::Config;
1212
use common::{CompileFail, ParseFail, Pretty, RunFail, RunPass, RunPassValgrind};
1313
use common::{Codegen, DebugInfoLldb, DebugInfoGdb, Rustdoc, CodegenUnits};
14+
use common::{Incremental};
1415
use errors::{self, ErrorKind};
1516
use header::TestProps;
1617
use header;
@@ -59,6 +60,7 @@ pub fn run(config: Config, testpaths: &TestPaths) {
5960
Codegen => run_codegen_test(&config, &props, &testpaths),
6061
Rustdoc => run_rustdoc_test(&config, &props, &testpaths),
6162
CodegenUnits => run_codegen_units_test(&config, &props, &testpaths),
63+
Incremental => run_incremental_test(&config, &props, &testpaths),
6264
}
6365
}
6466

@@ -1966,3 +1968,67 @@ fn run_codegen_units_test(config: &Config, props: &TestProps, testpaths: &TestPa
19661968
panic!();
19671969
}
19681970
}
1971+
1972+
fn run_incremental_test(config: &Config, props: &TestProps, testpaths: &TestPaths) {
1973+
// Basic plan for a test incremental/foo/bar.rs:
1974+
// - load list of revisions pass1, fail2, pass3
1975+
// - each should begin with `rpass`, `rfail`, or `cfail`
1976+
// - if `rpass`, expect compile and execution to succeed
1977+
// - if `cfail`, expect compilation to fail
1978+
// - if `rfail`, expect execution to fail
1979+
// - create a directory build/foo/bar.incremental
1980+
// - compile foo/bar.rs with -Z incremental=.../foo/bar.incremental and -C pass1
1981+
// - because name of revision starts with "pass", expect success
1982+
// - compile foo/bar.rs with -Z incremental=.../foo/bar.incremental and -C fail2
1983+
// - because name of revision starts with "fail", expect an error
1984+
// - load expected errors as usual, but filter for those that end in `[fail2]`
1985+
// - compile foo/bar.rs with -Z incremental=.../foo/bar.incremental and -C pass3
1986+
// - because name of revision starts with "pass", expect success
1987+
// - execute build/foo/bar.exe and save output
1988+
//
1989+
// FIXME -- use non-incremental mode as an oracle? That doesn't apply
1990+
// to #[rustc_dirty] and clean tests I guess
1991+
1992+
assert!(!props.revisions.is_empty(), "incremental tests require a list of revisions");
1993+
1994+
let output_base_name = output_base_name(config, testpaths);
1995+
1996+
// Create the incremental workproduct directory.
1997+
let incremental_dir = output_base_name.with_extension("incremental");
1998+
if incremental_dir.exists() {
1999+
fs::remove_dir_all(&incremental_dir).unwrap();
2000+
}
2001+
fs::create_dir_all(&incremental_dir).unwrap();
2002+
2003+
if config.verbose {
2004+
print!("incremental_dir={}", incremental_dir.display());
2005+
}
2006+
2007+
for revision in &props.revisions {
2008+
let mut revision_props = props.clone();
2009+
header::load_props_into(&mut revision_props, &testpaths.file, Some(&revision));
2010+
2011+
revision_props.compile_flags.extend(vec![
2012+
format!("-Z"),
2013+
format!("incremental={}", incremental_dir.display()),
2014+
format!("--cfg"),
2015+
format!("{}", revision),
2016+
]);
2017+
2018+
if config.verbose {
2019+
print!("revision={:?} revision_props={:#?}", revision, revision_props);
2020+
}
2021+
2022+
if revision.starts_with("rpass") {
2023+
run_rpass_test_revision(config, &revision_props, testpaths, Some(&revision));
2024+
} else if revision.starts_with("rfail") {
2025+
run_rfail_test_revision(config, &revision_props, testpaths, Some(&revision));
2026+
} else if revision.starts_with("cfail") {
2027+
run_cfail_test_revision(config, &revision_props, testpaths, Some(&revision));
2028+
} else {
2029+
fatal(
2030+
Some(revision),
2031+
"revision name must begin with rpass, rfail, or cfail");
2032+
}
2033+
}
2034+
}

0 commit comments

Comments
 (0)