@@ -106,6 +106,55 @@ impl<'tcx> TyCtxt<'tcx> {
106
106
}
107
107
}
108
108
109
+ #[ inline( always) ]
110
+ fn query_get_at < ' tcx , Cache , K > (
111
+ tcx : TyCtxt < ' tcx > ,
112
+ execute_query : fn (
113
+ & ' tcx dyn QueryEngine < ' tcx > ,
114
+ TyCtxt < ' tcx > ,
115
+ Span ,
116
+ Cache :: Key ,
117
+ QueryMode ,
118
+ ) -> Option < Cache :: Stored > ,
119
+ query_cache : & Cache ,
120
+ span : Span ,
121
+ key : K ,
122
+ ) -> Cache :: Stored
123
+ where
124
+ K : IntoQueryParam < Cache :: Key > ,
125
+ Cache :: Stored : Copy ,
126
+ Cache : QueryCache ,
127
+ {
128
+ let key = key. into_query_param ( ) ;
129
+ match try_get_cached ( tcx, query_cache, & key) {
130
+ Some ( value) => value,
131
+ None => execute_query ( tcx. queries , tcx, span, key, QueryMode :: Get ) . unwrap ( ) ,
132
+ }
133
+ }
134
+
135
+ #[ inline( always) ]
136
+ fn query_ensure < ' tcx , Cache , K > (
137
+ tcx : TyCtxt < ' tcx > ,
138
+ execute_query : fn (
139
+ & ' tcx dyn QueryEngine < ' tcx > ,
140
+ TyCtxt < ' tcx > ,
141
+ Span ,
142
+ Cache :: Key ,
143
+ QueryMode ,
144
+ ) -> Option < Cache :: Stored > ,
145
+ query_cache : & Cache ,
146
+ key : K ,
147
+ ) where
148
+ K : IntoQueryParam < Cache :: Key > ,
149
+ Cache :: Stored : Copy ,
150
+ Cache : QueryCache ,
151
+ {
152
+ let key = key. into_query_param ( ) ;
153
+ if try_get_cached ( tcx, query_cache, & key) . is_none ( ) {
154
+ execute_query ( tcx. queries , tcx, DUMMY_SP , key, QueryMode :: Ensure ) ;
155
+ }
156
+ }
157
+
109
158
macro_rules! query_helper_param_ty {
110
159
( DefId ) => { impl IntoQueryParam <DefId > } ;
111
160
( LocalDefId ) => { impl IntoQueryParam <LocalDefId > } ;
@@ -158,9 +207,9 @@ macro_rules! separate_provide_extern_default {
158
207
}
159
208
160
209
macro_rules! opt_remap_env_constness {
161
- ( [ ] [ $name: ident] ) => { } ;
210
+ ( [ ] [ $name: ident] ) => { $name } ;
162
211
( [ ( remap_env_constness) $( $rest: tt) * ] [ $name: ident] ) => {
163
- let $name = $name . without_const( ) ;
212
+ $name. without_const( )
164
213
} ;
165
214
( [ $other: tt $( $modifiers: tt) * ] [ $name: ident] ) => {
166
215
opt_remap_env_constness!( [ $( $modifiers) * ] [ $name] )
@@ -219,13 +268,12 @@ macro_rules! define_callbacks {
219
268
$( $( #[ $attr] ) *
220
269
#[ inline( always) ]
221
270
pub fn $name( self , key: query_helper_param_ty!( $( $K) * ) ) {
222
- let key = key. into_query_param( ) ;
223
- opt_remap_env_constness!( [ $( $modifiers) * ] [ key] ) ;
224
-
225
- match try_get_cached( self . tcx, & self . tcx. query_caches. $name, & key) {
226
- Some ( _) => return ,
227
- None => self . tcx. queries. $name( self . tcx, DUMMY_SP , key, QueryMode :: Ensure ) ,
228
- } ;
271
+ query_ensure(
272
+ self . tcx,
273
+ QueryEngine :: $name,
274
+ & self . tcx. query_caches. $name,
275
+ opt_remap_env_constness!( [ $( $modifiers) * ] [ key] ) ,
276
+ ) ;
229
277
} ) *
230
278
}
231
279
@@ -235,7 +283,13 @@ macro_rules! define_callbacks {
235
283
#[ must_use]
236
284
pub fn $name( self , key: query_helper_param_ty!( $( $K) * ) ) -> $V
237
285
{
238
- self . at( DUMMY_SP ) . $name( key)
286
+ query_get_at(
287
+ self ,
288
+ QueryEngine :: $name,
289
+ & self . query_caches. $name,
290
+ DUMMY_SP ,
291
+ opt_remap_env_constness!( [ $( $modifiers) * ] [ key] ) ,
292
+ )
239
293
} ) *
240
294
}
241
295
@@ -244,13 +298,13 @@ macro_rules! define_callbacks {
244
298
#[ inline( always) ]
245
299
pub fn $name( self , key: query_helper_param_ty!( $( $K) * ) ) -> $V
246
300
{
247
- let key = key . into_query_param ( ) ;
248
- opt_remap_env_constness! ( [ $ ( $modifiers ) * ] [ key ] ) ;
249
-
250
- match try_get_cached ( self . tcx , & self . tcx. query_caches. $name, & key ) {
251
- Some ( value ) => value ,
252
- None => self . tcx . queries . $name ( self . tcx , self . span , key , QueryMode :: Get ) . unwrap ( ) ,
253
- }
301
+ query_get_at (
302
+ self . tcx ,
303
+ QueryEngine :: $name ,
304
+ & self . tcx. query_caches. $name,
305
+ self . span ,
306
+ opt_remap_env_constness! ( [ $ ( $modifiers ) * ] [ key ] ) ,
307
+ )
254
308
} ) *
255
309
}
256
310
@@ -337,7 +391,7 @@ macro_rules! define_feedable {
337
391
#[ inline( always) ]
338
392
pub fn $name( self , value: query_values:: $name<' tcx>) -> $V {
339
393
let key = self . key( ) . into_query_param( ) ;
340
- opt_remap_env_constness!( [ $( $modifiers) * ] [ key] ) ;
394
+ let key = opt_remap_env_constness!( [ $( $modifiers) * ] [ key] ) ;
341
395
342
396
let tcx = self . tcx;
343
397
let cache = & tcx. query_caches. $name;
0 commit comments