@@ -626,11 +626,10 @@ impl<K: DepKind> DepGraph<K> {
626626
627627        // There may be multiple threads trying to mark the same dep node green concurrently 
628628
629-         let  dep_node_index = { 
630-             // We allocating an entry for the node in the current dependency graph and 
631-             // adding all the appropriate edges imported from the previous graph 
632-             data. current . intern_dark_green_node ( & data. previous ,  prev_dep_node_index) 
633-         } ; 
629+         // We allocating an entry for the node in the current dependency graph and 
630+         // adding all the appropriate edges imported from the previous graph 
631+         let  dep_node_index =
632+             data. current . promote_node_and_deps_to_current ( & data. previous ,  prev_dep_node_index) ; 
634633
635634        // ... emitting any stored diagnostic ... 
636635
@@ -713,7 +712,7 @@ impl<K: DepKind> DepGraph<K> {
713712        } 
714713    } 
715714
716-     // Returns true if the given node has been marked as green  during the 
715+     // Returns true if the given node has been marked as red  during the 
717716    // current compilation session. Used in various assertions 
718717    pub  fn  is_red ( & self ,  dep_node :  & DepNode < K > )  -> bool  { 
719718        self . node_color ( dep_node)  == Some ( DepNodeColor :: Red ) 
@@ -833,17 +832,11 @@ rustc_index::newtype_index! {
833832/// will be populated as we run queries or tasks. We never remove nodes from the 
834833/// graph: they are only added. 
835834/// 
836- /// The nodes in it are identified by a `DepNodeIndex`. Internally, this maps to 
837- /// a `HybridIndex`, which identifies which collection in the `data` field 
838- /// contains a node's data. Which collection is used for a node depends on 
839- /// whether the node was present in the `PreviousDepGraph`, and if so, the color 
840- /// of the node. Each type of node can share more or less data with the previous 
841- /// graph. When possible, we can store just the index of the node in the 
842- /// previous graph, rather than duplicating its data in our own collections. 
843- /// This is important, because these graph structures are some of the largest in 
844- /// the compiler. 
835+ /// The nodes in it are identified by a `DepNodeIndex`. We avoid keeping the nodes 
836+ /// in memory.  This is important, because these graph structures are some of the 
837+ /// largest in the compiler. 
845838/// 
846- /// For the same  reason, we also  avoid storing `DepNode`s more than once as map 
839+ /// For this  reason, we avoid storing `DepNode`s more than once as map 
847840/// keys. The `new_node_to_index` map only contains nodes not in the previous 
848841/// graph, and we map nodes in the previous graph to indices via a two-step 
849842/// mapping. `PreviousDepGraph` maps from `DepNode` to `SerializedDepNodeIndex`, 
@@ -939,6 +932,15 @@ impl<K: DepKind> CurrentDepGraph<K> {
939932        } 
940933    } 
941934
935+     #[ cfg( debug_assertions) ]  
936+     fn  record_edge ( & self ,  dep_node_index :  DepNodeIndex ,  key :  DepNode < K > )  { 
937+         if  let  Some ( forbidden_edge)  = & self . forbidden_edge  { 
938+             forbidden_edge. index_to_node . lock ( ) . insert ( dep_node_index,  key) ; 
939+         } 
940+     } 
941+ 
942+     /// Writes the node to the current dep-graph and allocates a `DepNodeIndex` for it. 
943+      /// Assumes that this is a node that has no equivalent in the previous dep-graph. 
942944     fn  intern_new_node ( 
943945        & self , 
944946        key :  DepNode < K > , 
@@ -951,9 +953,7 @@ impl<K: DepKind> CurrentDepGraph<K> {
951953                let  dep_node_index = self . encoder . borrow ( ) . send ( key,  current_fingerprint,  edges) ; 
952954                entry. insert ( dep_node_index) ; 
953955                #[ cfg( debug_assertions) ]  
954-                 if  let  Some ( forbidden_edge)  = & self . forbidden_edge  { 
955-                     forbidden_edge. index_to_node . lock ( ) . insert ( dep_node_index,  key) ; 
956-                 } 
956+                 self . record_edge ( dep_node_index,  key) ; 
957957                dep_node_index
958958            } 
959959        } 
@@ -964,37 +964,35 @@ impl<K: DepKind> CurrentDepGraph<K> {
964964        prev_graph :  & PreviousDepGraph < K > , 
965965        key :  DepNode < K > , 
966966        edges :  EdgesVec , 
967-         current_fingerprint :  Option < Fingerprint > , 
967+         fingerprint :  Option < Fingerprint > , 
968968        print_status :  bool , 
969969    )  -> ( DepNodeIndex ,  Option < ( SerializedDepNodeIndex ,  DepNodeColor ) > )  { 
970970        let  print_status = cfg ! ( debug_assertions)  && print_status; 
971971
972972        if  let  Some ( prev_index)  = prev_graph. node_to_index_opt ( & key)  { 
973973            // Determine the color and index of the new `DepNode`. 
974-             if  let  Some ( current_fingerprint )  = current_fingerprint  { 
975-                 if  current_fingerprint  == prev_graph. fingerprint_by_index ( prev_index)  { 
974+             if  let  Some ( fingerprint )  = fingerprint  { 
975+                 if  fingerprint  == prev_graph. fingerprint_by_index ( prev_index)  { 
976976                    if  print_status { 
977977                        eprintln ! ( "[task::green] {:?}" ,  key) ; 
978978                    } 
979979
980-                     // This is a light  green node: it existed in the previous compilation, 
980+                     // This is a green node: it existed in the previous compilation, 
981981                    // its query was re-executed, and it has the same result as before. 
982982                    let  mut  prev_index_to_index = self . prev_index_to_index . lock ( ) ; 
983983
984984                    let  dep_node_index = match  prev_index_to_index[ prev_index]  { 
985985                        Some ( dep_node_index)  => dep_node_index, 
986986                        None  => { 
987987                            let  dep_node_index =
988-                                 self . encoder . borrow ( ) . send ( key,  current_fingerprint ,  edges) ; 
988+                                 self . encoder . borrow ( ) . send ( key,  fingerprint ,  edges) ; 
989989                            prev_index_to_index[ prev_index]  = Some ( dep_node_index) ; 
990990                            dep_node_index
991991                        } 
992992                    } ; 
993993
994994                    #[ cfg( debug_assertions) ]  
995-                     if  let  Some ( forbidden_edge)  = & self . forbidden_edge  { 
996-                         forbidden_edge. index_to_node . lock ( ) . insert ( dep_node_index,  key) ; 
997-                     } 
995+                     self . record_edge ( dep_node_index,  key) ; 
998996                    ( dep_node_index,  Some ( ( prev_index,  DepNodeColor :: Green ( dep_node_index) ) ) ) 
999997                }  else  { 
1000998                    if  print_status { 
@@ -1009,16 +1007,14 @@ impl<K: DepKind> CurrentDepGraph<K> {
10091007                        Some ( dep_node_index)  => dep_node_index, 
10101008                        None  => { 
10111009                            let  dep_node_index =
1012-                                 self . encoder . borrow ( ) . send ( key,  current_fingerprint ,  edges) ; 
1010+                                 self . encoder . borrow ( ) . send ( key,  fingerprint ,  edges) ; 
10131011                            prev_index_to_index[ prev_index]  = Some ( dep_node_index) ; 
10141012                            dep_node_index
10151013                        } 
10161014                    } ; 
10171015
10181016                    #[ cfg( debug_assertions) ]  
1019-                     if  let  Some ( forbidden_edge)  = & self . forbidden_edge  { 
1020-                         forbidden_edge. index_to_node . lock ( ) . insert ( dep_node_index,  key) ; 
1021-                     } 
1017+                     self . record_edge ( dep_node_index,  key) ; 
10221018                    ( dep_node_index,  Some ( ( prev_index,  DepNodeColor :: Red ) ) ) 
10231019                } 
10241020            }  else  { 
@@ -1043,26 +1039,24 @@ impl<K: DepKind> CurrentDepGraph<K> {
10431039                } ; 
10441040
10451041                #[ cfg( debug_assertions) ]  
1046-                 if  let  Some ( forbidden_edge)  = & self . forbidden_edge  { 
1047-                     forbidden_edge. index_to_node . lock ( ) . insert ( dep_node_index,  key) ; 
1048-                 } 
1042+                 self . record_edge ( dep_node_index,  key) ; 
10491043                ( dep_node_index,  Some ( ( prev_index,  DepNodeColor :: Red ) ) ) 
10501044            } 
10511045        }  else  { 
10521046            if  print_status { 
10531047                eprintln ! ( "[task::new] {:?}" ,  key) ; 
10541048            } 
10551049
1056-             let  current_fingerprint  = current_fingerprint . unwrap_or ( Fingerprint :: ZERO ) ; 
1050+             let  fingerprint  = fingerprint . unwrap_or ( Fingerprint :: ZERO ) ; 
10571051
10581052            // This is a new node: it didn't exist in the previous compilation session. 
1059-             let  dep_node_index = self . intern_new_node ( key,  edges,  current_fingerprint ) ; 
1053+             let  dep_node_index = self . intern_new_node ( key,  edges,  fingerprint ) ; 
10601054
10611055            ( dep_node_index,  None ) 
10621056        } 
10631057    } 
10641058
1065-     fn  intern_dark_green_node ( 
1059+     fn  promote_node_and_deps_to_current ( 
10661060        & self , 
10671061        prev_graph :  & PreviousDepGraph < K > , 
10681062        prev_index :  SerializedDepNodeIndex , 
@@ -1086,9 +1080,7 @@ impl<K: DepKind> CurrentDepGraph<K> {
10861080                ) ; 
10871081                prev_index_to_index[ prev_index]  = Some ( dep_node_index) ; 
10881082                #[ cfg( debug_assertions) ]  
1089-                 if  let  Some ( forbidden_edge)  = & self . forbidden_edge  { 
1090-                     forbidden_edge. index_to_node . lock ( ) . insert ( dep_node_index,  key) ; 
1091-                 } 
1083+                 self . record_edge ( dep_node_index,  key) ; 
10921084                dep_node_index
10931085            } 
10941086        } 
0 commit comments