]> git.lizzy.rs Git - rust.git/commitdiff
Convert SerializedDepGraph to be a struct-of-arrays
authorWesley Wiser <wwiser@gmail.com>
Thu, 15 Mar 2018 22:56:20 +0000 (18:56 -0400)
committerWesley Wiser <wwiser@gmail.com>
Mon, 19 Mar 2018 23:45:35 +0000 (19:45 -0400)
Fixes #47326

src/librustc/dep_graph/graph.rs
src/librustc/dep_graph/prev.rs
src/librustc/dep_graph/serialized.rs
src/librustc_data_structures/indexed_vec.rs
src/librustc_incremental/persist/save.rs

index 0ad79eacd2b03f9a04981bf5d2a4e9db918b7089..d60c22064d3a0cd0ee3900a1dec51d175e28ea58 100644 (file)
@@ -476,10 +476,8 @@ pub fn serialize(&self) -> SerializedDepGraph {
             fingerprints.resize(current_dep_graph.nodes.len(), Fingerprint::ZERO);
         }
 
-        let nodes: IndexVec<_, (DepNode, Fingerprint)> =
-            current_dep_graph.nodes.iter_enumerated().map(|(idx, &dep_node)| {
-            (dep_node, fingerprints[idx])
-        }).collect();
+        let fingerprints = fingerprints.clone().convert_index_type();
+        let nodes = current_dep_graph.nodes.clone().convert_index_type();
 
         let total_edge_count: usize = current_dep_graph.edges.iter()
                                                              .map(|v| v.len())
@@ -503,6 +501,7 @@ pub fn serialize(&self) -> SerializedDepGraph {
 
         SerializedDepGraph {
             nodes,
+            fingerprints,
             edge_list_indices,
             edge_list_data,
         }
index 504b60e763e23543fc9e5663acbe5bbf6a842429..669a99019aa60176de63f093266766a75d8638a4 100644 (file)
@@ -23,7 +23,7 @@ impl PreviousDepGraph {
     pub fn new(data: SerializedDepGraph) -> PreviousDepGraph {
         let index: FxHashMap<_, _> = data.nodes
             .iter_enumerated()
-            .map(|(idx, &(dep_node, _))| (dep_node, idx))
+            .map(|(idx, &dep_node)| (dep_node, idx))
             .collect();
         PreviousDepGraph { data, index }
     }
@@ -41,7 +41,7 @@ pub fn edges_from(&self,
 
     #[inline]
     pub fn index_to_node(&self, dep_node_index: SerializedDepNodeIndex) -> DepNode {
-        self.data.nodes[dep_node_index].0
+        self.data.nodes[dep_node_index]
     }
 
     #[inline]
@@ -58,14 +58,14 @@ pub fn node_to_index_opt(&self, dep_node: &DepNode) -> Option<SerializedDepNodeI
     pub fn fingerprint_of(&self, dep_node: &DepNode) -> Option<Fingerprint> {
         self.index
             .get(dep_node)
-            .map(|&node_index| self.data.nodes[node_index].1)
+            .map(|&node_index| self.data.fingerprints[node_index])
     }
 
     #[inline]
     pub fn fingerprint_by_index(&self,
                                 dep_node_index: SerializedDepNodeIndex)
                                 -> Fingerprint {
-        self.data.nodes[dep_node_index].1
+        self.data.fingerprints[dep_node_index]
     }
 
     pub fn node_count(&self) -> usize {
index c96040ab9b6e3eab996aafdb875c90fc6d3217a4..60fc813a25d51eda38da1293b1a8943a89c35225 100644 (file)
 #[derive(Debug, RustcEncodable, RustcDecodable)]
 pub struct SerializedDepGraph {
     /// The set of all DepNodes in the graph
-    pub nodes: IndexVec<SerializedDepNodeIndex, (DepNode, Fingerprint)>,
+    pub nodes: IndexVec<SerializedDepNodeIndex, DepNode>,
+    /// 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>,
     /// 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.
@@ -35,6 +38,7 @@ impl SerializedDepGraph {
     pub fn new() -> SerializedDepGraph {
         SerializedDepGraph {
             nodes: IndexVec::new(),
+            fingerprints: IndexVec::new(),
             edge_list_indices: IndexVec::new(),
             edge_list_data: Vec::new(),
         }
index a5b1a7e57ab4668167dc893fb2bbf003396138d2..cbb3ff5171592be599cc292b6e07b477c627a949 100644 (file)
@@ -503,6 +503,13 @@ pub fn pick2_mut(&mut self, a: I, b: I) -> (&mut T, &mut T) {
             (c1, c2)
         }
     }
+
+    pub fn convert_index_type<Ix: Idx>(self) -> IndexVec<Ix, T> {
+        IndexVec {
+            raw: self.raw,
+            _marker: PhantomData,
+        }
+    }
 }
 
 impl<I: Idx, T: Clone> IndexVec<I, T> {
index ca1e3563089dbdfe226f2621604255d097d8b137..a5bc1106ba0b00fc24264b5378cd5711274e69ea 100644 (file)
@@ -162,7 +162,7 @@ struct Stat {
 
         let mut counts: FxHashMap<_, Stat> = FxHashMap();
 
-        for (i, &(node, _)) in serialized_graph.nodes.iter_enumerated() {
+        for (i, &node) in serialized_graph.nodes.iter_enumerated() {
             let stat = counts.entry(node.kind).or_insert(Stat {
                 kind: node.kind,
                 node_counter: 0,