Skip to content

Commit f842e54

Browse files
committed
Use $K:ty in query macros.
This is simpler and nicer than `$($K:tt)*`, and possible thanks to the previous two commits.
1 parent b43b942 commit f842e54

3 files changed

Lines changed: 27 additions & 26 deletions

File tree

compiler/rustc_middle/src/dep_graph/dep_node.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -354,11 +354,12 @@ impl StableOrd for WorkProductId {
354354
const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = ();
355355
}
356356

357+
// Note: `$K` and `$V` are unused but present so this can be called by `rustc_with_all_queries`.
357358
macro_rules! define_dep_nodes {
358359
(
359360
$(
360361
$(#[$attr:meta])*
361-
[$($modifiers:tt)*] fn $variant:ident($($K:tt)*) -> $V:ty,
362+
[$($modifiers:tt)*] fn $variant:ident($K:ty) -> $V:ty,
362363
)*
363364
) => {
364365

@@ -425,18 +426,18 @@ macro_rules! define_dep_nodes {
425426
}
426427

427428
// Create various data structures for each query, and also for a few things
428-
// that aren't queries.
429+
// that aren't queries. The key and return types aren't used, hence the use of `()`.
429430
rustc_with_all_queries!(define_dep_nodes![
430431
/// We use this for most things when incr. comp. is turned off.
431-
[] fn Null() -> (),
432+
[] fn Null(()) -> (),
432433
/// We use this to create a forever-red node.
433-
[] fn Red() -> (),
434-
[] fn SideEffect() -> (),
435-
[] fn AnonZeroDeps() -> (),
436-
[] fn TraitSelect() -> (),
437-
[] fn CompileCodegenUnit() -> (),
438-
[] fn CompileMonoItem() -> (),
439-
[] fn Metadata() -> (),
434+
[] fn Red(()) -> (),
435+
[] fn SideEffect(()) -> (),
436+
[] fn AnonZeroDeps(()) -> (),
437+
[] fn TraitSelect(()) -> (),
438+
[] fn CompileCodegenUnit(()) -> (),
439+
[] fn CompileMonoItem(()) -> (),
440+
[] fn Metadata(()) -> (),
440441
]);
441442

442443
// WARNING: `construct` is generic and does not know that `CompileCodegenUnit` takes `Symbol`s as keys.

compiler/rustc_middle/src/query/plumbing.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ macro_rules! define_callbacks {
293293
(
294294
$(
295295
$(#[$attr:meta])*
296-
[$($modifiers:tt)*] fn $name:ident($($K:tt)*) -> $V:ty,
296+
[$($modifiers:tt)*] fn $name:ident($K:ty) -> $V:ty,
297297
)*
298298
) => {
299299
$(
@@ -302,13 +302,13 @@ macro_rules! define_callbacks {
302302
use super::*;
303303
use $crate::query::erase::{self, Erased};
304304

305-
pub type Key<'tcx> = $($K)*;
305+
pub type Key<'tcx> = $K;
306306
pub type Value<'tcx> = $V;
307307

308308
pub type LocalKey<'tcx> = if_separate_provide_extern!(
309309
[$($modifiers)*]
310-
(<$($K)* as $crate::query::AsLocalKey>::LocalKey)
311-
($($K)*)
310+
(<$K as $crate::query::AsLocalKey>::LocalKey)
311+
($K)
312312
);
313313

314314
/// This type alias specifies the type returned from query providers and the type
@@ -349,7 +349,7 @@ macro_rules! define_callbacks {
349349
erase::erase_val(value)
350350
}
351351

352-
pub type Storage<'tcx> = <$($K)* as $crate::query::Key>::Cache<Erased<$V>>;
352+
pub type Storage<'tcx> = <$K as $crate::query::Key>::Cache<Erased<$V>>;
353353

354354
// Ensure that keys grow no larger than 88 bytes by accident.
355355
// Increase this limit if necessary, but do try to keep the size low if possible
@@ -360,7 +360,7 @@ macro_rules! define_callbacks {
360360
"the query `",
361361
stringify!($name),
362362
"` has a key type `",
363-
stringify!($($K)*),
363+
stringify!($K),
364364
"` that is too large"
365365
));
366366
}
@@ -410,7 +410,7 @@ macro_rules! define_callbacks {
410410
#[inline(always)]
411411
pub fn $name(
412412
self,
413-
key: impl $crate::query::IntoQueryParam<$($K)*>,
413+
key: impl $crate::query::IntoQueryParam<$K>,
414414
) -> if_return_result_from_ensure_ok!(
415415
[$($modifiers)*]
416416
(Result<(), ErrorGuaranteed>)
@@ -441,7 +441,7 @@ macro_rules! define_callbacks {
441441
$(
442442
$(#[$attr])*
443443
#[inline(always)]
444-
pub fn $name(self, key: impl $crate::query::IntoQueryParam<$($K)*>) {
444+
pub fn $name(self, key: impl $crate::query::IntoQueryParam<$K>) {
445445
crate::query::inner::query_ensure(
446446
self.tcx,
447447
self.tcx.query_system.fns.engine.$name,
@@ -458,7 +458,7 @@ macro_rules! define_callbacks {
458458
$(#[$attr])*
459459
#[inline(always)]
460460
#[must_use]
461-
pub fn $name(self, key: impl $crate::query::IntoQueryParam<$($K)*>) -> $V {
461+
pub fn $name(self, key: impl $crate::query::IntoQueryParam<$K>) -> $V {
462462
self.at(DUMMY_SP).$name(key)
463463
}
464464
)*
@@ -468,7 +468,7 @@ macro_rules! define_callbacks {
468468
$(
469469
$(#[$attr])*
470470
#[inline(always)]
471-
pub fn $name(self, key: impl $crate::query::IntoQueryParam<$($K)*>) -> $V {
471+
pub fn $name(self, key: impl $crate::query::IntoQueryParam<$K>) -> $V {
472472
use $crate::query::{erase, inner};
473473

474474
erase::restore_val::<$V>(inner::query_get_at(
@@ -494,7 +494,7 @@ macro_rules! define_callbacks {
494494
#[derive(Default)]
495495
pub struct QueryStates<'tcx> {
496496
$(
497-
pub $name: $crate::query::QueryState<'tcx, $($K)*>,
497+
pub $name: $crate::query::QueryState<'tcx, $K>,
498498
)*
499499
}
500500

@@ -571,15 +571,16 @@ macro_rules! define_callbacks {
571571
};
572572
}
573573

574+
// Note: `$V` is unused but present so this can be called by `rustc_with_all_queries`.
574575
macro_rules! define_feedable {
575576
(
576577
$(
577578
$(#[$attr:meta])*
578-
[$($modifiers:tt)*] fn $name:ident($($K:tt)*) -> $V:ty,
579+
[$($modifiers:tt)*] fn $name:ident($K:ty) -> $V:ty,
579580
)*
580581
) => {
581582
$(
582-
impl<'tcx, K: $crate::query::IntoQueryParam<$($K)*> + Copy> TyCtxtFeed<'tcx, K> {
583+
impl<'tcx, K: $crate::query::IntoQueryParam<$K> + Copy> TyCtxtFeed<'tcx, K> {
583584
$(#[$attr])*
584585
#[inline(always)]
585586
pub fn $name(self, value: $name::ProvidedValue<'tcx>) {

compiler/rustc_query_impl/src/plumbing.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -470,13 +470,12 @@ pub(crate) fn force_from_dep_node_inner<'tcx, C: QueryCache, const FLAGS: QueryF
470470
}
471471
}
472472

473-
// NOTE: `$V` isn't used here, but we still need to match on it so it can be passed to other macros
474-
// invoked by `rustc_with_all_queries`.
473+
// Note: `$K` and `$V` are unused but present so this can be called by `rustc_with_all_queries`.
475474
macro_rules! define_queries {
476475
(
477476
$(
478477
$(#[$attr:meta])*
479-
[$($modifiers:tt)*] fn $name:ident($($K:tt)*) -> $V:ty,
478+
[$($modifiers:tt)*] fn $name:ident($K:ty) -> $V:ty,
480479
)*
481480
) => {
482481

0 commit comments

Comments
 (0)