@@ -4,7 +4,7 @@ use super::query::DepGraphQuery;
44use super :: { DepKind , DepNode } ;
55use rustc_data_structures:: fingerprint:: Fingerprint ;
66use rustc_data_structures:: fx:: FxHashMap ;
7- use rustc_index:: vec:: { Idx , IndexVec } ;
7+ use rustc_index:: vec:: { Idx , IndexArray , IndexVec } ;
88use rustc_serialize:: { Decodable , Decoder , Encodable , Encoder } ;
99use std:: convert:: TryInto ;
1010use std:: ops:: Range ;
@@ -140,19 +140,17 @@ fn shrink_range(range: Range<usize>) -> Range<u32> {
140140}
141141
142142/// Data for use when recompiling the **previous crate**.
143- ///
144- /// Those IndexVec are never pushed to, so as to avoid large reallocations.
145143#[ derive( Debug ) ]
146144pub struct SerializedDepGraph < K : DepKind > {
147145 /// The set of all DepNodes in the graph
148- nodes : IndexVec < SerializedDepNodeIndex , DepNode < K > > ,
146+ nodes : IndexArray < SerializedDepNodeIndex , DepNode < K > > ,
149147 /// The set of all Fingerprints in the graph. Each Fingerprint corresponds to
150148 /// the DepNode at the same index in the nodes vector.
151- fingerprints : IndexVec < SerializedDepNodeIndex , Fingerprint > ,
149+ fingerprints : IndexArray < SerializedDepNodeIndex , Fingerprint > ,
152150 /// For each DepNode, stores the list of edges originating from that
153151 /// DepNode. Encoded as a [start, end) pair indexing into edge_list_data,
154152 /// which holds the actual DepNodeIndices of the target nodes.
155- edge_list_indices : IndexVec < SerializedDepNodeIndex , ColorAndOffset > ,
153+ edge_list_indices : IndexArray < SerializedDepNodeIndex , ColorAndOffset > ,
156154 /// A flattened list of all edge targets in the graph. Edge sources are
157155 /// implicit in edge_list_indices.
158156 edge_list_data : Vec < DepNodeIndex > ,
@@ -182,9 +180,9 @@ pub struct CurrentDepGraph<K: DepKind> {
182180impl < K : DepKind > Default for SerializedDepGraph < K > {
183181 fn default ( ) -> Self {
184182 Self {
185- nodes : IndexVec :: new ( ) ,
186- fingerprints : IndexVec :: new ( ) ,
187- edge_list_indices : IndexVec :: new ( ) ,
183+ nodes : IndexArray :: new ( ) ,
184+ fingerprints : IndexArray :: new ( ) ,
185+ edge_list_indices : IndexArray :: new ( ) ,
188186 edge_list_data : Vec :: new ( ) ,
189187 }
190188 }
@@ -606,20 +604,19 @@ fn edge_count_estimate(prev_graph_node_count: usize) -> usize {
606604impl < D : Decoder , K : DepKind + Decodable < D > > Decodable < D > for SerializedDepGraph < K > {
607605 fn decode ( d : & mut D ) -> Result < SerializedDepGraph < K > , D :: Error > {
608606 d. read_struct ( "SerializedDepGraph" , 4 , |d| {
609- let nodes: IndexVec < SerializedDepNodeIndex , DepNode < K > > =
610- d. read_struct_field ( "nodes" , 0 , |d| {
611- d. read_seq ( |d, len| {
612- let mut nodes = IndexVec :: with_capacity ( len) ;
613- for i in 0 ..len {
614- let node = d. read_seq_elt ( i, Decodable :: decode) ?;
615- nodes. push ( node) ;
616- }
617- Ok ( nodes)
618- } )
619- } ) ?;
607+ let nodes = d. read_struct_field ( "nodes" , 0 , |d| {
608+ d. read_seq ( |d, len| {
609+ let mut nodes = Vec :: with_capacity ( len) ;
610+ for i in 0 ..len {
611+ let node = d. read_seq_elt ( i, Decodable :: decode) ?;
612+ nodes. push ( node) ;
613+ }
614+ Ok ( nodes)
615+ } )
616+ } ) ?;
620617 let fingerprints = d. read_struct_field ( "fingerprints" , 1 , |d| {
621618 d. read_seq ( |d, len| {
622- let mut fingerprints = IndexVec :: with_capacity ( len) ;
619+ let mut fingerprints = Vec :: with_capacity ( len) ;
623620 for i in 0 ..len {
624621 let fingerprint = d. read_seq_elt ( i, Decodable :: decode) ?;
625622 fingerprints. push ( fingerprint) ;
@@ -639,7 +636,7 @@ impl<D: Decoder, K: DepKind + Decodable<D>> Decodable<D> for SerializedDepGraph<
639636 } ) ?;
640637 let edge_list_indices = d. read_struct_field ( "edge_list_ends" , 3 , |d| {
641638 d. read_seq ( |d, len| {
642- let mut indices = IndexVec :: with_capacity ( len) ;
639+ let mut indices = Vec :: with_capacity ( len) ;
643640 let mut start: u32 = 0 ;
644641 for i in 0 ..len {
645642 let end: u32 = d. read_seq_elt ( i, Decodable :: decode) ?;
@@ -650,7 +647,12 @@ impl<D: Decoder, K: DepKind + Decodable<D>> Decodable<D> for SerializedDepGraph<
650647 } )
651648 } ) ?;
652649
653- Ok ( SerializedDepGraph { nodes, fingerprints, edge_list_indices, edge_list_data } )
650+ Ok ( SerializedDepGraph {
651+ nodes : IndexArray :: from_vec ( nodes) ,
652+ fingerprints : IndexArray :: from_vec ( fingerprints) ,
653+ edge_list_indices : IndexArray :: from_vec ( edge_list_indices) ,
654+ edge_list_data,
655+ } )
654656 } )
655657 }
656658}
0 commit comments