@@ -626,11 +626,10 @@ impl<K: DepKind> DepGraph<K> {
626
626
627
627
// There may be multiple threads trying to mark the same dep node green concurrently
628
628
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) ;
634
633
635
634
// ... emitting any stored diagnostic ...
636
635
@@ -713,7 +712,7 @@ impl<K: DepKind> DepGraph<K> {
713
712
}
714
713
}
715
714
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
717
716
// current compilation session. Used in various assertions
718
717
pub fn is_red ( & self , dep_node : & DepNode < K > ) -> bool {
719
718
self . node_color ( dep_node) == Some ( DepNodeColor :: Red )
@@ -833,17 +832,11 @@ rustc_index::newtype_index! {
833
832
/// will be populated as we run queries or tasks. We never remove nodes from the
834
833
/// graph: they are only added.
835
834
///
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.
845
838
///
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
847
840
/// keys. The `new_node_to_index` map only contains nodes not in the previous
848
841
/// graph, and we map nodes in the previous graph to indices via a two-step
849
842
/// mapping. `PreviousDepGraph` maps from `DepNode` to `SerializedDepNodeIndex`,
@@ -939,6 +932,15 @@ impl<K: DepKind> CurrentDepGraph<K> {
939
932
}
940
933
}
941
934
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.
942
944
fn intern_new_node (
943
945
& self ,
944
946
key : DepNode < K > ,
@@ -951,9 +953,7 @@ impl<K: DepKind> CurrentDepGraph<K> {
951
953
let dep_node_index = self . encoder . borrow ( ) . send ( key, current_fingerprint, edges) ;
952
954
entry. insert ( dep_node_index) ;
953
955
#[ 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) ;
957
957
dep_node_index
958
958
}
959
959
}
@@ -964,37 +964,35 @@ impl<K: DepKind> CurrentDepGraph<K> {
964
964
prev_graph : & PreviousDepGraph < K > ,
965
965
key : DepNode < K > ,
966
966
edges : EdgesVec ,
967
- current_fingerprint : Option < Fingerprint > ,
967
+ fingerprint : Option < Fingerprint > ,
968
968
print_status : bool ,
969
969
) -> ( DepNodeIndex , Option < ( SerializedDepNodeIndex , DepNodeColor ) > ) {
970
970
let print_status = cfg ! ( debug_assertions) && print_status;
971
971
972
972
if let Some ( prev_index) = prev_graph. node_to_index_opt ( & key) {
973
973
// 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) {
976
976
if print_status {
977
977
eprintln ! ( "[task::green] {:?}" , key) ;
978
978
}
979
979
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,
981
981
// its query was re-executed, and it has the same result as before.
982
982
let mut prev_index_to_index = self . prev_index_to_index . lock ( ) ;
983
983
984
984
let dep_node_index = match prev_index_to_index[ prev_index] {
985
985
Some ( dep_node_index) => dep_node_index,
986
986
None => {
987
987
let dep_node_index =
988
- self . encoder . borrow ( ) . send ( key, current_fingerprint , edges) ;
988
+ self . encoder . borrow ( ) . send ( key, fingerprint , edges) ;
989
989
prev_index_to_index[ prev_index] = Some ( dep_node_index) ;
990
990
dep_node_index
991
991
}
992
992
} ;
993
993
994
994
#[ 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) ;
998
996
( dep_node_index, Some ( ( prev_index, DepNodeColor :: Green ( dep_node_index) ) ) )
999
997
} else {
1000
998
if print_status {
@@ -1009,16 +1007,14 @@ impl<K: DepKind> CurrentDepGraph<K> {
1009
1007
Some ( dep_node_index) => dep_node_index,
1010
1008
None => {
1011
1009
let dep_node_index =
1012
- self . encoder . borrow ( ) . send ( key, current_fingerprint , edges) ;
1010
+ self . encoder . borrow ( ) . send ( key, fingerprint , edges) ;
1013
1011
prev_index_to_index[ prev_index] = Some ( dep_node_index) ;
1014
1012
dep_node_index
1015
1013
}
1016
1014
} ;
1017
1015
1018
1016
#[ 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) ;
1022
1018
( dep_node_index, Some ( ( prev_index, DepNodeColor :: Red ) ) )
1023
1019
}
1024
1020
} else {
@@ -1043,26 +1039,24 @@ impl<K: DepKind> CurrentDepGraph<K> {
1043
1039
} ;
1044
1040
1045
1041
#[ 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) ;
1049
1043
( dep_node_index, Some ( ( prev_index, DepNodeColor :: Red ) ) )
1050
1044
}
1051
1045
} else {
1052
1046
if print_status {
1053
1047
eprintln ! ( "[task::new] {:?}" , key) ;
1054
1048
}
1055
1049
1056
- let current_fingerprint = current_fingerprint . unwrap_or ( Fingerprint :: ZERO ) ;
1050
+ let fingerprint = fingerprint . unwrap_or ( Fingerprint :: ZERO ) ;
1057
1051
1058
1052
// 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 ) ;
1060
1054
1061
1055
( dep_node_index, None )
1062
1056
}
1063
1057
}
1064
1058
1065
- fn intern_dark_green_node (
1059
+ fn promote_node_and_deps_to_current (
1066
1060
& self ,
1067
1061
prev_graph : & PreviousDepGraph < K > ,
1068
1062
prev_index : SerializedDepNodeIndex ,
@@ -1086,9 +1080,7 @@ impl<K: DepKind> CurrentDepGraph<K> {
1086
1080
) ;
1087
1081
prev_index_to_index[ prev_index] = Some ( dep_node_index) ;
1088
1082
#[ 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) ;
1092
1084
dep_node_index
1093
1085
}
1094
1086
}
0 commit comments