Make query helpers on TyCtxt take impl Into<DefId>

This commit is contained in:
Dylan MacKenzie 2020-04-09 10:29:08 -07:00
parent e82734e56b
commit 62b5aff1ae

View File

@ -234,18 +234,73 @@ macro_rules! hash_result {
macro_rules! define_queries { macro_rules! define_queries {
(<$tcx:tt> $($category:tt { (<$tcx:tt> $($category:tt {
$($(#[$attr:meta])* [$($modifiers:tt)*] fn $name:ident: $node:ident($K:ty) -> $V:ty,)* $($(#[$attr:meta])* [$($modifiers:tt)*] fn $name:ident: $node:ident($($K:tt)*) -> $V:ty,)*
},)*) => { },)*) => {
define_queries_inner! { <$tcx> define_queries_inner! { <$tcx>
$($( $(#[$attr])* category<$category> [$($modifiers)*] fn $name: $node($K) -> $V,)*)* $($( $(#[$attr])* category<$category> [$($modifiers)*] fn $name: $node($($K)*) -> $V,)*)*
} }
} }
} }
macro_rules! define_query_helper {
(TyCtxtAt<$tcx:tt>, $(#[$attr:meta])* $name:ident(DefId) -> $V:ty) => {
$(#[$attr])*
#[inline(always)]
pub fn $name(self, key: impl Into<DefId>) -> $V {
fn mono(this: TyCtxtAt<$tcx>, key: DefId) -> $V {
get_query::<queries::$name<'_>, _>(this.tcx, this.span, key)
}
mono(self, key.into())
}
};
(TyCtxtAt<$tcx:tt>, $(#[$attr:meta])* $name:ident($K:ty) -> $V:ty) => {
$(#[$attr])*
#[inline(always)]
pub fn $name(self, key: $K) -> $V {
get_query::<queries::$name<'_>, _>(self.tcx, self.span, key)
}
};
(TyCtxt<$tcx:tt>, $(#[$attr:meta])* $name:ident(DefId) -> $V:ty) => {
$(#[$attr])*
#[inline(always)]
pub fn $name(self, key: impl Into<DefId>) -> $V {
self.at(DUMMY_SP).$name(key)
}
};
(TyCtxt<$tcx:tt>, $(#[$attr:meta])* $name:ident($K:ty) -> $V:ty) => {
$(#[$attr])*
#[inline(always)]
pub fn $name(self, key: $K) -> $V {
self.at(DUMMY_SP).$name(key)
}
};
(TyCtxtEnsure<$tcx:tt>, $(#[$attr:meta])* $name:ident(DefId) -> $V:ty) => {
$(#[$attr])*
#[inline(always)]
pub fn $name(self, key: impl Into<DefId>) {
fn mono(this: TyCtxtEnsure<$tcx>, key: DefId) {
ensure_query::<queries::$name<'_>, _>(this.tcx, key)
}
mono(self, key.into())
}
};
(TyCtxtEnsure<$tcx:tt>, $(#[$attr:meta])* $name:ident($K:ty) -> $V:ty) => {
$(#[$attr])*
#[inline(always)]
pub fn $name(self, key: $K) {
ensure_query::<queries::$name<'_>, _>(self.tcx, key)
}
};
}
macro_rules! define_queries_inner { macro_rules! define_queries_inner {
(<$tcx:tt> (<$tcx:tt>
$($(#[$attr:meta])* category<$category:tt> $($(#[$attr:meta])* category<$category:tt>
[$($modifiers:tt)*] fn $name:ident: $node:ident($K:ty) -> $V:ty,)*) => { [$($modifiers:tt)*] fn $name:ident: $node:ident($($K:tt)*) -> $V:ty,)*) => {
use std::mem; use std::mem;
use crate::{ use crate::{
@ -263,7 +318,7 @@ macro_rules! define_queries_inner {
#[allow(nonstandard_style)] #[allow(nonstandard_style)]
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub enum Query<$tcx> { pub enum Query<$tcx> {
$($(#[$attr])* $name($K)),* $($(#[$attr])* $name($($K)*)),*
} }
impl<$tcx> Query<$tcx> { impl<$tcx> Query<$tcx> {
@ -321,7 +376,7 @@ macro_rules! define_queries_inner {
} }
$(impl<$tcx> QueryConfig<TyCtxt<$tcx>> for queries::$name<$tcx> { $(impl<$tcx> QueryConfig<TyCtxt<$tcx>> for queries::$name<$tcx> {
type Key = $K; type Key = $($K)*;
type Value = $V; type Value = $V;
const NAME: &'static str = stringify!($name); const NAME: &'static str = stringify!($name);
const CATEGORY: ProfileCategory = $category; const CATEGORY: ProfileCategory = $category;
@ -332,7 +387,7 @@ macro_rules! define_queries_inner {
const EVAL_ALWAYS: bool = is_eval_always!([$($modifiers)*]); const EVAL_ALWAYS: bool = is_eval_always!([$($modifiers)*]);
const DEP_KIND: dep_graph::DepKind = dep_graph::DepKind::$node; const DEP_KIND: dep_graph::DepKind = dep_graph::DepKind::$node;
type Cache = query_storage!([$($modifiers)*][$K, $V]); type Cache = query_storage!([$($modifiers)*][$($K)*, $V]);
#[inline(always)] #[inline(always)]
fn query_state<'a>(tcx: TyCtxt<$tcx>) -> &'a QueryState<TyCtxt<$tcx>, Self::Cache> { fn query_state<'a>(tcx: TyCtxt<$tcx>) -> &'a QueryState<TyCtxt<$tcx>, Self::Cache> {
@ -377,12 +432,8 @@ macro_rules! define_queries_inner {
pub tcx: TyCtxt<'tcx>, pub tcx: TyCtxt<'tcx>,
} }
impl TyCtxtEnsure<$tcx> { impl TyCtxtEnsure<'tcx> {
$($(#[$attr])* $( define_query_helper!(TyCtxtEnsure<'tcx>, $(#[$attr])* $name($($K)*) -> $V); )*
#[inline(always)]
pub fn $name(self, key: $K) {
ensure_query::<queries::$name<'_>, _>(self.tcx, key)
})*
} }
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
@ -419,11 +470,7 @@ macro_rules! define_queries_inner {
} }
} }
$($(#[$attr])* $( define_query_helper!(TyCtxt<$tcx>, $(#[$attr])* $name($($K)*) -> $V); )*
#[inline(always)]
pub fn $name(self, key: $K) -> $V {
self.at(DUMMY_SP).$name(key)
})*
/// All self-profiling events generated by the query engine use /// All self-profiling events generated by the query engine use
/// virtual `StringId`s for their `event_id`. This method makes all /// virtual `StringId`s for their `event_id`. This method makes all
@ -456,16 +503,12 @@ macro_rules! define_queries_inner {
} }
impl TyCtxtAt<$tcx> { impl TyCtxtAt<$tcx> {
$($(#[$attr])* $( define_query_helper!(TyCtxtAt<$tcx>, $(#[$attr])* $name($($K)*) -> $V); )*
#[inline(always)]
pub fn $name(self, key: $K) -> $V {
get_query::<queries::$name<'_>, _>(self.tcx, self.span, key)
})*
} }
define_provider_struct! { define_provider_struct! {
tcx: $tcx, tcx: $tcx,
input: ($(([$($modifiers)*] [$name] [$K] [$V]))*) input: ($(([$($modifiers)*] [$name] [$($K)*] [$V]))*)
} }
impl<$tcx> Copy for Providers<$tcx> {} impl<$tcx> Copy for Providers<$tcx> {}