@@ -7,6 +7,7 @@ use crate::dep_graph::{DepGraphData, HasDepContext};
7
7
use crate :: ich:: StableHashingContext ;
8
8
use crate :: query:: caches:: QueryCache ;
9
9
use crate :: query:: job:: { report_cycle, QueryInfo , QueryJob , QueryJobId , QueryJobInfo } ;
10
+ use crate :: query:: SerializedDepNodeIndex ;
10
11
use crate :: query:: { QueryContext , QueryMap , QuerySideEffects , QueryStackFrame } ;
11
12
use crate :: values:: Value ;
12
13
use crate :: HandleCycleError ;
@@ -19,7 +20,6 @@ use rustc_data_structures::sharded::Sharded;
19
20
use rustc_data_structures:: stack:: ensure_sufficient_stack;
20
21
use rustc_data_structures:: sync:: { Lock , LockGuard } ;
21
22
use rustc_errors:: { DiagnosticBuilder , ErrorGuaranteed , FatalError } ;
22
- use rustc_session:: Session ;
23
23
use rustc_span:: { Span , DUMMY_SP } ;
24
24
use std:: cell:: Cell ;
25
25
use std:: collections:: hash_map:: Entry ;
@@ -537,7 +537,7 @@ where
537
537
538
538
let ( prev_dep_node_index, dep_node_index) = dep_graph_data. try_mark_green ( qcx, & dep_node) ?;
539
539
540
- debug_assert ! ( dep_graph_data. is_green ( dep_node ) ) ;
540
+ debug_assert ! ( dep_graph_data. is_index_green ( prev_dep_node_index ) ) ;
541
541
542
542
// First we try to load the result from the on-disk cache.
543
543
// Some things are never cached on disk.
@@ -561,8 +561,7 @@ where
561
561
dep_graph_data. mark_debug_loaded_from_disk ( * dep_node)
562
562
}
563
563
564
- let prev_fingerprint =
565
- dep_graph_data. prev_fingerprint_of ( dep_node) . unwrap_or ( Fingerprint :: ZERO ) ;
564
+ let prev_fingerprint = dep_graph_data. prev_fingerprint_of ( prev_dep_node_index) ;
566
565
// If `-Zincremental-verify-ich` is specified, re-hash results from
567
566
// the cache and make sure that they have the expected fingerprint.
568
567
//
@@ -578,7 +577,7 @@ where
578
577
* qcx. dep_context ( ) ,
579
578
dep_graph_data,
580
579
& result,
581
- dep_node ,
580
+ prev_dep_node_index ,
582
581
query. hash_result ( ) ,
583
582
) ;
584
583
}
@@ -623,7 +622,7 @@ where
623
622
* qcx. dep_context ( ) ,
624
623
dep_graph_data,
625
624
& result,
626
- dep_node ,
625
+ prev_dep_node_index ,
627
626
query. hash_result ( ) ,
628
627
) ;
629
628
@@ -636,32 +635,38 @@ pub(crate) fn incremental_verify_ich<Tcx, V: Debug>(
636
635
tcx : Tcx ,
637
636
dep_graph_data : & DepGraphData < Tcx :: DepKind > ,
638
637
result : & V ,
639
- dep_node : & DepNode < Tcx :: DepKind > ,
638
+ prev_index : SerializedDepNodeIndex ,
640
639
hash_result : Option < fn ( & mut StableHashingContext < ' _ > , & V ) -> Fingerprint > ,
641
- ) -> Fingerprint
642
- where
640
+ ) where
643
641
Tcx : DepContext ,
644
642
{
645
- assert ! (
646
- dep_graph_data. is_green( dep_node) ,
647
- "fingerprint for green query instance not loaded from cache: {dep_node:?}" ,
648
- ) ;
643
+ if !dep_graph_data. is_index_green ( prev_index) {
644
+ incremental_verify_ich_not_green :: < Tcx > ( prev_index)
645
+ }
649
646
650
647
let new_hash = hash_result. map_or ( Fingerprint :: ZERO , |f| {
651
648
tcx. with_stable_hashing_context ( |mut hcx| f ( & mut hcx, result) )
652
649
} ) ;
653
650
654
- let old_hash = dep_graph_data. prev_fingerprint_of ( dep_node ) ;
651
+ let old_hash = dep_graph_data. prev_fingerprint_of ( prev_index ) ;
655
652
656
- if Some ( new_hash) != old_hash {
657
- incremental_verify_ich_failed (
658
- tcx. sess ( ) ,
659
- DebugArg :: from ( & dep_node) ,
660
- DebugArg :: from ( & result) ,
661
- ) ;
653
+ if new_hash != old_hash {
654
+ incremental_verify_ich_failed :: < Tcx > ( prev_index, DebugArg :: from ( & result) ) ;
662
655
}
656
+ }
663
657
664
- new_hash
658
+ #[ cold]
659
+ #[ inline( never) ]
660
+ fn incremental_verify_ich_not_green < Tcx > ( prev_index : SerializedDepNodeIndex )
661
+ where
662
+ Tcx : DepContext ,
663
+ {
664
+ Tcx :: with_context ( |tcx| {
665
+ panic ! (
666
+ "fingerprint for green query instance not loaded from cache: {:?}" ,
667
+ tcx. dep_graph( ) . data( ) . unwrap( ) . prev_node_of( prev_index)
668
+ )
669
+ } )
665
670
}
666
671
667
672
// This DebugArg business is largely a mirror of std::fmt::ArgumentV1, which is
@@ -706,7 +711,11 @@ impl std::fmt::Debug for DebugArg<'_> {
706
711
// different implementations for LLVM to chew on (and filling up the final
707
712
// binary, too).
708
713
#[ cold]
709
- fn incremental_verify_ich_failed ( sess : & Session , dep_node : DebugArg < ' _ > , result : DebugArg < ' _ > ) {
714
+ #[ inline( never) ]
715
+ fn incremental_verify_ich_failed < Tcx > ( prev_index : SerializedDepNodeIndex , result : DebugArg < ' _ > )
716
+ where
717
+ Tcx : DepContext ,
718
+ {
710
719
// When we emit an error message and panic, we try to debug-print the `DepNode`
711
720
// and query result. Unfortunately, this can cause us to run additional queries,
712
721
// which may result in another fingerprint mismatch while we're in the middle
@@ -719,21 +728,25 @@ fn incremental_verify_ich_failed(sess: &Session, dep_node: DebugArg<'_>, result:
719
728
720
729
let old_in_panic = INSIDE_VERIFY_PANIC . with ( |in_panic| in_panic. replace ( true ) ) ;
721
730
722
- if old_in_panic {
723
- sess. emit_err ( crate :: error:: Reentrant ) ;
724
- } else {
725
- let run_cmd = if let Some ( crate_name) = & sess. opts . crate_name {
726
- format ! ( "`cargo clean -p {crate_name}` or `cargo clean`" )
731
+ Tcx :: with_context ( |tcx| {
732
+ if old_in_panic {
733
+ tcx. sess ( ) . emit_err ( crate :: error:: Reentrant ) ;
727
734
} else {
728
- "`cargo clean`" . to_string ( )
729
- } ;
735
+ let run_cmd = if let Some ( crate_name) = & tcx. sess ( ) . opts . crate_name {
736
+ format ! ( "`cargo clean -p {crate_name}` or `cargo clean`" )
737
+ } else {
738
+ "`cargo clean`" . to_string ( )
739
+ } ;
730
740
731
- sess. emit_err ( crate :: error:: IncrementCompilation {
732
- run_cmd,
733
- dep_node : format ! ( "{dep_node:?}" ) ,
734
- } ) ;
735
- panic ! ( "Found unstable fingerprints for {dep_node:?}: {result:?}" ) ;
736
- }
741
+ let dep_node = tcx. dep_graph ( ) . data ( ) . unwrap ( ) . prev_node_of ( prev_index) ;
742
+
743
+ let dep_node = tcx. sess ( ) . emit_err ( crate :: error:: IncrementCompilation {
744
+ run_cmd,
745
+ dep_node : format ! ( "{dep_node:?}" ) ,
746
+ } ) ;
747
+ panic ! ( "Found unstable fingerprints for {dep_node:?}: {result:?}" ) ;
748
+ }
749
+ } ) ;
737
750
738
751
INSIDE_VERIFY_PANIC . with ( |in_panic| in_panic. set ( old_in_panic) ) ;
739
752
}
0 commit comments