Skip to content

Commit 0b0f90f

Browse files
committed
Move query names and Providers to parent module.
1 parent ea991bc commit 0b0f90f

File tree

2 files changed

+57
-63
lines changed

2 files changed

+57
-63
lines changed

compiler/rustc_middle/src/ty/query/mod.rs

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,44 @@ impl TyCtxt<'tcx> {
128128
}
129129
}
130130

131+
macro_rules! query_helper_param_ty {
132+
(DefId) => { impl IntoQueryParam<DefId> };
133+
($K:ty) => { $K };
134+
}
135+
131136
macro_rules! define_callbacks {
132137
(<$tcx:tt>
133138
$($(#[$attr:meta])*
134139
[$($modifiers:tt)*] fn $name:ident($($K:tt)*) -> $V:ty,)*) => {
135140

141+
// HACK(eddyb) this is like the `impl QueryConfig for queries::$name`
142+
// below, but using type aliases instead of associated types, to bypass
143+
// the limitations around normalizing under HRTB - for example, this:
144+
// `for<'tcx> fn(...) -> <queries::$name<'tcx> as QueryConfig<TyCtxt<'tcx>>>::Value`
145+
// doesn't currently normalize to `for<'tcx> fn(...) -> query_values::$name<'tcx>`.
146+
// This is primarily used by the `provide!` macro in `rustc_metadata`.
147+
#[allow(nonstandard_style, unused_lifetimes)]
148+
pub mod query_keys {
149+
use super::*;
150+
151+
$(pub type $name<$tcx> = $($K)*;)*
152+
}
153+
#[allow(nonstandard_style, unused_lifetimes)]
154+
pub mod query_values {
155+
use super::*;
156+
157+
$(pub type $name<$tcx> = $V;)*
158+
}
159+
#[allow(nonstandard_style, unused_lifetimes)]
160+
pub mod query_stored {
161+
use super::*;
162+
163+
$(pub type $name<$tcx> = <
164+
query_storage!([$($modifiers)*][$($K)*, $V])
165+
as QueryStorage
166+
>::Stored;)*
167+
}
168+
136169
impl TyCtxtEnsure<$tcx> {
137170
$($(#[$attr])*
138171
#[inline(always)]
@@ -159,7 +192,30 @@ macro_rules! define_callbacks {
159192
self.tcx.queries.$name(self.tcx, self.span, key.into_query_param(), QueryMode::Get).unwrap()
160193
})*
161194
}
162-
}
195+
196+
pub struct Providers {
197+
$(pub $name: for<'tcx> fn(
198+
TyCtxt<'tcx>,
199+
query_keys::$name<'tcx>,
200+
) -> query_values::$name<'tcx>,)*
201+
}
202+
203+
impl Default for Providers {
204+
fn default() -> Self {
205+
Providers {
206+
$($name: |_, key| bug!(
207+
"`tcx.{}({:?})` unsupported by its crate",
208+
stringify!($name), key
209+
),)*
210+
}
211+
}
212+
}
213+
214+
impl Copy for Providers {}
215+
impl Clone for Providers {
216+
fn clone(&self) -> Self { *self }
217+
}
218+
};
163219
}
164220

165221
// Each of these queries corresponds to a function pointer field in the

compiler/rustc_middle/src/ty/query/plumbing.rs

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -431,11 +431,6 @@ macro_rules! hash_result {
431431
};
432432
}
433433

434-
macro_rules! query_helper_param_ty {
435-
(DefId) => { impl IntoQueryParam<DefId> };
436-
($K:ty) => { $K };
437-
}
438-
439434
macro_rules! define_queries {
440435
(<$tcx:tt>
441436
$($(#[$attr:meta])*
@@ -513,34 +508,6 @@ macro_rules! define_queries {
513508
})*
514509
}
515510

516-
// HACK(eddyb) this is like the `impl QueryConfig for queries::$name`
517-
// below, but using type aliases instead of associated types, to bypass
518-
// the limitations around normalizing under HRTB - for example, this:
519-
// `for<'tcx> fn(...) -> <queries::$name<'tcx> as QueryConfig<TyCtxt<'tcx>>>::Value`
520-
// doesn't currently normalize to `for<'tcx> fn(...) -> query_values::$name<'tcx>`.
521-
// This is primarily used by the `provide!` macro in `rustc_metadata`.
522-
#[allow(nonstandard_style, unused_lifetimes)]
523-
pub mod query_keys {
524-
use super::*;
525-
526-
$(pub type $name<$tcx> = $($K)*;)*
527-
}
528-
#[allow(nonstandard_style, unused_lifetimes)]
529-
pub mod query_values {
530-
use super::*;
531-
532-
$(pub type $name<$tcx> = $V;)*
533-
}
534-
#[allow(nonstandard_style, unused_lifetimes)]
535-
pub mod query_stored {
536-
use super::*;
537-
538-
$(pub type $name<$tcx> = <
539-
query_storage!([$($modifiers)*][$($K)*, $V])
540-
as QueryStorage
541-
>::Stored;)*
542-
}
543-
544511
$(impl<$tcx> QueryConfig for queries::$name<$tcx> {
545512
type Key = $($K)*;
546513
type Value = $V;
@@ -669,11 +636,6 @@ macro_rules! define_queries {
669636
}
670637

671638
static QUERY_CALLBACKS: &[QueryStruct] = &make_dep_kind_array!(query_callbacks);
672-
673-
define_provider_struct! {
674-
tcx: $tcx,
675-
input: ($(([$($modifiers)*] [$name] [$($K)*] [$V]))*)
676-
}
677639
}
678640
}
679641

@@ -788,30 +750,6 @@ macro_rules! define_queries_struct {
788750
};
789751
}
790752

791-
macro_rules! define_provider_struct {
792-
(tcx: $tcx:tt,
793-
input: ($(([$($modifiers:tt)*] [$name:ident] [$K:ty] [$R:ty]))*)) => {
794-
pub struct Providers {
795-
$(pub $name: for<$tcx> fn(TyCtxt<$tcx>, $K) -> $R,)*
796-
}
797-
798-
impl Default for Providers {
799-
fn default() -> Self {
800-
$(fn $name<$tcx>(_: TyCtxt<$tcx>, key: $K) -> $R {
801-
bug!("`tcx.{}({:?})` unsupported by its crate",
802-
stringify!($name), key);
803-
})*
804-
Providers { $($name),* }
805-
}
806-
}
807-
808-
impl Copy for Providers {}
809-
impl Clone for Providers {
810-
fn clone(&self) -> Self { *self }
811-
}
812-
};
813-
}
814-
815753
fn describe_as_module(def_id: LocalDefId, tcx: TyCtxt<'_>) -> String {
816754
if def_id.is_top_level_module() {
817755
"top-level module".to_string()

0 commit comments

Comments
 (0)