]> git.lizzy.rs Git - rust.git/blob - src/librustc/dep_graph/prev.rs
Rollup merge of #59697 - euclio:label-fixes, r=zackmdavis
[rust.git] / src / librustc / dep_graph / prev.rs
1 use crate::ich::Fingerprint;
2 use rustc_data_structures::fx::FxHashMap;
3 use super::dep_node::DepNode;
4 use super::serialized::{SerializedDepGraph, SerializedDepNodeIndex};
5
6 #[derive(Debug, RustcEncodable, RustcDecodable, Default)]
7 pub struct PreviousDepGraph {
8     data: SerializedDepGraph,
9     index: FxHashMap<DepNode, SerializedDepNodeIndex>,
10 }
11
12 impl PreviousDepGraph {
13     pub fn new(data: SerializedDepGraph) -> PreviousDepGraph {
14         let index: FxHashMap<_, _> = data.nodes
15             .iter_enumerated()
16             .map(|(idx, &dep_node)| (dep_node, idx))
17             .collect();
18         PreviousDepGraph { data, index }
19     }
20
21     #[inline]
22     pub fn edge_targets_from(
23         &self,
24         dep_node_index: SerializedDepNodeIndex
25     ) -> &[SerializedDepNodeIndex] {
26         self.data.edge_targets_from(dep_node_index)
27     }
28
29     #[inline]
30     pub fn index_to_node(&self, dep_node_index: SerializedDepNodeIndex) -> DepNode {
31         self.data.nodes[dep_node_index]
32     }
33
34     #[inline]
35     pub fn node_to_index(&self, dep_node: &DepNode) -> SerializedDepNodeIndex {
36         self.index[dep_node]
37     }
38
39     #[inline]
40     pub fn node_to_index_opt(&self, dep_node: &DepNode) -> Option<SerializedDepNodeIndex> {
41         self.index.get(dep_node).cloned()
42     }
43
44     #[inline]
45     pub fn fingerprint_of(&self, dep_node: &DepNode) -> Option<Fingerprint> {
46         self.index
47             .get(dep_node)
48             .map(|&node_index| self.data.fingerprints[node_index])
49     }
50
51     #[inline]
52     pub fn fingerprint_by_index(&self,
53                                 dep_node_index: SerializedDepNodeIndex)
54                                 -> Fingerprint {
55         self.data.fingerprints[dep_node_index]
56     }
57
58     pub fn node_count(&self) -> usize {
59         self.index.len()
60     }
61 }