@@ -237,27 +237,32 @@ fn doc_comment_from_desc(list: &Punctuated<Expr, token::Comma>) -> Result<Attrib
237237}
238238
239239/// Add the impl of QueryDescription for the query to `impls` if one is requested
240- fn add_query_description_impl ( query : & Query , impls : & mut proc_macro2:: TokenStream ) {
241- let name = & query. name ;
242- let key = & query. key ;
243- let modifiers = & query. modifiers ;
240+ fn add_query_desc_cached_impl (
241+ query : & Query ,
242+ descs : & mut proc_macro2:: TokenStream ,
243+ cached : & mut proc_macro2:: TokenStream ,
244+ ) {
245+ let Query { name, key, modifiers, .. } = & query;
244246
245247 // Find out if we should cache the query on disk
246248 let cache = if let Some ( ( args, expr) ) = modifiers. cache . as_ref ( ) {
247249 let tcx = args. as_ref ( ) . map ( |t| quote ! { #t } ) . unwrap_or_else ( || quote ! { _ } ) ;
248250 // expr is a `Block`, meaning that `{ #expr }` gets expanded
249251 // to `{ { stmts... } }`, which triggers the `unused_braces` lint.
252+ // we're taking `key` by reference, but some rustc types usually prefer being passed by value
250253 quote ! {
251- #[ allow( unused_variables, unused_braces) ]
254+ #[ allow( unused_variables, unused_braces, rustc :: pass_by_value ) ]
252255 #[ inline]
253- fn cache_on_disk ( #tcx: TyCtxt <' tcx>, #key: & Self :: Key ) -> bool {
256+ pub fn #name< ' tcx> ( #tcx: TyCtxt <' tcx>, #key: & crate :: ty :: query :: query_keys :: #name< ' tcx> ) -> bool {
254257 #expr
255258 }
256259 }
257260 } else {
258261 quote ! {
262+ // we're taking `key` by reference, but some rustc types usually prefer being passed by value
263+ #[ allow( rustc:: pass_by_value) ]
259264 #[ inline]
260- fn cache_on_disk ( _: TyCtxt <' tcx>, _: & Self :: Key ) -> bool {
265+ pub fn #name< ' tcx> ( _: TyCtxt <' tcx>, _: & crate :: ty :: query :: query_keys :: #name< ' tcx> ) -> bool {
261266 false
262267 }
263268 }
@@ -268,19 +273,20 @@ fn add_query_description_impl(query: &Query, impls: &mut proc_macro2::TokenStrea
268273
269274 let desc = quote ! {
270275 #[ allow( unused_variables) ]
271- fn describe ( tcx: QueryCtxt <' tcx>, key: Self :: Key ) -> String {
272- let ( #tcx, #key) = ( * tcx, key) ;
276+ pub fn #name< ' tcx> ( tcx: TyCtxt <' tcx>, key: crate :: ty :: query :: query_keys :: #name< ' tcx> ) -> String {
277+ let ( #tcx, #key) = ( tcx, key) ;
273278 :: rustc_middle:: ty:: print:: with_no_trimmed_paths!(
274279 format!( #desc)
275280 )
276281 }
277282 } ;
278283
279- impls. extend ( quote ! {
280- ( #name) => {
281- #desc
282- #cache
283- } ;
284+ descs. extend ( quote ! {
285+ #desc
286+ } ) ;
287+
288+ cached. extend ( quote ! {
289+ #cache
284290 } ) ;
285291}
286292
@@ -289,6 +295,7 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream {
289295
290296 let mut query_stream = quote ! { } ;
291297 let mut query_description_stream = quote ! { } ;
298+ let mut query_cached_stream = quote ! { } ;
292299
293300 for query in queries. 0 {
294301 let Query { name, arg, modifiers, .. } = & query;
@@ -343,7 +350,7 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream {
343350 [ #attribute_stream] fn #name( #arg) #result,
344351 } ) ;
345352
346- add_query_description_impl ( & query, & mut query_description_stream) ;
353+ add_query_desc_cached_impl ( & query, & mut query_description_stream, & mut query_cached_stream ) ;
347354 }
348355
349356 TokenStream :: from ( quote ! {
@@ -357,9 +364,13 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream {
357364 }
358365 }
359366
360- # [ macro_export ]
361- macro_rules! rustc_query_description {
367+ pub mod descs {
368+ use super :: * ;
362369 #query_description_stream
363370 }
371+ pub mod cached {
372+ use super :: * ;
373+ #query_cached_stream
374+ }
364375 } )
365376}
0 commit comments