@@ -613,23 +613,28 @@ where
613
613
}
614
614
615
615
#[ inline( never) ]
616
- pub fn get_query < Q , CTX > ( tcx : CTX , span : Span , key : Q :: Key ) -> Q :: Stored
616
+ fn get_query_impl < CTX , C > (
617
+ tcx : CTX ,
618
+ state : & QueryState < CTX , C > ,
619
+ span : Span ,
620
+ key : C :: Key ,
621
+ query : & QueryVtable < CTX , C :: Key , C :: Value > ,
622
+ ) -> C :: Stored
617
623
where
618
- Q : QueryDescription < CTX > ,
619
- Q :: Key : crate :: dep_graph:: DepNodeParams < CTX > ,
620
624
CTX : QueryContext ,
625
+ C : QueryCache ,
626
+ C :: Key : Eq + Clone + crate :: dep_graph:: DepNodeParams < CTX > ,
627
+ C :: Stored : Clone ,
621
628
{
622
- debug ! ( "ty::query::get_query<{}>(key={:?}, span={:?})" , Q :: NAME , key, span) ;
623
-
624
629
try_get_cached (
625
630
tcx,
626
- Q :: query_state ( tcx ) ,
631
+ state ,
627
632
key,
628
633
|value, index| {
629
634
tcx. dep_graph ( ) . read_index ( index) ;
630
635
value. clone ( )
631
636
} ,
632
- |key, lookup| try_execute_query ( tcx, Q :: query_state ( tcx ) , span, key, lookup, & Q :: VTABLE ) ,
637
+ |key, lookup| try_execute_query ( tcx, state , span, key, lookup, query ) ,
633
638
)
634
639
}
635
640
@@ -640,21 +645,25 @@ where
640
645
/// side-effects -- e.g., in order to report errors for erroneous programs.
641
646
///
642
647
/// Note: The optimization is only available during incr. comp.
643
- pub fn ensure_query < Q , CTX > ( tcx : CTX , key : Q :: Key )
644
- where
645
- Q : QueryDescription < CTX > ,
646
- Q :: Key : crate :: dep_graph:: DepNodeParams < CTX > ,
648
+ fn ensure_query_impl < CTX , C > (
649
+ tcx : CTX ,
650
+ state : & QueryState < CTX , C > ,
651
+ key : C :: Key ,
652
+ query : & QueryVtable < CTX , C :: Key , C :: Value > ,
653
+ ) where
654
+ C : QueryCache ,
655
+ C :: Key : Eq + Clone + crate :: dep_graph:: DepNodeParams < CTX > ,
647
656
CTX : QueryContext ,
648
657
{
649
- if Q :: EVAL_ALWAYS {
650
- let _ = get_query :: < Q , _ > ( tcx, DUMMY_SP , key) ;
658
+ if query . eval_always {
659
+ let _ = get_query_impl ( tcx, state , DUMMY_SP , key, query ) ;
651
660
return ;
652
661
}
653
662
654
663
// Ensuring an anonymous query makes no sense
655
- assert ! ( !Q :: ANON ) ;
664
+ assert ! ( !query . anon ) ;
656
665
657
- let dep_node = Q :: to_dep_node ( tcx, & key) ;
666
+ let dep_node = query . to_dep_node ( tcx, & key) ;
658
667
659
668
match tcx. dep_graph ( ) . try_mark_green_and_read ( tcx, & dep_node) {
660
669
None => {
@@ -664,39 +673,73 @@ where
664
673
// DepNodeIndex. We must invoke the query itself. The performance cost
665
674
// this introduces should be negligible as we'll immediately hit the
666
675
// in-memory cache, or another query down the line will.
667
- let _ = get_query :: < Q , _ > ( tcx, DUMMY_SP , key) ;
676
+ let _ = get_query_impl ( tcx, state , DUMMY_SP , key, query ) ;
668
677
}
669
678
Some ( ( _, dep_node_index) ) => {
670
679
tcx. profiler ( ) . query_cache_hit ( dep_node_index. into ( ) ) ;
671
680
}
672
681
}
673
682
}
674
683
675
- pub fn force_query < Q , CTX > ( tcx : CTX , key : Q :: Key , span : Span , dep_node : DepNode < CTX :: DepKind > )
676
- where
677
- Q : QueryDescription < CTX > ,
684
+ fn force_query_impl < C , CTX > (
685
+ tcx : CTX ,
686
+ state : & QueryState < CTX , C > ,
687
+ key : C :: Key ,
688
+ span : Span ,
689
+ dep_node : DepNode < CTX :: DepKind > ,
690
+ query : & QueryVtable < CTX , C :: Key , C :: Value > ,
691
+ ) where
692
+ C : QueryCache ,
693
+ C :: Key : Eq + Clone + crate :: dep_graph:: DepNodeParams < CTX > ,
678
694
CTX : QueryContext ,
679
695
{
680
696
// We may be concurrently trying both execute and force a query.
681
697
// Ensure that only one of them runs the query.
682
698
683
699
try_get_cached (
684
700
tcx,
685
- Q :: query_state ( tcx ) ,
701
+ state ,
686
702
key,
687
703
|_, _| {
688
704
// Cache hit, do nothing
689
705
} ,
690
706
|key, lookup| {
691
- let job =
692
- match JobOwner :: try_start ( tcx, Q :: query_state ( tcx) , span, & key, lookup, & Q :: VTABLE )
693
- {
694
- TryGetJob :: NotYetStarted ( job) => job,
695
- TryGetJob :: Cycle ( _) => return ,
696
- #[ cfg( parallel_compiler) ]
697
- TryGetJob :: JobCompleted ( _) => return ,
698
- } ;
699
- force_query_with_job ( tcx, key, job, dep_node, & Q :: VTABLE ) ;
707
+ let job = match JobOwner :: try_start ( tcx, state, span, & key, lookup, query) {
708
+ TryGetJob :: NotYetStarted ( job) => job,
709
+ TryGetJob :: Cycle ( _) => return ,
710
+ #[ cfg( parallel_compiler) ]
711
+ TryGetJob :: JobCompleted ( _) => return ,
712
+ } ;
713
+ force_query_with_job ( tcx, key, job, dep_node, query) ;
700
714
} ,
701
715
) ;
702
716
}
717
+
718
+ pub fn get_query < Q , CTX > ( tcx : CTX , span : Span , key : Q :: Key ) -> Q :: Stored
719
+ where
720
+ Q : QueryDescription < CTX > ,
721
+ Q :: Key : crate :: dep_graph:: DepNodeParams < CTX > ,
722
+ CTX : QueryContext ,
723
+ {
724
+ debug ! ( "ty::query::get_query<{}>(key={:?}, span={:?})" , Q :: NAME , key, span) ;
725
+
726
+ get_query_impl ( tcx, Q :: query_state ( tcx) , span, key, & Q :: VTABLE )
727
+ }
728
+
729
+ pub fn ensure_query < Q , CTX > ( tcx : CTX , key : Q :: Key )
730
+ where
731
+ Q : QueryDescription < CTX > ,
732
+ Q :: Key : crate :: dep_graph:: DepNodeParams < CTX > ,
733
+ CTX : QueryContext ,
734
+ {
735
+ ensure_query_impl ( tcx, Q :: query_state ( tcx) , key, & Q :: VTABLE )
736
+ }
737
+
738
+ pub fn force_query < Q , CTX > ( tcx : CTX , key : Q :: Key , span : Span , dep_node : DepNode < CTX :: DepKind > )
739
+ where
740
+ Q : QueryDescription < CTX > ,
741
+ Q :: Key : crate :: dep_graph:: DepNodeParams < CTX > ,
742
+ CTX : QueryContext ,
743
+ {
744
+ force_query_impl ( tcx, Q :: query_state ( tcx) , key, span, dep_node, & Q :: VTABLE )
745
+ }
0 commit comments