@@ -537,28 +537,6 @@ impl<'tcx> TyCtxt<'tcx> {
537537 )
538538 }
539539
540- impl < ' tcx > TyCtxt < ' tcx > {
541- #[ inline( never) ]
542- pub ( super ) fn get_query < Q : QueryDescription < TyCtxt < ' tcx > > + ' tcx > (
543- self ,
544- span : Span ,
545- key : Q :: Key ,
546- ) -> Q :: Value {
547- debug ! ( "ty::query::get_query<{}>(key={:?}, span={:?})" , Q :: NAME , key, span) ;
548-
549- try_get_cached (
550- self ,
551- Q :: query_state ( self ) ,
552- key,
553- |value, index| {
554- self . dep_graph . read_index ( index) ;
555- value. clone ( )
556- } ,
557- |key, lookup| try_execute_query :: < Q , _ , _ > ( self , span, key, lookup) ,
558- )
559- }
560- }
561-
562540 #[ inline( always) ]
563541 fn try_execute_query < Q , CTX , K > (
564542 tcx : CTX ,
@@ -797,15 +775,64 @@ impl<'tcx> TyCtxt<'tcx> {
797775 ( result, dep_node_index)
798776 }
799777
800- impl < ' tcx > TyCtxt < ' tcx > {
778+ pub ( super ) trait QueryGetter : QueryContext {
779+ fn get_query < Q : QueryDescription < Self > > (
780+ self ,
781+ span : Span ,
782+ key : Q :: Key ,
783+ ) -> Q :: Value ;
784+
785+ /// Ensure that either this query has all green inputs or been executed.
786+ /// Executing `query::ensure(D)` is considered a read of the dep-node `D`.
787+ ///
788+ /// This function is particularly useful when executing passes for their
789+ /// side-effects -- e.g., in order to report errors for erroneous programs.
790+ ///
791+ /// Note: The optimization is only available during incr. comp.
792+ fn ensure_query < Q : QueryDescription < Self > > ( self , key : Q :: Key ) ;
793+
794+ fn force_query < Q : QueryDescription < Self > > (
795+ self ,
796+ key : Q :: Key ,
797+ span : Span ,
798+ dep_node : DepNode < Self :: DepKind > ,
799+ ) ;
800+ }
801+
802+ impl < CTX , K > QueryGetter for CTX
803+ where
804+ CTX : QueryContext < DepKind = K > ,
805+ CTX : HashStableContextProvider < <CTX as DepContext >:: StableHashingContext > ,
806+ K : DepKind ,
807+ {
808+ #[ inline( never) ]
809+ fn get_query < Q : QueryDescription < Self > > (
810+ self ,
811+ span : Span ,
812+ key : Q :: Key ,
813+ ) -> Q :: Value {
814+ debug ! ( "ty::query::get_query<{}>(key={:?}, span={:?})" , Q :: NAME , key, span) ;
815+
816+ try_get_cached (
817+ self ,
818+ Q :: query_state ( self ) ,
819+ key,
820+ |value, index| {
821+ self . dep_graph ( ) . read_index ( index) ;
822+ value. clone ( )
823+ } ,
824+ |key, lookup| try_execute_query :: < Q , _ , _ > ( self , span, key, lookup) ,
825+ )
826+ }
827+
801828 /// Ensure that either this query has all green inputs or been executed.
802829 /// Executing `query::ensure(D)` is considered a read of the dep-node `D`.
803830 ///
804831 /// This function is particularly useful when executing passes for their
805832 /// side-effects -- e.g., in order to report errors for erroneous programs.
806833 ///
807834 /// Note: The optimization is only available during incr. comp.
808- pub ( super ) fn ensure_query < Q : QueryDescription < TyCtxt < ' tcx > > + ' tcx > ( self , key : Q :: Key ) {
835+ fn ensure_query < Q : QueryDescription < Self > > ( self , key : Q :: Key ) {
809836 if Q :: EVAL_ALWAYS {
810837 let _ = self . get_query :: < Q > ( DUMMY_SP , key) ;
811838 return ;
@@ -816,7 +843,7 @@ impl<'tcx> TyCtxt<'tcx> {
816843
817844 let dep_node = Q :: to_dep_node ( self , & key) ;
818845
819- match self . dep_graph . try_mark_green_and_read ( self , & dep_node) {
846+ match self . dep_graph ( ) . try_mark_green_and_read ( self , & dep_node) {
820847 None => {
821848 // A None return from `try_mark_green_and_read` means that this is either
822849 // a new dep node or that the dep node has already been marked red.
@@ -827,17 +854,16 @@ impl<'tcx> TyCtxt<'tcx> {
827854 let _ = self . get_query :: < Q > ( DUMMY_SP , key) ;
828855 }
829856 Some ( ( _, dep_node_index) ) => {
830- self . prof . query_cache_hit ( dep_node_index. into ( ) ) ;
857+ self . profiler ( ) . query_cache_hit ( dep_node_index. into ( ) ) ;
831858 }
832859 }
833860 }
834861
835- #[ allow( dead_code) ]
836- pub ( super ) fn force_query < Q : QueryDescription < TyCtxt < ' tcx > > + ' tcx > (
862+ fn force_query < Q : QueryDescription < Self > > (
837863 self ,
838864 key : Q :: Key ,
839865 span : Span ,
840- dep_node : DepNode < crate :: dep_graph :: DepKind > ,
866+ dep_node : DepNode < Self :: DepKind > ,
841867 ) {
842868 // We may be concurrently trying both execute and force a query.
843869 // Ensure that only one of them runs the query.
0 commit comments