@@ -8,14 +8,15 @@ use std::sync::atomic::Ordering;
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,
@@ -1047,6 +1048,11 @@ pub(super) struct CurrentDepGraph<D: Deps> {
10471048 #[ cfg( debug_assertions) ]
10481049 forbidden_edge : Option < EdgeFilter > ,
10491050
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+
10501056 /// Anonymous `DepNode`s are nodes whose IDs we compute from the list of
10511057 /// their edges. This has the beneficial side-effect that multiple anonymous
10521058 /// nodes can be coalesced into one without changing the semantics of the
@@ -1068,7 +1074,7 @@ pub(super) struct CurrentDepGraph<D: Deps> {
10681074
10691075impl < D : Deps > CurrentDepGraph < D > {
10701076 fn new (
1071- profiler : & SelfProfilerRef ,
1077+ session : & Session ,
10721078 prev_graph_node_count : usize ,
10731079 encoder : FileEncoder ,
10741080 record_graph : bool ,
@@ -1100,7 +1106,7 @@ impl<D: Deps> CurrentDepGraph<D> {
11001106 prev_graph_node_count,
11011107 record_graph,
11021108 record_stats,
1103- profiler ,
1109+ & session . prof ,
11041110 previous,
11051111 ) ,
11061112 anon_node_to_index : Sharded :: new ( || {
@@ -1115,6 +1121,13 @@ impl<D: Deps> CurrentDepGraph<D> {
11151121 forbidden_edge,
11161122 #[ cfg( debug_assertions) ]
11171123 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+ } ) ,
11181131 total_read_count : AtomicU64 :: new ( 0 ) ,
11191132 total_duplicate_read_count : AtomicU64 :: new ( 0 ) ,
11201133 }
@@ -1143,6 +1156,13 @@ impl<D: Deps> CurrentDepGraph<D> {
11431156 #[ cfg( debug_assertions) ]
11441157 self . record_edge ( dep_node_index, key, current_fingerprint) ;
11451158
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+
11461166 dep_node_index
11471167 }
11481168
0 commit comments