Skip to content

Commit 14039a4

Browse files
committed
Auto merge of #44696 - michaelwoerister:fingerprints-in-dep-graph-3, r=nikomatsakis
incr.comp.: Move task result fingerprinting into DepGraph. This PR - makes the DepGraph store all `Fingerprints` of task results, - allows `DepNode` to be marked as input nodes, - makes HIR node hashing use the regular fingerprinting infrastructure, - removes the now unused `IncrementalHashesMap`, and - makes sure that `traits_in_scope_map` fingerprints are stable. r? @nikomatsakis cc @alexcrichton
2 parents 3eb19bf + 9798a88 commit 14039a4

File tree

26 files changed

+417
-515
lines changed

26 files changed

+417
-515
lines changed

src/librustc/dep_graph/dep_node.rs

+50-19
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,28 @@ macro_rules! erase {
8080
($x:tt) => ({})
8181
}
8282

83-
macro_rules! anon_attr_to_bool {
84-
(anon) => (true)
83+
macro_rules! is_anon_attr {
84+
(anon) => (true);
85+
($attr:ident) => (false);
86+
}
87+
88+
macro_rules! is_input_attr {
89+
(input) => (true);
90+
($attr:ident) => (false);
91+
}
92+
93+
macro_rules! contains_anon_attr {
94+
($($attr:ident),*) => ({$(is_anon_attr!($attr) | )* false});
95+
}
96+
97+
macro_rules! contains_input_attr {
98+
($($attr:ident),*) => ({$(is_input_attr!($attr) | )* false});
8599
}
86100

87101
macro_rules! define_dep_nodes {
88102
(<$tcx:tt>
89103
$(
90-
[$($anon:ident)*]
104+
[$($attr:ident),* ]
91105
$variant:ident $(( $($tuple_arg:tt),* ))*
92106
$({ $($struct_arg_name:ident : $struct_arg_ty:ty),* })*
93107
,)*
@@ -105,7 +119,9 @@ macro_rules! define_dep_nodes {
105119
match *self {
106120
$(
107121
DepKind :: $variant => {
108-
$(return !anon_attr_to_bool!($anon);)*
122+
if contains_anon_attr!($($attr),*) {
123+
return false;
124+
}
109125

110126
// tuple args
111127
$({
@@ -126,15 +142,20 @@ macro_rules! define_dep_nodes {
126142
}
127143
}
128144

129-
#[allow(unreachable_code)]
130145
#[inline]
131-
pub fn is_anon<$tcx>(&self) -> bool {
146+
pub fn is_anon(&self) -> bool {
132147
match *self {
133148
$(
134-
DepKind :: $variant => {
135-
$(return anon_attr_to_bool!($anon);)*
136-
false
137-
}
149+
DepKind :: $variant => { contains_anon_attr!($($attr),*) }
150+
)*
151+
}
152+
}
153+
154+
#[inline]
155+
pub fn is_input(&self) -> bool {
156+
match *self {
157+
$(
158+
DepKind :: $variant => { contains_input_attr!($($attr),*) }
138159
)*
139160
}
140161
}
@@ -366,6 +387,17 @@ impl DefId {
366387
}
367388
}
368389

390+
impl DepKind {
391+
#[inline]
392+
pub fn fingerprint_needed_for_crate_hash(self) -> bool {
393+
match self {
394+
DepKind::HirBody |
395+
DepKind::Krate => true,
396+
_ => false,
397+
}
398+
}
399+
}
400+
369401
define_dep_nodes!( <'tcx>
370402
// Represents the `Krate` as a whole (the `hir::Krate` value) (as
371403
// distinct from the krate module). This is basically a hash of
@@ -378,18 +410,17 @@ define_dep_nodes!( <'tcx>
378410
// suitable wrapper, you can use `tcx.dep_graph.ignore()` to gain
379411
// access to the krate, but you must remember to add suitable
380412
// edges yourself for the individual items that you read.
381-
[] Krate,
382-
383-
// Represents the HIR node with the given node-id
384-
[] Hir(DefId),
413+
[input] Krate,
385414

386415
// Represents the body of a function or method. The def-id is that of the
387416
// function/method.
388-
[] HirBody(DefId),
417+
[input] HirBody(DefId),
418+
419+
// Represents the HIR node with the given node-id
420+
[input] Hir(DefId),
389421

390-
// Represents the metadata for a given HIR node, typically found
391-
// in an extern crate.
392-
[] MetaData(DefId),
422+
// Represents metadata from an extern crate.
423+
[input] MetaData(DefId),
393424

394425
// Represents some artifact that we save to disk. Note that these
395426
// do not have a def-id as part of their identifier.
@@ -529,7 +560,7 @@ define_dep_nodes!( <'tcx>
529560
[] ExternCrate(DefId),
530561
[] LintLevels,
531562
[] Specializes { impl1: DefId, impl2: DefId },
532-
[] InScopeTraits(DefIndex),
563+
[input] InScopeTraits(DefIndex),
533564
[] ModuleExports(DefId),
534565
[] IsSanitizerRuntime(CrateNum),
535566
[] IsProfilerRuntime(CrateNum),

src/librustc/dep_graph/edges.rs

+1
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ impl DepGraphEdges {
123123
reads
124124
} = popped_node {
125125
debug_assert_eq!(node, key);
126+
debug_assert!(!node.kind.is_input() || reads.is_empty());
126127

127128
let target_id = self.get_or_create_node(node);
128129

src/librustc/dep_graph/graph.rs

+34-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,16 @@ use super::edges::{DepGraphEdges, DepNodeIndex};
2626

2727
#[derive(Clone)]
2828
pub struct DepGraph {
29-
data: Option<Rc<DepGraphData>>
29+
data: Option<Rc<DepGraphData>>,
30+
31+
// At the moment we are using DepNode as key here. In the future it might
32+
// be possible to use an IndexVec<DepNodeIndex, _> here. At the moment there
33+
// are a few problems with that:
34+
// - Some fingerprints are needed even if incr. comp. is disabled -- yet
35+
// we need to have a dep-graph to generate DepNodeIndices.
36+
// - The architecture is still in flux and it's not clear what how to best
37+
// implement things.
38+
fingerprints: Rc<RefCell<FxHashMap<DepNode, Fingerprint>>>
3039
}
3140

3241
struct DepGraphData {
@@ -57,7 +66,8 @@ impl DepGraph {
5766
}))
5867
} else {
5968
None
60-
}
69+
},
70+
fingerprints: Rc::new(RefCell::new(FxHashMap())),
6171
}
6272
}
6373

@@ -139,11 +149,27 @@ impl DepGraph {
139149

140150
let mut stable_hasher = StableHasher::new();
141151
result.hash_stable(&mut hcx, &mut stable_hasher);
142-
let _: Fingerprint = stable_hasher.finish();
152+
153+
assert!(self.fingerprints
154+
.borrow_mut()
155+
.insert(key, stable_hasher.finish())
156+
.is_none());
143157

144158
(result, dep_node_index)
145159
} else {
146-
(task(cx, arg), DepNodeIndex::INVALID)
160+
if key.kind.fingerprint_needed_for_crate_hash() {
161+
let mut hcx = cx.create_stable_hashing_context();
162+
let result = task(cx, arg);
163+
let mut stable_hasher = StableHasher::new();
164+
result.hash_stable(&mut hcx, &mut stable_hasher);
165+
assert!(self.fingerprints
166+
.borrow_mut()
167+
.insert(key, stable_hasher.finish())
168+
.is_none());
169+
(result, DepNodeIndex::INVALID)
170+
} else {
171+
(task(cx, arg), DepNodeIndex::INVALID)
172+
}
147173
}
148174
}
149175

@@ -195,6 +221,10 @@ impl DepGraph {
195221
}
196222
}
197223

224+
pub fn fingerprint_of(&self, dep_node: &DepNode) -> Option<Fingerprint> {
225+
self.fingerprints.borrow().get(dep_node).cloned()
226+
}
227+
198228
/// Indicates that a previous work product exists for `v`. This is
199229
/// invoked during initial start-up based on what nodes are clean
200230
/// (and what files exist in the incr. directory).

0 commit comments

Comments
 (0)