Skip to content

Commit 7ee4594

Browse files
Rollup merge of rust-lang#151893 - Zoxc:query-mod-move, r=nnethercote
Move the query list into a new `rustc_middle::queries` module This moves the query list from `rustc_middle::query` into a new `rustc_middle::queries` module. This splits up the use of the query system from the remaining implementation of it in `rustc_middle::query`, which conceptually belong to `rustc_query_system`. The goal is to let rustc crates define queries with their own `queries` module, and this makes `rustc_middle` also fit this pattern. The inner `queries` module used by the macros are renamed to `query_info`, so it doesn't conflict with the new outer name.
2 parents 1d05e3c + 9de16dd commit 7ee4594

11 files changed

Lines changed: 2907 additions & 2902 deletions

File tree

compiler/rustc_macros/src/query.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ fn add_query_desc_cached_impl(
289289
cached.extend(quote! {
290290
#[allow(unused_variables, unused_braces, rustc::pass_by_value)]
291291
#[inline]
292-
pub fn #name<'tcx>(#tcx: TyCtxt<'tcx>, #key: &crate::query::queries::#name::Key<'tcx>) -> bool {
292+
pub fn #name<'tcx>(#tcx: TyCtxt<'tcx>, #key: &crate::queries::#name::Key<'tcx>) -> bool {
293293
#ra_hint
294294
#expr
295295
}
@@ -301,7 +301,7 @@ fn add_query_desc_cached_impl(
301301

302302
let desc = quote! {
303303
#[allow(unused_variables)]
304-
pub fn #name<'tcx>(tcx: TyCtxt<'tcx>, key: crate::query::queries::#name::Key<'tcx>) -> String {
304+
pub fn #name<'tcx>(tcx: TyCtxt<'tcx>, key: crate::queries::#name::Key<'tcx>) -> String {
305305
let (#tcx, #key) = (tcx, key);
306306
format!(#desc)
307307
}

compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ use rustc_middle::bug;
1111
use rustc_middle::metadata::{AmbigModChild, ModChild};
1212
use rustc_middle::middle::exported_symbols::ExportedSymbol;
1313
use rustc_middle::middle::stability::DeprecationEntry;
14-
use rustc_middle::query::{ExternProviders, LocalCrate};
14+
use rustc_middle::queries::ExternProviders;
15+
use rustc_middle::query::LocalCrate;
1516
use rustc_middle::ty::fast_reject::SimplifiedType;
1617
use rustc_middle::ty::{self, TyCtxt};
1718
use rustc_middle::util::Providers;
@@ -134,8 +135,8 @@ macro_rules! provide_one {
134135
($tcx:ident, $def_id:ident, $other:ident, $cdata:ident, $name:ident => $compute:block) => {
135136
fn $name<'tcx>(
136137
$tcx: TyCtxt<'tcx>,
137-
def_id_arg: rustc_middle::query::queries::$name::Key<'tcx>,
138-
) -> rustc_middle::query::queries::$name::ProvidedValue<'tcx> {
138+
def_id_arg: rustc_middle::queries::$name::Key<'tcx>,
139+
) -> rustc_middle::queries::$name::ProvidedValue<'tcx> {
139140
let _prof_timer =
140141
$tcx.prof.generic_activity(concat!("metadata_decode_entry_", stringify!($name)));
141142

compiler/rustc_middle/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ mod values;
8686
#[macro_use]
8787
pub mod query;
8888
#[macro_use]
89+
pub mod queries;
90+
#[macro_use]
8991
pub mod dep_graph;
9092

9193
// Allows macros to refer to this crate as `::rustc_middle`

compiler/rustc_middle/src/queries.rs

Lines changed: 2775 additions & 0 deletions
Large diffs are not rendered by default.

compiler/rustc_middle/src/query/erase.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc_span::source_map::Spanned;
1515

1616
use crate::mir::interpret::EvalToValTreeResult;
1717
use crate::mir::mono::{MonoItem, NormalizationErrorInMono};
18-
use crate::query::CyclePlaceholder;
18+
use crate::query::plumbing::CyclePlaceholder;
1919
use crate::traits::solve;
2020
use crate::ty::adjustment::CoerceUnsizedInfo;
2121
use crate::ty::{self, Ty, TyCtxt};

compiler/rustc_middle/src/query/mod.rs

Lines changed: 6 additions & 2776 deletions
Large diffs are not rendered by default.

compiler/rustc_middle/src/query/plumbing.rs

Lines changed: 104 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ pub use sealed::IntoQueryParam;
1212

1313
use crate::dep_graph;
1414
use crate::dep_graph::DepKind;
15-
use crate::query::on_disk_cache::{CacheEncoder, EncodedDepNodeIndex, OnDiskCache};
16-
use crate::query::{
15+
use crate::queries::{
1716
ExternProviders, PerQueryVTables, Providers, QueryArenas, QueryCaches, QueryEngine, QueryStates,
1817
};
18+
use crate::query::on_disk_cache::{CacheEncoder, EncodedDepNodeIndex, OnDiskCache};
1919
use crate::ty::TyCtxt;
2020

2121
pub type WillCacheOnDiskForKeyFn<'tcx, Key> = fn(tcx: TyCtxt<'tcx>, key: &Key) -> bool;
@@ -189,8 +189,8 @@ macro_rules! query_ensure_select {
189189
}
190190

191191
macro_rules! query_helper_param_ty {
192-
(DefId) => { impl IntoQueryParam<DefId> };
193-
(LocalDefId) => { impl IntoQueryParam<LocalDefId> };
192+
(DefId) => { impl $crate::query::IntoQueryParam<DefId> };
193+
(LocalDefId) => { impl $crate::query::IntoQueryParam<LocalDefId> };
194194
($K:ty) => { $K };
195195
}
196196

@@ -213,7 +213,7 @@ macro_rules! local_key_if_separate_extern {
213213
$($K)*
214214
};
215215
([(separate_provide_extern) $($rest:tt)*] $($K:tt)*) => {
216-
<$($K)* as AsLocalKey>::LocalKey
216+
<$($K)* as $crate::query::AsLocalKey>::LocalKey
217217
};
218218
([$other:tt $($modifiers:tt)*] $($K:tt)*) => {
219219
local_key_if_separate_extern!([$($modifiers)*] $($K)*)
@@ -227,8 +227,8 @@ macro_rules! separate_provide_extern_decl {
227227
([(separate_provide_extern) $($rest:tt)*][$name:ident]) => {
228228
for<'tcx> fn(
229229
TyCtxt<'tcx>,
230-
queries::$name::Key<'tcx>,
231-
) -> queries::$name::ProvidedValue<'tcx>
230+
$name::Key<'tcx>,
231+
) -> $name::ProvidedValue<'tcx>
232232
};
233233
([$other:tt $($modifiers:tt)*][$($args:tt)*]) => {
234234
separate_provide_extern_decl!([$($modifiers)*][$($args)*])
@@ -266,94 +266,90 @@ macro_rules! define_callbacks {
266266
[$($modifiers:tt)*] fn $name:ident($($K:tt)*) -> $V:ty,
267267
)*
268268
) => {
269-
270-
#[allow(unused_lifetimes)]
271-
pub mod queries {
272-
$(pub mod $name {
273-
use super::super::*;
274-
use $crate::query::erase::{self, Erased};
275-
276-
pub type Key<'tcx> = $($K)*;
277-
pub type Value<'tcx> = $V;
278-
279-
pub type LocalKey<'tcx> = local_key_if_separate_extern!([$($modifiers)*] $($K)*);
280-
281-
/// This type alias specifies the type returned from query providers and the type
282-
/// used for decoding. For regular queries this is the declared returned type `V`,
283-
/// but `arena_cache` will use `<V as ArenaCached>::Provided` instead.
284-
pub type ProvidedValue<'tcx> = query_if_arena!(
285-
[$($modifiers)*]
286-
(<$V as $crate::query::arena_cached::ArenaCached<'tcx>>::Provided)
287-
($V)
269+
$(#[allow(unused_lifetimes)] pub mod $name {
270+
use super::*;
271+
use $crate::query::erase::{self, Erased};
272+
273+
pub type Key<'tcx> = $($K)*;
274+
pub type Value<'tcx> = $V;
275+
276+
pub type LocalKey<'tcx> = local_key_if_separate_extern!([$($modifiers)*] $($K)*);
277+
278+
/// This type alias specifies the type returned from query providers and the type
279+
/// used for decoding. For regular queries this is the declared returned type `V`,
280+
/// but `arena_cache` will use `<V as ArenaCached>::Provided` instead.
281+
pub type ProvidedValue<'tcx> = query_if_arena!(
282+
[$($modifiers)*]
283+
(<$V as $crate::query::arena_cached::ArenaCached<'tcx>>::Provided)
284+
($V)
285+
);
286+
287+
/// This function takes `ProvidedValue` and converts it to an erased `Value` by
288+
/// allocating it on an arena if the query has the `arena_cache` modifier. The
289+
/// value is then erased and returned. This will happen when computing the query
290+
/// using a provider or decoding a stored result.
291+
#[inline(always)]
292+
pub fn provided_to_erased<'tcx>(
293+
_tcx: TyCtxt<'tcx>,
294+
provided_value: ProvidedValue<'tcx>,
295+
) -> Erased<Value<'tcx>> {
296+
// Store the provided value in an arena and get a reference
297+
// to it, for queries with `arena_cache`.
298+
let value: Value<'tcx> = query_if_arena!([$($modifiers)*]
299+
{
300+
use $crate::query::arena_cached::ArenaCached;
301+
302+
if mem::needs_drop::<<$V as ArenaCached<'tcx>>::Allocated>() {
303+
<$V as ArenaCached>::alloc_in_arena(
304+
|v| _tcx.query_system.arenas.$name.alloc(v),
305+
provided_value,
306+
)
307+
} else {
308+
<$V as ArenaCached>::alloc_in_arena(
309+
|v| _tcx.arena.dropless.alloc(v),
310+
provided_value,
311+
)
312+
}
313+
}
314+
// Otherwise, the provided value is the value.
315+
(provided_value)
288316
);
317+
erase::erase_val(value)
318+
}
289319

290-
/// This function takes `ProvidedValue` and converts it to an erased `Value` by
291-
/// allocating it on an arena if the query has the `arena_cache` modifier. The
292-
/// value is then erased and returned. This will happen when computing the query
293-
/// using a provider or decoding a stored result.
294-
#[inline(always)]
295-
pub fn provided_to_erased<'tcx>(
296-
_tcx: TyCtxt<'tcx>,
297-
provided_value: ProvidedValue<'tcx>,
298-
) -> Erased<Value<'tcx>> {
299-
// Store the provided value in an arena and get a reference
300-
// to it, for queries with `arena_cache`.
301-
let value: Value<'tcx> = query_if_arena!([$($modifiers)*]
302-
{
303-
use $crate::query::arena_cached::ArenaCached;
304-
305-
if mem::needs_drop::<<$V as ArenaCached<'tcx>>::Allocated>() {
306-
<$V as ArenaCached>::alloc_in_arena(
307-
|v| _tcx.query_system.arenas.$name.alloc(v),
308-
provided_value,
309-
)
310-
} else {
311-
<$V as ArenaCached>::alloc_in_arena(
312-
|v| _tcx.arena.dropless.alloc(v),
313-
provided_value,
314-
)
315-
}
316-
}
317-
// Otherwise, the provided value is the value.
318-
(provided_value)
319-
);
320-
erase::erase_val(value)
320+
pub type Storage<'tcx> = <$($K)* as $crate::query::Key>::Cache<Erased<$V>>;
321+
322+
// Ensure that keys grow no larger than 88 bytes by accident.
323+
// Increase this limit if necessary, but do try to keep the size low if possible
324+
#[cfg(target_pointer_width = "64")]
325+
const _: () = {
326+
if size_of::<Key<'static>>() > 88 {
327+
panic!("{}", concat!(
328+
"the query `",
329+
stringify!($name),
330+
"` has a key type `",
331+
stringify!($($K)*),
332+
"` that is too large"
333+
));
321334
}
322-
323-
pub type Storage<'tcx> = <$($K)* as keys::Key>::Cache<Erased<$V>>;
324-
325-
// Ensure that keys grow no larger than 88 bytes by accident.
326-
// Increase this limit if necessary, but do try to keep the size low if possible
327-
#[cfg(target_pointer_width = "64")]
328-
const _: () = {
329-
if size_of::<Key<'static>>() > 88 {
330-
panic!("{}", concat!(
331-
"the query `",
332-
stringify!($name),
333-
"` has a key type `",
334-
stringify!($($K)*),
335-
"` that is too large"
336-
));
337-
}
338-
};
339-
340-
// Ensure that values grow no larger than 64 bytes by accident.
341-
// Increase this limit if necessary, but do try to keep the size low if possible
342-
#[cfg(target_pointer_width = "64")]
343-
#[cfg(not(feature = "rustc_randomized_layouts"))]
344-
const _: () = {
345-
if size_of::<Value<'static>>() > 64 {
346-
panic!("{}", concat!(
347-
"the query `",
348-
stringify!($name),
349-
"` has a value type `",
350-
stringify!($V),
351-
"` that is too large"
352-
));
353-
}
354-
};
355-
})*
356-
}
335+
};
336+
337+
// Ensure that values grow no larger than 64 bytes by accident.
338+
// Increase this limit if necessary, but do try to keep the size low if possible
339+
#[cfg(target_pointer_width = "64")]
340+
#[cfg(not(feature = "rustc_randomized_layouts"))]
341+
const _: () = {
342+
if size_of::<Value<'static>>() > 64 {
343+
panic!("{}", concat!(
344+
"the query `",
345+
stringify!($name),
346+
"` has a value type `",
347+
stringify!($V),
348+
"` that is too large"
349+
));
350+
}
351+
};
352+
})*
357353

