]> git.lizzy.rs Git - rust.git/blob - src/librustc/dep_graph/serialized.rs
120af4821e36f3496b3f7c599f89044b56bb2254
[rust.git] / src / librustc / dep_graph / serialized.rs
1 // Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 //! The data that we will serialize and deserialize.
12
13 use dep_graph::DepNode;
14 use ich::Fingerprint;
15 use rustc_data_structures::indexed_vec::{IndexVec, Idx};
16
17 newtype_index!(SerializedDepNodeIndex { derive[RustcEncodable, RustcDecodable] });
18
19 /// Data for use when recompiling the **current crate**.
20 #[derive(Debug, RustcEncodable, RustcDecodable)]
21 pub struct SerializedDepGraph {
22     /// The set of all DepNodes in the graph
23     pub nodes: IndexVec<SerializedDepNodeIndex, (DepNode, Fingerprint)>,
24     /// For each DepNode, stores the list of edges originating from that
25     /// DepNode. Encoded as a [start, end) pair indexing into edge_list_data,
26     /// which holds the actual DepNodeIndices of the target nodes.
27     pub edge_list_indices: IndexVec<SerializedDepNodeIndex, (u32, u32)>,
28     /// A flattened list of all edge targets in the graph. Edge sources are
29     /// implicit in edge_list_indices.
30     pub edge_list_data: Vec<SerializedDepNodeIndex>,
31 }
32
33 impl SerializedDepGraph {
34
35     pub fn new() -> SerializedDepGraph {
36         SerializedDepGraph {
37             nodes: IndexVec::new(),
38             edge_list_indices: IndexVec::new(),
39             edge_list_data: Vec::new(),
40         }
41     }
42
43     #[inline]
44     pub fn edge_targets_from(&self,
45                              source: SerializedDepNodeIndex)
46                              -> &[SerializedDepNodeIndex] {
47         let targets = self.edge_list_indices[source];
48         &self.edge_list_data[targets.0 as usize..targets.1 as usize]
49     }
50 }