@@ -8,14 +8,15 @@ use std::sync::atomic::Ordering;
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,
@@ -1047,6 +1048,11 @@ pub(super) struct CurrentDepGraph<D: Deps> {
1047
1048
#[ cfg( debug_assertions) ]
1048
1049
forbidden_edge : Option < EdgeFilter > ,
1049
1050
1051
+ /// Used to verify the absence of hash collisions among DepNodes.
1052
+ /// This field is only `Some` if the `-Z incremental_verify_depnodes` option is present.
1053
+ #[ cfg( debug_assertions) ]
1054
+ seen_dep_nodes : Option < Lock < FxHashSet < DepNode > > > ,
1055
+
1050
1056
/// Anonymous `DepNode`s are nodes whose IDs we compute from the list of
1051
1057
/// their edges. This has the beneficial side-effect that multiple anonymous
1052
1058
/// nodes can be coalesced into one without changing the semantics of the
@@ -1068,7 +1074,7 @@ pub(super) struct CurrentDepGraph<D: Deps> {
1068
1074
1069
1075
impl < D : Deps > CurrentDepGraph < D > {
1070
1076
fn new (
1071
- profiler : & SelfProfilerRef ,
1077
+ session : & Session ,
1072
1078
prev_graph_node_count : usize ,
1073
1079
encoder : FileEncoder ,
1074
1080
record_graph : bool ,
@@ -1100,7 +1106,7 @@ impl<D: Deps> CurrentDepGraph<D> {
1100
1106
prev_graph_node_count,
1101
1107
record_graph,
1102
1108
record_stats,
1103
- profiler ,
1109
+ & session . prof ,
1104
1110
previous,
1105
1111
) ,
1106
1112
anon_node_to_index : Sharded :: new ( || {
@@ -1115,6 +1121,13 @@ impl<D: Deps> CurrentDepGraph<D> {
1115
1121
forbidden_edge,
1116
1122
#[ cfg( debug_assertions) ]
1117
1123
fingerprints : Lock :: new ( IndexVec :: from_elem_n ( None , new_node_count_estimate) ) ,
1124
+ #[ cfg( debug_assertions) ]
1125
+ seen_dep_nodes : session. opts . unstable_opts . incremental_verify_depnodes . then ( || {
1126
+ Lock :: new ( FxHashSet :: with_capacity_and_hasher (
1127
+ new_node_count_estimate,
1128
+ Default :: default ( ) ,
1129
+ ) )
1130
+ } ) ,
1118
1131
total_read_count : AtomicU64 :: new ( 0 ) ,
1119
1132
total_duplicate_read_count : AtomicU64 :: new ( 0 ) ,
1120
1133
}
@@ -1143,6 +1156,13 @@ impl<D: Deps> CurrentDepGraph<D> {
1143
1156
#[ cfg( debug_assertions) ]
1144
1157
self . record_edge ( dep_node_index, key, current_fingerprint) ;
1145
1158
1159
+ #[ cfg( debug_assertions) ]
1160
+ if let Some ( ref seen_dep_nodes) = self . seen_dep_nodes {
1161
+ if !seen_dep_nodes. lock ( ) . insert ( key) {
1162
+ panic ! ( "Found duplicate dep-node {key:?}" ) ;
1163
+ }
1164
+ }
1165
+
1146
1166
dep_node_index
1147
1167
}
1148
1168
0 commit comments