358354
/// Holds per-query arenas for queries with the `arena_cache` modifier.
359355
#[derive(Default)]
@@ -371,10 +367,10 @@ macro_rules! define_callbacks {
371367

372368
#[derive(Default)]
373369
pub struct QueryCaches<'tcx> {
374-
$($(#[$attr])* pub $name: queries::$name::Storage<'tcx>,)*
370+
$($(#[$attr])* pub $name: $name::Storage<'tcx>,)*
375371
}
376372

377-
impl<'tcx> TyCtxtEnsureOk<'tcx> {
373+
impl<'tcx> $crate::query::TyCtxtEnsureOk<'tcx> {
378374
$($(#[$attr])*
379375
#[inline(always)]
380376
pub fn $name(
@@ -386,21 +382,21 @@ macro_rules! define_callbacks {
386382
self.tcx,
387383
self.tcx.query_system.fns.engine.$name,
388384
&self.tcx.query_system.caches.$name,
389-
key.into_query_param(),
385+
$crate::query::IntoQueryParam::into_query_param(key),
390386
false,
391387
)
392388
})*
393389
}
394390

395-
impl<'tcx> TyCtxtEnsureDone<'tcx> {
391+
impl<'tcx> $crate::query::TyCtxtEnsureDone<'tcx> {
396392
$($(#[$attr])*
397393
#[inline(always)]
398394
pub fn $name(self, key: query_helper_param_ty!($($K)*)) {
399395
crate::query::inner::query_ensure(
400396
self.tcx,
401397
self.tcx.query_system.fns.engine.$name,
402398
&self.tcx.query_system.caches.$name,
403-
key.into_query_param(),
399+
$crate::query::IntoQueryParam::into_query_param(key),
404400
true,
405401
);
406402
})*
@@ -416,7 +412,7 @@ macro_rules! define_callbacks {
416412
})*
417413
}
418414

419-
impl<'tcx> TyCtxtAt<'tcx> {
415+
impl<'tcx> $crate::query::TyCtxtAt<'tcx> {
420416
$($(#[$attr])*
421417
#[inline(always)]
422418
pub fn $name(self, key: query_helper_param_ty!($($K)*)) -> $V
@@ -428,7 +424,7 @@ macro_rules! define_callbacks {
428424
self.tcx.query_system.fns.engine.$name,
429425
&self.tcx.query_system.caches.$name,
430426
self.span,
431-
key.into_query_param(),
427+
$crate::query::IntoQueryParam::into_query_param(key),
432428
))
433429
})*
434430
}
@@ -438,22 +434,22 @@ macro_rules! define_callbacks {
438434
/// ("Per" just makes this pluralized name more visually distinct.)
439435
pub struct PerQueryVTables<'tcx> {
440436
$(
441-
pub $name: ::rustc_middle::query::plumbing::QueryVTable<'tcx, queries::$name::Storage<'tcx>>,
437+
pub $name: ::rustc_middle::query::plumbing::QueryVTable<'tcx, $name::Storage<'tcx>>,
442438
)*
443439
}
444440

445441
#[derive(Default)]
446442
pub struct QueryStates<'tcx> {
447443
$(
448-
pub $name: QueryState<'tcx, $($K)*>,
444+
pub $name: $crate::query::QueryState<'tcx, $($K)*>,
449445
)*
450446
}
451447

452448
pub struct Providers {
453449
$(pub $name: for<'tcx> fn(
454450
TyCtxt<'tcx>,
455-
queries::$name::LocalKey<'tcx>,
456-
) -> queries::$name::ProvidedValue<'tcx>,)*
451+
$name::LocalKey<'tcx>,
452+
) -> $name::ProvidedValue<'tcx>,)*
457453
}
458454

459455
pub struct ExternProviders {
@@ -490,23 +486,23 @@ macro_rules! define_callbacks {
490486
$(pub $name: for<'tcx> fn(
491487
TyCtxt<'tcx>,
492488
Span,
493-
queries::$name::Key<'tcx>,
494-
QueryMode,
489+
$name::Key<'tcx>,
490+
$crate::query::QueryMode,
495491
) -> Option<$crate::query::erase::Erased<$V>>,)*
496492
}
497493
};
498494
}
499495

500496
macro_rules! define_feedable {
501497
($($(#[$attr:meta])* [$($modifiers:tt)*] fn $name:ident($($K:tt)*) -> $V:ty,)*) => {
502-
$(impl<'tcx, K: IntoQueryParam<$($K)*> + Copy> TyCtxtFeed<'tcx, K> {
498+
$(impl<'tcx, K: $crate::query::IntoQueryParam<$($K)*> + Copy> TyCtxtFeed<'tcx, K> {
503499
$(#[$attr])*
504500
#[inline(always)]
505-
pub fn $name(self, value: queries::$name::ProvidedValue<'tcx>) {
501+
pub fn $name(self, value: $name::ProvidedValue<'tcx>) {
506502
let key = self.key().into_query_param();
507503

508504
let tcx = self.tcx;
509-
let erased_value = queries::$name::provided_to_erased(tcx, value);
505+
let erased_value = $name::provided_to_erased(tcx, value);
510506

511507
let dep_kind: dep_graph::DepKind = dep_graph::dep_kinds::$name;
512508

compiler/rustc_middle/src/util/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ pub mod bug;
22

33
#[derive(Default, Copy, Clone)]
44
pub struct Providers {
5-
pub queries: crate::query::Providers,
6-
pub extern_queries: crate::query::ExternProviders,
5+
pub queries: crate::queries::Providers,
6+
pub extern_queries: crate::queries::ExternProviders,
77
pub hooks: crate::hooks::Providers,
88
}

0 commit comments

Comments
 (0)