@@ -5,13 +5,18 @@ use rustc_data_structures::fingerprint::Fingerprint;
55use rustc_span:: ErrorGuaranteed ;
66
77use super :: QueryStackFrameExtra ;
8- use crate :: dep_graph:: { DepKind , DepNode , DepNodeParams , SerializedDepNodeIndex } ;
8+ use crate :: dep_graph:: { DepKind , DepNode , DepNodeParams , HasDepContext , SerializedDepNodeIndex } ;
99use crate :: ich:: StableHashingContext ;
1010use crate :: query:: caches:: QueryCache ;
1111use crate :: query:: { CycleError , CycleErrorHandling , DepNodeIndex , QueryContext , QueryState } ;
1212
1313pub type HashResult < V > = Option < fn ( & mut StableHashingContext < ' _ > , & V ) -> Fingerprint > ;
1414
15+ /// Unambiguous shorthand for `<This::Qcx as HasDepContext>::DepContext`.
16+ #[ expect( type_alias_bounds) ]
17+ type DepContext < This : QueryDispatcher > =
18+ <<This as QueryDispatcher >:: Qcx as HasDepContext >:: DepContext ;
19+
1520/// Trait that can be used as a vtable for a single query, providing operations
1621/// and metadata for that query.
1722///
@@ -20,49 +25,56 @@ pub type HashResult<V> = Option<fn(&mut StableHashingContext<'_>, &V) -> Fingerp
2025/// Those types are not visible from this `rustc_query_system` crate.
2126///
2227/// "Dispatcher" should be understood as a near-synonym of "vtable".
23- pub trait QueryDispatcher < Qcx : QueryContext > : Copy {
28+ pub trait QueryDispatcher : Copy {
2429 fn name ( self ) -> & ' static str ;
2530
31+ /// Query context used by this dispatcher, i.e. `rustc_query_impl::QueryCtxt`.
32+ type Qcx : QueryContext ;
33+
2634 // `Key` and `Value` are `Copy` instead of `Clone` to ensure copying them stays cheap,
2735 // but it isn't necessary.
28- type Key : DepNodeParams < Qcx :: DepContext > + Eq + Hash + Copy + Debug ;
36+ type Key : DepNodeParams < DepContext < Self > > + Eq + Hash + Copy + Debug ;
2937 type Value : Copy ;
3038
3139 type Cache : QueryCache < Key = Self :: Key , Value = Self :: Value > ;
3240
3341 fn format_value ( self ) -> fn ( & Self :: Value ) -> String ;
3442
3543 // Don't use this method to access query results, instead use the methods on TyCtxt
36- fn query_state < ' a > ( self , tcx : Qcx ) -> & ' a QueryState < Self :: Key , Qcx :: QueryInfo >
37- where
38- Qcx : ' a ;
44+ fn query_state < ' a > (
45+ self ,
46+ tcx : Self :: Qcx ,
47+ ) -> & ' a QueryState < Self :: Key , <Self :: Qcx as QueryContext >:: QueryInfo > ;
3948
4049 // Don't use this method to access query results, instead use the methods on TyCtxt
41- fn query_cache < ' a > ( self , tcx : Qcx ) -> & ' a Self :: Cache
42- where
43- Qcx : ' a ;
50+ fn query_cache < ' a > ( self , tcx : Self :: Qcx ) -> & ' a Self :: Cache ;
4451
45- fn cache_on_disk ( self , tcx : Qcx :: DepContext , key : & Self :: Key ) -> bool ;
52+ fn cache_on_disk ( self , tcx : DepContext < Self > , key : & Self :: Key ) -> bool ;
4653
4754 // Don't use this method to compute query results, instead use the methods on TyCtxt
48- fn execute_query ( self , tcx : Qcx :: DepContext , k : Self :: Key ) -> Self :: Value ;
55+ fn execute_query ( self , tcx : DepContext < Self > , k : Self :: Key ) -> Self :: Value ;
4956
50- fn compute ( self , tcx : Qcx , key : Self :: Key ) -> Self :: Value ;
57+ fn compute ( self , tcx : Self :: Qcx , key : Self :: Key ) -> Self :: Value ;
5158
5259 fn try_load_from_disk (
5360 self ,
54- tcx : Qcx ,
61+ tcx : Self :: Qcx ,
5562 key : & Self :: Key ,
5663 prev_index : SerializedDepNodeIndex ,
5764 index : DepNodeIndex ,
5865 ) -> Option < Self :: Value > ;
5966
60- fn loadable_from_disk ( self , qcx : Qcx , key : & Self :: Key , idx : SerializedDepNodeIndex ) -> bool ;
67+ fn loadable_from_disk (
68+ self ,
69+ qcx : Self :: Qcx ,
70+ key : & Self :: Key ,
71+ idx : SerializedDepNodeIndex ,
72+ ) -> bool ;
6173
6274 /// Synthesize an error value to let compilation continue after a cycle.
6375 fn value_from_cycle_error (
6476 self ,
65- tcx : Qcx :: DepContext ,
77+ tcx : DepContext < Self > ,
6678 cycle_error : & CycleError < QueryStackFrameExtra > ,
6779 guar : ErrorGuaranteed ,
6880 ) -> Self :: Value ;
@@ -77,7 +89,7 @@ pub trait QueryDispatcher<Qcx: QueryContext>: Copy {
7789 fn hash_result ( self ) -> HashResult < Self :: Value > ;
7890
7991 // Just here for convenience and checking that the key matches the kind, don't override this.
80- fn construct_dep_node ( self , tcx : Qcx :: DepContext , key : & Self :: Key ) -> DepNode {
92+ fn construct_dep_node ( self , tcx : DepContext < Self > , key : & Self :: Key ) -> DepNode {
8193 DepNode :: construct ( tcx, self . dep_kind ( ) , key)
8294 }
8395}
0 commit comments