2017-09-22 13:00:42 +02:00
|
|
|
use super::serialized::{SerializedDepGraph, SerializedDepNodeIndex};
|
2020-03-18 10:25:22 +01:00
|
|
|
use super::{DepKind, DepNode};
|
|
|
|
use rustc_data_structures::fingerprint::Fingerprint;
|
2019-12-22 17:42:04 -05:00
|
|
|
use rustc_data_structures::fx::FxHashMap;
|
2017-09-22 13:00:42 +02:00
|
|
|
|
2020-06-11 15:49:57 +01:00
|
|
|
#[derive(Debug, Encodable, Decodable)]
|
2020-03-18 10:25:22 +01:00
|
|
|
pub struct PreviousDepGraph<K: DepKind> {
|
|
|
|
data: SerializedDepGraph<K>,
|
|
|
|
index: FxHashMap<DepNode<K>, SerializedDepNodeIndex>,
|
2017-09-22 13:00:42 +02:00
|
|
|
}
|
|
|
|
|
2020-03-18 10:25:22 +01:00
|
|
|
impl<K: DepKind> Default for PreviousDepGraph<K> {
|
|
|
|
fn default() -> Self {
|
|
|
|
PreviousDepGraph { data: Default::default(), index: Default::default() }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<K: DepKind> PreviousDepGraph<K> {
|
|
|
|
pub fn new(data: SerializedDepGraph<K>) -> PreviousDepGraph<K> {
|
2019-12-22 17:42:04 -05:00
|
|
|
let index: FxHashMap<_, _> =
|
|
|
|
data.nodes.iter_enumerated().map(|(idx, &dep_node)| (dep_node, idx)).collect();
|
2017-09-22 13:00:42 +02:00
|
|
|
PreviousDepGraph { data, index }
|
|
|
|
}
|
|
|
|
|
2017-09-25 13:51:49 +02:00
|
|
|
#[inline]
|
2018-12-22 18:03:40 +01:00
|
|
|
pub fn edge_targets_from(
|
|
|
|
&self,
|
2019-12-22 17:42:04 -05:00
|
|
|
dep_node_index: SerializedDepNodeIndex,
|
2018-12-22 18:03:40 +01:00
|
|
|
) -> &[SerializedDepNodeIndex] {
|
|
|
|
self.data.edge_targets_from(dep_node_index)
|
2017-09-25 13:51:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2020-12-18 16:00:52 -08:00
|
|
|
pub fn index_to_node(&self, dep_node_index: SerializedDepNodeIndex) -> DepNode<K> {
|
2018-03-15 18:56:20 -04:00
|
|
|
self.data.nodes[dep_node_index]
|
2017-09-22 13:00:42 +02:00
|
|
|
}
|
|
|
|
|
2017-11-14 19:52:49 +01:00
|
|
|
#[inline]
|
2020-03-18 10:25:22 +01:00
|
|
|
pub fn node_to_index(&self, dep_node: &DepNode<K>) -> SerializedDepNodeIndex {
|
2017-11-14 19:52:49 +01:00
|
|
|
self.index[dep_node]
|
|
|
|
}
|
|
|
|
|
2018-02-13 17:40:46 +01:00
|
|
|
#[inline]
|
2020-03-18 10:25:22 +01:00
|
|
|
pub fn node_to_index_opt(&self, dep_node: &DepNode<K>) -> Option<SerializedDepNodeIndex> {
|
2018-02-13 17:40:46 +01:00
|
|
|
self.index.get(dep_node).cloned()
|
|
|
|
}
|
|
|
|
|
2017-09-25 13:51:49 +02:00
|
|
|
#[inline]
|
2020-03-18 10:25:22 +01:00
|
|
|
pub fn fingerprint_of(&self, dep_node: &DepNode<K>) -> Option<Fingerprint> {
|
2019-12-22 17:42:04 -05:00
|
|
|
self.index.get(dep_node).map(|&node_index| self.data.fingerprints[node_index])
|
2017-09-22 13:00:42 +02:00
|
|
|
}
|
2017-09-25 13:51:49 +02:00
|
|
|
|
|
|
|
#[inline]
|
2019-12-22 17:42:04 -05:00
|
|
|
pub fn fingerprint_by_index(&self, dep_node_index: SerializedDepNodeIndex) -> Fingerprint {
|
2018-03-15 18:56:20 -04:00
|
|
|
self.data.fingerprints[dep_node_index]
|
2017-09-25 13:51:49 +02:00
|
|
|
}
|
2017-12-19 18:01:19 +01:00
|
|
|
|
|
|
|
pub fn node_count(&self) -> usize {
|
|
|
|
self.index.len()
|
|
|
|
}
|
2017-09-22 13:00:42 +02:00
|
|
|
}
|