@@ -8,14 +8,15 @@ use std::sync::Arc;
8
8
9
9
use rustc_data_structures:: fingerprint:: Fingerprint ;
10
10
use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
11
- use rustc_data_structures:: profiling:: { QueryInvocationId , SelfProfilerRef } ;
11
+ use rustc_data_structures:: profiling:: QueryInvocationId ;
12
12
use rustc_data_structures:: sharded:: { self , Sharded } ;
13
13
use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
14
14
use rustc_data_structures:: sync:: { AtomicU32 , AtomicU64 , Lock , Lrc } ;
15
15
use rustc_data_structures:: unord:: UnordMap ;
16
16
use rustc_index:: IndexVec ;
17
17
use rustc_macros:: { Decodable , Encodable } ;
18
18
use rustc_serialize:: opaque:: { FileEncodeResult , FileEncoder } ;
19
+ use rustc_session:: Session ;
19
20
use tracing:: { debug, instrument} ;
20
21
#[ cfg( debug_assertions) ]
21
22
use { super :: debug:: EdgeFilter , std:: env} ;
@@ -119,7 +120,7 @@ where
119
120
120
121
impl < D : Deps > DepGraph < D > {
121
122
pub fn new (
122
- profiler : & SelfProfilerRef ,
123
+ session : & Session ,
123
124
prev_graph : Arc < SerializedDepGraph > ,
124
125
prev_work_products : WorkProductMap ,
125
126
encoder : FileEncoder ,
@@ -129,7 +130,7 @@ impl<D: Deps> DepGraph<D> {
129
130
let prev_graph_node_count = prev_graph. node_count ( ) ;
130
131
131
132
let current = CurrentDepGraph :: new (
132
- profiler ,
133
+ session ,
133
134
prev_graph_node_count,
134
135
encoder,
135
136
record_graph,
@@ -1057,6 +1058,11 @@ pub(super) struct CurrentDepGraph<D: Deps> {
1057
1058
#[ cfg( debug_assertions) ]
1058
1059
forbidden_edge : Option < EdgeFilter > ,
1059
1060
1061
+ /// Used to verify the absence of hash collisions among DepNodes.
1062
+ /// This field is only `Some` if the `-Z incremental_verify_depnodes` option is present.
1063
+ #[ cfg( debug_assertions) ]
1064
+ seen_dep_nodes : Option < Lock < FxHashSet < DepNode > > > ,
1065
+
1060
1066
/// Anonymous `DepNode`s are nodes whose IDs we compute from the list of
1061
1067
/// their edges. This has the beneficial side-effect that multiple anonymous
1062
1068
/// nodes can be coalesced into one without changing the semantics of the
@@ -1078,7 +1084,7 @@ pub(super) struct CurrentDepGraph<D: Deps> {
1078
1084
1079
1085
impl < D : Deps > CurrentDepGraph < D > {
1080
1086
fn new (
1081
- profiler : & SelfProfilerRef ,
1087
+ session : & Session ,
1082
1088
prev_graph_node_count : usize ,
1083
1089
encoder : FileEncoder ,
1084
1090
record_graph : bool ,
@@ -1110,7 +1116,7 @@ impl<D: Deps> CurrentDepGraph<D> {
1110
1116
prev_graph_node_count,
1111
1117
record_graph,
1112
1118
record_stats,
1113
- profiler ,
1119
+ & session . prof ,
1114
1120
previous,
1115
1121
) ,
1116
1122
anon_node_to_index : Sharded :: new ( || {
@@ -1125,6 +1131,13 @@ impl<D: Deps> CurrentDepGraph<D> {
1125
1131
forbidden_edge,
1126
1132
#[ cfg( debug_assertions) ]
1127
1133
fingerprints : Lock :: new ( IndexVec :: from_elem_n ( None , new_node_count_estimate) ) ,
1134
+ #[ cfg( debug_assertions) ]
1135
+ seen_dep_nodes : session. opts . unstable_opts . incremental_verify_depnodes . then ( || {
1136
+ Lock :: new ( FxHashSet :: with_capacity_and_hasher (
1137
+ new_node_count_estimate,
1138
+ Default :: default ( ) ,
1139
+ ) )
1140
+ } ) ,
1128
1141
total_read_count : AtomicU64 :: new ( 0 ) ,
1129
1142
total_duplicate_read_count : AtomicU64 :: new ( 0 ) ,
1130
1143
}
@@ -1153,6 +1166,13 @@ impl<D: Deps> CurrentDepGraph<D> {
1153
1166
#[ cfg( debug_assertions) ]
1154
1167
self . record_edge ( dep_node_index, key, current_fingerprint) ;
1155
1168
1169
+ #[ cfg( debug_assertions) ]
1170
+ if let Some ( ref seen_dep_nodes) = self . seen_dep_nodes {
1171
+ if !seen_dep_nodes. lock ( ) . insert ( key) {
1172
+ panic ! ( "Found duplicate dep-node {key:?}" ) ;
1173
+ }
1174
+ }
1175
+
1156
1176
dep_node_index
1157
1177
}
1158
1178
0 commit comments