@@ -8,14 +8,15 @@ use std::sync::Arc;
88
99use rustc_data_structures:: fingerprint:: Fingerprint ;
1010use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
11- use rustc_data_structures:: profiling:: { QueryInvocationId , SelfProfilerRef } ;
11+ use rustc_data_structures:: profiling:: QueryInvocationId ;
1212use rustc_data_structures:: sharded:: { self , Sharded } ;
1313use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
1414use rustc_data_structures:: sync:: { AtomicU32 , AtomicU64 , Lock , Lrc } ;
1515use rustc_data_structures:: unord:: UnordMap ;
1616use rustc_index:: IndexVec ;
1717use rustc_macros:: { Decodable , Encodable } ;
1818use rustc_serialize:: opaque:: { FileEncodeResult , FileEncoder } ;
19+ use rustc_session:: Session ;
1920use tracing:: { debug, instrument} ;
2021#[ cfg( debug_assertions) ]
2122use { super :: debug:: EdgeFilter , std:: env} ;
@@ -119,7 +120,7 @@ where
119120
120121impl < D : Deps > DepGraph < D > {
121122 pub fn new (
122- profiler : & SelfProfilerRef ,
123+ session : & Session ,
123124 prev_graph : Arc < SerializedDepGraph > ,
124125 prev_work_products : WorkProductMap ,
125126 encoder : FileEncoder ,
@@ -129,7 +130,7 @@ impl<D: Deps> DepGraph<D> {
129130 let prev_graph_node_count = prev_graph. node_count ( ) ;
130131
131132 let current = CurrentDepGraph :: new (
132- profiler ,
133+ session ,
133134 prev_graph_node_count,
134135 encoder,
135136 record_graph,
@@ -1057,6 +1058,11 @@ pub(super) struct CurrentDepGraph<D: Deps> {
10571058 #[ cfg( debug_assertions) ]
10581059 forbidden_edge : Option < EdgeFilter > ,
10591060
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+
10601066 /// Anonymous `DepNode`s are nodes whose IDs we compute from the list of
10611067 /// their edges. This has the beneficial side-effect that multiple anonymous
10621068 /// nodes can be coalesced into one without changing the semantics of the
@@ -1078,7 +1084,7 @@ pub(super) struct CurrentDepGraph<D: Deps> {
10781084
10791085impl < D : Deps > CurrentDepGraph < D > {
10801086 fn new (
1081- profiler : & SelfProfilerRef ,
1087+ session : & Session ,
10821088 prev_graph_node_count : usize ,
10831089 encoder : FileEncoder ,
10841090 record_graph : bool ,
@@ -1110,7 +1116,7 @@ impl<D: Deps> CurrentDepGraph<D> {
11101116 prev_graph_node_count,
11111117 record_graph,
11121118 record_stats,
1113- profiler ,
1119+ & session . prof ,
11141120 previous,
11151121 ) ,
11161122 anon_node_to_index : Sharded :: new ( || {
@@ -1125,6 +1131,13 @@ impl<D: Deps> CurrentDepGraph<D> {
11251131 forbidden_edge,
11261132 #[ cfg( debug_assertions) ]
11271133 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+ } ) ,
11281141 total_read_count : AtomicU64 :: new ( 0 ) ,
11291142 total_duplicate_read_count : AtomicU64 :: new ( 0 ) ,
11301143 }
@@ -1153,6 +1166,13 @@ impl<D: Deps> CurrentDepGraph<D> {
11531166 #[ cfg( debug_assertions) ]
11541167 self . record_edge ( dep_node_index, key, current_fingerprint) ;
11551168
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+
11561176 dep_node_index
11571177 }
11581178
0 commit comments