@@ -537,28 +537,6 @@ impl<'tcx> TyCtxt<'tcx> {
537
537
)
538
538
}
539
539
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
-
562
540
#[ inline( always) ]
563
541
fn try_execute_query < Q , CTX , K > (
564
542
tcx : CTX ,
@@ -797,15 +775,64 @@ impl<'tcx> TyCtxt<'tcx> {
797
775
( result, dep_node_index)
798
776
}
799
777
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
+
801
828
/// Ensure that either this query has all green inputs or been executed.
802
829
/// Executing `query::ensure(D)` is considered a read of the dep-node `D`.
803
830
///
804
831
/// This function is particularly useful when executing passes for their
805
832
/// side-effects -- e.g., in order to report errors for erroneous programs.
806
833
///
807
834
/// 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 ) {
809
836
if Q :: EVAL_ALWAYS {
810
837
let _ = self . get_query :: < Q > ( DUMMY_SP , key) ;
811
838
return ;
@@ -816,7 +843,7 @@ impl<'tcx> TyCtxt<'tcx> {
816
843
817
844
let dep_node = Q :: to_dep_node ( self , & key) ;
818
845
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) {
820
847
None => {
821
848
// A None return from `try_mark_green_and_read` means that this is either
822
849
// a new dep node or that the dep node has already been marked red.
@@ -827,17 +854,16 @@ impl<'tcx> TyCtxt<'tcx> {
827
854
let _ = self . get_query :: < Q > ( DUMMY_SP , key) ;
828
855
}
829
856
Some ( ( _, dep_node_index) ) => {
830
- self . prof . query_cache_hit ( dep_node_index. into ( ) ) ;
857
+ self . profiler ( ) . query_cache_hit ( dep_node_index. into ( ) ) ;
831
858
}
832
859
}
833
860
}
834
861
835
- #[ allow( dead_code) ]
836
- pub ( super ) fn force_query < Q : QueryDescription < TyCtxt < ' tcx > > + ' tcx > (
862
+ fn force_query < Q : QueryDescription < Self > > (
837
863
self ,
838
864
key : Q :: Key ,
839
865
span : Span ,
840
- dep_node : DepNode < crate :: dep_graph :: DepKind > ,
866
+ dep_node : DepNode < Self :: DepKind > ,
841
867
) {
842
868
// We may be concurrently trying both execute and force a query.
843
869
// Ensure that only one of them runs the query.
0 commit comments