@@ -102,16 +102,38 @@ impl<'tcx> TyCtxt<'tcx> {
102
102
}
103
103
}
104
104
105
- /// Helper for `TyCtxtEnsure` to avoid a closure.
106
- #[ inline( always) ]
107
- fn noop < T > ( _: & T ) { }
108
-
109
105
/// Helper to ensure that queries only return `Copy` types.
110
106
#[ inline( always) ]
111
107
fn copy < T : Copy > ( x : & T ) -> T {
112
108
* x
113
109
}
114
110
111
+ fn evaluate_query < ' tcx , Cache > (
112
+ tcx : TyCtxt < ' tcx > ,
113
+ execute_query : fn (
114
+ & ' tcx dyn QueryEngine < ' tcx > ,
115
+ TyCtxt < ' tcx > ,
116
+ Span ,
117
+ Cache :: Key ,
118
+ QueryMode ,
119
+ ) -> Option < Cache :: Stored > ,
120
+ query_cache : & Cache ,
121
+ span : Span ,
122
+ key : Cache :: Key ,
123
+ mode : QueryMode ,
124
+ ) -> Option < Cache :: Stored >
125
+ where
126
+ Cache :: Stored : Copy ,
127
+ Cache : QueryCache ,
128
+ {
129
+ let cached = try_get_cached ( tcx, query_cache, & key, copy) ;
130
+
131
+ match cached {
132
+ Ok ( value) => return value,
133
+ Err ( ( ) ) => ( ) ,
134
+ }
135
+ }
136
+
115
137
macro_rules! query_helper_param_ty {
116
138
( DefId ) => { impl IntoQueryParam <DefId > } ;
117
139
( $K: ty) => { $K } ;
@@ -220,14 +242,7 @@ macro_rules! define_callbacks {
220
242
let key = key. into_query_param( ) ;
221
243
opt_remap_env_constness!( [ $( $modifiers) * ] [ key] ) ;
222
244
223
- let cached = try_get_cached( self . tcx, & self . tcx. query_caches. $name, & key, noop) ;
224
-
225
- match cached {
226
- Ok ( ( ) ) => return ,
227
- Err ( ( ) ) => ( ) ,
228
- }
229
-
230
- self . tcx. queries. $name( self . tcx, DUMMY_SP , key, QueryMode :: Ensure ) ;
245
+ let _ = evaluate_query( self . tcx, QueryEngine :: $name, & self . tcx. query_caches. $name, DUMMY_SP , key, QueryMode :: Ensure ) ;
231
246
} ) *
232
247
}
233
248
@@ -249,14 +264,7 @@ macro_rules! define_callbacks {
249
264
let key = key. into_query_param( ) ;
250
265
opt_remap_env_constness!( [ $( $modifiers) * ] [ key] ) ;
251
266
252
- let cached = try_get_cached( self . tcx, & self . tcx. query_caches. $name, & key, copy) ;
253
-
254
- match cached {
255
- Ok ( value) => return value,
256
- Err ( ( ) ) => ( ) ,
257
- }
258
-
259
- self . tcx. queries. $name( self . tcx, self . span, key, QueryMode :: Get ) . unwrap( )
267
+ evaluate_query( self . tcx, QueryEngine :: $name, & self . tcx. query_caches. $name, self . span, key, QueryMode :: Get ) . unwrap( )
260
268
} ) *
261
269
}
262
270
0 commit comments