@@ -198,19 +198,20 @@ impl SerializedDepGraph {
198198
199199 // `node_max` is the number of indices including empty nodes while `node_count`
200200 // is the number of actually encoded nodes.
201- let ( node_max, node_count, edge_count) =
202- d. with_position ( d. len ( ) - 3 * IntEncodedWithFixedSize :: ENCODED_SIZE , |d| {
201+ let ( node_max, node_count, edge_count, chunk_count ) =
202+ d. with_position ( d. len ( ) - 4 * IntEncodedWithFixedSize :: ENCODED_SIZE , |d| {
203203 debug ! ( "position: {:?}" , d. position( ) ) ;
204204 let node_max = IntEncodedWithFixedSize :: decode ( d) . 0 as usize ;
205205 let node_count = IntEncodedWithFixedSize :: decode ( d) . 0 as usize ;
206206 let edge_count = IntEncodedWithFixedSize :: decode ( d) . 0 as usize ;
207- ( node_max, node_count, edge_count)
207+ let chunk_count = IntEncodedWithFixedSize :: decode ( d) . 0 as usize ;
208+ ( node_max, node_count, edge_count, chunk_count)
208209 } ) ;
209210 debug ! ( "position: {:?}" , d. position( ) ) ;
210211
211212 debug ! ( ?node_count, ?edge_count) ;
212213
213- let graph_bytes = d. len ( ) - ( 3 * IntEncodedWithFixedSize :: ENCODED_SIZE ) - d. position ( ) ;
214+ let graph_bytes = d. len ( ) - ( 4 * IntEncodedWithFixedSize :: ENCODED_SIZE ) - d. position ( ) ;
214215
215216 let mut nodes = IndexVec :: from_elem_n (
216217 DepNode { kind : D :: DEP_KIND_NULL , hash : PackedFingerprint :: from ( Fingerprint :: ZERO ) } ,
@@ -232,8 +233,7 @@ impl SerializedDepGraph {
232233 let mut edge_list_data =
233234 Vec :: with_capacity ( graph_bytes - node_count * size_of :: < SerializedNodeHeader < D > > ( ) ) ;
234235
235- let mut decoded_nodes = 0 ;
236- while decoded_nodes < node_count {
236+ for _ in 0 ..chunk_count {
237237 let mut current_index = d. read_u32 ( ) ;
238238
239239 loop {
@@ -246,8 +246,6 @@ impl SerializedDepGraph {
246246 break ;
247247 }
248248
249- decoded_nodes += 1 ;
250-
251249 let index = SerializedDepNodeIndex :: from_u32 ( current_index) ;
252250 current_index += 1 ;
253251
@@ -524,6 +522,7 @@ struct LocalEncoderState {
524522 encoder : MemEncoder ,
525523 node_count : usize ,
526524 edge_count : usize ,
525+ chunk_count : usize ,
527526
528527 in_chunk : bool ,
529528
@@ -535,6 +534,7 @@ struct LocalEncoderResult {
535534 node_max : u32 ,
536535 node_count : usize ,
537536 edge_count : usize ,
537+ chunk_count : usize ,
538538
539539 /// Stores the number of times we've encoded each dep kind.
540540 kind_stats : Vec < u32 > ,
@@ -562,6 +562,7 @@ impl<D: Deps> EncoderState<D> {
562562 remaining_node_index : 0 ,
563563 edge_count : 0 ,
564564 node_count : 0 ,
565+ chunk_count : 0 ,
565566 in_chunk : false ,
566567 encoder : MemEncoder :: new ( ) ,
567568 kind_stats : iter:: repeat_n ( 0 , D :: DEP_KIND_MAX as usize + 1 ) . collect ( ) ,
@@ -592,6 +593,7 @@ impl<D: Deps> EncoderState<D> {
592593 self . end_chunk ( local) ;
593594 }
594595 local. in_chunk = true ;
596+ local. chunk_count += 1 ;
595597 local. encoder . emit_u32 ( first_index) ;
596598 }
597599
@@ -758,21 +760,26 @@ impl<D: Deps> EncoderState<D> {
758760 node_max : local. next_node_index ,
759761 node_count : local. node_count ,
760762 edge_count : local. edge_count ,
763+ chunk_count : local. chunk_count ,
761764 }
762765 } ) ;
763766
764767 let mut encoder = self . file . lock ( ) . take ( ) . unwrap ( ) ;
765768
769+ encoder. emit_u64 ( 0xAC75672356237839 ) ;
770+
766771 let mut kind_stats: Vec < u32 > = iter:: repeat_n ( 0 , D :: DEP_KIND_MAX as usize + 1 ) . collect ( ) ;
767772
768773 let mut node_max = 0 ;
769774 let mut node_count = 0 ;
770775 let mut edge_count = 0 ;
776+ let mut chunk_count = 0 ;
771777
772778 for result in results {
773779 node_max = max ( node_max, result. node_max ) ;
774780 node_count += result. node_count ;
775781 edge_count += result. edge_count ;
782+ chunk_count += result. chunk_count ;
776783 for ( i, stat) in result. kind_stats . iter ( ) . enumerate ( ) {
777784 kind_stats[ i] += stat;
778785 }
@@ -790,6 +797,7 @@ impl<D: Deps> EncoderState<D> {
790797 IntEncodedWithFixedSize ( node_max. try_into ( ) . unwrap ( ) ) . encode ( & mut encoder) ;
791798 IntEncodedWithFixedSize ( node_count. try_into ( ) . unwrap ( ) ) . encode ( & mut encoder) ;
792799 IntEncodedWithFixedSize ( edge_count. try_into ( ) . unwrap ( ) ) . encode ( & mut encoder) ;
800+ IntEncodedWithFixedSize ( chunk_count. try_into ( ) . unwrap ( ) ) . encode ( & mut encoder) ;
793801 debug ! ( "position: {:?}" , encoder. position( ) ) ;
794802 // Drop the encoder so that nothing is written after the counts.
795803 let result = encoder. finish ( ) ;
0 commit comments