@@ -17,7 +17,6 @@ use rustc_data_structures::sharded::Sharded;
1717use rustc_data_structures:: sync:: { Lock , LockGuard } ;
1818use rustc_data_structures:: thin_vec:: ThinVec ;
1919use rustc_errors:: { Diagnostic , FatalError } ;
20- use rustc_span:: source_map:: DUMMY_SP ;
2120use rustc_span:: Span ;
2221use std:: collections:: hash_map:: Entry ;
2322use std:: hash:: { Hash , Hasher } ;
@@ -656,25 +655,19 @@ where
656655///
657656/// Note: The optimization is only available during incr. comp.
658657#[ 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 > ,
667661 CTX : QueryContext ,
668662{
669663 if query. eval_always {
670- let _ = get_query_impl ( tcx, state, DUMMY_SP , key, query) ;
671- return ;
664+ return false ;
672665 }
673666
674667 // Ensuring an anonymous query makes no sense
675668 assert ! ( !query. anon) ;
676669
677- let dep_node = query. to_dep_node ( tcx, & key) ;
670+ let dep_node = query. to_dep_node ( tcx, key) ;
678671
679672 match tcx. dep_graph ( ) . try_mark_green_and_read ( tcx, & dep_node) {
680673 None => {
@@ -684,10 +677,11 @@ fn ensure_query_impl<CTX, C>(
684677 // DepNodeIndex. We must invoke the query itself. The performance cost
685678 // this introduces should be negligible as we'll immediately hit the
686679 // in-memory cache, or another query down the line will.
687- let _ = get_query_impl ( tcx , state , DUMMY_SP , key , query ) ;
680+ false
688681 }
689682 Some ( ( _, dep_node_index) ) => {
690683 tcx. profiler ( ) . query_cache_hit ( dep_node_index. into ( ) ) ;
684+ true
691685 }
692686 }
693687}
@@ -752,7 +746,10 @@ where
752746{
753747 match caller {
754748 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) ;
756753 None
757754 }
758755 QueryCaller :: Get => {
0 commit comments