@@ -46,6 +46,7 @@ use rustc_data_structures::sync::Lock;
46
46
use rustc_index:: { Idx , IndexVec } ;
47
47
use rustc_serialize:: opaque:: { FileEncodeResult , FileEncoder , IntEncodedWithFixedSize , MemDecoder } ;
48
48
use rustc_serialize:: { Decodable , Decoder , Encodable , Encoder } ;
49
+ use std:: iter;
49
50
use std:: marker:: PhantomData ;
50
51
51
52
// The maximum value of `SerializedDepNodeIndex` leaves the upper two bits
@@ -81,8 +82,9 @@ pub struct SerializedDepGraph<K: DepKind> {
81
82
/// A flattened list of all edge targets in the graph, stored in the same
82
83
/// varint encoding that we use on disk. Edge sources are implicit in edge_list_indices.
83
84
edge_list_data : Vec < u8 > ,
84
- /// Reciprocal map to `nodes`.
85
- index : FxHashMap < DepNode < K > , SerializedDepNodeIndex > ,
85
+ /// Stores a map from fingerprints to nodes per dep node kind.
86
+ /// This is the reciprocal of `nodes`.
87
+ index : Vec < FxHashMap < PackedFingerprint , SerializedDepNodeIndex > > ,
86
88
}
87
89
88
90
impl < K : DepKind > Default for SerializedDepGraph < K > {
@@ -137,7 +139,7 @@ impl<K: DepKind> SerializedDepGraph<K> {
137
139
138
140
#[ inline]
139
141
pub fn node_to_index_opt ( & self , dep_node : & DepNode < K > ) -> Option < SerializedDepNodeIndex > {
140
- self . index . get ( dep_node) . cloned ( )
142
+ self . index . get ( dep_node. kind . to_u16 ( ) as usize ) ? . get ( & dep_node . hash ) . cloned ( )
141
143
}
142
144
143
145
#[ inline]
@@ -147,7 +149,7 @@ impl<K: DepKind> SerializedDepGraph<K> {
147
149
148
150
#[ inline]
149
151
pub fn node_count ( & self ) -> usize {
150
- self . index . len ( )
152
+ self . nodes . len ( )
151
153
}
152
154
}
153
155
@@ -220,7 +222,8 @@ impl<'a, K: DepKind + Decodable<MemDecoder<'a>>> Decodable<MemDecoder<'a>>
220
222
for _index in 0 ..node_count {
221
223
// Decode the header for this edge; the header packs together as many of the fixed-size
222
224
// fields as possible to limit the number of times we update decoder state.
223
- let node_header = SerializedNodeHeader { bytes : d. read_array ( ) , _marker : PhantomData } ;
225
+ let node_header =
226
+ SerializedNodeHeader :: < K > { bytes : d. read_array ( ) , _marker : PhantomData } ;
224
227
225
228
let _i: SerializedDepNodeIndex = nodes. push ( node_header. node ( ) ) ;
226
229
debug_assert_eq ! ( _i. index( ) , _index) ;
@@ -251,8 +254,12 @@ impl<'a, K: DepKind + Decodable<MemDecoder<'a>>> Decodable<MemDecoder<'a>>
251
254
// end of the array. This padding ensure it doesn't.
252
255
edge_list_data. extend ( & [ 0u8 ; DEP_NODE_PAD ] ) ;
253
256
254
- let index: FxHashMap < _ , _ > =
255
- nodes. iter_enumerated ( ) . map ( |( idx, & dep_node) | ( dep_node, idx) ) . collect ( ) ;
257
+ let mut index: Vec < _ > =
258
+ iter:: repeat ( FxHashMap :: default ( ) ) . take ( K :: MAX as usize + 1 ) . collect ( ) ;
259
+
260
+ for ( idx, node) in nodes. iter_enumerated ( ) {
261
+ index[ node. kind . to_u16 ( ) as usize ] . insert ( node. hash , idx) ;
262
+ }
256
263
257
264
SerializedDepGraph { nodes, fingerprints, edge_list_indices, edge_list_data, index }
258
265
}
0 commit comments