]> git.lizzy.rs Git - rust.git/blob - src/librustc_query_system/dep_graph/serialized.rs
Rollup merge of #75485 - RalfJung:pin, r=nagisa
[rust.git] / src / librustc_query_system / dep_graph / serialized.rs
1 //! The data that we will serialize and deserialize.
2
3 use super::{DepKind, DepNode};
4 use rustc_data_structures::fingerprint::Fingerprint;
5 use rustc_index::vec::IndexVec;
6
7 rustc_index::newtype_index! {
8     pub struct SerializedDepNodeIndex { .. }
9 }
10
11 /// Data for use when recompiling the **current crate**.
12 #[derive(Debug, Encodable, Decodable)]
13 pub struct SerializedDepGraph<K: DepKind> {
14     /// The set of all DepNodes in the graph
15     pub nodes: IndexVec<SerializedDepNodeIndex, DepNode<K>>,
16     /// The set of all Fingerprints in the graph. Each Fingerprint corresponds to
17     /// the DepNode at the same index in the nodes vector.
18     pub fingerprints: IndexVec<SerializedDepNodeIndex, Fingerprint>,
19     /// For each DepNode, stores the list of edges originating from that
20     /// DepNode. Encoded as a [start, end) pair indexing into edge_list_data,
21     /// which holds the actual DepNodeIndices of the target nodes.
22     pub edge_list_indices: IndexVec<SerializedDepNodeIndex, (u32, u32)>,
23     /// A flattened list of all edge targets in the graph. Edge sources are
24     /// implicit in edge_list_indices.
25     pub edge_list_data: Vec<SerializedDepNodeIndex>,
26 }
27
28 impl<K: DepKind> Default for SerializedDepGraph<K> {
29     fn default() -> Self {
30         SerializedDepGraph {
31             nodes: Default::default(),
32             fingerprints: Default::default(),
33             edge_list_indices: Default::default(),
34             edge_list_data: Default::default(),
35         }
36     }
37 }
38
39 impl<K: DepKind> SerializedDepGraph<K> {
40     #[inline]
41     pub fn edge_targets_from(&self, source: SerializedDepNodeIndex) -> &[SerializedDepNodeIndex] {
42         let targets = self.edge_list_indices[source];
43         &self.edge_list_data[targets.0 as usize..targets.1 as usize]
44     }
45 }