Skip to content

Commit ea2d90e

Browse files
committed
consider DepNode::Krate to be an input
This seems not only more correct but allows us to write tests that check whether the krate hash as a whole is clean/dirty
1 parent c42e0a3 commit ea2d90e

File tree

6 files changed

+57
-5
lines changed

6 files changed

+57
-5
lines changed

src/librustc/dep_graph/dep_node.rs

+5
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,11 @@ impl<D: Clone + Debug> DepNode<D> {
147147
}
148148
}
149149

150+
if label == "Krate" {
151+
// special case
152+
return Ok(DepNode::Krate);
153+
}
154+
150155
check! {
151156
CollectItem,
152157
BorrowCheck,

src/librustc_incremental/persist/dirty_clean.rs

+2
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ impl<'a, 'tcx> DirtyCleanVisitor<'a, 'tcx> {
133133
debug!("assert_dirty({:?})", dep_node);
134134

135135
match dep_node {
136+
DepNode::Krate |
136137
DepNode::Hir(_) => {
137138
// HIR nodes are inputs, so if we are asserting that the HIR node is
138139
// dirty, we check the dirty input set.
@@ -161,6 +162,7 @@ impl<'a, 'tcx> DirtyCleanVisitor<'a, 'tcx> {
161162
debug!("assert_clean({:?})", dep_node);
162163

163164
match dep_node {
165+
DepNode::Krate |
164166
DepNode::Hir(_) => {
165167
// For HIR nodes, check the inputs.
166168
if self.dirty_inputs.contains(&dep_node) {

src/librustc_incremental/persist/hash.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,19 @@ impl<'a, 'tcx> HashContext<'a, 'tcx> {
4545

4646
pub fn is_hashable(dep_node: &DepNode<DefId>) -> bool {
4747
match *dep_node {
48+
DepNode::Krate |
4849
DepNode::Hir(_) => true,
4950
DepNode::MetaData(def_id) => !def_id.is_local(),
5051
_ => false,
5152
}
5253
}
5354

54-
pub fn hash(&mut self, dep_node: &DepNode<DefId>) -> Option<(DefId, u64)> {
55+
pub fn hash(&mut self, dep_node: &DepNode<DefId>) -> Option<u64> {
5556
match *dep_node {
57+
DepNode::Krate => {
58+
Some(self.incremental_hashes_map[dep_node])
59+
}
60+
5661
// HIR nodes (which always come from our crate) are an input:
5762
DepNode::Hir(def_id) => {
5863
assert!(def_id.is_local(),
@@ -65,15 +70,15 @@ impl<'a, 'tcx> HashContext<'a, 'tcx> {
6570
def_id,
6671
self.tcx.item_path_str(def_id));
6772

68-
Some((def_id, self.incremental_hashes_map[dep_node]))
73+
Some(self.incremental_hashes_map[dep_node])
6974
}
7075

7176
// MetaData from other crates is an *input* to us.
7277
// MetaData nodes from *our* crates are an *output*; we
7378
// don't hash them, but we do compute a hash for them and
7479
// save it for others to use.
7580
DepNode::MetaData(def_id) if !def_id.is_local() => {
76-
Some((def_id, self.metadata_hash(def_id)))
81+
Some(self.metadata_hash(def_id))
7782
}
7883

7984
_ => {

src/librustc_incremental/persist/load.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ fn dirty_nodes<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
222222

223223
for hash in serialized_hashes {
224224
if let Some(dep_node) = retraced.map(&hash.dep_node) {
225-
let (_, current_hash) = hcx.hash(&dep_node).unwrap();
225+
let current_hash = hcx.hash(&dep_node).unwrap();
226226
if current_hash == hash.hash {
227227
continue;
228228
}

src/librustc_incremental/persist/preds.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl<'q> Predecessors<'q> {
6262
let mut hashes = FnvHashMap();
6363
for input in inputs.values().flat_map(|v| v.iter().cloned()) {
6464
hashes.entry(input)
65-
.or_insert_with(|| hcx.hash(input).unwrap().1);
65+
.or_insert_with(|| hcx.hash(input).unwrap());
6666
}
6767

6868
Predecessors {
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright 2014 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 incremental compilation tracking where we change field names
12+
// in between revisions (hashing should be stable).
13+
14+
// revisions:rpass1 rpass2 rpass3
15+
// compile-flags: -Z query-dep-graph
16+
17+
#![feature(rustc_attrs)]
18+
19+
// Check that reordering otherwise identical items is not considered a
20+
// change at all.
21+
#[rustc_clean(label="Krate", cfg="rpass2")]
22+
23+
// But removing an item, naturally, is.
24+
#[rustc_dirty(label="Krate", cfg="rpass3")]
25+
26+
#[cfg(rpass1)]
27+
pub struct X {
28+
pub x: u32,
29+
}
30+
31+
pub struct Y {
32+
pub x: u32,
33+
}
34+
35+
#[cfg(rpass2)]
36+
pub struct X {
37+
pub x: u32,
38+
}
39+
40+
pub fn main() { }

0 commit comments

Comments
 (0)