@@ -349,7 +349,7 @@ impl<K: DepKind> DepGraphData<K> {
349349 // in `DepGraph::try_mark_green()`.
350350 // 2. Two distinct query keys get mapped to the same `DepNode`
351351 // (see for example #48923).
352- self . assert_nonexistent_node ( & key, || {
352+ self . assert_dep_node_not_yet_allocated_in_current_session ( & key, || {
353353 format ! (
354354 "forcing query with already existing `DepNode`\n \
355355 - query-key: {arg:?}\n \
@@ -647,14 +647,19 @@ impl<K: DepKind> DepGraph<K> {
647647}
648648
649649impl < K : DepKind > DepGraphData < K > {
650- fn assert_nonexistent_node < S : std:: fmt:: Display > (
650+ fn assert_dep_node_not_yet_allocated_in_current_session < S : std:: fmt:: Display > (
651651 & self ,
652652 _dep_node : & DepNode < K > ,
653653 _msg : impl FnOnce ( ) -> S ,
654654 ) {
655655 #[ cfg( debug_assertions) ]
656- if let Some ( seen_dep_nodes) = & self . current . seen_dep_nodes {
657- let seen = seen_dep_nodes. lock ( ) . contains ( _dep_node) ;
656+ if let Some ( prev_index) = self . previous . node_to_index_opt ( _dep_node) {
657+ let current = self . current . prev_index_to_index . lock ( ) [ prev_index] ;
658+ assert ! ( current. is_none( ) , "{}" , _msg( ) )
659+ } else if let Some ( nodes_newly_allocated_in_current_session) =
660+ & self . current . nodes_newly_allocated_in_current_session
661+ {
662+ let seen = nodes_newly_allocated_in_current_session. lock ( ) . contains ( _dep_node) ;
658663 assert ! ( !seen, "{}" , _msg( ) ) ;
659664 }
660665 }
@@ -871,7 +876,7 @@ impl<K: DepKind> DepGraphData<K> {
871876 let frame = MarkFrame { index : prev_dep_node_index, parent : frame } ;
872877
873878 #[ cfg( not( parallel_compiler) ) ]
874- self . assert_nonexistent_node ( dep_node, || {
879+ self . assert_dep_node_not_yet_allocated_in_current_session ( dep_node, || {
875880 format ! ( "trying to mark existing {dep_node:?} as green" )
876881 } ) ;
877882 #[ cfg( not( parallel_compiler) ) ]
@@ -970,15 +975,15 @@ impl<K: DepKind> DepGraph<K> {
970975 self . node_color ( dep_node) . is_some_and ( |c| c. is_green ( ) )
971976 }
972977
973- pub fn assert_nonexistent_node < S : std:: fmt:: Display > (
978+ pub fn assert_dep_node_not_yet_allocated_in_current_session < S : std:: fmt:: Display > (
974979 & self ,
975980 dep_node : & DepNode < K > ,
976981 msg : impl FnOnce ( ) -> S ,
977982 ) {
978983 if cfg ! ( debug_assertions)
979984 && let Some ( data) = & self . data
980985 {
981- data. assert_nonexistent_node ( dep_node, msg)
986+ data. assert_dep_node_not_yet_allocated_in_current_session ( dep_node, msg)
982987 }
983988 }
984989
@@ -1120,8 +1125,11 @@ pub(super) struct CurrentDepGraph<K: DepKind> {
11201125
11211126 /// Used to verify the absence of hash collisions among DepNodes.
11221127 /// This field is only `Some` if the `-Z incremental_verify_ich` option is present.
1128+ ///
1129+ /// The map contains all DepNodes that have been allocated in the current session so far and
1130+ /// for which there is no equivalent in the previous session.
11231131 #[ cfg( debug_assertions) ]
1124- seen_dep_nodes : Option < Lock < FxHashSet < DepNode < K > > > > ,
1132+ nodes_newly_allocated_in_current_session : Option < Lock < FxHashSet < DepNode < K > > > > ,
11251133
11261134 /// Anonymous `DepNode`s are nodes whose IDs we compute from the list of
11271135 /// their edges. This has the beneficial side-effect that multiple anonymous
@@ -1205,12 +1213,16 @@ impl<K: DepKind> CurrentDepGraph<K> {
12051213 #[ cfg( debug_assertions) ]
12061214 fingerprints : Lock :: new ( IndexVec :: from_elem_n ( None , new_node_count_estimate) ) ,
12071215 #[ cfg( debug_assertions) ]
1208- seen_dep_nodes : session. opts . unstable_opts . incremental_verify_ich . then ( || {
1209- Lock :: new ( FxHashSet :: with_capacity_and_hasher (
1210- new_node_count_estimate,
1211- Default :: default ( ) ,
1212- ) )
1213- } ) ,
1216+ nodes_newly_allocated_in_current_session : session
1217+ . opts
1218+ . unstable_opts
1219+ . incremental_verify_ich
1220+ . then ( || {
1221+ Lock :: new ( FxHashSet :: with_capacity_and_hasher (
1222+ new_node_count_estimate,
1223+ Default :: default ( ) ,
1224+ ) )
1225+ } ) ,
12141226 total_read_count : AtomicU64 :: new ( 0 ) ,
12151227 total_duplicate_read_count : AtomicU64 :: new ( 0 ) ,
12161228 node_intern_event_id,
@@ -1242,8 +1254,10 @@ impl<K: DepKind> CurrentDepGraph<K> {
12421254 self . record_edge ( dep_node_index, key, current_fingerprint) ;
12431255
12441256 #[ cfg( debug_assertions) ]
1245- if let Some ( ref seen_dep_nodes) = self . seen_dep_nodes {
1246- if !seen_dep_nodes. lock ( ) . insert ( key) {
1257+ if let Some ( ref nodes_newly_allocated_in_current_session) =
1258+ self . nodes_newly_allocated_in_current_session
1259+ {
1260+ if !nodes_newly_allocated_in_current_session. lock ( ) . insert ( key) {
12471261 panic ! ( "Found duplicate dep-node {key:?}" ) ;
12481262 }
12491263 }
0 commit comments