@@ -8,6 +8,7 @@ use rustc_data_structures::steal::Steal;
88use rustc_data_structures:: sync:: { AtomicU32 , AtomicU64 , Lock , Lrc , Ordering } ;
99use rustc_index:: IndexVec ;
1010use rustc_serialize:: opaque:: { FileEncodeResult , FileEncoder } ;
11+ use rustc_session:: Session ;
1112use smallvec:: { smallvec, SmallVec } ;
1213use std:: assert_matches:: assert_matches;
1314use std:: collections:: hash_map:: Entry ;
@@ -114,7 +115,7 @@ where
114115
115116impl < K : DepKind > DepGraph < K > {
116117 pub fn new (
117- profiler : & SelfProfilerRef ,
118+ session : & Session ,
118119 prev_graph : SerializedDepGraph < K > ,
119120 prev_work_products : FxHashMap < WorkProductId , WorkProduct > ,
120121 encoder : FileEncoder ,
@@ -124,7 +125,7 @@ impl<K: DepKind> DepGraph<K> {
124125 let prev_graph_node_count = prev_graph. node_count ( ) ;
125126
126127 let current = CurrentDepGraph :: new (
127- profiler ,
128+ session ,
128129 prev_graph_node_count,
129130 encoder,
130131 record_graph,
@@ -135,7 +136,7 @@ impl<K: DepKind> DepGraph<K> {
135136
136137 // Instantiate a dependy-less node only once for anonymous queries.
137138 let _green_node_index = current. intern_new_node (
138- profiler ,
139+ & session . prof ,
139140 DepNode { kind : DepKind :: NULL , hash : current. anon_id_seed . into ( ) } ,
140141 smallvec ! [ ] ,
141142 Fingerprint :: ZERO ,
@@ -144,7 +145,7 @@ impl<K: DepKind> DepGraph<K> {
144145
145146 // Instantiate a dependy-less red node only once for anonymous queries.
146147 let ( red_node_index, red_node_prev_index_and_color) = current. intern_node (
147- profiler ,
148+ & session . prof ,
148149 & prev_graph,
149150 DepNode { kind : DepKind :: RED , hash : Fingerprint :: ZERO . into ( ) } ,
150151 smallvec ! [ ] ,
@@ -1075,6 +1076,11 @@ pub(super) struct CurrentDepGraph<K: DepKind> {
10751076 #[ cfg( debug_assertions) ]
10761077 forbidden_edge : Option < EdgeFilter < K > > ,
10771078
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+
10781084 /// Anonymous `DepNode`s are nodes whose IDs we compute from the list of
10791085 /// their edges. This has the beneficial side-effect that multiple anonymous
10801086 /// nodes can be coalesced into one without changing the semantics of the
@@ -1102,7 +1108,7 @@ pub(super) struct CurrentDepGraph<K: DepKind> {
11021108
11031109impl < K : DepKind > CurrentDepGraph < K > {
11041110 fn new (
1105- profiler : & SelfProfilerRef ,
1111+ session : & Session ,
11061112 prev_graph_node_count : usize ,
11071113 encoder : FileEncoder ,
11081114 record_graph : bool ,
@@ -1132,7 +1138,8 @@ impl<K: DepKind> CurrentDepGraph<K> {
11321138
11331139 let new_node_count_estimate = 102 * prev_graph_node_count / 100 + 200 ;
11341140
1135- let node_intern_event_id = profiler
1141+ let node_intern_event_id = session
1142+ . prof
11361143 . get_or_alloc_cached_string ( "incr_comp_intern_dep_graph_node" )
11371144 . map ( EventId :: from_label) ;
11381145
@@ -1155,6 +1162,13 @@ impl<K: DepKind> CurrentDepGraph<K> {
11551162 forbidden_edge,
11561163 #[ cfg( debug_assertions) ]
11571164 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+ } ) ,
11581172 total_read_count : AtomicU64 :: new ( 0 ) ,
11591173 total_duplicate_read_count : AtomicU64 :: new ( 0 ) ,
11601174 node_intern_event_id,
@@ -1185,6 +1199,13 @@ impl<K: DepKind> CurrentDepGraph<K> {
11851199 #[ cfg( debug_assertions) ]
11861200 self . record_edge ( dep_node_index, key, current_fingerprint) ;
11871201
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+
11881209 dep_node_index
11891210 }
11901211
0 commit comments