@@ -17,7 +17,6 @@ use rustc_data_structures::sharded::Sharded;
17
17
use rustc_data_structures:: sync:: { Lock , LockGuard } ;
18
18
use rustc_data_structures:: thin_vec:: ThinVec ;
19
19
use rustc_errors:: { Diagnostic , FatalError } ;
20
- use rustc_span:: source_map:: DUMMY_SP ;
21
20
use rustc_span:: Span ;
22
21
use std:: collections:: hash_map:: Entry ;
23
22
use std:: fmt:: Debug ;
@@ -641,31 +640,26 @@ where
641
640
642
641
/// Ensure that either this query has all green inputs or been executed.
643
642
/// Executing `query::ensure(D)` is considered a read of the dep-node `D`.
643
+ /// Returns true if the query should still run.
644
644
///
645
645
/// This function is particularly useful when executing passes for their
646
646
/// side-effects -- e.g., in order to report errors for erroneous programs.
647
647
///
648
648
/// Note: The optimization is only available during incr. comp.
649
649
#[ inline( never) ]
650
- fn ensure_query_impl < CTX , C > (
651
- tcx : CTX ,
652
- state : & QueryState < CTX :: DepKind , CTX :: Query , C > ,
653
- key : C :: Key ,
654
- query : & QueryVtable < CTX , C :: Key , C :: Value > ,
655
- ) where
656
- C : QueryCache ,
657
- C :: Key : crate :: dep_graph:: DepNodeParams < CTX > ,
650
+ fn ensure_must_run < CTX , K , V > ( tcx : CTX , key : & K , query : & QueryVtable < CTX , K , V > ) -> bool
651
+ where
652
+ K : crate :: dep_graph:: DepNodeParams < CTX > ,
658
653
CTX : QueryContext ,
659
654
{
660
655
if query. eval_always {
661
- let _ = get_query_impl ( tcx, state, DUMMY_SP , key, query) ;
662
- return ;
656
+ return true ;
663
657
}
664
658
665
659
// Ensuring an anonymous query makes no sense
666
660
assert ! ( !query. anon) ;
667
661
668
- let dep_node = query. to_dep_node ( tcx, & key) ;
662
+ let dep_node = query. to_dep_node ( tcx, key) ;
669
663
670
664
match tcx. dep_graph ( ) . try_mark_green_and_read ( tcx, & dep_node) {
671
665
None => {
@@ -675,10 +669,11 @@ fn ensure_query_impl<CTX, C>(
675
669
// DepNodeIndex. We must invoke the query itself. The performance cost
676
670
// this introduces should be negligible as we'll immediately hit the
677
671
// in-memory cache, or another query down the line will.
678
- let _ = get_query_impl ( tcx , state , DUMMY_SP , key , query ) ;
672
+ true
679
673
}
680
674
Some ( ( _, dep_node_index) ) => {
681
675
tcx. profiler ( ) . query_cache_hit ( dep_node_index. into ( ) ) ;
676
+ false
682
677
}
683
678
}
684
679
}
@@ -720,24 +715,27 @@ fn force_query_impl<CTX, C>(
720
715
) ;
721
716
}
722
717
723
- pub fn get_query < Q , CTX > ( tcx : CTX , span : Span , key : Q :: Key ) -> Q :: Stored
724
- where
725
- Q : QueryDescription < CTX > ,
726
- Q :: Key : crate :: dep_graph:: DepNodeParams < CTX > ,
727
- CTX : QueryContext ,
728
- {
729
- debug ! ( "ty::query::get_query<{}>(key={:?}, span={:?})" , Q :: NAME , key, span) ;
730
-
731
- get_query_impl ( tcx, Q :: query_state ( tcx) , span, key, & Q :: VTABLE )
718
+ pub enum QueryMode {
719
+ Get ,
720
+ Ensure ,
732
721
}
733
722
734
- pub fn ensure_query < Q , CTX > ( tcx : CTX , key : Q :: Key )
723
+ pub fn get_query < Q , CTX > ( tcx : CTX , span : Span , key : Q :: Key , mode : QueryMode ) -> Option < Q :: Stored >
735
724
where
736
725
Q : QueryDescription < CTX > ,
737
726
Q :: Key : crate :: dep_graph:: DepNodeParams < CTX > ,
738
727
CTX : QueryContext ,
739
728
{
740
- ensure_query_impl ( tcx, Q :: query_state ( tcx) , key, & Q :: VTABLE )
729
+ let query = & Q :: VTABLE ;
730
+ if let QueryMode :: Ensure = mode {
731
+ if !ensure_must_run ( tcx, & key, query) {
732
+ return None ;
733
+ }
734
+ }
735
+
736
+ debug ! ( "ty::query::get_query<{}>(key={:?}, span={:?})" , Q :: NAME , key, span) ;
737
+ let value = get_query_impl ( tcx, Q :: query_state ( tcx) , span, key, query) ;
738
+ Some ( value)
741
739
}
742
740
743
741
pub fn force_query < Q , CTX > ( tcx : CTX , key : Q :: Key , span : Span , dep_node : DepNode < CTX :: DepKind > )
0 commit comments