Skip to content

Commit

Permalink
Auto merge of #39281 - michaelwoerister:make-cc-incr-comp-opt-in, r=n…
Browse files Browse the repository at this point in the history
…ikomatsakis

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
  • Loading branch information
bors committed Jan 27, 2017
2 parents 025fb7d + 197f037 commit fece9c7
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 13 deletions.
2 changes: 2 additions & 0 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
"attempt to recover from parse errors (experimental)"),
incremental: Option<String> = (None, parse_opt_string, [UNTRACKED],
"enable incremental compilation (experimental)"),
incremental_cc: bool = (false, parse_bool, [UNTRACKED],
"enable cross-crate incremental compilation (even more experimental)"),
incremental_info: bool = (false, parse_bool, [UNTRACKED],
"print high-level information about incremental reuse (or the lack thereof)"),
incremental_dump_hash: bool = (false, parse_bool, [UNTRACKED],
Expand Down
8 changes: 6 additions & 2 deletions src/librustc_incremental/persist/preds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@ pub struct Predecessors<'query> {

impl<'q> Predecessors<'q> {
pub fn new(query: &'q DepGraphQuery<DefId>, hcx: &mut HashContext) -> Self {
// Find nodes for which we want to know the full set of preds
let tcx = hcx.tcx;

let collect_for_metadata = tcx.sess.opts.debugging_opts.incremental_cc ||
tcx.sess.opts.debugging_opts.query_dep_graph;

// Find nodes for which we want to know the full set of preds
let node_count = query.graph.len_nodes();

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

// if -Z query-dep-graph is passed, save more extended data
// to enable better unit testing
Expand Down
26 changes: 15 additions & 11 deletions src/librustc_incremental/persist/save.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,21 @@ pub fn save_dep_graph<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
let preds = Predecessors::new(&query, &mut hcx);
let mut current_metadata_hashes = FxHashMap();

// IMPORTANT: We are saving the metadata hashes *before* the dep-graph,
// since metadata-encoding might add new entries to the
// DefIdDirectory (which is saved in the dep-graph file).
save_in(sess,
metadata_hash_export_path(sess),
|e| encode_metadata_hashes(tcx,
svh,
&preds,
&mut builder,
&mut current_metadata_hashes,
e));
if sess.opts.debugging_opts.incremental_cc ||
sess.opts.debugging_opts.query_dep_graph {
// IMPORTANT: We are saving the metadata hashes *before* the dep-graph,
// since metadata-encoding might add new entries to the
// DefIdDirectory (which is saved in the dep-graph file).
save_in(sess,
metadata_hash_export_path(sess),
|e| encode_metadata_hashes(tcx,
svh,
&preds,
&mut builder,
&mut current_metadata_hashes,
e));
}

save_in(sess,
dep_graph_path(sess),
|e| encode_dep_graph(&preds, &mut builder, e));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-flags: -Z incremental-cc

pub struct Point {
pub x: f32,
pub y: f32,
Expand Down
2 changes: 2 additions & 0 deletions src/test/incremental/callee_caller_cross_crate/auxiliary/a.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-flags: -Z incremental-cc

#![crate_type="rlib"]

#[cfg(rpass1)]
Expand Down
2 changes: 2 additions & 0 deletions src/test/incremental/change_private_fn_cc/auxiliary/point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-flags: -Z incremental-cc

pub struct Point {
pub x: f32,
pub y: f32,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-flags: -Z incremental-cc

pub struct Point {
pub x: f32,
pub y: f32,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-flags: -Z incremental-cc

#![allow(warnings)]
#![crate_name = "a"]
#![crate_type = "rlib"]
Expand Down
1 change: 1 addition & 0 deletions src/test/incremental/rlib_cross_crate/auxiliary/a.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-flags: -Z incremental-cc
// no-prefer-dynamic

#![crate_type="rlib"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-flags: -Z incremental-cc

#![crate_type="rlib"]

#[cfg(rpass1)]
Expand Down
2 changes: 2 additions & 0 deletions src/test/incremental/type_alias_cross_crate/auxiliary/a.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-flags: -Z incremental-cc

#![crate_type="rlib"]

#[cfg(rpass1)]
Expand Down

0 comments on commit fece9c7

Please sign in to comment.