@@ -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:: hash:: { Hash , Hasher } ;
@@ -656,25 +655,19 @@ where
656
655
///
657
656
/// Note: The optimization is only available during incr. comp.
658
657
#[ inline( never) ]
659
- fn ensure_query_impl < CTX , C > (
660
- tcx : CTX ,
661
- state : & QueryState < CTX :: DepKind , CTX :: Query , C > ,
662
- key : C :: Key ,
663
- query : & QueryVtable < CTX , C :: Key , C :: Value > ,
664
- ) where
665
- C : QueryCache ,
666
- C :: Key : crate :: dep_graph:: DepNodeParams < CTX > ,
658
+ fn ensure_query_impl < CTX , K , V > ( tcx : CTX , key : & K , query : & QueryVtable < CTX , K , V > ) -> bool
659
+ where
660
+ K : crate :: dep_graph:: DepNodeParams < CTX > ,
667
661
CTX : QueryContext ,
668
662
{
669
663
if query. eval_always {
670
- let _ = get_query_impl ( tcx, state, DUMMY_SP , key, query) ;
671
- return ;
664
+ return false ;
672
665
}
673
666
674
667
// Ensuring an anonymous query makes no sense
675
668
assert ! ( !query. anon) ;
676
669
677
- let dep_node = query. to_dep_node ( tcx, & key) ;
670
+ let dep_node = query. to_dep_node ( tcx, key) ;
678
671
679
672
match tcx. dep_graph ( ) . try_mark_green_and_read ( tcx, & dep_node) {
680
673
None => {
@@ -684,10 +677,11 @@ fn ensure_query_impl<CTX, C>(
684
677
// DepNodeIndex. We must invoke the query itself. The performance cost
685
678
// this introduces should be negligible as we'll immediately hit the
686
679
// in-memory cache, or another query down the line will.
687
- let _ = get_query_impl ( tcx , state , DUMMY_SP , key , query ) ;
680
+ false
688
681
}
689
682
Some ( ( _, dep_node_index) ) => {
690
683
tcx. profiler ( ) . query_cache_hit ( dep_node_index. into ( ) ) ;
684
+ true
691
685
}
692
686
}
693
687
}
@@ -752,7 +746,10 @@ where
752
746
{
753
747
match caller {
754
748
QueryCaller :: Ensure => {
755
- ensure_query_impl ( tcx, state, key, query) ;
749
+ if ensure_query_impl ( tcx, & key, query) {
750
+ return None ;
751
+ }
752
+ let _ = get_query_impl ( tcx, state, span, key, query) ;
756
753
None
757
754
}
758
755
QueryCaller :: Get => {
0 commit comments