@@ -4,7 +4,7 @@ use super::query::DepGraphQuery;
4
4
use super :: { DepKind , DepNode } ;
5
5
use rustc_data_structures:: fingerprint:: Fingerprint ;
6
6
use rustc_data_structures:: fx:: FxHashMap ;
7
- use rustc_index:: vec:: { Idx , IndexVec } ;
7
+ use rustc_index:: vec:: { Idx , IndexArray , IndexVec } ;
8
8
use rustc_serialize:: { Decodable , Decoder , Encodable , Encoder } ;
9
9
use std:: convert:: TryInto ;
10
10
use std:: ops:: Range ;
@@ -140,19 +140,17 @@ fn shrink_range(range: Range<usize>) -> Range<u32> {
140
140
}
141
141
142
142
/// Data for use when recompiling the **previous crate**.
143
- ///
144
- /// Those IndexVec are never pushed to, so as to avoid large reallocations.
145
143
#[ derive( Debug ) ]
146
144
pub struct SerializedDepGraph < K : DepKind > {
147
145
/// The set of all DepNodes in the graph
148
- nodes : IndexVec < SerializedDepNodeIndex , DepNode < K > > ,
146
+ nodes : IndexArray < SerializedDepNodeIndex , DepNode < K > > ,
149
147
/// The set of all Fingerprints in the graph. Each Fingerprint corresponds to
150
148
/// the DepNode at the same index in the nodes vector.
151
- fingerprints : IndexVec < SerializedDepNodeIndex , Fingerprint > ,
149
+ fingerprints : IndexArray < SerializedDepNodeIndex , Fingerprint > ,
152
150
/// For each DepNode, stores the list of edges originating from that
153
151
/// DepNode. Encoded as a [start, end) pair indexing into edge_list_data,
154
152
/// which holds the actual DepNodeIndices of the target nodes.
155
- edge_list_indices : IndexVec < SerializedDepNodeIndex , ColorAndOffset > ,
153
+ edge_list_indices : IndexArray < SerializedDepNodeIndex , ColorAndOffset > ,
156
154
/// A flattened list of all edge targets in the graph. Edge sources are
157
155
/// implicit in edge_list_indices.
158
156
edge_list_data : Vec < DepNodeIndex > ,
@@ -182,9 +180,9 @@ pub struct CurrentDepGraph<K: DepKind> {
182
180
impl < K : DepKind > Default for SerializedDepGraph < K > {
183
181
fn default ( ) -> Self {
184
182
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 ( ) ,
188
186
edge_list_data : Vec :: new ( ) ,
189
187
}
190
188
}
@@ -606,20 +604,19 @@ fn edge_count_estimate(prev_graph_node_count: usize) -> usize {
606
604
impl < D : Decoder , K : DepKind + Decodable < D > > Decodable < D > for SerializedDepGraph < K > {
607
605
fn decode ( d : & mut D ) -> Result < SerializedDepGraph < K > , D :: Error > {
608
606
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
+ } ) ?;
620
617
let fingerprints = d. read_struct_field ( "fingerprints" , 1 , |d| {
621
618
d. read_seq ( |d, len| {
622
- let mut fingerprints = IndexVec :: with_capacity ( len) ;
619
+ let mut fingerprints = Vec :: with_capacity ( len) ;
623
620
for i in 0 ..len {
624
621
let fingerprint = d. read_seq_elt ( i, Decodable :: decode) ?;
625
622
fingerprints. push ( fingerprint) ;
@@ -639,7 +636,7 @@ impl<D: Decoder, K: DepKind + Decodable<D>> Decodable<D> for SerializedDepGraph<
639
636
} ) ?;
640
637
let edge_list_indices = d. read_struct_field ( "edge_list_ends" , 3 , |d| {
641
638
d. read_seq ( |d, len| {
642
- let mut indices = IndexVec :: with_capacity ( len) ;
639
+ let mut indices = Vec :: with_capacity ( len) ;
643
640
let mut start: u32 = 0 ;
644
641
for i in 0 ..len {
645
642
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<
650
647
} )
651
648
} ) ?;
652
649
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
+ } )
654
656
} )
655
657
}
656
658
}
0 commit comments