From 24dbb61e5895e0f1433182f17d34eda1c94b130f Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Tue, 19 Jan 2021 19:44:27 +0100 Subject: [PATCH] Move query names and Providers to parent module. --- compiler/rustc_middle/src/ty/query/mod.rs | 66 ++++++++++++++++- .../rustc_middle/src/ty/query/plumbing.rs | 70 ------------------- 2 files changed, 65 insertions(+), 71 deletions(-) diff --git a/compiler/rustc_middle/src/ty/query/mod.rs b/compiler/rustc_middle/src/ty/query/mod.rs index a2f3c6eedcb8b..faef1f048cc2b 100644 --- a/compiler/rustc_middle/src/ty/query/mod.rs +++ b/compiler/rustc_middle/src/ty/query/mod.rs @@ -127,11 +127,52 @@ impl TyCtxt<'tcx> { } } +macro_rules! query_helper_param_ty { + (DefId) => { impl IntoQueryParam }; + ($K:ty) => { $K }; +} + macro_rules! define_callbacks { (<$tcx:tt> $($(#[$attr:meta])* [$($modifiers:tt)*] fn $name:ident($($K:tt)*) -> $V:ty,)*) => { + // HACK(eddyb) this is like the `impl QueryConfig for queries::$name` + // below, but using type aliases instead of associated types, to bypass + // the limitations around normalizing under HRTB - for example, this: + // `for<'tcx> fn(...) -> as QueryConfig>>::Value` + // doesn't currently normalize to `for<'tcx> fn(...) -> query_values::$name<'tcx>`. + // This is primarily used by the `provide!` macro in `rustc_metadata`. + #[allow(nonstandard_style, unused_lifetimes)] + pub mod query_keys { + use super::*; + + $(pub type $name<$tcx> = $($K)*;)* + } + #[allow(nonstandard_style, unused_lifetimes)] + pub mod query_values { + use super::*; + + $(pub type $name<$tcx> = $V;)* + } + #[allow(nonstandard_style, unused_lifetimes)] + pub mod query_storage { + use super::*; + + $(pub type $name<$tcx> = query_storage!([$($modifiers)*][$($K)*, $V]);)* + } + #[allow(nonstandard_style, unused_lifetimes)] + pub mod query_stored { + use super::*; + + $(pub type $name<$tcx> = as QueryStorage>::Stored;)* + } + + #[derive(Default)] + pub struct QueryCaches<$tcx> { + $($(#[$attr])* $name: QueryCacheStore>,)* + } + impl TyCtxtEnsure<$tcx> { $($(#[$attr])* #[inline(always)] @@ -176,7 +217,30 @@ macro_rules! define_callbacks { self.tcx.queries.$name(self.tcx, self.span, key, lookup, QueryMode::Get).unwrap() })* } - } + + pub struct Providers { + $(pub $name: for<'tcx> fn( + TyCtxt<'tcx>, + query_keys::$name<'tcx>, + ) -> query_values::$name<'tcx>,)* + } + + impl Default for Providers { + fn default() -> Self { + Providers { + $($name: |_, key| bug!( + "`tcx.{}({:?})` unsupported by its crate", + stringify!($name), key + ),)* + } + } + } + + impl Copy for Providers {} + impl Clone for Providers { + fn clone(&self) -> Self { *self } + } + }; } // Each of these queries corresponds to a function pointer field in the diff --git a/compiler/rustc_middle/src/ty/query/plumbing.rs b/compiler/rustc_middle/src/ty/query/plumbing.rs index 61bc4f3c1c446..32ed7e7363510 100644 --- a/compiler/rustc_middle/src/ty/query/plumbing.rs +++ b/compiler/rustc_middle/src/ty/query/plumbing.rs @@ -430,11 +430,6 @@ macro_rules! hash_result { }; } -macro_rules! query_helper_param_ty { - (DefId) => { impl IntoQueryParam }; - ($K:ty) => { $K }; -} - macro_rules! define_queries { (<$tcx:tt> $($(#[$attr:meta])* @@ -512,42 +507,6 @@ macro_rules! define_queries { })* } - // HACK(eddyb) this is like the `impl QueryConfig for queries::$name` - // below, but using type aliases instead of associated types, to bypass - // the limitations around normalizing under HRTB - for example, this: - // `for<'tcx> fn(...) -> as QueryConfig>>::Value` - // doesn't currently normalize to `for<'tcx> fn(...) -> query_values::$name<'tcx>`. - // This is primarily used by the `provide!` macro in `rustc_metadata`. - #[allow(nonstandard_style, unused_lifetimes)] - pub mod query_keys { - use super::*; - - $(pub type $name<$tcx> = $($K)*;)* - } - #[allow(nonstandard_style, unused_lifetimes)] - pub mod query_values { - use super::*; - - $(pub type $name<$tcx> = $V;)* - } - #[allow(nonstandard_style, unused_lifetimes)] - pub mod query_storage { - use super::*; - - $(pub type $name<$tcx> = query_storage!([$($modifiers)*][$($K)*, $V]);)* - } - #[allow(nonstandard_style, unused_lifetimes)] - pub mod query_stored { - use super::*; - - $(pub type $name<$tcx> = as QueryStorage>::Stored;)* - } - - #[derive(Default)] - pub struct QueryCaches<$tcx> { - $($(#[$attr])* $name: QueryCacheStore>,)* - } - $(impl<$tcx> QueryConfig for queries::$name<$tcx> { type Key = $($K)*; type Value = $V; @@ -683,11 +642,6 @@ macro_rules! define_queries { } static QUERY_CALLBACKS: &[QueryStruct] = &make_dep_kind_array!(query_callbacks); - - define_provider_struct! { - tcx: $tcx, - input: ($(([$($modifiers)*] [$name] [$($K)*] [$V]))*) - } } } @@ -774,30 +728,6 @@ macro_rules! define_queries_struct { }; } -macro_rules! define_provider_struct { - (tcx: $tcx:tt, - input: ($(([$($modifiers:tt)*] [$name:ident] [$K:ty] [$R:ty]))*)) => { - pub struct Providers { - $(pub $name: for<$tcx> fn(TyCtxt<$tcx>, $K) -> $R,)* - } - - impl Default for Providers { - fn default() -> Self { - $(fn $name<$tcx>(_: TyCtxt<$tcx>, key: $K) -> $R { - bug!("`tcx.{}({:?})` unsupported by its crate", - stringify!($name), key); - })* - Providers { $($name),* } - } - } - - impl Copy for Providers {} - impl Clone for Providers { - fn clone(&self) -> Self { *self } - } - }; -} - fn describe_as_module(def_id: LocalDefId, tcx: TyCtxt<'_>) -> String { if def_id.is_top_level_module() { "top-level module".to_string()