@@ -5,9 +5,9 @@ use super::{DepKind, DepNode, DepNodeIndex};
5
5
use rustc_data_structures:: fingerprint:: Fingerprint ;
6
6
use rustc_data_structures:: fx:: FxHashMap ;
7
7
use rustc_data_structures:: sync:: { AtomicU32 , Lock , Lrc , Ordering } ;
8
- use rustc_index:: vec:: { Idx , IndexVec } ;
8
+ use rustc_index:: vec:: IndexVec ;
9
9
use rustc_serialize:: opaque:: { self , FileEncodeResult , FileEncoder , IntEncodedWithFixedSize } ;
10
- use rustc_serialize:: { Decodable , Encodable } ;
10
+ use rustc_serialize:: { Decodable , Decoder , Encodable } ;
11
11
use smallvec:: SmallVec ;
12
12
use std:: convert:: TryInto ;
13
13
@@ -85,31 +85,41 @@ impl<'a, K: DepKind + Decodable<opaque::Decoder<'a>>> Decodable<opaque::Decoder<
85
85
let mut edge_list_data = Vec :: with_capacity ( edge_count) ;
86
86
87
87
for _index in 0 ..node_count {
88
- let node = NodeInfo :: < K , SerializedDepNodeIndex > :: decode ( d) ?;
89
- debug ! ( ?_index, ?node) ;
90
-
91
- let _i: SerializedDepNodeIndex = nodes. push ( node. node ) ;
92
- debug_assert_eq ! ( _i. index( ) , _index) ;
93
- let _i: SerializedDepNodeIndex = fingerprints. push ( node. fingerprint ) ;
94
- debug_assert_eq ! ( _i. index( ) , _index) ;
95
-
96
- let start = edge_list_data. len ( ) . try_into ( ) . unwrap ( ) ;
97
- edge_list_data. extend ( node. edges . into_iter ( ) ) ;
98
- let end = edge_list_data. len ( ) . try_into ( ) . unwrap ( ) ;
99
-
100
- let _i: SerializedDepNodeIndex = edge_list_indices. push ( ( start, end) ) ;
101
- debug_assert_eq ! ( _i. index( ) , _index) ;
88
+ d. read_struct ( "NodeInfo" , 3 , |d| {
89
+ let dep_node: DepNode < K > = d. read_struct_field ( "node" , 0 , Decodable :: decode) ?;
90
+ let _i: SerializedDepNodeIndex = nodes. push ( dep_node) ;
91
+ debug_assert_eq ! ( _i. index( ) , _index) ;
92
+
93
+ let fingerprint: Fingerprint =
94
+ d. read_struct_field ( "fingerprint" , 1 , Decodable :: decode) ?;
95
+ let _i: SerializedDepNodeIndex = fingerprints. push ( fingerprint) ;
96
+ debug_assert_eq ! ( _i. index( ) , _index) ;
97
+
98
+ d. read_struct_field ( "edges" , 2 , |d| {
99
+ d. read_seq ( |d, len| {
100
+ let start = edge_list_data. len ( ) . try_into ( ) . unwrap ( ) ;
101
+ for e in 0 ..len {
102
+ let edge = d. read_seq_elt ( e, Decodable :: decode) ?;
103
+ edge_list_data. push ( edge) ;
104
+ }
105
+ let end = edge_list_data. len ( ) . try_into ( ) . unwrap ( ) ;
106
+ let _i: SerializedDepNodeIndex = edge_list_indices. push ( ( start, end) ) ;
107
+ debug_assert_eq ! ( _i. index( ) , _index) ;
108
+ Ok ( ( ) )
109
+ } )
110
+ } )
111
+ } ) ?;
102
112
}
103
113
104
114
Ok ( SerializedDepGraph { nodes, fingerprints, edge_list_indices, edge_list_data } )
105
115
}
106
116
}
107
117
108
118
#[ derive( Debug , Encodable , Decodable ) ]
109
- pub struct NodeInfo < K : DepKind , I : Idx > {
119
+ pub struct NodeInfo < K : DepKind > {
110
120
node : DepNode < K > ,
111
121
fingerprint : Fingerprint ,
112
- edges : SmallVec < [ I ; 8 ] > ,
122
+ edges : SmallVec < [ DepNodeIndex ; 8 ] > ,
113
123
}
114
124
115
125
struct Stat < K : DepKind > {
@@ -128,7 +138,7 @@ struct Stats<K: DepKind> {
128
138
fn encode_node < K : DepKind > (
129
139
encoder : & mut FileEncoder ,
130
140
_index : DepNodeIndex ,
131
- node : & NodeInfo < K , DepNodeIndex > ,
141
+ node : & NodeInfo < K > ,
132
142
_record_graph : & Option < Lrc < Lock < DepGraphQuery < K > > > > ,
133
143
record_stats : & Option < Lrc < Lock < Stats < K > > > > ,
134
144
) -> FileEncodeResult {
@@ -181,7 +191,7 @@ pub struct GraphEncoder<K: DepKind> {
181
191
182
192
#[ cfg( parallel_compiler) ]
183
193
pub struct GraphEncoder < K : DepKind > {
184
- send : WorkerLocal < mpsc:: Sender < ( DepNodeIndex , NodeInfo < K , DepNodeIndex > ) > > ,
194
+ send : WorkerLocal < mpsc:: Sender < ( DepNodeIndex , NodeInfo < K > ) > > ,
185
195
thread : thread:: JoinHandle < FileEncodeResult > ,
186
196
counter : AtomicU32 ,
187
197
record_graph : Option < Lrc < Lock < DepGraphQuery < K > > > > ,
@@ -350,8 +360,8 @@ impl<K: DepKind + Encodable<FileEncoder>> GraphEncoder<K> {
350
360
#[ instrument( skip( encoder, recv, process) ) ]
351
361
fn encode_graph < K : DepKind + Encodable < FileEncoder > > (
352
362
mut encoder : FileEncoder ,
353
- recv : mpsc:: Receiver < ( DepNodeIndex , NodeInfo < K , DepNodeIndex > ) > ,
354
- process : impl Fn ( & mut FileEncoder , DepNodeIndex , & NodeInfo < K , DepNodeIndex > ) -> FileEncodeResult ,
363
+ recv : mpsc:: Receiver < ( DepNodeIndex , NodeInfo < K > ) > ,
364
+ process : impl Fn ( & mut FileEncoder , DepNodeIndex , & NodeInfo < K > ) -> FileEncodeResult ,
355
365
) -> FileEncodeResult {
356
366
let mut edge_count: usize = 0 ;
357
367
let node_count: usize = ordered_recv ( recv, |index, node| {
@@ -366,8 +376,8 @@ fn encode_graph<K: DepKind + Encodable<FileEncoder>>(
366
376
/// the messages may not arrive in order. This function sorts them as they come.
367
377
#[ cfg( parallel_compiler) ]
368
378
fn ordered_recv < K : DepKind + Encodable < opaque:: FileEncoder > > (
369
- recv : mpsc:: Receiver < ( DepNodeIndex , NodeInfo < K , DepNodeIndex > ) > ,
370
- mut f : impl FnMut ( DepNodeIndex , & NodeInfo < K , DepNodeIndex > ) -> FileEncodeResult ,
379
+ recv : mpsc:: Receiver < ( DepNodeIndex , NodeInfo < K > ) > ,
380
+ mut f : impl FnMut ( DepNodeIndex , & NodeInfo < K > ) -> FileEncodeResult ,
371
381
) -> Result < usize , std:: io:: Error > {
372
382
let mut pending = Vec :: < ( DepNodeIndex , _ ) > :: new ( ) ;
373
383
let mut expected = DepNodeIndex :: new ( 0 ) ;
0 commit comments