@@ -86,14 +86,11 @@ struct QueryModifiers {
86
86
desc : ( Option < Ident > , Punctuated < Expr , Token ! [ , ] > ) ,
87
87
88
88
/// Use this type for the in-memory cache.
89
- storage : Option < Type > ,
89
+ arena_cache : Option < Ident > ,
90
90
91
91
/// Cache the query to disk if the `Block` returns true.
92
92
cache : Option < ( Option < Pat > , Block ) > ,
93
93
94
- /// Custom code to load the query from disk.
95
- load_cached : Option < ( Ident , Ident , Block ) > ,
96
-
97
94
/// A cycle error for this query aborting the compilation with a fatal error.
98
95
fatal_cycle : Option < Ident > ,
99
96
@@ -120,8 +117,7 @@ struct QueryModifiers {
120
117
}
121
118
122
119
fn parse_query_modifiers ( input : ParseStream < ' _ > ) -> Result < QueryModifiers > {
123
- let mut load_cached = None ;
124
- let mut storage = None ;
120
+ let mut arena_cache = None ;
125
121
let mut cache = None ;
126
122
let mut desc = None ;
127
123
let mut fatal_cycle = None ;
@@ -173,21 +169,8 @@ fn parse_query_modifiers(input: ParseStream<'_>) -> Result<QueryModifiers> {
173
169
} ;
174
170
let block = input. parse ( ) ?;
175
171
try_insert ! ( cache = ( args, block) ) ;
176
- } else if modifier == "load_cached" {
177
- // Parse a load_cached modifier like:
178
- // `load_cached(tcx, id) { tcx.on_disk_cache.try_load_query_result(tcx, id) }`
179
- let args;
180
- parenthesized ! ( args in input) ;
181
- let tcx = args. parse ( ) ?;
182
- args. parse :: < Token ! [ , ] > ( ) ?;
183
- let id = args. parse ( ) ?;
184
- let block = input. parse ( ) ?;
185
- try_insert ! ( load_cached = ( tcx, id, block) ) ;
186
- } else if modifier == "storage" {
187
- let args;
188
- parenthesized ! ( args in input) ;
189
- let ty = args. parse ( ) ?;
190
- try_insert ! ( storage = ty) ;
172
+ } else if modifier == "arena_cache" {
173
+ try_insert ! ( arena_cache = modifier) ;
191
174
} else if modifier == "fatal_cycle" {
192
175
try_insert ! ( fatal_cycle = modifier) ;
193
176
} else if modifier == "cycle_delay_bug" {
@@ -212,8 +195,7 @@ fn parse_query_modifiers(input: ParseStream<'_>) -> Result<QueryModifiers> {
212
195
return Err ( input. error ( "no description provided" ) ) ;
213
196
} ;
214
197
Ok ( QueryModifiers {
215
- load_cached,
216
- storage,
198
+ arena_cache,
217
199
cache,
218
200
desc,
219
201
fatal_cycle,
@@ -262,20 +244,6 @@ fn add_query_description_impl(query: &Query, impls: &mut proc_macro2::TokenStrea
262
244
263
245
// Find out if we should cache the query on disk
264
246
let cache = if let Some ( ( args, expr) ) = modifiers. cache . as_ref ( ) {
265
- let try_load_from_disk = if let Some ( ( tcx, id, block) ) = modifiers. load_cached . as_ref ( ) {
266
- // Use custom code to load the query from disk
267
- quote ! {
268
- const TRY_LOAD_FROM_DISK : Option <fn ( QueryCtxt <' tcx>, SerializedDepNodeIndex ) -> Option <Self :: Value >>
269
- = Some ( |#tcx, #id| { #block } ) ;
270
- }
271
- } else {
272
- // Use the default code to load the query from disk
273
- quote ! {
274
- const TRY_LOAD_FROM_DISK : Option <fn ( QueryCtxt <' tcx>, SerializedDepNodeIndex ) -> Option <Self :: Value >>
275
- = Some ( |tcx, id| tcx. on_disk_cache( ) . as_ref( ) ?. try_load_query_result( * tcx, id) ) ;
276
- }
277
- } ;
278
-
279
247
let tcx = args. as_ref ( ) . map ( |t| quote ! { #t } ) . unwrap_or_else ( || quote ! { _ } ) ;
280
248
// expr is a `Block`, meaning that `{ #expr }` gets expanded
281
249
// to `{ { stmts... } }`, which triggers the `unused_braces` lint.
@@ -285,20 +253,13 @@ fn add_query_description_impl(query: &Query, impls: &mut proc_macro2::TokenStrea
285
253
fn cache_on_disk( #tcx: TyCtxt <' tcx>, #key: & Self :: Key ) -> bool {
286
254
#expr
287
255
}
288
-
289
- #try_load_from_disk
290
256
}
291
257
} else {
292
- if modifiers. load_cached . is_some ( ) {
293
- panic ! ( "load_cached modifier on query `{}` without a cache modifier" , name) ;
294
- }
295
258
quote ! {
296
259
#[ inline]
297
260
fn cache_on_disk( _: TyCtxt <' tcx>, _: & Self :: Key ) -> bool {
298
261
false
299
262
}
300
-
301
- const TRY_LOAD_FROM_DISK : Option <fn ( QueryCtxt <' tcx>, SerializedDepNodeIndex ) -> Option <Self :: Value >> = None ;
302
263
}
303
264
} ;
304
265
@@ -347,42 +308,28 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream {
347
308
348
309
let mut attributes = Vec :: new ( ) ;
349
310
350
- // Pass on the fatal_cycle modifier
351
- if let Some ( fatal_cycle) = & modifiers. fatal_cycle {
352
- attributes. push ( quote ! { ( #fatal_cycle) } ) ;
353
- } ;
354
- // Pass on the storage modifier
355
- if let Some ( ref ty) = modifiers. storage {
356
- let span = ty. span ( ) ;
357
- attributes. push ( quote_spanned ! { span=> ( storage #ty) } ) ;
358
- } ;
359
- // Pass on the cycle_delay_bug modifier
360
- if let Some ( cycle_delay_bug) = & modifiers. cycle_delay_bug {
361
- attributes. push ( quote ! { ( #cycle_delay_bug) } ) ;
362
- } ;
363
- // Pass on the no_hash modifier
364
- if let Some ( no_hash) = & modifiers. no_hash {
365
- attributes. push ( quote ! { ( #no_hash) } ) ;
366
- } ;
367
- // Pass on the anon modifier
368
- if let Some ( anon) = & modifiers. anon {
369
- attributes. push ( quote ! { ( #anon) } ) ;
370
- } ;
371
- // Pass on the eval_always modifier
372
- if let Some ( eval_always) = & modifiers. eval_always {
373
- attributes. push ( quote ! { ( #eval_always) } ) ;
374
- } ;
375
- // Pass on the depth_limit modifier
376
- if let Some ( depth_limit) = & modifiers. depth_limit {
377
- attributes. push ( quote ! { ( #depth_limit) } ) ;
378
- } ;
379
- // Pass on the separate_provide_extern modifier
380
- if let Some ( separate_provide_extern) = & modifiers. separate_provide_extern {
381
- attributes. push ( quote ! { ( #separate_provide_extern) } ) ;
311
+ macro_rules! passthrough {
312
+ ( $( $modifier: ident ) ,+ $( , ) ? ) => {
313
+ $( if let Some ( $modifier) = & modifiers. $modifier {
314
+ attributes. push( quote! { ( #$modifier) } ) ;
315
+ } ; ) +
316
+ }
382
317
}
383
- // Pass on the remap_env_constness modifier
384
- if let Some ( remap_env_constness) = & modifiers. remap_env_constness {
385
- attributes. push ( quote ! { ( #remap_env_constness) } ) ;
318
+
319
+ passthrough ! (
320
+ fatal_cycle,
321
+ arena_cache,
322
+ cycle_delay_bug,
323
+ no_hash,
324
+ anon,
325
+ eval_always,
326
+ depth_limit,
327
+ separate_provide_extern,
328
+ remap_env_constness,
329
+ ) ;
330
+
331
+ if modifiers. cache . is_some ( ) {
332
+ attributes. push ( quote ! { ( cache) } ) ;
386
333
}
387
334
388
335
// This uses the span of the query definition for the commas,
0 commit comments