@@ -606,105 +606,87 @@ where
606
606
( result, dep_node_index)
607
607
}
608
608
609
- pub trait QueryGetter : QueryContext {
610
- fn get_query < Q : QueryDescription < Self > > ( self , span : Span , key : Q :: Key ) -> Q :: Value ;
611
-
612
- /// Ensure that either this query has all green inputs or been executed.
613
- /// Executing `query::ensure(D)` is considered a read of the dep-node `D`.
614
- ///
615
- /// This function is particularly useful when executing passes for their
616
- /// side-effects -- e.g., in order to report errors for erroneous programs.
617
- ///
618
- /// Note: The optimization is only available during incr. comp.
619
- fn ensure_query < Q : QueryDescription < Self > > ( self , key : Q :: Key ) ;
609
+ #[ inline( never) ]
610
+ pub fn get_query < Q , CTX > ( tcx : CTX , span : Span , key : Q :: Key ) -> Q :: Value
611
+ where
612
+ Q : QueryDescription < CTX > ,
613
+ CTX : QueryContext ,
614
+ {
615
+ debug ! ( "ty::query::get_query<{}>(key={:?}, span={:?})" , Q :: NAME , key, span) ;
620
616
621
- fn force_query < Q : QueryDescription < Self > > (
622
- self ,
623
- key : Q :: Key ,
624
- span : Span ,
625
- dep_node : DepNode < Self :: DepKind > ,
626
- ) ;
617
+ try_get_cached (
618
+ tcx,
619
+ Q :: query_state ( tcx) ,
620
+ key,
621
+ |value, index| {
622
+ tcx. dep_graph ( ) . read_index ( index) ;
623
+ value. clone ( )
624
+ } ,
625
+ |key, lookup| try_execute_query :: < Q , _ > ( tcx, span, key, lookup) ,
626
+ )
627
627
}
628
628
629
- impl < CTX > QueryGetter for CTX
629
+ /// Ensure that either this query has all green inputs or been executed.
630
+ /// Executing `query::ensure(D)` is considered a read of the dep-node `D`.
631
+ ///
632
+ /// This function is particularly useful when executing passes for their
633
+ /// side-effects -- e.g., in order to report errors for erroneous programs.
634
+ ///
635
+ /// Note: The optimization is only available during incr. comp.
636
+ pub fn ensure_query < Q , CTX > ( tcx : CTX , key : Q :: Key )
630
637
where
638
+ Q : QueryDescription < CTX > ,
631
639
CTX : QueryContext ,
632
640
{
633
- #[ inline( never) ]
634
- fn get_query < Q : QueryDescription < Self > > ( self , span : Span , key : Q :: Key ) -> Q :: Value {
635
- debug ! ( "ty::query::get_query<{}>(key={:?}, span={:?})" , Q :: NAME , key, span) ;
636
-
637
- try_get_cached (
638
- self ,
639
- Q :: query_state ( self ) ,
640
- key,
641
- |value, index| {
642
- self . dep_graph ( ) . read_index ( index) ;
643
- value. clone ( )
644
- } ,
645
- |key, lookup| try_execute_query :: < Q , _ > ( self , span, key, lookup) ,
646
- )
641
+ if Q :: EVAL_ALWAYS {
642
+ let _ = get_query :: < Q , _ > ( tcx, DUMMY_SP , key) ;
643
+ return ;
647
644
}
648
645
649
- /// Ensure that either this query has all green inputs or been executed.
650
- /// Executing `query::ensure(D)` is considered a read of the dep-node `D`.
651
- ///
652
- /// This function is particularly useful when executing passes for their
653
- /// side-effects -- e.g., in order to report errors for erroneous programs.
654
- ///
655
- /// Note: The optimization is only available during incr. comp.
656
- fn ensure_query < Q : QueryDescription < Self > > ( self , key : Q :: Key ) {
657
- if Q :: EVAL_ALWAYS {
658
- let _ = self . get_query :: < Q > ( DUMMY_SP , key) ;
659
- return ;
660
- }
646
+ // Ensuring an anonymous query makes no sense
647
+ assert ! ( !Q :: ANON ) ;
661
648
662
- // Ensuring an anonymous query makes no sense
663
- assert ! ( !Q :: ANON ) ;
664
-
665
- let dep_node = Q :: to_dep_node ( self , & key) ;
649
+ let dep_node = Q :: to_dep_node ( tcx, & key) ;
666
650
667
- match self . dep_graph ( ) . try_mark_green_and_read ( self , & dep_node) {
668
- None => {
669
- // A None return from `try_mark_green_and_read` means that this is either
670
- // a new dep node or that the dep node has already been marked red.
671
- // Either way, we can't call `dep_graph.read()` as we don't have the
672
- // DepNodeIndex. We must invoke the query itself. The performance cost
673
- // this introduces should be negligible as we'll immediately hit the
674
- // in-memory cache, or another query down the line will.
675
- let _ = self . get_query :: < Q > ( DUMMY_SP , key) ;
676
- }
677
- Some ( ( _, dep_node_index) ) => {
678
- self . profiler ( ) . query_cache_hit ( dep_node_index. into ( ) ) ;
679
- }
651
+ match tcx. dep_graph ( ) . try_mark_green_and_read ( tcx, & dep_node) {
652
+ None => {
653
+ // A None return from `try_mark_green_and_read` means that this is either
654
+ // a new dep node or that the dep node has already been marked red.
655
+ // Either way, we can't call `dep_graph.read()` as we don't have the
656
+ // DepNodeIndex. We must invoke the query itself. The performance cost
657
+ // this introduces should be negligible as we'll immediately hit the
658
+ // in-memory cache, or another query down the line will.
659
+ let _ = get_query :: < Q , _ > ( tcx, DUMMY_SP , key) ;
660
+ }
661
+ Some ( ( _, dep_node_index) ) => {
662
+ tcx. profiler ( ) . query_cache_hit ( dep_node_index. into ( ) ) ;
680
663
}
681
664
}
665
+ }
682
666
683
- fn force_query < Q : QueryDescription < Self > > (
684
- self ,
685
- key : Q :: Key ,
686
- span : Span ,
687
- dep_node : DepNode < Self :: DepKind > ,
688
- ) {
689
- // We may be concurrently trying both execute and force a query.
690
- // Ensure that only one of them runs the query.
691
-
692
- try_get_cached (
693
- self ,
694
- Q :: query_state ( self ) ,
695
- key,
696
- |_, _| {
697
- // Cache hit, do nothing
698
- } ,
699
- |key, lookup| {
700
- let job = match JobOwner :: try_start :: < Q > ( self , span, & key, lookup) {
701
- TryGetJob :: NotYetStarted ( job) => job,
702
- TryGetJob :: Cycle ( _) => return ,
703
- #[ cfg( parallel_compiler) ]
704
- TryGetJob :: JobCompleted ( _) => return ,
705
- } ;
706
- force_query_with_job :: < Q , _ > ( self , key, job, dep_node) ;
707
- } ,
708
- ) ;
709
- }
667
+ pub fn force_query < Q , CTX > ( tcx : CTX , key : Q :: Key , span : Span , dep_node : DepNode < CTX :: DepKind > )
668
+ where
669
+ Q : QueryDescription < CTX > ,
670
+ CTX : QueryContext ,
671
+ {
672
+ // We may be concurrently trying both execute and force a query.
673
+ // Ensure that only one of them runs the query.
674
+
675
+ try_get_cached (
676
+ tcx,
677
+ Q :: query_state ( tcx) ,
678
+ key,
679
+ |_, _| {
680
+ // Cache hit, do nothing
681
+ } ,
682
+ |key, lookup| {
683
+ let job = match JobOwner :: try_start :: < Q > ( tcx, span, & key, lookup) {
684
+ TryGetJob :: NotYetStarted ( job) => job,
685
+ TryGetJob :: Cycle ( _) => return ,
686
+ #[ cfg( parallel_compiler) ]
687
+ TryGetJob :: JobCompleted ( _) => return ,
688
+ } ;
689
+ force_query_with_job :: < Q , _ > ( tcx, key, job, dep_node) ;
690
+ } ,
691
+ ) ;
710
692
}
0 commit comments