@@ -343,6 +343,14 @@ impl<K: DepKind> DepGraphData<K> {
343
343
task : fn ( Ctxt , A ) -> R ,
344
344
hash_result : Option < fn ( & mut StableHashingContext < ' _ > , & R ) -> Fingerprint > ,
345
345
) -> ( R , DepNodeIndex ) {
346
+ self . assert_nonexistent_node ( & key, || {
347
+ format ! (
348
+ "forcing query with already existing `DepNode`\n \
349
+ - query-key: {arg:?}\n \
350
+ - dep-node: {key:?}"
351
+ )
352
+ } ) ;
353
+
346
354
let with_deps = |task_deps| K :: with_deps ( task_deps, || task ( cx, arg) ) ;
347
355
let ( result, edges) = if cx. dep_context ( ) . is_eval_always ( key. kind ) {
348
356
( with_deps ( TaskDepsRef :: EvalAlways ) , smallvec ! [ ] )
@@ -633,6 +641,18 @@ impl<K: DepKind> DepGraph<K> {
633
641
}
634
642
635
643
impl < K : DepKind > DepGraphData < K > {
644
+ fn assert_nonexistent_node < S : std:: fmt:: Display > (
645
+ & self ,
646
+ _dep_node : & DepNode < K > ,
647
+ _msg : impl FnOnce ( ) -> S ,
648
+ ) {
649
+ #[ cfg( debug_assertions) ]
650
+ if let Some ( seen_dep_nodes) = & self . current . seen_dep_nodes {
651
+ let seen = seen_dep_nodes. lock ( ) . contains ( _dep_node) ;
652
+ assert ! ( !seen, "{}" , _msg( ) ) ;
653
+ }
654
+ }
655
+
636
656
fn node_color ( & self , dep_node : & DepNode < K > ) -> Option < DepNodeColor > {
637
657
if let Some ( prev_index) = self . previous . node_to_index_opt ( dep_node) {
638
658
self . colors . get ( prev_index)
@@ -940,6 +960,18 @@ impl<K: DepKind> DepGraph<K> {
940
960
self . node_color ( dep_node) . is_some_and ( |c| c. is_green ( ) )
941
961
}
942
962
963
+ pub fn assert_nonexistent_node < S : std:: fmt:: Display > (
964
+ & self ,
965
+ dep_node : & DepNode < K > ,
966
+ msg : impl FnOnce ( ) -> S ,
967
+ ) {
968
+ if cfg ! ( debug_assertions)
969
+ && let Some ( data) = & self . data
970
+ {
971
+ data. assert_nonexistent_node ( dep_node, msg)
972
+ }
973
+ }
974
+
943
975
/// This method loads all on-disk cacheable query results into memory, so
944
976
/// they can be written out to the new cache file again. Most query results
945
977
/// will already be in memory but in the case where we marked something as
0 commit comments