@@ -346,6 +346,14 @@ impl<D: Deps> DepGraphData<D> {
346
346
task : fn ( Ctxt , A ) -> R ,
347
347
hash_result : Option < fn ( & mut StableHashingContext < ' _ > , & R ) -> Fingerprint > ,
348
348
) -> ( R , DepNodeIndex ) {
349
+ self . assert_nonexistent_node ( & key, || {
350
+ format ! (
351
+ "forcing query with already existing `DepNode`\n \
352
+ - query-key: {arg:?}\n \
353
+ - dep-node: {key:?}"
354
+ )
355
+ } ) ;
356
+
349
357
let with_deps = |task_deps| D :: with_deps ( task_deps, || task ( cx, arg) ) ;
350
358
let ( result, edges) = if cx. dep_context ( ) . is_eval_always ( key. kind ) {
351
359
( with_deps ( TaskDepsRef :: EvalAlways ) , EdgesVec :: new ( ) )
@@ -620,6 +628,18 @@ impl<D: Deps> DepGraph<D> {
620
628
}
621
629
622
630
impl < D : Deps > DepGraphData < D > {
631
+ fn assert_nonexistent_node < S : std:: fmt:: Display > (
632
+ & self ,
633
+ _dep_node : & DepNode ,
634
+ _msg : impl FnOnce ( ) -> S ,
635
+ ) {
636
+ #[ cfg( debug_assertions) ]
637
+ if let Some ( seen_dep_nodes) = & self . current . seen_dep_nodes {
638
+ let seen = seen_dep_nodes. lock ( ) . contains ( _dep_node) ;
639
+ assert ! ( !seen, "{}" , _msg( ) ) ;
640
+ }
641
+ }
642
+
623
643
fn node_color ( & self , dep_node : & DepNode ) -> Option < DepNodeColor > {
624
644
if let Some ( prev_index) = self . previous . node_to_index_opt ( dep_node) {
625
645
self . colors . get ( prev_index)
@@ -914,6 +934,18 @@ impl<D: Deps> DepGraph<D> {
914
934
self . node_color ( dep_node) . is_some_and ( |c| c. is_green ( ) )
915
935
}
916
936
937
+ pub fn assert_nonexistent_node < S : std:: fmt:: Display > (
938
+ & self ,
939
+ dep_node : & DepNode ,
940
+ msg : impl FnOnce ( ) -> S ,
941
+ ) {
942
+ if cfg ! ( debug_assertions)
943
+ && let Some ( data) = & self . data
944
+ {
945
+ data. assert_nonexistent_node ( dep_node, msg)
946
+ }
947
+ }
948
+
917
949
/// This method loads all on-disk cacheable query results into memory, so
918
950
/// they can be written out to the new cache file again. Most query results
919
951
/// will already be in memory but in the case where we marked something as
0 commit comments