@@ -7,6 +7,7 @@ use crate::dep_graph::{DepGraphData, HasDepContext};
77use crate :: ich:: StableHashingContext ;
88use crate :: query:: caches:: QueryCache ;
99use crate :: query:: job:: { report_cycle, QueryInfo , QueryJob , QueryJobId , QueryJobInfo } ;
10+ use crate :: query:: SerializedDepNodeIndex ;
1011use crate :: query:: { QueryContext , QueryMap , QuerySideEffects , QueryStackFrame } ;
1112use crate :: values:: Value ;
1213use crate :: HandleCycleError ;
@@ -19,7 +20,6 @@ use rustc_data_structures::sharded::Sharded;
1920use rustc_data_structures:: stack:: ensure_sufficient_stack;
2021use rustc_data_structures:: sync:: { Lock , LockGuard } ;
2122use rustc_errors:: { DiagnosticBuilder , ErrorGuaranteed , FatalError } ;
22- use rustc_session:: Session ;
2323use rustc_span:: { Span , DUMMY_SP } ;
2424use std:: cell:: Cell ;
2525use std:: collections:: hash_map:: Entry ;
@@ -537,7 +537,7 @@ where
537537
538538 let ( prev_dep_node_index, dep_node_index) = dep_graph_data. try_mark_green ( qcx, & dep_node) ?;
539539
540- debug_assert ! ( dep_graph_data. is_green ( dep_node ) ) ;
540+ debug_assert ! ( dep_graph_data. is_index_green ( prev_dep_node_index ) ) ;
541541
542542 // First we try to load the result from the on-disk cache.
543543 // Some things are never cached on disk.
@@ -561,8 +561,7 @@ where
561561 dep_graph_data. mark_debug_loaded_from_disk ( * dep_node)
562562 }
563563
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) ;
566565 // If `-Zincremental-verify-ich` is specified, re-hash results from
567566 // the cache and make sure that they have the expected fingerprint.
568567 //
@@ -578,7 +577,7 @@ where
578577 * qcx. dep_context ( ) ,
579578 dep_graph_data,
580579 & result,
581- dep_node ,
580+ prev_dep_node_index ,
582581 query. hash_result ( ) ,
583582 ) ;
584583 }
@@ -623,7 +622,7 @@ where
623622 * qcx. dep_context ( ) ,
624623 dep_graph_data,
625624 & result,
626- dep_node ,
625+ prev_dep_node_index ,
627626 query. hash_result ( ) ,
628627 ) ;
629628
@@ -636,77 +635,50 @@ pub(crate) fn incremental_verify_ich<Tcx, V: Debug>(
636635 tcx : Tcx ,
637636 dep_graph_data : & DepGraphData < Tcx :: DepKind > ,
638637 result : & V ,
639- dep_node : & DepNode < Tcx :: DepKind > ,
638+ prev_index : SerializedDepNodeIndex ,
640639 hash_result : Option < fn ( & mut StableHashingContext < ' _ > , & V ) -> Fingerprint > ,
641- ) -> Fingerprint
642- where
640+ ) where
643641 Tcx : DepContext ,
644642{
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+ }
649646
650647 let new_hash = hash_result. map_or ( Fingerprint :: ZERO , |f| {
651648 tcx. with_stable_hashing_context ( |mut hcx| f ( & mut hcx, result) )
652649 } ) ;
653650
654- let old_hash = dep_graph_data. prev_fingerprint_of ( dep_node ) ;
651+ let old_hash = dep_graph_data. prev_fingerprint_of ( prev_index ) ;
655652
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, result) ;
662655 }
663-
664- new_hash
665656}
666657
667- // This DebugArg business is largely a mirror of std::fmt::ArgumentV1, which is
668- // currently not exposed publicly.
669- //
670- // The PR which added this attempted to use `&dyn Debug` instead, but that
671- // showed statistically significant worse compiler performance. It's not
672- // actually clear what the cause there was -- the code should be cold. If this
673- // can be replaced with `&dyn Debug` with on perf impact, then it probably
674- // should be.
675- extern "C" {
676- type Opaque ;
677- }
678-
679- struct DebugArg < ' a > {
680- value : & ' a Opaque ,
681- fmt : fn ( & Opaque , & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result ,
682- }
683-
684- impl < ' a , T > From < & ' a T > for DebugArg < ' a >
658+ #[ cold]
659+ #[ inline( never) ]
660+ fn incremental_verify_ich_not_green < Tcx > ( tcx : Tcx , prev_index : SerializedDepNodeIndex )
685661where
686- T : std :: fmt :: Debug ,
662+ Tcx : DepContext ,
687663{
688- fn from ( value : & ' a T ) -> DebugArg < ' a > {
689- DebugArg {
690- value : unsafe { std:: mem:: transmute ( value) } ,
691- fmt : unsafe {
692- std:: mem:: transmute ( <T as std:: fmt:: Debug >:: fmt as fn ( _, _) -> std:: fmt:: Result )
693- } ,
694- }
695- }
696- }
697-
698- impl std:: fmt:: Debug for DebugArg < ' _ > {
699- fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
700- ( self . fmt ) ( self . value , f)
701- }
664+ panic ! (
665+ "fingerprint for green query instance not loaded from cache: {:?}" ,
666+ tcx. dep_graph( ) . data( ) . unwrap( ) . prev_node_of( prev_index)
667+ )
702668}
703669
704- // Note that this is marked #[cold] and intentionally takes the equivalent of
705- // `dyn Debug` for its arguments, as we want to avoid generating a bunch of
706- // different implementations for LLVM to chew on (and filling up the final
707- // binary, too).
670+ // Note that this is marked #[cold] and intentionally takes `dyn Debug` for `result`,
671+ // as we want to avoid generating a bunch of different implementations for LLVM to
672+ // chew on (and filling up the final binary, too).
708673#[ cold]
709- fn incremental_verify_ich_failed ( sess : & Session , dep_node : DebugArg < ' _ > , result : DebugArg < ' _ > ) {
674+ #[ inline( never) ]
675+ fn incremental_verify_ich_failed < Tcx > (
676+ tcx : Tcx ,
677+ prev_index : SerializedDepNodeIndex ,
678+ result : & dyn Debug ,
679+ ) where
680+ Tcx : DepContext ,
681+ {
710682 // When we emit an error message and panic, we try to debug-print the `DepNode`
711683 // and query result. Unfortunately, this can cause us to run additional queries,
712684 // which may result in another fingerprint mismatch while we're in the middle
@@ -720,15 +692,17 @@ fn incremental_verify_ich_failed(sess: &Session, dep_node: DebugArg<'_>, result:
720692 let old_in_panic = INSIDE_VERIFY_PANIC . with ( |in_panic| in_panic. replace ( true ) ) ;
721693
722694 if old_in_panic {
723- sess. emit_err ( crate :: error:: Reentrant ) ;
695+ tcx . sess ( ) . emit_err ( crate :: error:: Reentrant ) ;
724696 } else {
725- let run_cmd = if let Some ( crate_name) = & sess. opts . crate_name {
697+ let run_cmd = if let Some ( crate_name) = & tcx . sess ( ) . opts . crate_name {
726698 format ! ( "`cargo clean -p {crate_name}` or `cargo clean`" )
727699 } else {
728700 "`cargo clean`" . to_string ( )
729701 } ;
730702
731- sess. emit_err ( crate :: error:: IncrementCompilation {
703+ let dep_node = tcx. dep_graph ( ) . data ( ) . unwrap ( ) . prev_node_of ( prev_index) ;
704+
705+ let dep_node = tcx. sess ( ) . emit_err ( crate :: error:: IncrementCompilation {
732706 run_cmd,
733707 dep_node : format ! ( "{dep_node:?}" ) ,
734708 } ) ;
0 commit comments