Skip to content

Commit fece9c7

Browse files
committed
Auto merge of #39281 - michaelwoerister:make-cc-incr-comp-opt-in, r=nikomatsakis
incr.comp.: Make cross-crate tracking for incr. comp. opt-in. The current implementation of cross-crate dependency tracking can cause quite long compile times and high memory usage for some crates (see #39208 for example). This PR therefore makes that part of dependency tracking optional. Incremental compilation still works, it will only have very coarse dep-tracking for upstream crates. r? @nikomatsakis
2 parents 025fb7d + 197f037 commit fece9c7

File tree

11 files changed

+38
-13
lines changed
  • src
    • librustc/session
    • librustc_incremental/persist
    • test/incremental
      • add_private_fn_at_krate_root_cc/auxiliary
      • callee_caller_cross_crate/auxiliary
      • change_private_fn_cc/auxiliary
      • change_private_impl_method_cc/auxiliary
      • remove-private-item-cross-crate/auxiliary
      • rlib_cross_crate/auxiliary
      • struct_change_field_type_cross_crate/auxiliary
      • type_alias_cross_crate/auxiliary

11 files changed

+38
-13
lines changed

src/librustc/session/config.rs

+2
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
899899
"attempt to recover from parse errors (experimental)"),
900900
incremental: Option<String> = (None, parse_opt_string, [UNTRACKED],
901901
"enable incremental compilation (experimental)"),
902+
incremental_cc: bool = (false, parse_bool, [UNTRACKED],
903+
"enable cross-crate incremental compilation (even more experimental)"),
902904
incremental_info: bool = (false, parse_bool, [UNTRACKED],
903905
"print high-level information about incremental reuse (or the lack thereof)"),
904906
incremental_dump_hash: bool = (false, parse_bool, [UNTRACKED],

src/librustc_incremental/persist/preds.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,12 @@ pub struct Predecessors<'query> {
3333

3434
impl<'q> Predecessors<'q> {
3535
pub fn new(query: &'q DepGraphQuery<DefId>, hcx: &mut HashContext) -> Self {
36-
// Find nodes for which we want to know the full set of preds
3736
let tcx = hcx.tcx;
37+
38+
let collect_for_metadata = tcx.sess.opts.debugging_opts.incremental_cc ||
39+
tcx.sess.opts.debugging_opts.query_dep_graph;
40+
41+
// Find nodes for which we want to know the full set of preds
3842
let node_count = query.graph.len_nodes();
3943

4044
// Set up some data structures the cache predecessor search needs:
@@ -52,7 +56,7 @@ impl<'q> Predecessors<'q> {
5256
.enumerate()
5357
.filter(|&(_, node)| match node.data {
5458
DepNode::WorkProduct(_) => true,
55-
DepNode::MetaData(ref def_id) => def_id.is_local(),
59+
DepNode::MetaData(ref def_id) => collect_for_metadata && def_id.is_local(),
5660

5761
// if -Z query-dep-graph is passed, save more extended data
5862
// to enable better unit testing

src/librustc_incremental/persist/save.rs

+15-11
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,21 @@ pub fn save_dep_graph<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
5555
let preds = Predecessors::new(&query, &mut hcx);
5656
let mut current_metadata_hashes = FxHashMap();
5757

58-
// IMPORTANT: We are saving the metadata hashes *before* the dep-graph,
59-
// since metadata-encoding might add new entries to the
60-
// DefIdDirectory (which is saved in the dep-graph file).
61-
save_in(sess,
62-
metadata_hash_export_path(sess),
63-
|e| encode_metadata_hashes(tcx,
64-
svh,
65-
&preds,
66-
&mut builder,
67-
&mut current_metadata_hashes,
68-
e));
58+
if sess.opts.debugging_opts.incremental_cc ||
59+
sess.opts.debugging_opts.query_dep_graph {
60+
// IMPORTANT: We are saving the metadata hashes *before* the dep-graph,
61+
// since metadata-encoding might add new entries to the
62+
// DefIdDirectory (which is saved in the dep-graph file).
63+
save_in(sess,
64+
metadata_hash_export_path(sess),
65+
|e| encode_metadata_hashes(tcx,
66+
svh,
67+
&preds,
68+
&mut builder,
69+
&mut current_metadata_hashes,
70+
e));
71+
}
72+
6973
save_in(sess,
7074
dep_graph_path(sess),
7175
|e| encode_dep_graph(&preds, &mut builder, e));

src/test/incremental/add_private_fn_at_krate_root_cc/auxiliary/point.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// compile-flags: -Z incremental-cc
12+
1113
pub struct Point {
1214
pub x: f32,
1315
pub y: f32,

src/test/incremental/callee_caller_cross_crate/auxiliary/a.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// compile-flags: -Z incremental-cc
12+
1113
#![crate_type="rlib"]
1214

1315
#[cfg(rpass1)]

src/test/incremental/change_private_fn_cc/auxiliary/point.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// compile-flags: -Z incremental-cc
12+
1113
pub struct Point {
1214
pub x: f32,
1315
pub y: f32,

src/test/incremental/change_private_impl_method_cc/auxiliary/point.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// compile-flags: -Z incremental-cc
12+
1113
pub struct Point {
1214
pub x: f32,
1315
pub y: f32,

src/test/incremental/remove-private-item-cross-crate/auxiliary/a.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// compile-flags: -Z incremental-cc
12+
1113
#![allow(warnings)]
1214
#![crate_name = "a"]
1315
#![crate_type = "rlib"]

src/test/incremental/rlib_cross_crate/auxiliary/a.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// compile-flags: -Z incremental-cc
1112
// no-prefer-dynamic
1213

1314
#![crate_type="rlib"]

src/test/incremental/struct_change_field_type_cross_crate/auxiliary/a.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// compile-flags: -Z incremental-cc
12+
1113
#![crate_type="rlib"]
1214

1315
#[cfg(rpass1)]

src/test/incremental/type_alias_cross_crate/auxiliary/a.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// compile-flags: -Z incremental-cc
12+
1113
#![crate_type="rlib"]
1214

1315
#[cfg(rpass1)]

0 commit comments

Comments
 (0)