Skip to content

Commit 24dbb61

Browse files
committed
Move query names and Providers to parent module.
1 parent 8e5d613 commit 24dbb61

File tree

2 files changed

+65
-71
lines changed

2 files changed

+65
-71
lines changed

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

+65-1
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,52 @@ impl TyCtxt<'tcx> {
127127
}
128128
}
129129

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

140+
// HACK(eddyb) this is like the `impl QueryConfig for queries::$name`
141+
// below, but using type aliases instead of associated types, to bypass
142+
// the limitations around normalizing under HRTB - for example, this:
143+
// `for<'tcx> fn(...) -> <queries::$name<'tcx> as QueryConfig<TyCtxt<'tcx>>>::Value`
144+
// doesn't currently normalize to `for<'tcx> fn(...) -> query_values::$name<'tcx>`.
145+
// This is primarily used by the `provide!` macro in `rustc_metadata`.
146+
#[allow(nonstandard_style, unused_lifetimes)]
147+
pub mod query_keys {
148+
use super::*;
149+
150+
$(pub type $name<$tcx> = $($K)*;)*
151+
}
152+
#[allow(nonstandard_style, unused_lifetimes)]
153+
pub mod query_values {
154+
use super::*;
155+
156+
$(pub type $name<$tcx> = $V;)*
157+
}
158+
#[allow(nonstandard_style, unused_lifetimes)]
159+
pub mod query_storage {
160+
use super::*;
161+
162+
$(pub type $name<$tcx> = query_storage!([$($modifiers)*][$($K)*, $V]);)*
163+
}
164+
#[allow(nonstandard_style, unused_lifetimes)]
165+
pub mod query_stored {
166+
use super::*;
167+
168+
$(pub type $name<$tcx> = <query_storage::$name<$tcx> as QueryStorage>::Stored;)*
169+
}
170+
171+
#[derive(Default)]
172+
pub struct QueryCaches<$tcx> {
173+
$($(#[$attr])* $name: QueryCacheStore<query_storage::$name<$tcx>>,)*
174+
}
175+
135176
impl TyCtxtEnsure<$tcx> {
136177
$($(#[$attr])*
137178
#[inline(always)]
@@ -176,7 +217,30 @@ macro_rules! define_callbacks {
176217
self.tcx.queries.$name(self.tcx, self.span, key, lookup, QueryMode::Get).unwrap()
177218
})*
178219
}
179-
}
220+
221+
pub struct Providers {
222+
$(pub $name: for<'tcx> fn(
223+
TyCtxt<'tcx>,
224+
query_keys::$name<'tcx>,
225+
) -> query_values::$name<'tcx>,)*
226+
}
227+
228+
impl Default for Providers {
229+
fn default() -> Self {
230+
Providers {
231+
$($name: |_, key| bug!(
232+
"`tcx.{}({:?})` unsupported by its crate",
233+
stringify!($name), key
234+
),)*
235+
}
236+
}
237+
}
238+
239+
impl Copy for Providers {}
240+
impl Clone for Providers {
241+
fn clone(&self) -> Self { *self }
242+
}
243+
};
180244
}
181245

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

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

-70
Original file line numberDiff line numberDiff line change
@@ -430,11 +430,6 @@ macro_rules! hash_result {
430430
};
431431
}
432432

433-
macro_rules! query_helper_param_ty {
434-
(DefId) => { impl IntoQueryParam<DefId> };
435-
($K:ty) => { $K };
436-
}
437-
438433
macro_rules! define_queries {
439434
(<$tcx:tt>
440435
$($(#[$attr:meta])*
@@ -512,42 +507,6 @@ macro_rules! define_queries {
512507
})*
513508
}
514509

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

685644
static QUERY_CALLBACKS: &[QueryStruct] = &make_dep_kind_array!(query_callbacks);
686-
687-
define_provider_struct! {
688-
tcx: $tcx,
689-
input: ($(([$($modifiers)*] [$name] [$($K)*] [$V]))*)
690-
}
691645
}
692646
}
693647

@@ -774,30 +728,6 @@ macro_rules! define_queries_struct {
774728
};
775729
}
776730

777-
macro_rules! define_provider_struct {
778-
(tcx: $tcx:tt,
779-
input: ($(([$($modifiers:tt)*] [$name:ident] [$K:ty] [$R:ty]))*)) => {
780-
pub struct Providers {
781-
$(pub $name: for<$tcx> fn(TyCtxt<$tcx>, $K) -> $R,)*
782-
}
783-
784-
impl Default for Providers {
785-
fn default() -> Self {
786-
$(fn $name<$tcx>(_: TyCtxt<$tcx>, key: $K) -> $R {
787-
bug!("`tcx.{}({:?})` unsupported by its crate",
788-
stringify!($name), key);
789-
})*
790-
Providers { $($name),* }
791-
}
792-
}
793-
794-
impl Copy for Providers {}
795-
impl Clone for Providers {
796-
fn clone(&self) -> Self { *self }
797-
}
798-
};
799-
}
800-
801731
fn describe_as_module(def_id: LocalDefId, tcx: TyCtxt<'_>) -> String {
802732
if def_id.is_top_level_module() {
803733
"top-level module".to_string()

0 commit comments

Comments
 (0)