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.
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.
11 //! The data that we will serialize and deserialize.
13 use dep_graph::DepNode;
15 use rustc_data_structures::indexed_vec::{IndexVec, Idx};
17 newtype_index!(SerializedDepNodeIndex { derive[RustcEncodable, RustcDecodable] });
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>,
33 impl SerializedDepGraph {
35 pub fn new() -> SerializedDepGraph {
37 nodes: IndexVec::new(),
38 edge_list_indices: IndexVec::new(),
39 edge_list_data: Vec::new(),
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]