1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
use rustc::dep_graph::{DepGraphQuery, DepNode};
use rustc::hir::def_id::DefId;
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::graph::{Graph, NodeIndex};
use super::hash::*;
use ich::Fingerprint;
mod compress;
pub struct Predecessors<'query> {
pub reduced_graph: Graph<&'query DepNode<DefId>, ()>,
pub bootstrap_outputs: Vec<&'query DepNode<DefId>>,
pub hashes: FxHashMap<&'query DepNode<DefId>, Fingerprint>,
}
impl<'q> Predecessors<'q> {
pub fn new(query: &'q DepGraphQuery<DefId>, hcx: &mut HashContext) -> Self {
let tcx = hcx.tcx;
let collect_for_metadata = tcx.sess.opts.debugging_opts.incremental_cc ||
tcx.sess.opts.debugging_opts.query_dep_graph;
let is_output = |node: &DepNode<DefId>| -> bool {
match *node {
DepNode::WorkProduct(_) => true,
DepNode::MetaData(ref def_id) => collect_for_metadata && def_id.is_local(),
DepNode::TypeckTables(_) |
DepNode::TransCrateItem(_) => tcx.sess.opts.debugging_opts.query_dep_graph,
_ => false,
}
};
let compress::Reduction { graph, input_nodes } =
compress::reduce_graph(&query.graph, HashContext::is_hashable, |n| is_output(n));
let mut hashes = FxHashMap();
for input_index in input_nodes {
let input = *graph.node_data(input_index);
debug!("computing hash for input node `{:?}`", input);
hashes.entry(input)
.or_insert_with(|| hcx.hash(input).unwrap());
}
let bootstrap_outputs: Vec<&'q DepNode<DefId>> =
(0 .. graph.len_nodes())
.map(NodeIndex)
.filter(|&n| graph.incoming_edges(n).next().is_none())
.map(|n| *graph.node_data(n))
.filter(|n| is_output(n))
.collect();
Predecessors {
reduced_graph: graph,
bootstrap_outputs: bootstrap_outputs,
hashes: hashes,
}
}
}