Skip to content

Commit cca0f97

Browse files
authored
Rollup merge of rust-lang#111703 - Zoxc:queries-mod, r=cjgillot
Merge query property modules into one This merges all the query modules that defines types into a single module per query with a normal naming convention for type aliases. r? ``@cjgillot``
2 parents d2823a1 + f6c6d10 commit cca0f97

File tree

6 files changed

+96
-125
lines changed

6 files changed

+96
-125
lines changed

compiler/rustc_macros/src/query.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ fn add_query_desc_cached_impl(
253253
quote! {
254254
#[allow(unused_variables, unused_braces, rustc::pass_by_value)]
255255
#[inline]
256-
pub fn #name<'tcx>(#tcx: TyCtxt<'tcx>, #key: &crate::query::query_keys::#name<'tcx>) -> bool {
256+
pub fn #name<'tcx>(#tcx: TyCtxt<'tcx>, #key: &crate::query::queries::#name::Key<'tcx>) -> bool {
257257
#expr
258258
}
259259
}
@@ -262,7 +262,7 @@ fn add_query_desc_cached_impl(
262262
// we're taking `key` by reference, but some rustc types usually prefer being passed by value
263263
#[allow(rustc::pass_by_value)]
264264
#[inline]
265-
pub fn #name<'tcx>(_: TyCtxt<'tcx>, _: &crate::query::query_keys::#name<'tcx>) -> bool {
265+
pub fn #name<'tcx>(_: TyCtxt<'tcx>, _: &crate::query::queries::#name::Key<'tcx>) -> bool {
266266
false
267267
}
268268
}
@@ -273,7 +273,7 @@ fn add_query_desc_cached_impl(
273273

274274
let desc = quote! {
275275
#[allow(unused_variables)]
276-
pub fn #name<'tcx>(tcx: TyCtxt<'tcx>, key: crate::query::query_keys::#name<'tcx>) -> String {
276+
pub fn #name<'tcx>(tcx: TyCtxt<'tcx>, key: crate::query::queries::#name::Key<'tcx>) -> String {
277277
let (#tcx, #key) = (tcx, key);
278278
::rustc_middle::ty::print::with_no_trimmed_paths!(
279279
format!(#desc)

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ macro_rules! provide_one {
114114
($tcx:ident, $def_id:ident, $other:ident, $cdata:ident, $name:ident => $compute:block) => {
115115
fn $name<'tcx>(
116116
$tcx: TyCtxt<'tcx>,
117-
def_id_arg: rustc_middle::query::query_keys::$name<'tcx>,
118-
) -> rustc_middle::query::query_provided::$name<'tcx> {
117+
def_id_arg: rustc_middle::query::queries::$name::Key<'tcx>,
118+
) -> rustc_middle::query::queries::$name::ProvidedValue<'tcx> {
119119
let _prof_timer =
120120
$tcx.prof.generic_activity(concat!("metadata_decode_entry_", stringify!($name)));
121121

compiler/rustc_middle/src/query/plumbing.rs

+64-93
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,8 @@ macro_rules! separate_provide_extern_decl {
221221
([(separate_provide_extern) $($rest:tt)*][$name:ident]) => {
222222
for<'tcx> fn(
223223
TyCtxt<'tcx>,
224-
query_keys::$name<'tcx>,
225-
) -> query_provided::$name<'tcx>
224+
queries::$name::Key<'tcx>,
225+
) -> queries::$name::ProvidedValue<'tcx>
226226
};
227227
([$other:tt $($modifiers:tt)*][$($args:tt)*]) => {
228228
separate_provide_extern_decl!([$($modifiers)*][$($args)*])
@@ -252,60 +252,37 @@ macro_rules! define_callbacks {
252252
$($(#[$attr:meta])*
253253
[$($modifiers:tt)*] fn $name:ident($($K:tt)*) -> $V:ty,)*) => {
254254

255-
// HACK(eddyb) this is like the `impl QueryConfig for queries::$name`
256-
// below, but using type aliases instead of associated types, to bypass
257-
// the limitations around normalizing under HRTB - for example, this:
258-
// `for<'tcx> fn(...) -> <queries::$name<'tcx> as QueryConfig<TyCtxt<'tcx>>>::Value`
259-
// doesn't currently normalize to `for<'tcx> fn(...) -> query_values::$name<'tcx>`.
260-
// This is primarily used by the `provide!` macro in `rustc_metadata`.
261-
#[allow(nonstandard_style, unused_lifetimes)]
262-
pub mod query_keys {
263-
use super::*;
264-
265-
$(pub type $name<'tcx> = $($K)*;)*
266-
}
267-
#[allow(nonstandard_style, unused_lifetimes)]
268-
pub mod query_keys_local {
269-
use super::*;
270-
271-
$(pub type $name<'tcx> = local_key_if_separate_extern!([$($modifiers)*] $($K)*);)*
272-
}
273-
#[allow(nonstandard_style, unused_lifetimes)]
274-
pub mod query_values {
275-
use super::*;
255+
#[allow(unused_lifetimes)]
256+
pub mod queries {
257+
$(pub mod $name {
258+
use super::super::*;
276259

277-
$(pub type $name<'tcx> = $V;)*
278-
}
260+
pub type Key<'tcx> = $($K)*;
261+
pub type Value<'tcx> = $V;
279262

280-
/// This module specifies the type returned from query providers and the type used for
281-
/// decoding. For regular queries this is the declared returned type `V`, but
282-
/// `arena_cache` will use `<V as Deref>::Target` instead.
283-
#[allow(nonstandard_style, unused_lifetimes)]
284-
pub mod query_provided {
285-
use super::*;
263+
pub type LocalKey<'tcx> = local_key_if_separate_extern!([$($modifiers)*] $($K)*);
286264

287-
$(
288-
pub type $name<'tcx> = query_if_arena!([$($modifiers)*] (<$V as Deref>::Target) ($V));
289-
)*
290-
}
291-
292-
/// This module has a function per query which takes a `query_provided` value and coverts
293-
/// it to a regular `V` value by allocating it on an arena if the query has the
294-
/// `arena_cache` modifier. This will happen when computing the query using a provider or
295-
/// decoding a stored result.
296-
#[allow(nonstandard_style, unused_lifetimes)]
297-
pub mod query_provided_to_value {
298-
use super::*;
265+
/// This type alias specifies the type returned from query providers and the type
266+
/// used for decoding. For regular queries this is the declared returned type `V`,
267+
/// but `arena_cache` will use `<V as Deref>::Target` instead.
268+
pub type ProvidedValue<'tcx> = query_if_arena!(
269+
[$($modifiers)*]
270+
(<$V as Deref>::Target)
271+
($V)
272+
);
299273

300-
$(
274+
/// This function takes `ProvidedValue` and coverts it to an erased `Value` by
275+
/// allocating it on an arena if the query has the `arena_cache` modifier. The
276+
/// value is then erased and returned. This will happen when computing the query
277+
/// using a provider or decoding a stored result.
301278
#[inline(always)]
302-
pub fn $name<'tcx>(
279+
pub fn provided_to_erased<'tcx>(
303280
_tcx: TyCtxt<'tcx>,
304-
value: query_provided::$name<'tcx>,
305-
) -> Erase<query_values::$name<'tcx>> {
281+
value: ProvidedValue<'tcx>,
282+
) -> Erase<Value<'tcx>> {
306283
erase(query_if_arena!([$($modifiers)*]
307284
{
308-
if mem::needs_drop::<query_provided::$name<'tcx>>() {
285+
if mem::needs_drop::<ProvidedValue<'tcx>>() {
309286
&*_tcx.query_system.arenas.$name.alloc(value)
310287
} else {
311288
&*_tcx.arena.dropless.alloc(value)
@@ -314,47 +291,41 @@ macro_rules! define_callbacks {
314291
(value)
315292
))
316293
}
317-
)*
318-
}
319-
#[allow(nonstandard_style, unused_lifetimes)]
320-
pub mod query_storage {
321-
use super::*;
322294

323-
$(
324-
pub type $name<'tcx> = <<$($K)* as Key>::CacheSelector as CacheSelector<'tcx, Erase<$V>>>::Cache;
325-
)*
295+
pub type Storage<'tcx> = <
296+
<$($K)* as keys::Key>::CacheSelector as CacheSelector<'tcx, Erase<$V>>
297+
>::Cache;
298+
299+
// Ensure that keys grow no larger than 64 bytes
300+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
301+
const _: () = {
302+
if mem::size_of::<Key<'static>>() > 64 {
303+
panic!("{}", concat!(
304+
"the query `",
305+
stringify!($name),
306+
"` has a key type `",
307+
stringify!($($K)*),
308+
"` that is too large"
309+
));
310+
}
311+
};
312+
313+
// Ensure that values grow no larger than 64 bytes
314+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
315+
const _: () = {
316+
if mem::size_of::<Value<'static>>() > 64 {
317+
panic!("{}", concat!(
318+
"the query `",
319+
stringify!($name),
320+
"` has a value type `",
321+
stringify!($V),
322+
"` that is too large"
323+
));
324+
}
325+
};
326+
})*
326327
}
327328

328-
$(
329-
// Ensure that keys grow no larger than 64 bytes
330-
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
331-
const _: () = {
332-
if mem::size_of::<query_keys::$name<'static>>() > 64 {
333-
panic!("{}", concat!(
334-
"the query `",
335-
stringify!($name),
336-
"` has a key type `",
337-
stringify!($($K)*),
338-
"` that is too large"
339-
));
340-
}
341-
};
342-
343-
// Ensure that values grow no larger than 64 bytes
344-
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
345-
const _: () = {
346-
if mem::size_of::<query_values::$name<'static>>() > 64 {
347-
panic!("{}", concat!(
348-
"the query `",
349-
stringify!($name),
350-
"` has a value type `",
351-
stringify!($V),
352-
"` that is too large"
353-
));
354-
}
355-
};
356-
)*
357-
358329
pub struct QueryArenas<'tcx> {
359330
$($(#[$attr])* pub $name: query_if_arena!([$($modifiers)*]
360331
(WorkerLocal<TypedArena<<$V as Deref>::Target>>)
@@ -375,7 +346,7 @@ macro_rules! define_callbacks {
375346

376347
#[derive(Default)]
377348
pub struct QueryCaches<'tcx> {
378-
$($(#[$attr])* pub $name: query_storage::$name<'tcx>,)*
349+
$($(#[$attr])* pub $name: queries::$name::Storage<'tcx>,)*
379350
}
380351

381352
impl<'tcx> TyCtxtEnsure<'tcx> {
@@ -433,7 +404,7 @@ macro_rules! define_callbacks {
433404

434405
pub struct DynamicQueries<'tcx> {
435406
$(
436-
pub $name: DynamicQuery<'tcx, query_storage::$name<'tcx>>,
407+
pub $name: DynamicQuery<'tcx, queries::$name::Storage<'tcx>>,
437408
)*
438409
}
439410

@@ -447,8 +418,8 @@ macro_rules! define_callbacks {
447418
pub struct Providers {
448419
$(pub $name: for<'tcx> fn(
449420
TyCtxt<'tcx>,
450-
query_keys_local::$name<'tcx>,
451-
) -> query_provided::$name<'tcx>,)*
421+
queries::$name::LocalKey<'tcx>,
422+
) -> queries::$name::ProvidedValue<'tcx>,)*
452423
}
453424

454425
pub struct ExternProviders {
@@ -493,7 +464,7 @@ macro_rules! define_callbacks {
493464
$(pub $name: for<'tcx> fn(
494465
TyCtxt<'tcx>,
495466
Span,
496-
query_keys::$name<'tcx>,
467+
queries::$name::Key<'tcx>,
497468
QueryMode,
498469
) -> Option<Erase<$V>>,)*
499470
}
@@ -517,11 +488,11 @@ macro_rules! define_feedable {
517488
$(impl<'tcx, K: IntoQueryParam<$($K)*> + Copy> TyCtxtFeed<'tcx, K> {
518489
$(#[$attr])*
519490
#[inline(always)]
520-
pub fn $name(self, value: query_provided::$name<'tcx>) {
491+
pub fn $name(self, value: queries::$name::ProvidedValue<'tcx>) {
521492
let key = self.key().into_query_param();
522493

523494
let tcx = self.tcx;
524-
let erased = query_provided_to_value::$name(tcx, value);
495+
let erased = queries::$name::provided_to_erased(tcx, value);
525496
let value = restore::<$V>(erased);
526497
let cache = &tcx.query_system.caches.$name;
527498

compiler/rustc_query_impl/src/lib.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#[macro_use]
1616
extern crate rustc_middle;
1717

18-
use crate::plumbing::{encode_all_query_results, try_mark_green};
18+
use crate::plumbing::{__rust_begin_short_backtrace, encode_all_query_results, try_mark_green};
1919
use field_offset::offset_of;
2020
use rustc_data_structures::stable_hasher::HashStable;
2121
use rustc_data_structures::sync::AtomicU64;
@@ -27,8 +27,7 @@ use rustc_middle::query::on_disk_cache::OnDiskCache;
2727
use rustc_middle::query::plumbing::{DynamicQuery, QuerySystem, QuerySystemFns};
2828
use rustc_middle::query::AsLocalKey;
2929
use rustc_middle::query::{
30-
query_keys, query_provided, query_provided_to_value, query_storage, query_values,
31-
DynamicQueries, ExternProviders, Providers, QueryCaches, QueryEngine, QueryStates,
30+
queries, DynamicQueries, ExternProviders, Providers, QueryCaches, QueryEngine, QueryStates,
3231
};
3332
use rustc_middle::ty::TyCtxt;
3433
use rustc_query_system::dep_graph::SerializedDepNodeIndex;

0 commit comments

Comments
 (0)