@@ -8,6 +8,7 @@ use rustc_data_structures::steal::Steal;
8
8
use rustc_data_structures:: sync:: { AtomicU32 , AtomicU64 , Lock , Lrc , Ordering } ;
9
9
use rustc_index:: IndexVec ;
10
10
use rustc_serialize:: opaque:: { FileEncodeResult , FileEncoder } ;
11
+ use rustc_session:: Session ;
11
12
use smallvec:: { smallvec, SmallVec } ;
12
13
use std:: assert_matches:: assert_matches;
13
14
use std:: collections:: hash_map:: Entry ;
@@ -114,7 +115,7 @@ where
114
115
115
116
impl < K : DepKind > DepGraph < K > {
116
117
pub fn new (
117
- profiler : & SelfProfilerRef ,
118
+ session : & Session ,
118
119
prev_graph : SerializedDepGraph < K > ,
119
120
prev_work_products : FxHashMap < WorkProductId , WorkProduct > ,
120
121
encoder : FileEncoder ,
@@ -124,7 +125,7 @@ impl<K: DepKind> DepGraph<K> {
124
125
let prev_graph_node_count = prev_graph. node_count ( ) ;
125
126
126
127
let current = CurrentDepGraph :: new (
127
- profiler ,
128
+ session ,
128
129
prev_graph_node_count,
129
130
encoder,
130
131
record_graph,
@@ -135,7 +136,7 @@ impl<K: DepKind> DepGraph<K> {
135
136
136
137
// Instantiate a dependy-less node only once for anonymous queries.
137
138
let _green_node_index = current. intern_new_node (
138
- profiler ,
139
+ & session . prof ,
139
140
DepNode { kind : DepKind :: NULL , hash : current. anon_id_seed . into ( ) } ,
140
141
smallvec ! [ ] ,
141
142
Fingerprint :: ZERO ,
@@ -144,7 +145,7 @@ impl<K: DepKind> DepGraph<K> {
144
145
145
146
// Instantiate a dependy-less red node only once for anonymous queries.
146
147
let ( red_node_index, red_node_prev_index_and_color) = current. intern_node (
147
- profiler ,
148
+ & session . prof ,
148
149
& prev_graph,
149
150
DepNode { kind : DepKind :: RED , hash : Fingerprint :: ZERO . into ( ) } ,
150
151
smallvec ! [ ] ,
@@ -1075,6 +1076,11 @@ pub(super) struct CurrentDepGraph<K: DepKind> {
1075
1076
#[ cfg( debug_assertions) ]
1076
1077
forbidden_edge : Option < EdgeFilter < K > > ,
1077
1078
1079
+ /// Used to verify the absence of hash collisions among DepNodes.
1080
+ /// This field is only `Some` if the `-Z incremental_verify_depnodes` option is present.
1081
+ #[ cfg( debug_assertions) ]
1082
+ seen_dep_nodes : Option < Lock < FxHashSet < DepNode < K > > > > ,
1083
+
1078
1084
/// Anonymous `DepNode`s are nodes whose IDs we compute from the list of
1079
1085
/// their edges. This has the beneficial side-effect that multiple anonymous
1080
1086
/// nodes can be coalesced into one without changing the semantics of the
@@ -1102,7 +1108,7 @@ pub(super) struct CurrentDepGraph<K: DepKind> {
1102
1108
1103
1109
impl < K : DepKind > CurrentDepGraph < K > {
1104
1110
fn new (
1105
- profiler : & SelfProfilerRef ,
1111
+ session : & Session ,
1106
1112
prev_graph_node_count : usize ,
1107
1113
encoder : FileEncoder ,
1108
1114
record_graph : bool ,
@@ -1132,7 +1138,8 @@ impl<K: DepKind> CurrentDepGraph<K> {
1132
1138
1133
1139
let new_node_count_estimate = 102 * prev_graph_node_count / 100 + 200 ;
1134
1140
1135
- let node_intern_event_id = profiler
1141
+ let node_intern_event_id = session
1142
+ . prof
1136
1143
. get_or_alloc_cached_string ( "incr_comp_intern_dep_graph_node" )
1137
1144
. map ( EventId :: from_label) ;
1138
1145
@@ -1155,6 +1162,13 @@ impl<K: DepKind> CurrentDepGraph<K> {
1155
1162
forbidden_edge,
1156
1163
#[ cfg( debug_assertions) ]
1157
1164
fingerprints : Lock :: new ( IndexVec :: from_elem_n ( None , new_node_count_estimate) ) ,
1165
+ #[ cfg( debug_assertions) ]
1166
+ seen_dep_nodes : session. opts . unstable_opts . incremental_verify_depnodes . then ( || {
1167
+ Lock :: new ( FxHashSet :: with_capacity_and_hasher (
1168
+ new_node_count_estimate,
1169
+ Default :: default ( ) ,
1170
+ ) )
1171
+ } ) ,
1158
1172
total_read_count : AtomicU64 :: new ( 0 ) ,
1159
1173
total_duplicate_read_count : AtomicU64 :: new ( 0 ) ,
1160
1174
node_intern_event_id,
@@ -1185,6 +1199,13 @@ impl<K: DepKind> CurrentDepGraph<K> {
1185
1199
#[ cfg( debug_assertions) ]
1186
1200
self . record_edge ( dep_node_index, key, current_fingerprint) ;
1187
1201
1202
+ #[ cfg( debug_assertions) ]
1203
+ if let Some ( ref seen_dep_nodes) = self . seen_dep_nodes {
1204
+ if !seen_dep_nodes. lock ( ) . insert ( key) {
1205
+ panic ! ( "Found duplicate dep-node {key:?}" ) ;
1206
+ }
1207
+ }
1208
+
1188
1209
dep_node_index
1189
1210
}
1190
1211
0 commit comments