Move query names and Providers to parent module.
This commit is contained in:
parent
8e5d613a11
commit
24dbb61e58
|
@ -127,11 +127,52 @@ impl TyCtxt<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
macro_rules! query_helper_param_ty {
|
||||
(DefId) => { impl IntoQueryParam<DefId> };
|
||||
($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(...) -> <queries::$name<'tcx> as QueryConfig<TyCtxt<'tcx>>>::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> = <query_storage::$name<$tcx> as QueryStorage>::Stored;)*
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct QueryCaches<$tcx> {
|
||||
$($(#[$attr])* $name: QueryCacheStore<query_storage::$name<$tcx>>,)*
|
||||
}
|
||||
|
||||
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
|
||||
|
|
|
@ -430,11 +430,6 @@ macro_rules! hash_result {
|
|||
};
|
||||
}
|
||||
|
||||
macro_rules! query_helper_param_ty {
|
||||
(DefId) => { impl IntoQueryParam<DefId> };
|
||||
($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(...) -> <queries::$name<'tcx> as QueryConfig<TyCtxt<'tcx>>>::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> = <query_storage::$name<$tcx> as QueryStorage>::Stored;)*
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct QueryCaches<$tcx> {
|
||||
$($(#[$attr])* $name: QueryCacheStore<query_storage::$name<$tcx>>,)*
|
||||
}
|
||||
|
||||
$(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()
|
||||
|
|
Loading…
Reference in New Issue