Simplify macro

This commit is contained in:
Dylan MacKenzie 2020-04-10 13:44:15 -07:00
parent 6e5a21069d
commit fd8cf3c5e3

View File

@ -242,59 +242,9 @@ macro_rules! define_queries {
}
}
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! query_helper_param_ty {
(DefId) => { impl Into<DefId> };
($K:ty) => { $K };
}
macro_rules! define_queries_inner {
@ -432,8 +382,12 @@ macro_rules! define_queries_inner {
pub tcx: TyCtxt<'tcx>,
}
impl TyCtxtEnsure<'tcx> {
$( define_query_helper!(TyCtxtEnsure<'tcx>, $(#[$attr])* $name($($K)*) -> $V); )*
impl TyCtxtEnsure<$tcx> {
$($(#[$attr])*
#[inline(always)]
pub fn $name(self, key: query_helper_param_ty!($($K)*)) {
ensure_query::<queries::$name<'_>, _>(self.tcx, key.into())
})*
}
#[derive(Copy, Clone)]
@ -470,7 +424,11 @@ macro_rules! define_queries_inner {
}
}
$( define_query_helper!(TyCtxt<$tcx>, $(#[$attr])* $name($($K)*) -> $V); )*
$($(#[$attr])*
#[inline(always)]
pub fn $name(self, key: query_helper_param_ty!($($K)*)) -> $V {
self.at(DUMMY_SP).$name(key)
})*
/// All self-profiling events generated by the query engine use
/// virtual `StringId`s for their `event_id`. This method makes all
@ -503,7 +461,11 @@ macro_rules! define_queries_inner {
}
impl TyCtxtAt<$tcx> {
$( define_query_helper!(TyCtxtAt<$tcx>, $(#[$attr])* $name($($K)*) -> $V); )*
$($(#[$attr])*
#[inline(always)]
pub fn $name(self, key: query_helper_param_ty!($($K)*)) -> $V {
get_query::<queries::$name<'_>, _>(self.tcx, self.span, key.into())
})*
}
define_provider_struct! {