2018-12-03 00:14:35 +00:00
|
|
|
use proc_macro::TokenStream;
|
2021-06-08 00:39:42 +00:00
|
|
|
use quote::{quote, quote_spanned};
|
2019-04-05 11:11:44 +00:00
|
|
|
use syn::parse::{Parse, ParseStream, Result};
|
2018-12-03 00:14:35 +00:00
|
|
|
use syn::punctuated::Punctuated;
|
2019-03-18 07:19:23 +00:00
|
|
|
use syn::spanned::Spanned;
|
2018-12-03 00:14:35 +00:00
|
|
|
use syn::{
|
2022-08-21 22:44:39 +00:00
|
|
|
braced, parenthesized, parse_macro_input, parse_quote, token, AttrStyle, Attribute, Block,
|
|
|
|
Error, Expr, Ident, Pat, ReturnType, Token, Type,
|
2018-12-03 00:14:35 +00:00
|
|
|
};
|
|
|
|
|
2019-03-18 07:19:23 +00:00
|
|
|
mod kw {
|
|
|
|
syn::custom_keyword!(query);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Ensures only doc comment attributes are used
|
2020-09-17 04:03:00 +00:00
|
|
|
fn check_attributes(attrs: Vec<Attribute>) -> Result<Vec<Attribute>> {
|
|
|
|
let inner = |attr: Attribute| {
|
2023-03-27 13:44:06 +00:00
|
|
|
if !attr.path().is_ident("doc") {
|
2020-09-17 04:03:00 +00:00
|
|
|
Err(Error::new(attr.span(), "attributes not supported on queries"))
|
|
|
|
} else if attr.style != AttrStyle::Outer {
|
|
|
|
Err(Error::new(
|
|
|
|
attr.span(),
|
|
|
|
"attributes must be outer attributes (`///`), not inner attributes",
|
|
|
|
))
|
|
|
|
} else {
|
|
|
|
Ok(attr)
|
2019-03-18 07:19:23 +00:00
|
|
|
}
|
2020-09-17 04:03:00 +00:00
|
|
|
};
|
|
|
|
attrs.into_iter().map(inner).collect()
|
2019-03-18 07:19:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// A compiler query. `query ... { ... }`
|
2018-12-03 00:14:35 +00:00
|
|
|
struct Query {
|
2020-09-17 04:03:00 +00:00
|
|
|
doc_comments: Vec<Attribute>,
|
2022-08-21 22:44:39 +00:00
|
|
|
modifiers: QueryModifiers,
|
2018-12-03 00:14:35 +00:00
|
|
|
name: Ident,
|
2022-08-21 22:44:39 +00:00
|
|
|
key: Pat,
|
2018-12-03 00:14:35 +00:00
|
|
|
arg: Type,
|
|
|
|
result: ReturnType,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Parse for Query {
|
|
|
|
fn parse(input: ParseStream<'_>) -> Result<Self> {
|
2022-08-21 22:44:39 +00:00
|
|
|
let mut doc_comments = check_attributes(input.call(Attribute::parse_outer)?)?;
|
2018-12-03 00:14:35 +00:00
|
|
|
|
2019-03-18 07:19:23 +00:00
|
|
|
// Parse the query declaration. Like `query type_of(key: DefId) -> Ty<'tcx>`
|
|
|
|
input.parse::<kw::query>()?;
|
2018-12-03 00:14:35 +00:00
|
|
|
let name: Ident = input.parse()?;
|
|
|
|
let arg_content;
|
|
|
|
parenthesized!(arg_content in input);
|
2023-03-27 13:44:06 +00:00
|
|
|
let key = Pat::parse_single(&arg_content)?;
|
2018-12-03 00:14:35 +00:00
|
|
|
arg_content.parse::<Token![:]>()?;
|
|
|
|
let arg = arg_content.parse()?;
|
|
|
|
let result = input.parse()?;
|
|
|
|
|
2019-03-18 07:19:23 +00:00
|
|
|
// Parse the query modifiers
|
2018-12-03 00:14:35 +00:00
|
|
|
let content;
|
|
|
|
braced!(content in input);
|
2022-08-21 22:44:39 +00:00
|
|
|
let modifiers = parse_query_modifiers(&content)?;
|
|
|
|
|
|
|
|
// If there are no doc-comments, give at least some idea of what
|
|
|
|
// it does by showing the query description.
|
|
|
|
if doc_comments.is_empty() {
|
|
|
|
doc_comments.push(doc_comment_from_desc(&modifiers.desc.1)?);
|
|
|
|
}
|
2018-12-03 00:14:35 +00:00
|
|
|
|
2020-09-17 04:03:00 +00:00
|
|
|
Ok(Query { doc_comments, modifiers, name, key, arg, result })
|
2018-12-03 00:14:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-18 07:19:23 +00:00
|
|
|
/// A type used to greedily parse another type until the input is empty.
|
2018-12-03 00:14:35 +00:00
|
|
|
struct List<T>(Vec<T>);
|
|
|
|
|
|
|
|
impl<T: Parse> Parse for List<T> {
|
|
|
|
fn parse(input: ParseStream<'_>) -> Result<Self> {
|
|
|
|
let mut list = Vec::new();
|
|
|
|
while !input.is_empty() {
|
|
|
|
list.push(input.parse()?);
|
|
|
|
}
|
|
|
|
Ok(List(list))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-18 13:17:26 +00:00
|
|
|
struct QueryModifiers {
|
|
|
|
/// The description of the query.
|
2020-05-31 15:11:51 +00:00
|
|
|
desc: (Option<Ident>, Punctuated<Expr, Token![,]>),
|
2019-03-18 13:17:26 +00:00
|
|
|
|
2020-02-14 17:29:20 +00:00
|
|
|
/// Use this type for the in-memory cache.
|
2022-09-02 02:17:35 +00:00
|
|
|
arena_cache: Option<Ident>,
|
2020-02-14 17:29:20 +00:00
|
|
|
|
2019-04-05 11:11:44 +00:00
|
|
|
/// Cache the query to disk if the `Block` returns true.
|
2022-08-21 22:44:39 +00:00
|
|
|
cache: Option<(Option<Pat>, Block)>,
|
2019-03-18 13:17:26 +00:00
|
|
|
|
|
|
|
/// A cycle error for this query aborting the compilation with a fatal error.
|
2021-06-08 00:39:42 +00:00
|
|
|
fatal_cycle: Option<Ident>,
|
2019-03-20 15:06:09 +00:00
|
|
|
|
2019-03-29 02:05:19 +00:00
|
|
|
/// A cycle error results in a delay_bug call
|
2021-06-08 00:39:42 +00:00
|
|
|
cycle_delay_bug: Option<Ident>,
|
2019-03-29 02:05:19 +00:00
|
|
|
|
2023-10-26 17:30:53 +00:00
|
|
|
/// A cycle error results in a stashed cycle error that can be unstashed and canceled later
|
|
|
|
cycle_stash: Option<Ident>,
|
|
|
|
|
2019-03-20 15:06:09 +00:00
|
|
|
/// Don't hash the result, instead just mark a query red if it runs
|
2021-06-08 00:39:42 +00:00
|
|
|
no_hash: Option<Ident>,
|
2019-03-20 15:53:55 +00:00
|
|
|
|
2019-03-20 16:13:44 +00:00
|
|
|
/// Generate a dep node based on the dependencies of the query
|
2021-06-08 00:39:42 +00:00
|
|
|
anon: Option<Ident>,
|
2019-03-20 17:00:08 +00:00
|
|
|
|
2022-08-24 01:42:12 +00:00
|
|
|
/// Always evaluate the query, ignoring its dependencies
|
2021-06-08 00:39:42 +00:00
|
|
|
eval_always: Option<Ident>,
|
2021-05-30 15:24:54 +00:00
|
|
|
|
2022-08-24 01:42:12 +00:00
|
|
|
/// Whether the query has a call depth limit
|
|
|
|
depth_limit: Option<Ident>,
|
|
|
|
|
2021-05-30 15:24:54 +00:00
|
|
|
/// Use a separate query provider for local and extern crates
|
|
|
|
separate_provide_extern: Option<Ident>,
|
2021-12-06 11:47:54 +00:00
|
|
|
|
2022-03-22 20:45:32 +00:00
|
|
|
/// Generate a `feed` method to set the query's value from another query.
|
|
|
|
feedable: Option<Ident>,
|
2023-10-18 15:53:06 +00:00
|
|
|
|
|
|
|
/// Forward the result on ensure if the query gets recomputed, and
|
|
|
|
/// return `Ok(())` otherwise. Only applicable to queries returning
|
|
|
|
/// `Result<(), ErrorGuaranteed>`
|
|
|
|
ensure_forwards_result_if_red: Option<Ident>,
|
2019-03-18 13:17:26 +00:00
|
|
|
}
|
|
|
|
|
2022-08-21 22:44:39 +00:00
|
|
|
fn parse_query_modifiers(input: ParseStream<'_>) -> Result<QueryModifiers> {
|
2022-09-02 02:17:35 +00:00
|
|
|
let mut arena_cache = None;
|
2019-03-18 13:17:26 +00:00
|
|
|
let mut cache = None;
|
|
|
|
let mut desc = None;
|
2021-06-08 00:39:42 +00:00
|
|
|
let mut fatal_cycle = None;
|
|
|
|
let mut cycle_delay_bug = None;
|
2023-10-26 17:30:53 +00:00
|
|
|
let mut cycle_stash = None;
|
2021-06-08 00:39:42 +00:00
|
|
|
let mut no_hash = None;
|
|
|
|
let mut anon = None;
|
|
|
|
let mut eval_always = None;
|
2022-08-24 01:42:12 +00:00
|
|
|
let mut depth_limit = None;
|
2021-05-30 15:24:54 +00:00
|
|
|
let mut separate_provide_extern = None;
|
2022-03-22 20:45:32 +00:00
|
|
|
let mut feedable = None;
|
2023-10-18 15:53:06 +00:00
|
|
|
let mut ensure_forwards_result_if_red = None;
|
2022-08-21 22:44:39 +00:00
|
|
|
|
|
|
|
while !input.is_empty() {
|
|
|
|
let modifier: Ident = input.parse()?;
|
|
|
|
|
|
|
|
macro_rules! try_insert {
|
|
|
|
($name:ident = $expr:expr) => {
|
|
|
|
if $name.is_some() {
|
|
|
|
return Err(Error::new(modifier.span(), "duplicate modifier"));
|
2021-12-06 11:47:54 +00:00
|
|
|
}
|
2022-08-21 22:44:39 +00:00
|
|
|
$name = Some($expr);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if modifier == "desc" {
|
|
|
|
// Parse a description modifier like:
|
|
|
|
// `desc { |tcx| "foo {}", tcx.item_path(key) }`
|
|
|
|
let attr_content;
|
|
|
|
braced!(attr_content in input);
|
|
|
|
let tcx = if attr_content.peek(Token![|]) {
|
|
|
|
attr_content.parse::<Token![|]>()?;
|
|
|
|
let tcx = attr_content.parse()?;
|
|
|
|
attr_content.parse::<Token![|]>()?;
|
|
|
|
Some(tcx)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
2023-03-27 13:44:06 +00:00
|
|
|
let list = attr_content.parse_terminated(Expr::parse, Token![,])?;
|
2022-08-21 22:44:39 +00:00
|
|
|
try_insert!(desc = (tcx, list));
|
|
|
|
} else if modifier == "cache_on_disk_if" {
|
|
|
|
// Parse a cache modifier like:
|
|
|
|
// `cache(tcx) { |tcx| key.is_local() }`
|
|
|
|
let args = if input.peek(token::Paren) {
|
|
|
|
let args;
|
|
|
|
parenthesized!(args in input);
|
2023-03-27 13:44:06 +00:00
|
|
|
let tcx = Pat::parse_single(&args)?;
|
2022-08-21 22:44:39 +00:00
|
|
|
Some(tcx)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
|
|
|
let block = input.parse()?;
|
|
|
|
try_insert!(cache = (args, block));
|
2022-09-02 02:17:35 +00:00
|
|
|
} else if modifier == "arena_cache" {
|
|
|
|
try_insert!(arena_cache = modifier);
|
2022-08-21 22:44:39 +00:00
|
|
|
} else if modifier == "fatal_cycle" {
|
|
|
|
try_insert!(fatal_cycle = modifier);
|
|
|
|
} else if modifier == "cycle_delay_bug" {
|
|
|
|
try_insert!(cycle_delay_bug = modifier);
|
2023-10-26 17:30:53 +00:00
|
|
|
} else if modifier == "cycle_stash" {
|
|
|
|
try_insert!(cycle_stash = modifier);
|
2022-08-21 22:44:39 +00:00
|
|
|
} else if modifier == "no_hash" {
|
|
|
|
try_insert!(no_hash = modifier);
|
|
|
|
} else if modifier == "anon" {
|
|
|
|
try_insert!(anon = modifier);
|
|
|
|
} else if modifier == "eval_always" {
|
|
|
|
try_insert!(eval_always = modifier);
|
2022-08-24 01:42:12 +00:00
|
|
|
} else if modifier == "depth_limit" {
|
|
|
|
try_insert!(depth_limit = modifier);
|
2022-08-21 22:44:39 +00:00
|
|
|
} else if modifier == "separate_provide_extern" {
|
|
|
|
try_insert!(separate_provide_extern = modifier);
|
2022-03-22 20:45:32 +00:00
|
|
|
} else if modifier == "feedable" {
|
|
|
|
try_insert!(feedable = modifier);
|
2023-10-18 15:53:06 +00:00
|
|
|
} else if modifier == "ensure_forwards_result_if_red" {
|
|
|
|
try_insert!(ensure_forwards_result_if_red = modifier);
|
2022-08-21 22:44:39 +00:00
|
|
|
} else {
|
|
|
|
return Err(Error::new(modifier.span(), "unknown query modifier"));
|
2019-03-18 13:17:26 +00:00
|
|
|
}
|
|
|
|
}
|
2022-08-21 22:44:39 +00:00
|
|
|
let Some(desc) = desc else {
|
|
|
|
return Err(input.error("no description provided"));
|
|
|
|
};
|
|
|
|
Ok(QueryModifiers {
|
2022-09-02 02:17:35 +00:00
|
|
|
arena_cache,
|
2019-03-18 13:17:26 +00:00
|
|
|
cache,
|
|
|
|
desc,
|
|
|
|
fatal_cycle,
|
2019-03-29 02:05:19 +00:00
|
|
|
cycle_delay_bug,
|
2023-10-26 17:30:53 +00:00
|
|
|
cycle_stash,
|
2019-03-20 15:06:09 +00:00
|
|
|
no_hash,
|
2019-03-20 16:13:44 +00:00
|
|
|
anon,
|
2019-03-20 16:22:16 +00:00
|
|
|
eval_always,
|
2022-08-24 01:42:12 +00:00
|
|
|
depth_limit,
|
2021-05-30 15:24:54 +00:00
|
|
|
separate_provide_extern,
|
2022-03-22 20:45:32 +00:00
|
|
|
feedable,
|
2023-10-18 15:53:06 +00:00
|
|
|
ensure_forwards_result_if_red,
|
2022-08-21 22:44:39 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
fn doc_comment_from_desc(list: &Punctuated<Expr, token::Comma>) -> Result<Attribute> {
|
|
|
|
use ::syn::*;
|
|
|
|
let mut iter = list.iter();
|
|
|
|
let format_str: String = match iter.next() {
|
|
|
|
Some(&Expr::Lit(ExprLit { lit: Lit::Str(ref lit_str), .. })) => {
|
|
|
|
lit_str.value().replace("`{}`", "{}") // We add them later anyways for consistency
|
|
|
|
}
|
|
|
|
_ => return Err(Error::new(list.span(), "Expected a string literal")),
|
|
|
|
};
|
|
|
|
let mut fmt_fragments = format_str.split("{}");
|
|
|
|
let mut doc_string = fmt_fragments.next().unwrap().to_string();
|
|
|
|
iter.map(::quote::ToTokens::to_token_stream).zip(fmt_fragments).for_each(
|
|
|
|
|(tts, next_fmt_fragment)| {
|
|
|
|
use ::core::fmt::Write;
|
|
|
|
write!(
|
|
|
|
&mut doc_string,
|
|
|
|
" `{}` {}",
|
|
|
|
tts.to_string().replace(" . ", "."),
|
|
|
|
next_fmt_fragment,
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
},
|
|
|
|
);
|
2022-12-19 09:31:55 +00:00
|
|
|
let doc_string = format!("[query description - consider adding a doc-comment!] {doc_string}");
|
2022-08-21 22:44:39 +00:00
|
|
|
Ok(parse_quote! { #[doc = #doc_string] })
|
2019-03-18 13:17:26 +00:00
|
|
|
}
|
|
|
|
|
2019-03-18 07:19:23 +00:00
|
|
|
/// Add the impl of QueryDescription for the query to `impls` if one is requested
|
2022-10-10 18:03:19 +00:00
|
|
|
fn add_query_desc_cached_impl(
|
|
|
|
query: &Query,
|
|
|
|
descs: &mut proc_macro2::TokenStream,
|
|
|
|
cached: &mut proc_macro2::TokenStream,
|
|
|
|
) {
|
|
|
|
let Query { name, key, modifiers, .. } = &query;
|
2019-03-18 07:19:23 +00:00
|
|
|
|
|
|
|
// Find out if we should cache the query on disk
|
2020-05-31 15:11:51 +00:00
|
|
|
let cache = if let Some((args, expr)) = modifiers.cache.as_ref() {
|
2022-08-21 22:44:39 +00:00
|
|
|
let tcx = args.as_ref().map(|t| quote! { #t }).unwrap_or_else(|| quote! { _ });
|
2020-03-27 20:55:15 +00:00
|
|
|
// expr is a `Block`, meaning that `{ #expr }` gets expanded
|
|
|
|
// to `{ { stmts... } }`, which triggers the `unused_braces` lint.
|
2022-10-10 18:03:19 +00:00
|
|
|
// we're taking `key` by reference, but some rustc types usually prefer being passed by value
|
2019-03-18 07:19:23 +00:00
|
|
|
quote! {
|
2022-10-10 18:03:19 +00:00
|
|
|
#[allow(unused_variables, unused_braces, rustc::pass_by_value)]
|
2021-10-17 15:37:20 +00:00
|
|
|
#[inline]
|
2023-05-18 01:39:35 +00:00
|
|
|
pub fn #name<'tcx>(#tcx: TyCtxt<'tcx>, #key: &crate::query::queries::#name::Key<'tcx>) -> bool {
|
2019-03-18 07:19:23 +00:00
|
|
|
#expr
|
|
|
|
}
|
|
|
|
}
|
2020-05-31 15:11:51 +00:00
|
|
|
} else {
|
2021-10-17 15:37:20 +00:00
|
|
|
quote! {
|
2022-10-10 18:03:19 +00:00
|
|
|
// we're taking `key` by reference, but some rustc types usually prefer being passed by value
|
|
|
|
#[allow(rustc::pass_by_value)]
|
2021-10-17 15:37:20 +00:00
|
|
|
#[inline]
|
2023-05-18 01:39:35 +00:00
|
|
|
pub fn #name<'tcx>(_: TyCtxt<'tcx>, _: &crate::query::queries::#name::Key<'tcx>) -> bool {
|
2021-10-17 15:37:20 +00:00
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
2020-05-31 15:11:51 +00:00
|
|
|
};
|
|
|
|
|
2022-08-21 22:44:39 +00:00
|
|
|
let (tcx, desc) = &modifiers.desc;
|
2021-02-23 22:02:05 +00:00
|
|
|
let tcx = tcx.as_ref().map_or_else(|| quote! { _ }, |t| quote! { #t });
|
2020-05-31 15:11:51 +00:00
|
|
|
|
|
|
|
let desc = quote! {
|
|
|
|
#[allow(unused_variables)]
|
2023-05-18 01:39:35 +00:00
|
|
|
pub fn #name<'tcx>(tcx: TyCtxt<'tcx>, key: crate::query::queries::#name::Key<'tcx>) -> String {
|
2022-10-10 18:03:19 +00:00
|
|
|
let (#tcx, #key) = (tcx, key);
|
2022-02-16 18:04:48 +00:00
|
|
|
::rustc_middle::ty::print::with_no_trimmed_paths!(
|
|
|
|
format!(#desc)
|
|
|
|
)
|
2020-05-31 15:11:51 +00:00
|
|
|
}
|
|
|
|
};
|
2019-03-18 07:19:23 +00:00
|
|
|
|
2022-10-10 18:03:19 +00:00
|
|
|
descs.extend(quote! {
|
|
|
|
#desc
|
|
|
|
});
|
|
|
|
|
|
|
|
cached.extend(quote! {
|
|
|
|
#cache
|
2019-03-18 07:19:23 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-12-03 00:14:35 +00:00
|
|
|
pub fn rustc_queries(input: TokenStream) -> TokenStream {
|
2021-01-31 20:37:17 +00:00
|
|
|
let queries = parse_macro_input!(input as List<Query>);
|
2018-12-03 00:14:35 +00:00
|
|
|
|
|
|
|
let mut query_stream = quote! {};
|
|
|
|
let mut query_description_stream = quote! {};
|
2022-10-10 18:03:19 +00:00
|
|
|
let mut query_cached_stream = quote! {};
|
2022-03-22 20:45:32 +00:00
|
|
|
let mut feedable_queries = quote! {};
|
2018-12-03 00:14:35 +00:00
|
|
|
|
2022-08-21 22:44:39 +00:00
|
|
|
for query in queries.0 {
|
|
|
|
let Query { name, arg, modifiers, .. } = &query;
|
2021-01-31 20:40:03 +00:00
|
|
|
let result_full = &query.result;
|
|
|
|
let result = match query.result {
|
|
|
|
ReturnType::Default => quote! { -> () },
|
|
|
|
_ => quote! { #result_full },
|
|
|
|
};
|
2018-12-03 00:14:35 +00:00
|
|
|
|
2021-01-31 20:40:03 +00:00
|
|
|
let mut attributes = Vec::new();
|
2019-03-20 15:06:09 +00:00
|
|
|
|
2022-09-02 02:21:29 +00:00
|
|
|
macro_rules! passthrough {
|
|
|
|
( $( $modifier:ident ),+ $(,)? ) => {
|
|
|
|
$( if let Some($modifier) = &modifiers.$modifier {
|
|
|
|
attributes.push(quote! { (#$modifier) });
|
|
|
|
}; )+
|
|
|
|
}
|
2021-12-06 11:47:54 +00:00
|
|
|
}
|
2019-03-20 16:13:44 +00:00
|
|
|
|
2022-09-02 02:21:29 +00:00
|
|
|
passthrough!(
|
|
|
|
fatal_cycle,
|
|
|
|
arena_cache,
|
|
|
|
cycle_delay_bug,
|
2023-10-26 17:30:53 +00:00
|
|
|
cycle_stash,
|
2022-09-02 02:21:29 +00:00
|
|
|
no_hash,
|
|
|
|
anon,
|
|
|
|
eval_always,
|
|
|
|
depth_limit,
|
|
|
|
separate_provide_extern,
|
2023-10-18 15:53:06 +00:00
|
|
|
ensure_forwards_result_if_red,
|
2022-09-02 02:21:29 +00:00
|
|
|
);
|
|
|
|
|
2022-09-15 11:54:03 +00:00
|
|
|
if modifiers.cache.is_some() {
|
|
|
|
attributes.push(quote! { (cache) });
|
2021-12-06 11:47:54 +00:00
|
|
|
}
|
2022-09-14 17:11:53 +00:00
|
|
|
// Pass on the cache modifier
|
2022-09-05 11:43:11 +00:00
|
|
|
if modifiers.cache.is_some() {
|
|
|
|
attributes.push(quote! { (cache) });
|
|
|
|
}
|
|
|
|
|
2021-06-08 00:39:42 +00:00
|
|
|
// This uses the span of the query definition for the commas,
|
|
|
|
// which can be important if we later encounter any ambiguity
|
|
|
|
// errors with any of the numerous macro_rules! macros that
|
|
|
|
// we use. Using the call-site span would result in a span pointing
|
|
|
|
// at the entire `rustc_queries!` invocation, which wouldn't
|
|
|
|
// be very useful.
|
|
|
|
let span = name.span();
|
|
|
|
let attribute_stream = quote_spanned! {span=> #(#attributes),*};
|
2022-08-29 23:46:56 +00:00
|
|
|
let doc_comments = &query.doc_comments;
|
2021-01-31 20:40:03 +00:00
|
|
|
// Add the query to the group
|
|
|
|
query_stream.extend(quote! {
|
|
|
|
#(#doc_comments)*
|
|
|
|
[#attribute_stream] fn #name(#arg) #result,
|
|
|
|
});
|
2019-06-24 23:41:16 +00:00
|
|
|
|
2022-03-22 20:45:32 +00:00
|
|
|
if modifiers.feedable.is_some() {
|
2022-10-29 13:04:38 +00:00
|
|
|
assert!(modifiers.anon.is_none(), "Query {name} cannot be both `feedable` and `anon`.");
|
|
|
|
assert!(
|
|
|
|
modifiers.eval_always.is_none(),
|
|
|
|
"Query {name} cannot be both `feedable` and `eval_always`."
|
|
|
|
);
|
2022-03-22 20:45:32 +00:00
|
|
|
feedable_queries.extend(quote! {
|
|
|
|
#(#doc_comments)*
|
|
|
|
[#attribute_stream] fn #name(#arg) #result,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-10-10 18:03:19 +00:00
|
|
|
add_query_desc_cached_impl(&query, &mut query_description_stream, &mut query_cached_stream);
|
2021-01-31 20:40:03 +00:00
|
|
|
}
|
2019-03-20 15:53:55 +00:00
|
|
|
|
2018-12-03 00:14:35 +00:00
|
|
|
TokenStream::from(quote! {
|
2021-01-19 19:40:16 +00:00
|
|
|
#[macro_export]
|
2018-12-03 00:14:35 +00:00
|
|
|
macro_rules! rustc_query_append {
|
2022-09-07 02:26:02 +00:00
|
|
|
($macro:ident! $( [$($other:tt)*] )?) => {
|
2022-08-24 05:02:37 +00:00
|
|
|
$macro! {
|
2022-09-07 02:26:02 +00:00
|
|
|
$( $($other)* )?
|
2018-12-03 00:14:35 +00:00
|
|
|
#query_stream
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-03-22 20:45:32 +00:00
|
|
|
macro_rules! rustc_feedable_queries {
|
|
|
|
( $macro:ident! ) => {
|
|
|
|
$macro!(#feedable_queries);
|
|
|
|
}
|
|
|
|
}
|
2022-10-10 18:03:19 +00:00
|
|
|
pub mod descs {
|
|
|
|
use super::*;
|
2021-10-17 15:37:20 +00:00
|
|
|
#query_description_stream
|
2021-01-19 18:43:59 +00:00
|
|
|
}
|
2022-10-10 18:03:19 +00:00
|
|
|
pub mod cached {
|
|
|
|
use super::*;
|
|
|
|
#query_cached_stream
|
|
|
|
}
|
2018-12-03 00:14:35 +00:00
|
|
|
})
|
|
|
|
}
|