2017-09-22 13:00:42 +02:00
|
|
|
//! The data that we will serialize and deserialize.
|
|
|
|
|
2020-03-18 10:25:22 +01:00
|
|
|
use super::{DepKind, DepNode};
|
|
|
|
use rustc_data_structures::fingerprint::Fingerprint;
|
2020-01-05 15:01:00 +00:00
|
|
|
use rustc_index::vec::IndexVec;
|
2017-09-22 13:00:42 +02:00
|
|
|
|
2019-09-26 05:38:33 +00:00
|
|
|
rustc_index::newtype_index! {
|
2018-07-25 13:41:32 +03:00
|
|
|
pub struct SerializedDepNodeIndex { .. }
|
|
|
|
}
|
2017-09-22 13:00:42 +02:00
|
|
|
|
|
|
|
/// Data for use when recompiling the **current crate**.
|
2020-06-11 15:49:57 +01:00
|
|
|
#[derive(Debug, Encodable, Decodable)]
|
2020-03-18 10:25:22 +01:00
|
|
|
pub struct SerializedDepGraph<K: DepKind> {
|
2017-09-22 13:00:42 +02:00
|
|
|
/// The set of all DepNodes in the graph
|
2020-03-18 10:25:22 +01:00
|
|
|
pub nodes: IndexVec<SerializedDepNodeIndex, DepNode<K>>,
|
2018-03-15 18:56:20 -04:00
|
|
|
/// The set of all Fingerprints in the graph. Each Fingerprint corresponds to
|
|
|
|
/// the DepNode at the same index in the nodes vector.
|
|
|
|
pub fingerprints: IndexVec<SerializedDepNodeIndex, Fingerprint>,
|
2017-09-22 13:00:42 +02:00
|
|
|
/// For each DepNode, stores the list of edges originating from that
|
|
|
|
/// DepNode. Encoded as a [start, end) pair indexing into edge_list_data,
|
|
|
|
/// which holds the actual DepNodeIndices of the target nodes.
|
|
|
|
pub edge_list_indices: IndexVec<SerializedDepNodeIndex, (u32, u32)>,
|
|
|
|
/// A flattened list of all edge targets in the graph. Edge sources are
|
|
|
|
/// implicit in edge_list_indices.
|
|
|
|
pub edge_list_data: Vec<SerializedDepNodeIndex>,
|
|
|
|
}
|
|
|
|
|
2020-03-18 10:25:22 +01:00
|
|
|
impl<K: DepKind> Default for SerializedDepGraph<K> {
|
|
|
|
fn default() -> Self {
|
|
|
|
SerializedDepGraph {
|
|
|
|
nodes: Default::default(),
|
|
|
|
fingerprints: Default::default(),
|
|
|
|
edge_list_indices: Default::default(),
|
|
|
|
edge_list_data: Default::default(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<K: DepKind> SerializedDepGraph<K> {
|
2017-09-28 16:19:10 +02:00
|
|
|
#[inline]
|
2019-12-22 17:42:04 -05:00
|
|
|
pub fn edge_targets_from(&self, source: SerializedDepNodeIndex) -> &[SerializedDepNodeIndex] {
|
2017-09-22 13:00:42 +02:00
|
|
|
let targets = self.edge_list_indices[source];
|
|
|
|
&self.edge_list_data[targets.0 as usize..targets.1 as usize]
|
|
|
|
}
|
|
|
|
}
|