mirror of
https://github.com/rust-lang/rust.git
synced 2024-10-30 22:12:15 +00:00
Merge query property modules into one
This commit is contained in:
parent
77c836e1ae
commit
f6c6d10443
@ -253,7 +253,7 @@ fn add_query_desc_cached_impl(
|
||||
quote! {
|
||||
#[allow(unused_variables, unused_braces, rustc::pass_by_value)]
|
||||
#[inline]
|
||||
pub fn #name<'tcx>(#tcx: TyCtxt<'tcx>, #key: &crate::query::query_keys::#name<'tcx>) -> bool {
|
||||
pub fn #name<'tcx>(#tcx: TyCtxt<'tcx>, #key: &crate::query::queries::#name::Key<'tcx>) -> bool {
|
||||
#expr
|
||||
}
|
||||
}
|
||||
@ -262,7 +262,7 @@ fn add_query_desc_cached_impl(
|
||||
// we're taking `key` by reference, but some rustc types usually prefer being passed by value
|
||||
#[allow(rustc::pass_by_value)]
|
||||
#[inline]
|
||||
pub fn #name<'tcx>(_: TyCtxt<'tcx>, _: &crate::query::query_keys::#name<'tcx>) -> bool {
|
||||
pub fn #name<'tcx>(_: TyCtxt<'tcx>, _: &crate::query::queries::#name::Key<'tcx>) -> bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
@ -273,7 +273,7 @@ fn add_query_desc_cached_impl(
|
||||
|
||||
let desc = quote! {
|
||||
#[allow(unused_variables)]
|
||||
pub fn #name<'tcx>(tcx: TyCtxt<'tcx>, key: crate::query::query_keys::#name<'tcx>) -> String {
|
||||
pub fn #name<'tcx>(tcx: TyCtxt<'tcx>, key: crate::query::queries::#name::Key<'tcx>) -> String {
|
||||
let (#tcx, #key) = (tcx, key);
|
||||
::rustc_middle::ty::print::with_no_trimmed_paths!(
|
||||
format!(#desc)
|
||||
|
@ -114,8 +114,8 @@ macro_rules! provide_one {
|
||||
($tcx:ident, $def_id:ident, $other:ident, $cdata:ident, $name:ident => $compute:block) => {
|
||||
fn $name<'tcx>(
|
||||
$tcx: TyCtxt<'tcx>,
|
||||
def_id_arg: rustc_middle::query::query_keys::$name<'tcx>,
|
||||
) -> rustc_middle::query::query_provided::$name<'tcx> {
|
||||
def_id_arg: rustc_middle::query::queries::$name::Key<'tcx>,
|
||||
) -> rustc_middle::query::queries::$name::ProvidedValue<'tcx> {
|
||||
let _prof_timer =
|
||||
$tcx.prof.generic_activity(concat!("metadata_decode_entry_", stringify!($name)));
|
||||
|
||||
|
@ -221,8 +221,8 @@ macro_rules! separate_provide_extern_decl {
|
||||
([(separate_provide_extern) $($rest:tt)*][$name:ident]) => {
|
||||
for<'tcx> fn(
|
||||
TyCtxt<'tcx>,
|
||||
query_keys::$name<'tcx>,
|
||||
) -> query_provided::$name<'tcx>
|
||||
queries::$name::Key<'tcx>,
|
||||
) -> queries::$name::ProvidedValue<'tcx>
|
||||
};
|
||||
([$other:tt $($modifiers:tt)*][$($args:tt)*]) => {
|
||||
separate_provide_extern_decl!([$($modifiers)*][$($args)*])
|
||||
@ -252,60 +252,37 @@ macro_rules! define_callbacks {
|
||||
$($(#[$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::*;
|
||||
#[allow(unused_lifetimes)]
|
||||
pub mod queries {
|
||||
$(pub mod $name {
|
||||
use super::super::*;
|
||||
|
||||
$(pub type $name<'tcx> = $($K)*;)*
|
||||
}
|
||||
#[allow(nonstandard_style, unused_lifetimes)]
|
||||
pub mod query_keys_local {
|
||||
use super::*;
|
||||
pub type Key<'tcx> = $($K)*;
|
||||
pub type Value<'tcx> = $V;
|
||||
|
||||
$(pub type $name<'tcx> = local_key_if_separate_extern!([$($modifiers)*] $($K)*);)*
|
||||
}
|
||||
#[allow(nonstandard_style, unused_lifetimes)]
|
||||
pub mod query_values {
|
||||
use super::*;
|
||||
pub type LocalKey<'tcx> = local_key_if_separate_extern!([$($modifiers)*] $($K)*);
|
||||
|
||||
$(pub type $name<'tcx> = $V;)*
|
||||
}
|
||||
/// This type alias specifies the type returned from query providers and the type
|
||||
/// used for decoding. For regular queries this is the declared returned type `V`,
|
||||
/// but `arena_cache` will use `<V as Deref>::Target` instead.
|
||||
pub type ProvidedValue<'tcx> = query_if_arena!(
|
||||
[$($modifiers)*]
|
||||
(<$V as Deref>::Target)
|
||||
($V)
|
||||
);
|
||||
|
||||
/// This module specifies the type returned from query providers and the type used for
|
||||
/// decoding. For regular queries this is the declared returned type `V`, but
|
||||
/// `arena_cache` will use `<V as Deref>::Target` instead.
|
||||
#[allow(nonstandard_style, unused_lifetimes)]
|
||||
pub mod query_provided {
|
||||
use super::*;
|
||||
|
||||
$(
|
||||
pub type $name<'tcx> = query_if_arena!([$($modifiers)*] (<$V as Deref>::Target) ($V));
|
||||
)*
|
||||
}
|
||||
|
||||
/// This module has a function per query which takes a `query_provided` value and coverts
|
||||
/// it to a regular `V` value by allocating it on an arena if the query has the
|
||||
/// `arena_cache` modifier. This will happen when computing the query using a provider or
|
||||
/// decoding a stored result.
|
||||
#[allow(nonstandard_style, unused_lifetimes)]
|
||||
pub mod query_provided_to_value {
|
||||
use super::*;
|
||||
|
||||
$(
|
||||
/// This function takes `ProvidedValue` and coverts it to an erased `Value` by
|
||||
/// allocating it on an arena if the query has the `arena_cache` modifier. The
|
||||
/// value is then erased and returned. This will happen when computing the query
|
||||
/// using a provider or decoding a stored result.
|
||||
#[inline(always)]
|
||||
pub fn $name<'tcx>(
|
||||
pub fn provided_to_erased<'tcx>(
|
||||
_tcx: TyCtxt<'tcx>,
|
||||
value: query_provided::$name<'tcx>,
|
||||
) -> Erase<query_values::$name<'tcx>> {
|
||||
value: ProvidedValue<'tcx>,
|
||||
) -> Erase<Value<'tcx>> {
|
||||
erase(query_if_arena!([$($modifiers)*]
|
||||
{
|
||||
if mem::needs_drop::<query_provided::$name<'tcx>>() {
|
||||
if mem::needs_drop::<ProvidedValue<'tcx>>() {
|
||||
&*_tcx.query_system.arenas.$name.alloc(value)
|
||||
} else {
|
||||
&*_tcx.arena.dropless.alloc(value)
|
||||
@ -314,22 +291,15 @@ macro_rules! define_callbacks {
|
||||
(value)
|
||||
))
|
||||
}
|
||||
)*
|
||||
}
|
||||
#[allow(nonstandard_style, unused_lifetimes)]
|
||||
pub mod query_storage {
|
||||
use super::*;
|
||||
|
||||
$(
|
||||
pub type $name<'tcx> = <<$($K)* as Key>::CacheSelector as CacheSelector<'tcx, Erase<$V>>>::Cache;
|
||||
)*
|
||||
}
|
||||
pub type Storage<'tcx> = <
|
||||
<$($K)* as keys::Key>::CacheSelector as CacheSelector<'tcx, Erase<$V>>
|
||||
>::Cache;
|
||||
|
||||
$(
|
||||
// Ensure that keys grow no larger than 64 bytes
|
||||
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
|
||||
const _: () = {
|
||||
if mem::size_of::<query_keys::$name<'static>>() > 64 {
|
||||
if mem::size_of::<Key<'static>>() > 64 {
|
||||
panic!("{}", concat!(
|
||||
"the query `",
|
||||
stringify!($name),
|
||||
@ -343,7 +313,7 @@ macro_rules! define_callbacks {
|
||||
// Ensure that values grow no larger than 64 bytes
|
||||
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
|
||||
const _: () = {
|
||||
if mem::size_of::<query_values::$name<'static>>() > 64 {
|
||||
if mem::size_of::<Value<'static>>() > 64 {
|
||||
panic!("{}", concat!(
|
||||
"the query `",
|
||||
stringify!($name),
|
||||
@ -353,7 +323,8 @@ macro_rules! define_callbacks {
|
||||
));
|
||||
}
|
||||
};
|
||||
)*
|
||||
})*
|
||||
}
|
||||
|
||||
pub struct QueryArenas<'tcx> {
|
||||
$($(#[$attr])* pub $name: query_if_arena!([$($modifiers)*]
|
||||
@ -375,7 +346,7 @@ macro_rules! define_callbacks {
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct QueryCaches<'tcx> {
|
||||
$($(#[$attr])* pub $name: query_storage::$name<'tcx>,)*
|
||||
$($(#[$attr])* pub $name: queries::$name::Storage<'tcx>,)*
|
||||
}
|
||||
|
||||
impl<'tcx> TyCtxtEnsure<'tcx> {
|
||||
@ -433,7 +404,7 @@ macro_rules! define_callbacks {
|
||||
|
||||
pub struct DynamicQueries<'tcx> {
|
||||
$(
|
||||
pub $name: DynamicQuery<'tcx, query_storage::$name<'tcx>>,
|
||||
pub $name: DynamicQuery<'tcx, queries::$name::Storage<'tcx>>,
|
||||
)*
|
||||
}
|
||||
|
||||
@ -447,8 +418,8 @@ macro_rules! define_callbacks {
|
||||
pub struct Providers {
|
||||
$(pub $name: for<'tcx> fn(
|
||||
TyCtxt<'tcx>,
|
||||
query_keys_local::$name<'tcx>,
|
||||
) -> query_provided::$name<'tcx>,)*
|
||||
queries::$name::LocalKey<'tcx>,
|
||||
) -> queries::$name::ProvidedValue<'tcx>,)*
|
||||
}
|
||||
|
||||
pub struct ExternProviders {
|
||||
@ -493,7 +464,7 @@ macro_rules! define_callbacks {
|
||||
$(pub $name: for<'tcx> fn(
|
||||
TyCtxt<'tcx>,
|
||||
Span,
|
||||
query_keys::$name<'tcx>,
|
||||
queries::$name::Key<'tcx>,
|
||||
QueryMode,
|
||||
) -> Option<Erase<$V>>,)*
|
||||
}
|
||||
@ -517,11 +488,11 @@ macro_rules! define_feedable {
|
||||
$(impl<'tcx, K: IntoQueryParam<$($K)*> + Copy> TyCtxtFeed<'tcx, K> {
|
||||
$(#[$attr])*
|
||||
#[inline(always)]
|
||||
pub fn $name(self, value: query_provided::$name<'tcx>) {
|
||||
pub fn $name(self, value: queries::$name::ProvidedValue<'tcx>) {
|
||||
let key = self.key().into_query_param();
|
||||
|
||||
let tcx = self.tcx;
|
||||
let erased = query_provided_to_value::$name(tcx, value);
|
||||
let erased = queries::$name::provided_to_erased(tcx, value);
|
||||
let value = restore::<$V>(erased);
|
||||
let cache = &tcx.query_system.caches.$name;
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
#[macro_use]
|
||||
extern crate rustc_middle;
|
||||
|
||||
use crate::plumbing::{encode_all_query_results, try_mark_green};
|
||||
use crate::plumbing::{__rust_begin_short_backtrace, encode_all_query_results, try_mark_green};
|
||||
use field_offset::offset_of;
|
||||
use rustc_data_structures::stable_hasher::HashStable;
|
||||
use rustc_data_structures::sync::AtomicU64;
|
||||
@ -27,8 +27,7 @@ use rustc_middle::query::on_disk_cache::OnDiskCache;
|
||||
use rustc_middle::query::plumbing::{DynamicQuery, QuerySystem, QuerySystemFns};
|
||||
use rustc_middle::query::AsLocalKey;
|
||||
use rustc_middle::query::{
|
||||
query_keys, query_provided, query_provided_to_value, query_storage, query_values,
|
||||
DynamicQueries, ExternProviders, Providers, QueryCaches, QueryEngine, QueryStates,
|
||||
queries, DynamicQueries, ExternProviders, Providers, QueryCaches, QueryEngine, QueryStates,
|
||||
};
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_query_system::dep_graph::SerializedDepNodeIndex;
|
||||
|
@ -518,11 +518,11 @@ macro_rules! define_queries {
|
||||
pub fn __rust_end_short_backtrace<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
span: Span,
|
||||
key: query_keys::$name<'tcx>,
|
||||
key: queries::$name::Key<'tcx>,
|
||||
mode: QueryMode,
|
||||
) -> Option<Erase<query_values::$name<'tcx>>> {
|
||||
) -> Option<Erase<queries::$name::Value<'tcx>>> {
|
||||
get_query_incr(
|
||||
queries::$name::config(tcx),
|
||||
query_config::$name::config(tcx),
|
||||
QueryCtxt::new(tcx),
|
||||
span,
|
||||
key,
|
||||
@ -543,11 +543,11 @@ macro_rules! define_queries {
|
||||
pub fn __rust_end_short_backtrace<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
span: Span,
|
||||
key: query_keys::$name<'tcx>,
|
||||
key: queries::$name::Key<'tcx>,
|
||||
__mode: QueryMode,
|
||||
) -> Option<Erase<query_values::$name<'tcx>>> {
|
||||
) -> Option<Erase<queries::$name::Value<'tcx>>> {
|
||||
Some(get_query_non_incr(
|
||||
queries::$name::config(tcx),
|
||||
query_config::$name::config(tcx),
|
||||
QueryCtxt::new(tcx),
|
||||
span,
|
||||
key,
|
||||
@ -570,7 +570,7 @@ macro_rules! define_queries {
|
||||
}
|
||||
|
||||
#[allow(nonstandard_style)]
|
||||
mod queries {
|
||||
mod query_config {
|
||||
use std::marker::PhantomData;
|
||||
|
||||
$(
|
||||
@ -586,7 +586,7 @@ macro_rules! define_queries {
|
||||
use super::*;
|
||||
|
||||
$(
|
||||
pub(super) fn $name<'tcx>() -> DynamicQuery<'tcx, query_storage::$name<'tcx>> {
|
||||
pub(super) fn $name<'tcx>() -> DynamicQuery<'tcx, queries::$name::Storage<'tcx>> {
|
||||
DynamicQuery {
|
||||
name: stringify!($name),
|
||||
eval_always: is_eval_always!([$($modifiers)*]),
|
||||
@ -597,9 +597,8 @@ macro_rules! define_queries {
|
||||
cache_on_disk: |tcx, key| ::rustc_middle::query::cached::$name(tcx, key),
|
||||
execute_query: |tcx, key| erase(tcx.$name(key)),
|
||||
compute: |tcx, key| {
|
||||
use crate::plumbing::__rust_begin_short_backtrace;
|
||||
__rust_begin_short_backtrace(||
|
||||
query_provided_to_value::$name(
|
||||
queries::$name::provided_to_erased(
|
||||
tcx,
|
||||
call_provider!([$($modifiers)*][tcx, $name, key])
|
||||
)
|
||||
@ -609,12 +608,14 @@ macro_rules! define_queries {
|
||||
try_load_from_disk: should_ever_cache_on_disk!([$($modifiers)*] {
|
||||
|tcx, key, prev_index, index| {
|
||||
if ::rustc_middle::query::cached::$name(tcx, key) {
|
||||
let value = $crate::plumbing::try_load_from_disk::<query_provided::$name<'tcx>>(
|
||||
let value = $crate::plumbing::try_load_from_disk::<
|
||||
queries::$name::ProvidedValue<'tcx>
|
||||
>(
|
||||
tcx,
|
||||
prev_index,
|
||||
index,
|
||||
);
|
||||
value.map(|value| query_provided_to_value::$name(tcx, value))
|
||||
value.map(|value| queries::$name::provided_to_erased(tcx, value))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@ -623,7 +624,7 @@ macro_rules! define_queries {
|
||||
|_tcx, _key, _prev_index, _index| None
|
||||
}),
|
||||
value_from_cycle_error: |tcx, cycle| {
|
||||
let result: query_values::$name<'tcx> = Value::from_cycle_error(tcx, cycle);
|
||||
let result: queries::$name::Value<'tcx> = Value::from_cycle_error(tcx, cycle);
|
||||
erase(result)
|
||||
},
|
||||
loadable_from_disk: |_tcx, _key, _index| {
|
||||
@ -634,18 +635,18 @@ macro_rules! define_queries {
|
||||
false
|
||||
})
|
||||
},
|
||||
hash_result: hash_result!([$($modifiers)*][query_values::$name<'tcx>]),
|
||||
format_value: |value| format!("{:?}", restore::<query_values::$name<'tcx>>(*value)),
|
||||
hash_result: hash_result!([$($modifiers)*][queries::$name::Value<'tcx>]),
|
||||
format_value: |value| format!("{:?}", restore::<queries::$name::Value<'tcx>>(*value)),
|
||||
}
|
||||
}
|
||||
)*
|
||||
}
|
||||
|
||||
$(impl<'tcx> QueryConfigRestored<'tcx> for queries::$name<'tcx> {
|
||||
type RestoredValue = query_values::$name<'tcx>;
|
||||
$(impl<'tcx> QueryConfigRestored<'tcx> for query_config::$name<'tcx> {
|
||||
type RestoredValue = queries::$name::Value<'tcx>;
|
||||
type Config = DynamicConfig<
|
||||
'tcx,
|
||||
query_storage::$name<'tcx>,
|
||||
queries::$name::Storage<'tcx>,
|
||||
{ is_anon!([$($modifiers)*]) },
|
||||
{ depth_limit!([$($modifiers)*]) },
|
||||
{ feedable!([$($modifiers)*]) },
|
||||
@ -660,7 +661,7 @@ macro_rules! define_queries {
|
||||
|
||||
#[inline(always)]
|
||||
fn restore(value: <Self::Config as QueryConfig<QueryCtxt<'tcx>>>::Value) -> Self::RestoredValue {
|
||||
restore::<query_values::$name<'tcx>>(value)
|
||||
restore::<queries::$name::Value<'tcx>>(value)
|
||||
}
|
||||
})*
|
||||
|
||||
@ -730,7 +731,7 @@ macro_rules! define_queries {
|
||||
}
|
||||
|
||||
$(pub(crate) fn $name<'tcx>()-> DepKindStruct<'tcx> {
|
||||
$crate::plumbing::query_callback::<queries::$name<'tcx>>(
|
||||
$crate::plumbing::query_callback::<query_config::$name<'tcx>>(
|
||||
is_anon!([$($modifiers)*]),
|
||||
is_eval_always!([$($modifiers)*]),
|
||||
)
|
||||
@ -785,8 +786,8 @@ macro_rules! define_queries {
|
||||
)
|
||||
},
|
||||
encode_query_results: expand_if_cached!([$($modifiers)*], |tcx, encoder, query_result_index|
|
||||
$crate::plumbing::encode_query_results::<super::queries::$name<'tcx>>(
|
||||
super::queries::$name::config(tcx),
|
||||
$crate::plumbing::encode_query_results::<super::query_config::$name<'tcx>>(
|
||||
super::query_config::$name::config(tcx),
|
||||
QueryCtxt::new(tcx),
|
||||
encoder,
|
||||
query_result_index,
|
||||
|
@ -24,7 +24,7 @@ use rustc_hir::def::DefKind;
|
||||
use rustc_hir::def_id::LocalDefId;
|
||||
use rustc_interface::interface::Compiler;
|
||||
use rustc_interface::{Config, Queries};
|
||||
use rustc_middle::query::query_values::mir_borrowck;
|
||||
use rustc_middle::query::queries::mir_borrowck::ProvidedValue;
|
||||
use rustc_middle::query::{ExternProviders, Providers};
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_session::Session;
|
||||
@ -126,7 +126,7 @@ thread_local! {
|
||||
RefCell::new(HashMap::new());
|
||||
}
|
||||
|
||||
fn mir_borrowck<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> mir_borrowck<'tcx> {
|
||||
fn mir_borrowck<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> ProvidedValue<'tcx> {
|
||||
let body_with_facts = rustc_borrowck::consumers::get_body_with_borrowck_facts(tcx, def_id);
|
||||
// SAFETY: The reader casts the 'static lifetime to 'tcx before using it.
|
||||
let body_with_facts: BodyWithBorrowckFacts<'static> =
|
||||
|
Loading…
Reference in New Issue
Block a user