Skip to content

Commit a40b6ae

Browse files
Save dep-tracking hash of commandline arguments in dep-graph file.
.. and use it to purge the incremental compilation cache if necessary.
1 parent cf93818 commit a40b6ae

File tree

4 files changed

+55
-2
lines changed

4 files changed

+55
-2
lines changed

src/librustc_incremental/persist/directory.rs

+4
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ impl<'a,'tcx> DefIdDirectoryBuilder<'a,'tcx> {
158158
}
159159
}
160160

161+
pub fn tcx(&self) -> TyCtxt<'a, 'tcx, 'tcx> {
162+
self.tcx
163+
}
164+
161165
pub fn add(&mut self, def_id: DefId) -> DefPathIndex {
162166
debug!("DefIdDirectoryBuilder: def_id={:?}", def_id);
163167
let tcx = self.tcx;

src/librustc_incremental/persist/load.rs

+17-2
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,25 @@ pub fn decode_dep_graph<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
102102
work_products_data: &[u8])
103103
-> Result<(), Error>
104104
{
105+
// Decode the list of work_products
106+
let mut work_product_decoder = Decoder::new(work_products_data, 0);
107+
let work_products = try!(<Vec<SerializedWorkProduct>>::decode(&mut work_product_decoder));
108+
105109
// Deserialize the directory and dep-graph.
106110
let mut dep_graph_decoder = Decoder::new(dep_graph_data, 0);
111+
let prev_commandline_args_hash = try!(u64::decode(&mut dep_graph_decoder));
112+
113+
if prev_commandline_args_hash != tcx.sess.opts.dep_tracking_hash() {
114+
// We can't reuse the cache, purge it.
115+
debug!("decode_dep_graph: differing commandline arg hashes");
116+
for swp in work_products {
117+
delete_dirty_work_product(tcx, swp);
118+
}
119+
120+
// No need to do any further work
121+
return Ok(());
122+
}
123+
107124
let directory = try!(DefIdDirectory::decode(&mut dep_graph_decoder));
108125
let serialized_dep_graph = try!(SerializedDepGraph::decode(&mut dep_graph_decoder));
109126

@@ -180,8 +197,6 @@ pub fn decode_dep_graph<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
180197

181198
// Add in work-products that are still clean, and delete those that are
182199
// dirty.
183-
let mut work_product_decoder = Decoder::new(work_products_data, 0);
184-
let work_products = try!(<Vec<SerializedWorkProduct>>::decode(&mut work_product_decoder));
185200
reconcile_work_products(tcx, work_products, &dirty_target_nodes);
186201

187202
Ok(())

src/librustc_incremental/persist/save.rs

+4
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ pub fn encode_dep_graph(preds: &Predecessors,
105105
builder: &mut DefIdDirectoryBuilder,
106106
encoder: &mut Encoder)
107107
-> io::Result<()> {
108+
// First encode the commandline arguments hash
109+
let tcx = builder.tcx();
110+
try!(tcx.sess.opts.dep_tracking_hash().encode(encoder));
111+
108112
// Create a flat list of (Input, WorkProduct) edges for
109113
// serialization.
110114
let mut edges = vec![];
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Test that changing a tracked commandline argument invalidates
12+
// the cache while changing an untracked one doesn't.
13+
14+
// revisions:rpass1 rpass2 rpass3
15+
16+
#![feature(rustc_attrs)]
17+
18+
#![rustc_partition_translated(module="commandline_args", cfg="rpass2")]
19+
#![rustc_partition_reused(module="commandline_args", cfg="rpass3")]
20+
21+
// Between revisions 1 and 2, we are changing the debuginfo-level, which should
22+
// invalidate the cache. Between revisions 2 and 3, we are adding `--verbose`
23+
// which should have no effect on the cache:
24+
//[rpass1] compile-flags: -C debuginfo=0
25+
//[rpass2] compile-flags: -C debuginfo=2
26+
//[rpass3] compile-flags: -C debuginfo=2 --verbose
27+
28+
pub fn main() {
29+
println!("hello world");
30+
}

0 commit comments

Comments
 (0)