diff options
| author | Dylan MacKenzie <ecstaticmorse@gmail.com> | 2020-04-10 13:44:15 -0700 |
|---|---|---|
| committer | Dylan MacKenzie <ecstaticmorse@gmail.com> | 2020-04-11 15:18:51 -0700 |
| commit | fd8cf3c5e3adffc5ef147c8a55d3532481172c42 (patch) | |
| tree | b3e0bcd9a8595d66d63dcb3aec1069e06c472c66 | |
| parent | 6e5a21069dc7e975b2ed9ca821e4f419ba011d97 (diff) | |
| download | rust-fd8cf3c5e3adffc5ef147c8a55d3532481172c42.tar.gz rust-fd8cf3c5e3adffc5ef147c8a55d3532481172c42.zip | |
Simplify macro
| -rw-r--r-- | src/librustc_middle/ty/query/plumbing.rs | 76 |
1 files changed, 19 insertions, 57 deletions
diff --git a/src/librustc_middle/ty/query/plumbing.rs b/src/librustc_middle/ty/query/plumbing.rs index 612507711fd..f3a49438f5b 100644 --- a/src/librustc_middle/ty/query/plumbing.rs +++ b/src/librustc_middle/ty/query/plumbing.rs @@ -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! { |
