@@ -136,16 +136,22 @@ impl<K: DepKind> DepGraph<K> {
136
136
137
137
pub fn query ( & self ) -> DepGraphQuery < K > {
138
138
// We call this before acquiring locks, since it also acquires them.
139
+ // The extra locking is not a big deal, as this gets called rarely.
139
140
let edge_count = self . edge_count ( ) ;
140
141
let data = self . data . as_ref ( ) . unwrap ( ) ;
141
142
let previous = & data. previous ;
143
+
144
+ // Note locking order: `prev_index_to_index`, then `data`.
142
145
let prev_index_to_index = data. current . prev_index_to_index . lock ( ) ;
143
146
let data = data. current . data . lock ( ) ;
144
147
let node_count = data. hybrid_indices . len ( ) ;
145
148
146
149
let mut nodes = Vec :: with_capacity ( node_count) ;
147
150
let mut edge_list_indices = Vec :: with_capacity ( node_count) ;
148
151
let mut edge_list_data = Vec :: with_capacity ( edge_count) ;
152
+
153
+ // See `serialize` for notes on the approach used here.
154
+
149
155
edge_list_data. extend ( data. unshared_edges . iter ( ) . map ( |i| i. index ( ) ) ) ;
150
156
151
157
for & hybrid_index in data. hybrid_indices . iter ( ) {
@@ -285,6 +291,8 @@ impl<K: DepKind> DepGraph<K> {
285
291
eprintln ! ( "[task::green] {:?}" , key) ;
286
292
}
287
293
294
+ // This is a light green node: it existed in the previous compilation,
295
+ // its query was re-executed, and it has the same result as before.
288
296
let dep_node_index =
289
297
data. current . intern_light_green_node ( & data. previous , prev_index, edges) ;
290
298
@@ -294,6 +302,8 @@ impl<K: DepKind> DepGraph<K> {
294
302
eprintln ! ( "[task::red] {:?}" , key) ;
295
303
}
296
304
305
+ // This is a red node: it existed in the previous compilation, its query
306
+ // was re-executed, but it has a different result from before.
297
307
let dep_node_index = data. current . intern_red_node (
298
308
& data. previous ,
299
309
prev_index,
@@ -308,14 +318,17 @@ impl<K: DepKind> DepGraph<K> {
308
318
eprintln ! ( "[task::unknown] {:?}" , key) ;
309
319
}
310
320
321
+ // This is a red node, effectively: it existed in the previous compilation
322
+ // session, its query was re-executed, but it doesn't compute a result hash
323
+ // (i.e. it represents a `no_hash` query), so we have no way of determining
324
+ // whether or not the result was the same as before.
311
325
let dep_node_index = data. current . intern_red_node (
312
326
& data. previous ,
313
327
prev_index,
314
328
edges,
315
329
Fingerprint :: ZERO ,
316
330
) ;
317
331
318
- // Mark the node as Red if we can't hash the result
319
332
( DepNodeColor :: Red , dep_node_index)
320
333
} ;
321
334
@@ -333,6 +346,7 @@ impl<K: DepKind> DepGraph<K> {
333
346
eprintln ! ( "[task::new] {:?}" , key) ;
334
347
}
335
348
349
+ // This is a new node: it didn't exist in the previous compilation session.
336
350
data. current . intern_new_node (
337
351
& data. previous ,
338
352
key,
@@ -343,6 +357,10 @@ impl<K: DepKind> DepGraph<K> {
343
357
344
358
( result, dep_node_index)
345
359
} else {
360
+ // Incremental compilation is turned off. We just execute the task
361
+ // without tracking. We still provide a dep-node index that uniquely
362
+ // identifies the task so that we have a cheap way of referring to
363
+ // the query for self-profiling.
346
364
( task ( cx, arg) , self . next_virtual_depnode_index ( ) )
347
365
}
348
366
}
@@ -568,9 +586,12 @@ impl<K: DepKind> DepGraph<K> {
568
586
type SDNI = SerializedDepNodeIndex ;
569
587
570
588
// We call this before acquiring locks, since it also acquires them.
589
+ // The extra locking is not a big deal, as this only gets called once.
571
590
let edge_count = self . edge_count ( ) ;
572
591
let data = self . data . as_ref ( ) . unwrap ( ) ;
573
592
let previous = & data. previous ;
593
+
594
+ // Note locking order: `prev_index_to_index`, then `data`.
574
595
let prev_index_to_index = data. current . prev_index_to_index . lock ( ) ;
575
596
let data = data. current . data . lock ( ) ;
576
597
let node_count = data. hybrid_indices . len ( ) ;
@@ -579,6 +600,17 @@ impl<K: DepKind> DepGraph<K> {
579
600
let mut fingerprints = IndexVec :: with_capacity ( node_count) ;
580
601
let mut edge_list_indices = IndexVec :: with_capacity ( node_count) ;
581
602
let mut edge_list_data = Vec :: with_capacity ( edge_count) ;
603
+
604
+ // `rustc_middle::ty::query::OnDiskCache` expects nodes to be in
605
+ // `DepNodeIndex` order. The edges in `edge_list_data`, on the other
606
+ // hand, don't need to be in a particular order, as long as each node
607
+ // can reference its edges as a contiguous range within it. This is why
608
+ // we're able to copy `unshared_edges` directly into `edge_list_data`.
609
+ // It meets the above requirements, and each non-dark-green node already
610
+ // knows the range of edges to reference within it, which they'll push
611
+ // onto `edge_list_indices`. Dark green nodes, however, don't have their
612
+ // edges in `unshared_edges`, so need to add them to `edge_list_data`.
613
+
582
614
edge_list_data. extend ( data. unshared_edges . iter ( ) . map ( |i| SDNI :: new ( i. index ( ) ) ) ) ;
583
615
584
616
for & hybrid_index in data. hybrid_indices . iter ( ) {
0 commit comments