@@ -12,7 +12,7 @@ use std::marker::ConstParamTy;
1212
1313use rustc_data_structures:: sync:: AtomicU64 ;
1414use rustc_middle:: arena:: Arena ;
15- use rustc_middle:: dep_graph:: { self , DepKind , DepKindVTable , DepNodeIndex } ;
15+ use rustc_middle:: dep_graph:: { self , DepKind , DepKindVTable , DepNode , DepNodeIndex } ;
1616use rustc_middle:: queries:: {
1717 self , ExternProviders , Providers , QueryCaches , QueryEngine , QueryStates ,
1818} ;
@@ -23,8 +23,7 @@ use rustc_middle::query::values::Value;
2323use rustc_middle:: ty:: TyCtxt ;
2424use rustc_query_system:: dep_graph:: SerializedDepNodeIndex ;
2525use rustc_query_system:: query:: {
26- CycleError , CycleErrorHandling , HashResult , QueryCache , QueryDispatcher , QueryMap , QueryMode ,
27- QueryState ,
26+ CycleError , CycleErrorHandling , HashResult , QueryCache , QueryMap , QueryMode , QueryState ,
2827} ;
2928use rustc_span:: { ErrorGuaranteed , Span } ;
3029
@@ -51,8 +50,8 @@ struct QueryFlags {
5150 is_feedable : bool ,
5251}
5352
54- /// Combines a [`QueryVTable`] with some additional compile-time booleans
55- /// to implement [`QueryDispatcher`], for use by code in [`rustc_query_system`] .
53+ /// Combines a [`QueryVTable`] with some additional compile-time booleans.
54+ /// "Dispatcher" should be understood as a near-synonym of "vtable" .
5655///
5756/// Baking these boolean flags into the type gives a modest but measurable
5857/// improvement to compiler perf and compiler code size; see
@@ -74,65 +73,60 @@ impl<'tcx, C: QueryCache, const FLAGS: QueryFlags> Clone
7473 }
7574}
7675
77- // This is `impl QueryDispatcher for SemiDynamicQueryDispatcher`.
78- impl < ' tcx , C : QueryCache , const FLAGS : QueryFlags > QueryDispatcher < ' tcx >
79- for SemiDynamicQueryDispatcher < ' tcx , C , FLAGS >
80- {
81- type Qcx = QueryCtxt < ' tcx > ;
82- type Key = C :: Key ;
83- type Value = C :: Value ;
84- type Cache = C ;
85-
76+ impl < ' tcx , C : QueryCache , const FLAGS : QueryFlags > SemiDynamicQueryDispatcher < ' tcx , C , FLAGS > {
8677 #[ inline( always) ]
8778 fn name ( self ) -> & ' static str {
8879 self . vtable . name
8980 }
9081
9182 #[ inline( always) ]
92- fn will_cache_on_disk_for_key ( self , tcx : TyCtxt < ' tcx > , key : & Self :: Key ) -> bool {
83+ fn will_cache_on_disk_for_key ( self , tcx : TyCtxt < ' tcx > , key : & C :: Key ) -> bool {
9384 self . vtable . will_cache_on_disk_for_key_fn . map_or ( false , |f| f ( tcx, key) )
9485 }
9586
87+ // Don't use this method to access query results, instead use the methods on TyCtxt.
9688 #[ inline( always) ]
97- fn query_state ( self , qcx : QueryCtxt < ' tcx > ) -> & ' tcx QueryState < ' tcx , Self :: Key > {
89+ fn query_state ( self , qcx : QueryCtxt < ' tcx > ) -> & ' tcx QueryState < ' tcx , C :: Key > {
9890 // Safety:
9991 // This is just manually doing the subfield referencing through pointer math.
10092 unsafe {
10193 & * ( & qcx. tcx . query_system . states as * const QueryStates < ' tcx > )
10294 . byte_add ( self . vtable . query_state )
103- . cast :: < QueryState < ' tcx , Self :: Key > > ( )
95+ . cast :: < QueryState < ' tcx , C :: Key > > ( )
10496 }
10597 }
10698
99+ // Don't use this method to access query results, instead use the methods on TyCtxt.
107100 #[ inline( always) ]
108- fn query_cache ( self , qcx : QueryCtxt < ' tcx > ) -> & ' tcx Self :: Cache {
101+ fn query_cache ( self , qcx : QueryCtxt < ' tcx > ) -> & ' tcx C {
109102 // Safety:
110103 // This is just manually doing the subfield referencing through pointer math.
111104 unsafe {
112105 & * ( & qcx. tcx . query_system . caches as * const QueryCaches < ' tcx > )
113106 . byte_add ( self . vtable . query_cache )
114- . cast :: < Self :: Cache > ( )
107+ . cast :: < C > ( )
115108 }
116109 }
117110
111+ // Don't use this method to compute query results, instead use the methods on TyCtxt.
118112 #[ inline( always) ]
119- fn execute_query ( self , tcx : TyCtxt < ' tcx > , key : Self :: Key ) -> Self :: Value {
113+ fn execute_query ( self , tcx : TyCtxt < ' tcx > , key : C :: Key ) -> C :: Value {
120114 ( self . vtable . execute_query ) ( tcx, key)
121115 }
122116
123117 #[ inline( always) ]
124- fn compute ( self , qcx : QueryCtxt < ' tcx > , key : Self :: Key ) -> Self :: Value {
118+ fn compute ( self , qcx : QueryCtxt < ' tcx > , key : C :: Key ) -> C :: Value {
125119 ( self . vtable . compute_fn ) ( qcx. tcx , key)
126120 }
127121
128122 #[ inline( always) ]
129123 fn try_load_from_disk (
130124 self ,
131125 qcx : QueryCtxt < ' tcx > ,
132- key : & Self :: Key ,
126+ key : & C :: Key ,
133127 prev_index : SerializedDepNodeIndex ,
134128 index : DepNodeIndex ,
135- ) -> Option < Self :: Value > {
129+ ) -> Option < C :: Value > {
136130 // `?` will return None immediately for queries that never cache to disk.
137131 self . vtable . try_load_from_disk_fn ?( qcx. tcx , key, prev_index, index)
138132 }
@@ -141,23 +135,24 @@ impl<'tcx, C: QueryCache, const FLAGS: QueryFlags> QueryDispatcher<'tcx>
141135 fn is_loadable_from_disk (
142136 self ,
143137 qcx : QueryCtxt < ' tcx > ,
144- key : & Self :: Key ,
138+ key : & C :: Key ,
145139 index : SerializedDepNodeIndex ,
146140 ) -> bool {
147141 self . vtable . is_loadable_from_disk_fn . map_or ( false , |f| f ( qcx. tcx , key, index) )
148142 }
149143
144+ /// Synthesize an error value to let compilation continue after a cycle.
150145 fn value_from_cycle_error (
151146 self ,
152147 tcx : TyCtxt < ' tcx > ,
153148 cycle_error : & CycleError ,
154149 guar : ErrorGuaranteed ,
155- ) -> Self :: Value {
150+ ) -> C :: Value {
156151 ( self . vtable . value_from_cycle_error ) ( tcx, cycle_error, guar)
157152 }
158153
159154 #[ inline( always) ]
160- fn format_value ( self ) -> fn ( & Self :: Value ) -> String {
155+ fn format_value ( self ) -> fn ( & C :: Value ) -> String {
161156 self . vtable . format_value
162157 }
163158
@@ -192,13 +187,17 @@ impl<'tcx, C: QueryCache, const FLAGS: QueryFlags> QueryDispatcher<'tcx>
192187 }
193188
194189 #[ inline( always) ]
195- fn hash_result ( self ) -> HashResult < Self :: Value > {
190+ fn hash_result ( self ) -> HashResult < C :: Value > {
196191 self . vtable . hash_result
197192 }
193+
194+ fn construct_dep_node ( self , tcx : TyCtxt < ' tcx > , key : & C :: Key ) -> DepNode {
195+ DepNode :: construct ( tcx, self . dep_kind ( ) , key)
196+ }
198197}
199198
200199/// Provides access to vtable-like operations for a query
201- /// (by creating a [`QueryDispatcher `]),
200+ /// (by creating a [`SemiDynamicQueryDispatcher `]),
202201/// but also keeps track of the "unerased" value type of the query
203202/// (i.e. the actual result type in the query declaration).
204203///
@@ -210,7 +209,7 @@ impl<'tcx, C: QueryCache, const FLAGS: QueryFlags> QueryDispatcher<'tcx>
210209/// on the type `rustc_query_impl::query_impl::$name::QueryType`.
211210trait QueryDispatcherUnerased < ' tcx , C : QueryCache , const FLAGS : QueryFlags > {
212211 type UnerasedValue ;
213- //type Dispatcher: QueryDispatcher<'tcx, Qcx = QueryCtxt<'tcx>>;
212+ //type Dispatcher: QueryDispatcher<'tcx, Qcx = QueryCtxt<'tcx>>; // njn: remove
214213
215214 const NAME : & ' static & ' static str ;
216215
0 commit comments