@@ -14,6 +14,7 @@ use rustc_data_structures::cold_path;
14
14
use rustc_data_structures:: fingerprint:: Fingerprint ;
15
15
use rustc_data_structures:: fx:: { FxHashMap , FxHasher } ;
16
16
use rustc_data_structures:: sharded:: Sharded ;
17
+ use rustc_data_structures:: stable_hasher:: HashStable ;
17
18
use rustc_data_structures:: sync:: { Lock , LockGuard } ;
18
19
use rustc_data_structures:: thin_vec:: ThinVec ;
19
20
use rustc_errors:: { Diagnostic , FatalError } ;
@@ -157,7 +158,7 @@ where
157
158
158
159
impl < ' tcx , D , Q , C > JobOwner < ' tcx , D , Q , C >
159
160
where
160
- D : Copy + Clone + Eq + Hash ,
161
+ D : Copy + Clone + Eq + Hash + DepKind ,
161
162
Q : Clone ,
162
163
C : QueryCache ,
163
164
{
@@ -179,7 +180,8 @@ where
179
180
query : & QueryVtable < CTX , C :: Key , C :: Value > ,
180
181
) -> TryGetJob < ' b , CTX :: DepKind , CTX :: Query , C >
181
182
where
182
- CTX : QueryContext ,
183
+ CTX : QueryContext < DepKind = D , Query = Q > ,
184
+ Q : HashStable < CTX :: StableHashingContext > ,
183
185
{
184
186
let lock = & mut * lookup. lock ;
185
187
@@ -622,31 +624,6 @@ where
622
624
( result, dep_node_index)
623
625
}
624
626
625
- #[ inline( never) ]
626
- fn get_query_impl < CTX , C > (
627
- tcx : CTX ,
628
- state : & QueryState < CTX :: DepKind , CTX :: Query , C > ,
629
- span : Span ,
630
- key : C :: Key ,
631
- query : & QueryVtable < CTX , C :: Key , C :: Value > ,
632
- ) -> C :: Stored
633
- where
634
- CTX : QueryContext ,
635
- C : QueryCache ,
636
- C :: Key : crate :: dep_graph:: DepNodeParams < CTX > ,
637
- {
638
- try_get_cached (
639
- tcx,
640
- state,
641
- key,
642
- |value, index| {
643
- tcx. dep_graph ( ) . read_index ( index) ;
644
- value. clone ( )
645
- } ,
646
- |key, lookup| try_execute_query ( tcx, state, span, key, lookup, query) ,
647
- )
648
- }
649
-
650
627
/// Ensure that either this query has all green inputs or been executed.
651
628
/// Executing `query::ensure(D)` is considered a read of the dep-node `D`.
652
629
///
@@ -686,43 +663,6 @@ where
686
663
}
687
664
}
688
665
689
- #[ inline( never) ]
690
- fn force_query_impl < CTX , C > (
691
- tcx : CTX ,
692
- state : & QueryState < CTX :: DepKind , CTX :: Query , C > ,
693
- key : C :: Key ,
694
- span : Span ,
695
- dep_node : DepNode < CTX :: DepKind > ,
696
- query : & QueryVtable < CTX , C :: Key , C :: Value > ,
697
- ) where
698
- C : QueryCache ,
699
- C :: Key : crate :: dep_graph:: DepNodeParams < CTX > ,
700
- CTX : QueryContext ,
701
- {
702
- // We may be concurrently trying both execute and force a query.
703
- // Ensure that only one of them runs the query.
704
-
705
- try_get_cached (
706
- tcx,
707
- state,
708
- key,
709
- |_, _| {
710
- // Cache hit, do nothing
711
- } ,
712
- |key, lookup| {
713
- let job = match JobOwner :: < ' _ , CTX :: DepKind , CTX :: Query , C > :: try_start (
714
- tcx, state, span, & key, lookup, query,
715
- ) {
716
- TryGetJob :: NotYetStarted ( job) => job,
717
- TryGetJob :: Cycle ( _) => return ,
718
- #[ cfg( parallel_compiler) ]
719
- TryGetJob :: JobCompleted ( _) => return ,
720
- } ;
721
- force_query_with_job ( tcx, key, job, dep_node, query) ;
722
- } ,
723
- ) ;
724
- }
725
-
726
666
pub enum QueryCaller < DK > {
727
667
Ensure ,
728
668
Get ,
@@ -744,23 +684,58 @@ where
744
684
C :: Stored : Clone ,
745
685
CTX : QueryContext ,
746
686
{
747
- match caller {
748
- QueryCaller :: Ensure => {
749
- if ensure_query_impl ( tcx, & key, query) {
750
- return None ;
751
- }
752
- let _ = get_query_impl ( tcx, state, span, key, query) ;
753
- None
754
- }
755
- QueryCaller :: Get => {
756
- let ret = get_query_impl ( tcx, state, span, key, query) ;
757
- Some ( ret)
758
- }
759
- QueryCaller :: Force ( dep_node) => {
760
- force_query_impl ( tcx, state, key, span, dep_node, query) ;
761
- None
687
+ if let QueryCaller :: Ensure = caller {
688
+ if ensure_query_impl ( tcx, & key, query) {
689
+ return None ;
762
690
}
763
691
}
692
+
693
+ try_get_cached (
694
+ tcx,
695
+ state,
696
+ key,
697
+ |value, index| {
698
+ match & caller {
699
+ QueryCaller :: Ensure => {
700
+ tcx. dep_graph ( ) . read_index ( index) ;
701
+ None
702
+ }
703
+ QueryCaller :: Get => {
704
+ tcx. dep_graph ( ) . read_index ( index) ;
705
+ Some ( value. clone ( ) )
706
+ }
707
+ QueryCaller :: Force ( _) => {
708
+ // Cache hit, do nothing
709
+ None
710
+ }
711
+ }
712
+ } ,
713
+ |key, lookup| {
714
+ match & caller {
715
+ QueryCaller :: Ensure => {
716
+ try_execute_query ( tcx, state, span, key, lookup, query) ;
717
+ None
718
+ }
719
+ QueryCaller :: Get => {
720
+ let value = try_execute_query ( tcx, state, span, key, lookup, query) ;
721
+ Some ( value)
722
+ }
723
+ QueryCaller :: Force ( dep_node) => {
724
+ // We may be concurrently trying both execute and force a query.
725
+ // Ensure that only one of them runs the query.
726
+
727
+ let job = match JobOwner :: try_start ( tcx, state, span, & key, lookup, query) {
728
+ TryGetJob :: NotYetStarted ( job) => job,
729
+ TryGetJob :: Cycle ( _) => return None ,
730
+ #[ cfg( parallel_compiler) ]
731
+ TryGetJob :: JobCompleted ( _) => return None ,
732
+ } ;
733
+ force_query_with_job ( tcx, key, job, * dep_node, query) ;
734
+ None
735
+ }
736
+ }
737
+ } ,
738
+ )
764
739
}
765
740
766
741
#[ inline( always) ]
0 commit comments