@@ -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:: convert:: TryFrom ;
@@ -647,25 +646,19 @@ where
647
646
///
648
647
/// Note: The optimization is only available during incr. comp.
649
648
#[ inline( never) ]
650
- fn ensure_query_impl < CTX , C > (
651
- tcx : CTX ,
652
- state : & QueryState < CTX , C > ,
653
- key : C :: Key ,
654
- query : & QueryVtable < CTX , C :: Key , C :: Value > ,
655
- ) where
656
- C : QueryCache ,
657
- C :: Key : Eq + Clone + crate :: dep_graph:: DepNodeParams < CTX > ,
649
+ fn ensure_query_impl < CTX , K , V > ( tcx : CTX , key : & K , query : & QueryVtable < CTX , K , V > ) -> bool
650
+ where
651
+ K : Eq + Clone + crate :: dep_graph:: DepNodeParams < CTX > ,
658
652
CTX : QueryContext ,
659
653
{
660
654
if query. eval_always {
661
- let _ = get_query_impl ( tcx, state, DUMMY_SP , key, query) ;
662
- return ;
655
+ return false ;
663
656
}
664
657
665
658
// Ensuring an anonymous query makes no sense
666
659
assert ! ( !query. anon) ;
667
660
668
- let dep_node = query. to_dep_node ( tcx, & key) ;
661
+ let dep_node = query. to_dep_node ( tcx, key) ;
669
662
670
663
match tcx. dep_graph ( ) . try_mark_green_and_read ( tcx, & dep_node) {
671
664
None => {
@@ -675,10 +668,11 @@ fn ensure_query_impl<CTX, C>(
675
668
// DepNodeIndex. We must invoke the query itself. The performance cost
676
669
// this introduces should be negligible as we'll immediately hit the
677
670
// in-memory cache, or another query down the line will.
678
- let _ = get_query_impl ( tcx , state , DUMMY_SP , key , query ) ;
671
+ false
679
672
}
680
673
Some ( ( _, dep_node_index) ) => {
681
674
tcx. profiler ( ) . query_cache_hit ( dep_node_index. into ( ) ) ;
675
+ true
682
676
}
683
677
}
684
678
}
@@ -741,7 +735,10 @@ where
741
735
{
742
736
match caller {
743
737
QueryCaller :: Ensure => {
744
- ensure_query_impl ( tcx, state, key, query) ;
738
+ if ensure_query_impl ( tcx, & key, query) {
739
+ return None ;
740
+ }
741
+ let _ = get_query_impl ( tcx, state, span, key, query) ;
745
742
None
746
743
}
747
744
QueryCaller :: Get => {
0 commit comments