@@ -136,16 +136,22 @@ impl<K: DepKind> DepGraph<K> {
136136
137137 pub fn query ( & self ) -> DepGraphQuery < K > {
138138 // 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.
139140 let edge_count = self . edge_count ( ) ;
140141 let data = self . data . as_ref ( ) . unwrap ( ) ;
141142 let previous = & data. previous ;
143+
144+ // Note locking order: `prev_index_to_index`, then `data`.
142145 let prev_index_to_index = data. current . prev_index_to_index . lock ( ) ;
143146 let data = data. current . data . lock ( ) ;
144147 let node_count = data. hybrid_indices . len ( ) ;
145148
146149 let mut nodes = Vec :: with_capacity ( node_count) ;
147150 let mut edge_list_indices = Vec :: with_capacity ( node_count) ;
148151 let mut edge_list_data = Vec :: with_capacity ( edge_count) ;
152+
153+ // See `serialize` for notes on the approach used here.
154+
149155 edge_list_data. extend ( data. unshared_edges . iter ( ) . map ( |i| i. index ( ) ) ) ;
150156
151157 for & hybrid_index in data. hybrid_indices . iter ( ) {
@@ -285,6 +291,8 @@ impl<K: DepKind> DepGraph<K> {
285291 eprintln ! ( "[task::green] {:?}" , key) ;
286292 }
287293
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.
288296 let dep_node_index =
289297 data. current . intern_light_green_node ( & data. previous , prev_index, edges) ;
290298
@@ -294,6 +302,8 @@ impl<K: DepKind> DepGraph<K> {
294302 eprintln ! ( "[task::red] {:?}" , key) ;
295303 }
296304
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.
297307 let dep_node_index = data. current . intern_red_node (
298308 & data. previous ,
299309 prev_index,
@@ -308,14 +318,17 @@ impl<K: DepKind> DepGraph<K> {
308318 eprintln ! ( "[task::unknown] {:?}" , key) ;
309319 }
310320
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.
311325 let dep_node_index = data. current . intern_red_node (
312326 & data. previous ,
313327 prev_index,
314328 edges,
315329 Fingerprint :: ZERO ,
316330 ) ;
317331
318- // Mark the node as Red if we can't hash the result
319332 ( DepNodeColor :: Red , dep_node_index)
320333 } ;
321334
@@ -333,6 +346,7 @@ impl<K: DepKind> DepGraph<K> {
333346 eprintln ! ( "[task::new] {:?}" , key) ;
334347 }
335348
349+ // This is a new node: it didn't exist in the previous compilation session.
336350 data. current . intern_new_node (
337351 & data. previous ,
338352 key,
@@ -343,6 +357,10 @@ impl<K: DepKind> DepGraph<K> {
343357
344358 ( result, dep_node_index)
345359 } 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.
346364 ( task ( cx, arg) , self . next_virtual_depnode_index ( ) )
347365 }
348366 }
@@ -568,9 +586,12 @@ impl<K: DepKind> DepGraph<K> {
568586 type SDNI = SerializedDepNodeIndex ;
569587
570588 // 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.
571590 let edge_count = self . edge_count ( ) ;
572591 let data = self . data . as_ref ( ) . unwrap ( ) ;
573592 let previous = & data. previous ;
593+
594+ // Note locking order: `prev_index_to_index`, then `data`.
574595 let prev_index_to_index = data. current . prev_index_to_index . lock ( ) ;
575596 let data = data. current . data . lock ( ) ;
576597 let node_count = data. hybrid_indices . len ( ) ;
@@ -579,6 +600,17 @@ impl<K: DepKind> DepGraph<K> {
579600 let mut fingerprints = IndexVec :: with_capacity ( node_count) ;
580601 let mut edge_list_indices = IndexVec :: with_capacity ( node_count) ;
581602 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+
582614 edge_list_data. extend ( data. unshared_edges . iter ( ) . map ( |i| SDNI :: new ( i. index ( ) ) ) ) ;
583615
584616 for & hybrid_index in data. hybrid_indices . iter ( ) {
0 commit comments