diff --git a/compiler/rustc_macros/src/query.rs b/compiler/rustc_macros/src/query.rs index 52c93133f79..32a15413c6f 100644 --- a/compiler/rustc_macros/src/query.rs +++ b/compiler/rustc_macros/src/query.rs @@ -400,10 +400,8 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream { TokenStream::from(quote! { #[macro_export] macro_rules! rustc_query_append { - ([$($macro:tt)*][$($other:tt)*]) => { + ([$($macro:tt)*]) => { $($macro)* { - $($other)* - #query_stream } } diff --git a/compiler/rustc_middle/src/dep_graph/dep_node.rs b/compiler/rustc_middle/src/dep_graph/dep_node.rs index 2d095438fc4..156a9641272 100644 --- a/compiler/rustc_middle/src/dep_graph/dep_node.rs +++ b/compiler/rustc_middle/src/dep_graph/dep_node.rs @@ -143,7 +143,7 @@ pub fn fingerprint_style(self, tcx: TyCtxt<'_>) -> FingerprintStyle { } macro_rules! define_dep_nodes { - (<$tcx:tt> + ( $( [$($attrs:tt)*] $variant:ident $(( $tuple_arg_ty:ty $(,)? ))* @@ -179,7 +179,7 @@ pub mod label_strs { ); } -rustc_dep_node_append!([define_dep_nodes!][ <'tcx> +rustc_dep_node_append!([define_dep_nodes!][ // We use this for most things when incr. comp. is turned off. [] Null, diff --git a/compiler/rustc_middle/src/ty/query.rs b/compiler/rustc_middle/src/ty/query.rs index 2452bcf6a61..736ab69c812 100644 --- a/compiler/rustc_middle/src/ty/query.rs +++ b/compiler/rustc_middle/src/ty/query.rs @@ -173,7 +173,7 @@ macro_rules! opt_remap_env_constness { } macro_rules! define_callbacks { - (<$tcx:tt> + ( $($(#[$attr:meta])* [$($modifiers:tt)*] fn $name:ident($($K:tt)*) -> $V:ty,)*) => { @@ -187,33 +187,33 @@ macro_rules! define_callbacks { pub mod query_keys { use super::*; - $(pub type $name<$tcx> = $($K)*;)* + $(pub type $name<'tcx> = $($K)*;)* } #[allow(nonstandard_style, unused_lifetimes)] pub mod query_values { use super::*; - $(pub type $name<$tcx> = $V;)* + $(pub type $name<'tcx> = $V;)* } #[allow(nonstandard_style, unused_lifetimes)] pub mod query_storage { use super::*; - $(pub type $name<$tcx> = query_storage!([$($modifiers)*][$($K)*, $V]);)* + $(pub type $name<'tcx> = query_storage!([$($modifiers)*][$($K)*, $V]);)* } #[allow(nonstandard_style, unused_lifetimes)] pub mod query_stored { use super::*; - $(pub type $name<$tcx> = as QueryStorage>::Stored;)* + $(pub type $name<'tcx> = as QueryStorage>::Stored;)* } #[derive(Default)] - pub struct QueryCaches<$tcx> { - $($(#[$attr])* pub $name: query_storage::$name<$tcx>,)* + pub struct QueryCaches<'tcx> { + $($(#[$attr])* pub $name: query_storage::$name<'tcx>,)* } - impl<$tcx> TyCtxtEnsure<$tcx> { + impl<'tcx> TyCtxtEnsure<'tcx> { $($(#[$attr])* #[inline(always)] pub fn $name(self, key: query_helper_param_ty!($($K)*)) { @@ -231,20 +231,20 @@ pub fn $name(self, key: query_helper_param_ty!($($K)*)) { })* } - impl<$tcx> TyCtxt<$tcx> { + impl<'tcx> TyCtxt<'tcx> { $($(#[$attr])* #[inline(always)] #[must_use] - pub fn $name(self, key: query_helper_param_ty!($($K)*)) -> query_stored::$name<$tcx> + pub fn $name(self, key: query_helper_param_ty!($($K)*)) -> query_stored::$name<'tcx> { self.at(DUMMY_SP).$name(key) })* } - impl<$tcx> TyCtxtAt<$tcx> { + impl<'tcx> TyCtxtAt<'tcx> { $($(#[$attr])* #[inline(always)] - pub fn $name(self, key: query_helper_param_ty!($($K)*)) -> query_stored::$name<$tcx> + pub fn $name(self, key: query_helper_param_ty!($($K)*)) -> query_stored::$name<'tcx> { let key = key.into_query_param(); opt_remap_env_constness!([$($modifiers)*][key]); @@ -311,11 +311,11 @@ pub trait QueryEngine<'tcx>: rustc_data_structures::sync::Sync { $($(#[$attr])* fn $name( &'tcx self, - tcx: TyCtxt<$tcx>, + tcx: TyCtxt<'tcx>, span: Span, - key: query_keys::$name<$tcx>, + key: query_keys::$name<'tcx>, mode: QueryMode, - ) -> Option>;)* + ) -> Option>;)* } }; } @@ -332,7 +332,7 @@ fn $name( // Queries marked with `fatal_cycle` do not need the latter implementation, // as they will raise an fatal error on query cycles instead. -rustc_query_append! { [define_callbacks!][<'tcx>] } +rustc_query_append! { [define_callbacks!] } mod sealed { use super::{DefId, LocalDefId}; diff --git a/compiler/rustc_query_impl/src/lib.rs b/compiler/rustc_query_impl/src/lib.rs index df187ea0c94..d8c85ab9faa 100644 --- a/compiler/rustc_query_impl/src/lib.rs +++ b/compiler/rustc_query_impl/src/lib.rs @@ -55,7 +55,7 @@ fn describe_as_module(def_id: LocalDefId, tcx: TyCtxt<'_>) -> String { } } -rustc_query_append! { [define_queries!][<'tcx>] } +rustc_query_append! { [define_queries!] } impl<'tcx> Queries<'tcx> { // Force codegen in the dyn-trait transformation in this crate. diff --git a/compiler/rustc_query_impl/src/plumbing.rs b/compiler/rustc_query_impl/src/plumbing.rs index 339683cf689..cb54edb2952 100644 --- a/compiler/rustc_query_impl/src/plumbing.rs +++ b/compiler/rustc_query_impl/src/plumbing.rs @@ -234,11 +234,10 @@ macro_rules! get_provider { } macro_rules! define_queries { - (<$tcx:tt> + ( $($(#[$attr:meta])* [$($modifiers:tt)*] fn $name:ident($($K:tt)*) -> $V:ty,)*) => { define_queries_struct! { - tcx: $tcx, input: ($(([$($modifiers)*] [$($attr)*] [$name]))*) } @@ -247,7 +246,7 @@ mod make_query { // Create an eponymous constructor for each query. $(#[allow(nonstandard_style)] $(#[$attr])* - pub fn $name<$tcx>(tcx: QueryCtxt<$tcx>, key: query_keys::$name<$tcx>) -> QueryStackFrame { + pub fn $name<'tcx>(tcx: QueryCtxt<'tcx>, key: query_keys::$name<'tcx>) -> QueryStackFrame { let kind = dep_graph::DepKind::$name; let name = stringify!($name); // Disable visible paths printing for performance reasons. @@ -295,32 +294,32 @@ pub fn $name<$tcx>(tcx: QueryCtxt<$tcx>, key: query_keys::$name<$tcx>) -> QueryS mod queries { use std::marker::PhantomData; - $(pub struct $name<$tcx> { - data: PhantomData<&$tcx ()> + $(pub struct $name<'tcx> { + data: PhantomData<&'tcx ()> })* } - $(impl<$tcx> QueryConfig for queries::$name<$tcx> { - type Key = query_keys::$name<$tcx>; - type Value = query_values::$name<$tcx>; - type Stored = query_stored::$name<$tcx>; + $(impl<'tcx> QueryConfig for queries::$name<'tcx> { + type Key = query_keys::$name<'tcx>; + type Value = query_values::$name<'tcx>; + type Stored = query_stored::$name<'tcx>; const NAME: &'static str = stringify!($name); } - impl<$tcx> QueryDescription> for queries::$name<$tcx> { - rustc_query_description! { $name<$tcx> } + impl<'tcx> QueryDescription> for queries::$name<'tcx> { + rustc_query_description! { $name<'tcx> } - type Cache = query_storage::$name<$tcx>; + type Cache = query_storage::$name<'tcx>; #[inline(always)] - fn query_state<'a>(tcx: QueryCtxt<$tcx>) -> &'a QueryState - where QueryCtxt<$tcx>: 'a + fn query_state<'a>(tcx: QueryCtxt<'tcx>) -> &'a QueryState + where QueryCtxt<'tcx>: 'a { &tcx.queries.$name } #[inline(always)] - fn query_cache<'a>(tcx: QueryCtxt<$tcx>) -> &'a Self::Cache + fn query_cache<'a>(tcx: QueryCtxt<'tcx>) -> &'a Self::Cache where 'tcx:'a { &tcx.query_caches.$name @@ -328,7 +327,7 @@ fn query_cache<'a>(tcx: QueryCtxt<$tcx>) -> &'a Self::Cache #[inline] fn make_vtable(tcx: QueryCtxt<'tcx>, key: &Self::Key) -> - QueryVTable, Self::Key, Self::Value> + QueryVTable, Self::Key, Self::Value> { let compute = get_provider!([$($modifiers)*][tcx, $name, key]); let cache_on_disk = Self::cache_on_disk(tcx.tcx, key); @@ -465,28 +464,25 @@ pub fn query_callbacks<'tcx>(arena: &'tcx Arena<'tcx>) -> &'tcx [DepKindStruct] } } -// FIXME(eddyb) this macro (and others?) use `$tcx` and `'tcx` interchangeably. -// We should either not take `$tcx` at all and use `'tcx` everywhere, or use -// `$tcx` everywhere (even if that isn't necessary due to lack of hygiene). macro_rules! define_queries_struct { - (tcx: $tcx:tt, + ( input: ($(([$($modifiers:tt)*] [$($attr:tt)*] [$name:ident]))*)) => { - pub struct Queries<$tcx> { + pub struct Queries<'tcx> { local_providers: Box, extern_providers: Box, - pub on_disk_cache: Option>, + pub on_disk_cache: Option>, jobs: AtomicU64, - $($(#[$attr])* $name: QueryState>,)* + $($(#[$attr])* $name: QueryState>,)* } - impl<$tcx> Queries<$tcx> { + impl<'tcx> Queries<'tcx> { pub fn new( local_providers: Providers, extern_providers: ExternProviders, - on_disk_cache: Option>, + on_disk_cache: Option>, ) -> Self { Queries { local_providers: Box::new(local_providers), @@ -498,8 +494,8 @@ pub fn new( } pub(crate) fn try_collect_active_jobs( - &$tcx self, - tcx: TyCtxt<$tcx>, + &'tcx self, + tcx: TyCtxt<'tcx>, ) -> Option { let tcx = QueryCtxt { tcx, queries: self }; let mut jobs = QueryMap::default(); @@ -532,13 +528,13 @@ fn try_mark_green(&'tcx self, tcx: TyCtxt<'tcx>, dep_node: &dep_graph::DepNode) #[tracing::instrument(level = "trace", skip(self, tcx))] fn $name( &'tcx self, - tcx: TyCtxt<$tcx>, + tcx: TyCtxt<'tcx>, span: Span, - key: query_keys::$name<$tcx>, + key: query_keys::$name<'tcx>, mode: QueryMode, - ) -> Option> { + ) -> Option> { let qcx = QueryCtxt { tcx, queries: self }; - get_query::, _>(qcx, span, key, mode) + get_query::, _>(qcx, span, key, mode) })* } }; diff --git a/compiler/rustc_query_impl/src/profiling_support.rs b/compiler/rustc_query_impl/src/profiling_support.rs index 551f094209e..34586750947 100644 --- a/compiler/rustc_query_impl/src/profiling_support.rs +++ b/compiler/rustc_query_impl/src/profiling_support.rs @@ -306,7 +306,7 @@ pub fn alloc_self_profile_query_strings(tcx: TyCtxt<'_>) { let mut string_cache = QueryKeyStringCache::new(); macro_rules! alloc_once { - (<$tcx:tt> + ( $($(#[$attr:meta])* [$($modifiers:tt)*] fn $name:ident($K:ty) -> $V:ty,)* ) => { $({ @@ -320,5 +320,5 @@ macro_rules! alloc_once { } } - rustc_query_append! { [alloc_once!][<'tcx>] } + rustc_query_append! { [alloc_once!] } }