Skip to content

Commit b537619

Browse files
committed
Remove $tcx metavariable from rustc_query_append
It's not actually necessary and it makes the code harder to read.
1 parent 87991d5 commit b537619

File tree

6 files changed

+49
-55
lines changed

6 files changed

+49
-55
lines changed

compiler/rustc_macros/src/query.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -400,10 +400,8 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream {
400400
TokenStream::from(quote! {
401401
#[macro_export]
402402
macro_rules! rustc_query_append {
403-
([$($macro:tt)*][$($other:tt)*]) => {
403+
([$($macro:tt)*]) => {
404404
$($macro)* {
405-
$($other)*
406-
407405
#query_stream
408406
}
409407
}

compiler/rustc_middle/src/dep_graph/dep_node.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ impl DepKind {
143143
}
144144

145145
macro_rules! define_dep_nodes {
146-
(<$tcx:tt>
146+
(
147147
$(
148148
[$($attrs:tt)*]
149149
$variant:ident $(( $tuple_arg_ty:ty $(,)? ))*
@@ -179,7 +179,7 @@ macro_rules! define_dep_nodes {
179179
);
180180
}
181181

182-
rustc_dep_node_append!([define_dep_nodes!][ <'tcx>
182+
rustc_dep_node_append!([define_dep_nodes!][
183183
// We use this for most things when incr. comp. is turned off.
184184
[] Null,
185185

compiler/rustc_middle/src/ty/query.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ macro_rules! opt_remap_env_constness {
173173
}
174174

175175
macro_rules! define_callbacks {
176-
(<$tcx:tt>
176+
(
177177
$($(#[$attr:meta])*
178178
[$($modifiers:tt)*] fn $name:ident($($K:tt)*) -> $V:ty,)*) => {
179179

@@ -187,33 +187,33 @@ macro_rules! define_callbacks {
187187
pub mod query_keys {
188188
use super::*;
189189

190-
$(pub type $name<$tcx> = $($K)*;)*
190+
$(pub type $name<'tcx> = $($K)*;)*
191191
}
192192
#[allow(nonstandard_style, unused_lifetimes)]
193193
pub mod query_values {
194194
use super::*;
195195

196-
$(pub type $name<$tcx> = $V;)*
196+
$(pub type $name<'tcx> = $V;)*
197197
}
198198
#[allow(nonstandard_style, unused_lifetimes)]
199199
pub mod query_storage {
200200
use super::*;
201201

202-
$(pub type $name<$tcx> = query_storage!([$($modifiers)*][$($K)*, $V]);)*
202+
$(pub type $name<'tcx> = query_storage!([$($modifiers)*][$($K)*, $V]);)*
203203
}
204204
#[allow(nonstandard_style, unused_lifetimes)]
205205
pub mod query_stored {
206206
use super::*;
207207

208-
$(pub type $name<$tcx> = <query_storage::$name<$tcx> as QueryStorage>::Stored;)*
208+
$(pub type $name<'tcx> = <query_storage::$name<'tcx> as QueryStorage>::Stored;)*
209209
}
210210

211211
#[derive(Default)]
212-
pub struct QueryCaches<$tcx> {
213-
$($(#[$attr])* pub $name: query_storage::$name<$tcx>,)*
212+
pub struct QueryCaches<'tcx> {
213+
$($(#[$attr])* pub $name: query_storage::$name<'tcx>,)*
214214
}
215215

216-
impl<$tcx> TyCtxtEnsure<$tcx> {
216+
impl<'tcx> TyCtxtEnsure<'tcx> {
217217
$($(#[$attr])*
218218
#[inline(always)]
219219
pub fn $name(self, key: query_helper_param_ty!($($K)*)) {
@@ -231,20 +231,20 @@ macro_rules! define_callbacks {
231231
})*
232232
}
233233

234-
impl<$tcx> TyCtxt<$tcx> {
234+
impl<'tcx> TyCtxt<'tcx> {
235235
$($(#[$attr])*
236236
#[inline(always)]
237237
#[must_use]
238-
pub fn $name(self, key: query_helper_param_ty!($($K)*)) -> query_stored::$name<$tcx>
238+
pub fn $name(self, key: query_helper_param_ty!($($K)*)) -> query_stored::$name<'tcx>
239239
{
240240
self.at(DUMMY_SP).$name(key)
241241
})*
242242
}
243243

244-
impl<$tcx> TyCtxtAt<$tcx> {
244+
impl<'tcx> TyCtxtAt<'tcx> {
245245
$($(#[$attr])*
246246
#[inline(always)]
247-
pub fn $name(self, key: query_helper_param_ty!($($K)*)) -> query_stored::$name<$tcx>
247+
pub fn $name(self, key: query_helper_param_ty!($($K)*)) -> query_stored::$name<'tcx>
248248
{
249249
let key = key.into_query_param();
250250
opt_remap_env_constness!([$($modifiers)*][key]);
@@ -311,11 +311,11 @@ macro_rules! define_callbacks {
311311
$($(#[$attr])*
312312
fn $name(
313313
&'tcx self,
314-
tcx: TyCtxt<$tcx>,
314+
tcx: TyCtxt<'tcx>,
315315
span: Span,
316-
key: query_keys::$name<$tcx>,
316+
key: query_keys::$name<'tcx>,
317317
mode: QueryMode,
318-
) -> Option<query_stored::$name<$tcx>>;)*
318+
) -> Option<query_stored::$name<'tcx>>;)*
319319
}
320320
};
321321
}
@@ -332,7 +332,7 @@ macro_rules! define_callbacks {
332332
// Queries marked with `fatal_cycle` do not need the latter implementation,
333333
// as they will raise an fatal error on query cycles instead.
334334

335-
rustc_query_append! { [define_callbacks!][<'tcx>] }
335+
rustc_query_append! { [define_callbacks!] }
336336

337337
mod sealed {
338338
use super::{DefId, LocalDefId};

compiler/rustc_query_impl/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ fn describe_as_module(def_id: LocalDefId, tcx: TyCtxt<'_>) -> String {
5555
}
5656
}
5757

58-
rustc_query_append! { [define_queries!][<'tcx>] }
58+
rustc_query_append! { [define_queries!] }
5959

6060
impl<'tcx> Queries<'tcx> {
6161
// Force codegen in the dyn-trait transformation in this crate.

compiler/rustc_query_impl/src/plumbing.rs

+27-31
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,10 @@ macro_rules! get_provider {
234234
}
235235

236236
macro_rules! define_queries {
237-
(<$tcx:tt>
237+
(
238238
$($(#[$attr:meta])*
239239
[$($modifiers:tt)*] fn $name:ident($($K:tt)*) -> $V:ty,)*) => {
240240
define_queries_struct! {
241-
tcx: $tcx,
242241
input: ($(([$($modifiers)*] [$($attr)*] [$name]))*)
243242
}
244243

@@ -247,7 +246,7 @@ macro_rules! define_queries {
247246

248247
// Create an eponymous constructor for each query.
249248
$(#[allow(nonstandard_style)] $(#[$attr])*
250-
pub fn $name<$tcx>(tcx: QueryCtxt<$tcx>, key: query_keys::$name<$tcx>) -> QueryStackFrame {
249+
pub fn $name<'tcx>(tcx: QueryCtxt<'tcx>, key: query_keys::$name<'tcx>) -> QueryStackFrame {
251250
let kind = dep_graph::DepKind::$name;
252251
let name = stringify!($name);
253252
// Disable visible paths printing for performance reasons.
@@ -295,40 +294,40 @@ macro_rules! define_queries {
295294
mod queries {
296295
use std::marker::PhantomData;
297296

298-
$(pub struct $name<$tcx> {
299-
data: PhantomData<&$tcx ()>
297+
$(pub struct $name<'tcx> {
298+
data: PhantomData<&'tcx ()>
300299
})*
301300
}
302301

303-
$(impl<$tcx> QueryConfig for queries::$name<$tcx> {
304-
type Key = query_keys::$name<$tcx>;
305-
type Value = query_values::$name<$tcx>;
306-
type Stored = query_stored::$name<$tcx>;
302+
$(impl<'tcx> QueryConfig for queries::$name<'tcx> {
303+
type Key = query_keys::$name<'tcx>;
304+
type Value = query_values::$name<'tcx>;
305+
type Stored = query_stored::$name<'tcx>;
307306
const NAME: &'static str = stringify!($name);
308307
}
309308

310-
impl<$tcx> QueryDescription<QueryCtxt<$tcx>> for queries::$name<$tcx> {
311-
rustc_query_description! { $name<$tcx> }
309+
impl<'tcx> QueryDescription<QueryCtxt<'tcx>> for queries::$name<'tcx> {
310+
rustc_query_description! { $name<'tcx> }
312311

313-
type Cache = query_storage::$name<$tcx>;
312+
type Cache = query_storage::$name<'tcx>;
314313

315314
#[inline(always)]
316-
fn query_state<'a>(tcx: QueryCtxt<$tcx>) -> &'a QueryState<Self::Key>
317-
where QueryCtxt<$tcx>: 'a
315+
fn query_state<'a>(tcx: QueryCtxt<'tcx>) -> &'a QueryState<Self::Key>
316+
where QueryCtxt<'tcx>: 'a
318317
{
319318
&tcx.queries.$name
320319
}
321320

322321
#[inline(always)]
323-
fn query_cache<'a>(tcx: QueryCtxt<$tcx>) -> &'a Self::Cache
322+
fn query_cache<'a>(tcx: QueryCtxt<'tcx>) -> &'a Self::Cache
324323
where 'tcx:'a
325324
{
326325
&tcx.query_caches.$name
327326
}
328327

329328
#[inline]
330329
fn make_vtable(tcx: QueryCtxt<'tcx>, key: &Self::Key) ->
331-
QueryVTable<QueryCtxt<$tcx>, Self::Key, Self::Value>
330+
QueryVTable<QueryCtxt<'tcx>, Self::Key, Self::Value>
332331
{
333332
let compute = get_provider!([$($modifiers)*][tcx, $name, key]);
334333
let cache_on_disk = Self::cache_on_disk(tcx.tcx, key);
@@ -465,28 +464,25 @@ macro_rules! define_queries {
465464
}
466465
}
467466

468-
// FIXME(eddyb) this macro (and others?) use `$tcx` and `'tcx` interchangeably.
469-
// We should either not take `$tcx` at all and use `'tcx` everywhere, or use
470-
// `$tcx` everywhere (even if that isn't necessary due to lack of hygiene).
471467
macro_rules! define_queries_struct {
472-
(tcx: $tcx:tt,
468+
(
473469
input: ($(([$($modifiers:tt)*] [$($attr:tt)*] [$name:ident]))*)) => {
474-
pub struct Queries<$tcx> {
470+
pub struct Queries<'tcx> {
475471
local_providers: Box<Providers>,
476472
extern_providers: Box<ExternProviders>,
477473

478-
pub on_disk_cache: Option<OnDiskCache<$tcx>>,
474+
pub on_disk_cache: Option<OnDiskCache<'tcx>>,
479475

480476
jobs: AtomicU64,
481477

482-
$($(#[$attr])* $name: QueryState<query_keys::$name<$tcx>>,)*
478+
$($(#[$attr])* $name: QueryState<query_keys::$name<'tcx>>,)*
483479
}
484480

485-
impl<$tcx> Queries<$tcx> {
481+
impl<'tcx> Queries<'tcx> {
486482
pub fn new(
487483
local_providers: Providers,
488484
extern_providers: ExternProviders,
489-
on_disk_cache: Option<OnDiskCache<$tcx>>,
485+
on_disk_cache: Option<OnDiskCache<'tcx>>,
490486
) -> Self {
491487
Queries {
492488
local_providers: Box::new(local_providers),
@@ -498,8 +494,8 @@ macro_rules! define_queries_struct {
498494
}
499495

500496
pub(crate) fn try_collect_active_jobs(
501-
&$tcx self,
502-
tcx: TyCtxt<$tcx>,
497+
&'tcx self,
498+
tcx: TyCtxt<'tcx>,
503499
) -> Option<QueryMap> {
504500
let tcx = QueryCtxt { tcx, queries: self };
505501
let mut jobs = QueryMap::default();
@@ -532,13 +528,13 @@ macro_rules! define_queries_struct {
532528
#[tracing::instrument(level = "trace", skip(self, tcx))]
533529
fn $name(
534530
&'tcx self,
535-
tcx: TyCtxt<$tcx>,
531+
tcx: TyCtxt<'tcx>,
536532
span: Span,
537-
key: query_keys::$name<$tcx>,
533+
key: query_keys::$name<'tcx>,
538534
mode: QueryMode,
539-
) -> Option<query_stored::$name<$tcx>> {
535+
) -> Option<query_stored::$name<'tcx>> {
540536
let qcx = QueryCtxt { tcx, queries: self };
541-
get_query::<queries::$name<$tcx>, _>(qcx, span, key, mode)
537+
get_query::<queries::$name<'tcx>, _>(qcx, span, key, mode)
542538
})*
543539
}
544540
};

compiler/rustc_query_impl/src/profiling_support.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ pub fn alloc_self_profile_query_strings(tcx: TyCtxt<'_>) {
306306
let mut string_cache = QueryKeyStringCache::new();
307307

308308
macro_rules! alloc_once {
309-
(<$tcx:tt>
309+
(
310310
$($(#[$attr:meta])* [$($modifiers:tt)*] fn $name:ident($K:ty) -> $V:ty,)*
311311
) => {
312312
$({
@@ -320,5 +320,5 @@ pub fn alloc_self_profile_query_strings(tcx: TyCtxt<'_>) {
320320
}
321321
}
322322

323-
rustc_query_append! { [alloc_once!][<'tcx>] }
323+
rustc_query_append! { [alloc_once!] }
324324
}

0 commit comments

Comments
 (0)