Skip to content

Commit

Permalink
Move query names and Providers to parent module.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgillot committed Feb 19, 2021
1 parent 8e5d613 commit 24dbb61
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 71 deletions.
66 changes: 65 additions & 1 deletion compiler/rustc_middle/src/ty/query/mod.rs
Expand Up @@ -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)]
Expand Down Expand Up @@ -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
Expand Down
70 changes: 0 additions & 70 deletions compiler/rustc_middle/src/ty/query/plumbing.rs
Expand Up @@ -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])*
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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]))*)
}
}
}

Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 24dbb61

Please sign in to comment.