Auto merge of #100436 - jyn514:macro-query-system, r=cjgillot
try and simplify some things in the query system
This commit is contained in:
commit
76531befc4
7 changed files with 120 additions and 113 deletions
|
@ -400,10 +400,8 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream {
|
||||||
TokenStream::from(quote! {
|
TokenStream::from(quote! {
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! rustc_query_append {
|
macro_rules! rustc_query_append {
|
||||||
([$($macro:tt)*][$($other:tt)*]) => {
|
([$($macro:tt)*]) => {
|
||||||
$($macro)* {
|
$($macro)* {
|
||||||
$($other)*
|
|
||||||
|
|
||||||
#query_stream
|
#query_stream
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,9 +76,9 @@ impl ProcessQueryValue<'_, Option<DeprecationEntry>> for Option<Deprecation> {
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! provide_one {
|
macro_rules! provide_one {
|
||||||
(<$lt:tt> $tcx:ident, $def_id:ident, $other:ident, $cdata:ident, $name:ident => { table }) => {
|
($tcx:ident, $def_id:ident, $other:ident, $cdata:ident, $name:ident => { table }) => {
|
||||||
provide_one! {
|
provide_one! {
|
||||||
<$lt> $tcx, $def_id, $other, $cdata, $name => {
|
$tcx, $def_id, $other, $cdata, $name => {
|
||||||
$cdata
|
$cdata
|
||||||
.root
|
.root
|
||||||
.tables
|
.tables
|
||||||
|
@ -89,9 +89,9 @@ macro_rules! provide_one {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
(<$lt:tt> $tcx:ident, $def_id:ident, $other:ident, $cdata:ident, $name:ident => { table_direct }) => {
|
($tcx:ident, $def_id:ident, $other:ident, $cdata:ident, $name:ident => { table_direct }) => {
|
||||||
provide_one! {
|
provide_one! {
|
||||||
<$lt> $tcx, $def_id, $other, $cdata, $name => {
|
$tcx, $def_id, $other, $cdata, $name => {
|
||||||
// We don't decode `table_direct`, since it's not a Lazy, but an actual value
|
// We don't decode `table_direct`, since it's not a Lazy, but an actual value
|
||||||
$cdata
|
$cdata
|
||||||
.root
|
.root
|
||||||
|
@ -102,11 +102,11 @@ macro_rules! provide_one {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
(<$lt:tt> $tcx:ident, $def_id:ident, $other:ident, $cdata:ident, $name:ident => $compute:block) => {
|
($tcx:ident, $def_id:ident, $other:ident, $cdata:ident, $name:ident => $compute:block) => {
|
||||||
fn $name<$lt>(
|
fn $name<'tcx>(
|
||||||
$tcx: TyCtxt<$lt>,
|
$tcx: TyCtxt<'tcx>,
|
||||||
def_id_arg: ty::query::query_keys::$name<$lt>,
|
def_id_arg: ty::query::query_keys::$name<'tcx>,
|
||||||
) -> ty::query::query_values::$name<$lt> {
|
) -> ty::query::query_values::$name<'tcx> {
|
||||||
let _prof_timer =
|
let _prof_timer =
|
||||||
$tcx.prof.generic_activity(concat!("metadata_decode_entry_", stringify!($name)));
|
$tcx.prof.generic_activity(concat!("metadata_decode_entry_", stringify!($name)));
|
||||||
|
|
||||||
|
@ -130,11 +130,11 @@ macro_rules! provide_one {
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! provide {
|
macro_rules! provide {
|
||||||
(<$lt:tt> $tcx:ident, $def_id:ident, $other:ident, $cdata:ident,
|
($tcx:ident, $def_id:ident, $other:ident, $cdata:ident,
|
||||||
$($name:ident => { $($compute:tt)* })*) => {
|
$($name:ident => { $($compute:tt)* })*) => {
|
||||||
pub fn provide_extern(providers: &mut ExternProviders) {
|
pub fn provide_extern(providers: &mut ExternProviders) {
|
||||||
$(provide_one! {
|
$(provide_one! {
|
||||||
<$lt> $tcx, $def_id, $other, $cdata, $name => { $($compute)* }
|
$tcx, $def_id, $other, $cdata, $name => { $($compute)* }
|
||||||
})*
|
})*
|
||||||
|
|
||||||
*providers = ExternProviders {
|
*providers = ExternProviders {
|
||||||
|
@ -187,7 +187,7 @@ impl IntoArgs for (CrateNum, SimplifiedType) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
provide! { <'tcx> tcx, def_id, other, cdata,
|
provide! { tcx, def_id, other, cdata,
|
||||||
explicit_item_bounds => { table }
|
explicit_item_bounds => { table }
|
||||||
explicit_predicates_of => { table }
|
explicit_predicates_of => { table }
|
||||||
generics_of => { table }
|
generics_of => { table }
|
||||||
|
|
|
@ -143,7 +143,7 @@ impl DepKind {
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! define_dep_nodes {
|
macro_rules! define_dep_nodes {
|
||||||
(<$tcx:tt>
|
(
|
||||||
$(
|
$(
|
||||||
[$($attrs:tt)*]
|
[$($attrs:tt)*]
|
||||||
$variant:ident $(( $tuple_arg_ty:ty $(,)? ))*
|
$variant:ident $(( $tuple_arg_ty:ty $(,)? ))*
|
||||||
|
@ -179,7 +179,7 @@ macro_rules! define_dep_nodes {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
rustc_dep_node_append!([define_dep_nodes!][ <'tcx>
|
rustc_dep_node_append!([define_dep_nodes!][
|
||||||
// We use this for most things when incr. comp. is turned off.
|
// We use this for most things when incr. comp. is turned off.
|
||||||
[] Null,
|
[] Null,
|
||||||
|
|
||||||
|
|
|
@ -173,7 +173,7 @@ macro_rules! opt_remap_env_constness {
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! define_callbacks {
|
macro_rules! define_callbacks {
|
||||||
(<$tcx:tt>
|
(
|
||||||
$($(#[$attr:meta])*
|
$($(#[$attr:meta])*
|
||||||
[$($modifiers:tt)*] fn $name:ident($($K:tt)*) -> $V:ty,)*) => {
|
[$($modifiers:tt)*] fn $name:ident($($K:tt)*) -> $V:ty,)*) => {
|
||||||
|
|
||||||
|
@ -187,33 +187,33 @@ macro_rules! define_callbacks {
|
||||||
pub mod query_keys {
|
pub mod query_keys {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
$(pub type $name<$tcx> = $($K)*;)*
|
$(pub type $name<'tcx> = $($K)*;)*
|
||||||
}
|
}
|
||||||
#[allow(nonstandard_style, unused_lifetimes)]
|
#[allow(nonstandard_style, unused_lifetimes)]
|
||||||
pub mod query_values {
|
pub mod query_values {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
$(pub type $name<$tcx> = $V;)*
|
$(pub type $name<'tcx> = $V;)*
|
||||||
}
|
}
|
||||||
#[allow(nonstandard_style, unused_lifetimes)]
|
#[allow(nonstandard_style, unused_lifetimes)]
|
||||||
pub mod query_storage {
|
pub mod query_storage {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
$(pub type $name<$tcx> = query_storage!([$($modifiers)*][$($K)*, $V]);)*
|
$(pub type $name<'tcx> = query_storage!([$($modifiers)*][$($K)*, $V]);)*
|
||||||
}
|
}
|
||||||
#[allow(nonstandard_style, unused_lifetimes)]
|
#[allow(nonstandard_style, unused_lifetimes)]
|
||||||
pub mod query_stored {
|
pub mod query_stored {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
$(pub type $name<$tcx> = <query_storage::$name<$tcx> as QueryStorage>::Stored;)*
|
$(pub type $name<'tcx> = <query_storage::$name<'tcx> as QueryStorage>::Stored;)*
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct QueryCaches<$tcx> {
|
pub struct QueryCaches<'tcx> {
|
||||||
$($(#[$attr])* pub $name: query_storage::$name<$tcx>,)*
|
$($(#[$attr])* pub $name: query_storage::$name<'tcx>,)*
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<$tcx> TyCtxtEnsure<$tcx> {
|
impl<'tcx> TyCtxtEnsure<'tcx> {
|
||||||
$($(#[$attr])*
|
$($(#[$attr])*
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn $name(self, key: query_helper_param_ty!($($K)*)) {
|
pub fn $name(self, key: query_helper_param_ty!($($K)*)) {
|
||||||
|
@ -231,20 +231,20 @@ macro_rules! define_callbacks {
|
||||||
})*
|
})*
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<$tcx> TyCtxt<$tcx> {
|
impl<'tcx> TyCtxt<'tcx> {
|
||||||
$($(#[$attr])*
|
$($(#[$attr])*
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn $name(self, key: query_helper_param_ty!($($K)*)) -> query_stored::$name<$tcx>
|
pub fn $name(self, key: query_helper_param_ty!($($K)*)) -> query_stored::$name<'tcx>
|
||||||
{
|
{
|
||||||
self.at(DUMMY_SP).$name(key)
|
self.at(DUMMY_SP).$name(key)
|
||||||
})*
|
})*
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<$tcx> TyCtxtAt<$tcx> {
|
impl<'tcx> TyCtxtAt<'tcx> {
|
||||||
$($(#[$attr])*
|
$($(#[$attr])*
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn $name(self, key: query_helper_param_ty!($($K)*)) -> query_stored::$name<$tcx>
|
pub fn $name(self, key: query_helper_param_ty!($($K)*)) -> query_stored::$name<'tcx>
|
||||||
{
|
{
|
||||||
let key = key.into_query_param();
|
let key = key.into_query_param();
|
||||||
opt_remap_env_constness!([$($modifiers)*][key]);
|
opt_remap_env_constness!([$($modifiers)*][key]);
|
||||||
|
@ -311,11 +311,11 @@ macro_rules! define_callbacks {
|
||||||
$($(#[$attr])*
|
$($(#[$attr])*
|
||||||
fn $name(
|
fn $name(
|
||||||
&'tcx self,
|
&'tcx self,
|
||||||
tcx: TyCtxt<$tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
span: Span,
|
span: Span,
|
||||||
key: query_keys::$name<$tcx>,
|
key: query_keys::$name<'tcx>,
|
||||||
mode: QueryMode,
|
mode: QueryMode,
|
||||||
) -> Option<query_stored::$name<$tcx>>;)*
|
) -> Option<query_stored::$name<'tcx>>;)*
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -332,7 +332,7 @@ macro_rules! define_callbacks {
|
||||||
// Queries marked with `fatal_cycle` do not need the latter implementation,
|
// Queries marked with `fatal_cycle` do not need the latter implementation,
|
||||||
// as they will raise an fatal error on query cycles instead.
|
// as they will raise an fatal error on query cycles instead.
|
||||||
|
|
||||||
rustc_query_append! { [define_callbacks!][<'tcx>] }
|
rustc_query_append! { [define_callbacks!] }
|
||||||
|
|
||||||
mod sealed {
|
mod sealed {
|
||||||
use super::{DefId, LocalDefId};
|
use super::{DefId, LocalDefId};
|
||||||
|
|
|
@ -15,7 +15,6 @@ extern crate rustc_macros;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate rustc_middle;
|
extern crate rustc_middle;
|
||||||
|
|
||||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
|
||||||
use rustc_data_structures::sync::AtomicU64;
|
use rustc_data_structures::sync::AtomicU64;
|
||||||
use rustc_middle::arena::Arena;
|
use rustc_middle::arena::Arena;
|
||||||
use rustc_middle::dep_graph::{self, DepKindStruct, SerializedDepNodeIndex};
|
use rustc_middle::dep_graph::{self, DepKindStruct, SerializedDepNodeIndex};
|
||||||
|
@ -55,7 +54,7 @@ fn describe_as_module(def_id: LocalDefId, tcx: TyCtxt<'_>) -> String {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rustc_query_append! { [define_queries!][<'tcx>] }
|
rustc_query_append! { [define_queries!] }
|
||||||
|
|
||||||
impl<'tcx> Queries<'tcx> {
|
impl<'tcx> Queries<'tcx> {
|
||||||
// Force codegen in the dyn-trait transformation in this crate.
|
// Force codegen in the dyn-trait transformation in this crate.
|
||||||
|
|
|
@ -2,13 +2,18 @@
|
||||||
//! generate the actual methods on tcx which find and execute the provider,
|
//! generate the actual methods on tcx which find and execute the provider,
|
||||||
//! manage the caches, and so forth.
|
//! manage the caches, and so forth.
|
||||||
|
|
||||||
|
use crate::keys::Key;
|
||||||
use crate::{on_disk_cache, Queries};
|
use crate::{on_disk_cache, Queries};
|
||||||
use rustc_middle::dep_graph::{DepNodeIndex, SerializedDepNodeIndex};
|
use rustc_middle::dep_graph::{self, DepKind, DepNodeIndex, SerializedDepNodeIndex};
|
||||||
use rustc_middle::ty::tls::{self, ImplicitCtxt};
|
use rustc_middle::ty::tls::{self, ImplicitCtxt};
|
||||||
use rustc_middle::ty::TyCtxt;
|
use rustc_middle::ty::{self, TyCtxt};
|
||||||
use rustc_query_system::dep_graph::HasDepContext;
|
use rustc_query_system::dep_graph::HasDepContext;
|
||||||
use rustc_query_system::query::{QueryContext, QueryJobId, QueryMap, QuerySideEffects};
|
use rustc_query_system::ich::StableHashingContext;
|
||||||
|
use rustc_query_system::query::{
|
||||||
|
QueryContext, QueryJobId, QueryMap, QuerySideEffects, QueryStackFrame,
|
||||||
|
};
|
||||||
|
|
||||||
|
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||||
use rustc_data_structures::sync::Lock;
|
use rustc_data_structures::sync::Lock;
|
||||||
use rustc_data_structures::thin_vec::ThinVec;
|
use rustc_data_structures::thin_vec::ThinVec;
|
||||||
use rustc_errors::{Diagnostic, Handler};
|
use rustc_errors::{Diagnostic, Handler};
|
||||||
|
@ -233,36 +238,24 @@ macro_rules! get_provider {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! define_queries {
|
pub(crate) fn create_query_frame<
|
||||||
(<$tcx:tt>
|
'tcx,
|
||||||
$($(#[$attr:meta])*
|
K: Copy + Key + for<'a> HashStable<StableHashingContext<'a>>,
|
||||||
[$($modifiers:tt)*] fn $name:ident($($K:tt)*) -> $V:ty,)*) => {
|
>(
|
||||||
define_queries_struct! {
|
tcx: QueryCtxt<'tcx>,
|
||||||
tcx: $tcx,
|
do_describe: fn(QueryCtxt<'tcx>, K) -> String,
|
||||||
input: ($(([$($modifiers)*] [$($attr)*] [$name]))*)
|
key: K,
|
||||||
}
|
kind: DepKind,
|
||||||
|
name: &'static str,
|
||||||
mod make_query {
|
) -> QueryStackFrame {
|
||||||
use super::*;
|
|
||||||
|
|
||||||
// Create an eponymous constructor for each query.
|
|
||||||
$(#[allow(nonstandard_style)] $(#[$attr])*
|
|
||||||
pub fn $name<$tcx>(tcx: QueryCtxt<$tcx>, key: query_keys::$name<$tcx>) -> QueryStackFrame {
|
|
||||||
let kind = dep_graph::DepKind::$name;
|
|
||||||
let name = stringify!($name);
|
|
||||||
// Disable visible paths printing for performance reasons.
|
// Disable visible paths printing for performance reasons.
|
||||||
// Showing visible path instead of any path is not that important in production.
|
// Showing visible path instead of any path is not that important in production.
|
||||||
let description = ty::print::with_no_visible_paths!(
|
let description = ty::print::with_no_visible_paths!(
|
||||||
// Force filename-line mode to avoid invoking `type_of` query.
|
// Force filename-line mode to avoid invoking `type_of` query.
|
||||||
ty::print::with_forced_impl_filename_line!(
|
ty::print::with_forced_impl_filename_line!(do_describe(tcx, key))
|
||||||
queries::$name::describe(tcx, key)
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
let description = if tcx.sess.verbose() {
|
let description =
|
||||||
format!("{} [{}]", description, name)
|
if tcx.sess.verbose() { format!("{} [{}]", description, name) } else { description };
|
||||||
} else {
|
|
||||||
description
|
|
||||||
};
|
|
||||||
let span = if kind == dep_graph::DepKind::def_span {
|
let span = if kind == dep_graph::DepKind::def_span {
|
||||||
// The `def_span` query is used to calculate `default_span`,
|
// The `def_span` query is used to calculate `default_span`,
|
||||||
// so exit to avoid infinite recursion.
|
// so exit to avoid infinite recursion.
|
||||||
|
@ -288,6 +281,27 @@ macro_rules! define_queries {
|
||||||
};
|
};
|
||||||
|
|
||||||
QueryStackFrame::new(name, description, span, def_kind, hash)
|
QueryStackFrame::new(name, description, span, def_kind, hash)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NOTE: `$V` isn't used here, but we still need to match on it so it can be passed to other macros
|
||||||
|
// invoked by `rustc_query_append`.
|
||||||
|
macro_rules! define_queries {
|
||||||
|
(
|
||||||
|
$($(#[$attr:meta])*
|
||||||
|
[$($modifiers:tt)*] fn $name:ident($($K:tt)*) -> $V:ty,)*) => {
|
||||||
|
define_queries_struct! {
|
||||||
|
input: ($(([$($modifiers)*] [$($attr)*] [$name]))*)
|
||||||
|
}
|
||||||
|
|
||||||
|
mod make_query {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
// Create an eponymous constructor for each query.
|
||||||
|
$(#[allow(nonstandard_style)] $(#[$attr])*
|
||||||
|
pub fn $name<'tcx>(tcx: QueryCtxt<'tcx>, key: <queries::$name<'tcx> as QueryConfig>::Key) -> QueryStackFrame {
|
||||||
|
let kind = dep_graph::DepKind::$name;
|
||||||
|
let name = stringify!($name);
|
||||||
|
$crate::plumbing::create_query_frame(tcx, queries::$name::describe, key, kind, name)
|
||||||
})*
|
})*
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -295,32 +309,32 @@ macro_rules! define_queries {
|
||||||
mod queries {
|
mod queries {
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
$(pub struct $name<$tcx> {
|
$(pub struct $name<'tcx> {
|
||||||
data: PhantomData<&$tcx ()>
|
data: PhantomData<&'tcx ()>
|
||||||
})*
|
})*
|
||||||
}
|
}
|
||||||
|
|
||||||
$(impl<$tcx> QueryConfig for queries::$name<$tcx> {
|
$(impl<'tcx> QueryConfig for queries::$name<'tcx> {
|
||||||
type Key = query_keys::$name<$tcx>;
|
type Key = query_keys::$name<'tcx>;
|
||||||
type Value = query_values::$name<$tcx>;
|
type Value = query_values::$name<'tcx>;
|
||||||
type Stored = query_stored::$name<$tcx>;
|
type Stored = query_stored::$name<'tcx>;
|
||||||
const NAME: &'static str = stringify!($name);
|
const NAME: &'static str = stringify!($name);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<$tcx> QueryDescription<QueryCtxt<$tcx>> for queries::$name<$tcx> {
|
impl<'tcx> QueryDescription<QueryCtxt<'tcx>> for queries::$name<'tcx> {
|
||||||
rustc_query_description! { $name<$tcx> }
|
rustc_query_description! { $name<'tcx> }
|
||||||
|
|
||||||
type Cache = query_storage::$name<$tcx>;
|
type Cache = query_storage::$name<'tcx>;
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn query_state<'a>(tcx: QueryCtxt<$tcx>) -> &'a QueryState<Self::Key>
|
fn query_state<'a>(tcx: QueryCtxt<'tcx>) -> &'a QueryState<Self::Key>
|
||||||
where QueryCtxt<$tcx>: 'a
|
where QueryCtxt<'tcx>: 'a
|
||||||
{
|
{
|
||||||
&tcx.queries.$name
|
&tcx.queries.$name
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn query_cache<'a>(tcx: QueryCtxt<$tcx>) -> &'a Self::Cache
|
fn query_cache<'a>(tcx: QueryCtxt<'tcx>) -> &'a Self::Cache
|
||||||
where 'tcx:'a
|
where 'tcx:'a
|
||||||
{
|
{
|
||||||
&tcx.query_caches.$name
|
&tcx.query_caches.$name
|
||||||
|
@ -328,7 +342,7 @@ macro_rules! define_queries {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn make_vtable(tcx: QueryCtxt<'tcx>, key: &Self::Key) ->
|
fn make_vtable(tcx: QueryCtxt<'tcx>, key: &Self::Key) ->
|
||||||
QueryVTable<QueryCtxt<$tcx>, Self::Key, Self::Value>
|
QueryVTable<QueryCtxt<'tcx>, Self::Key, Self::Value>
|
||||||
{
|
{
|
||||||
let compute = get_provider!([$($modifiers)*][tcx, $name, key]);
|
let compute = get_provider!([$($modifiers)*][tcx, $name, key]);
|
||||||
let cache_on_disk = Self::cache_on_disk(tcx.tcx, key);
|
let cache_on_disk = Self::cache_on_disk(tcx.tcx, key);
|
||||||
|
@ -349,7 +363,6 @@ macro_rules! define_queries {
|
||||||
mod query_callbacks {
|
mod query_callbacks {
|
||||||
use super::*;
|
use super::*;
|
||||||
use rustc_middle::dep_graph::DepNode;
|
use rustc_middle::dep_graph::DepNode;
|
||||||
use rustc_middle::ty::query::query_keys;
|
|
||||||
use rustc_query_system::dep_graph::DepNodeParams;
|
use rustc_query_system::dep_graph::DepNodeParams;
|
||||||
use rustc_query_system::query::{force_query, QueryDescription};
|
use rustc_query_system::query::{force_query, QueryDescription};
|
||||||
use rustc_query_system::dep_graph::FingerprintStyle;
|
use rustc_query_system::dep_graph::FingerprintStyle;
|
||||||
|
@ -411,7 +424,7 @@ macro_rules! define_queries {
|
||||||
let is_eval_always = is_eval_always!([$($modifiers)*]);
|
let is_eval_always = is_eval_always!([$($modifiers)*]);
|
||||||
|
|
||||||
let fingerprint_style =
|
let fingerprint_style =
|
||||||
<query_keys::$name<'_> as DepNodeParams<TyCtxt<'_>>>::fingerprint_style();
|
<<queries::$name<'_> as QueryConfig>::Key as DepNodeParams<TyCtxt<'_>>>::fingerprint_style();
|
||||||
|
|
||||||
if is_anon || !fingerprint_style.reconstructible() {
|
if is_anon || !fingerprint_style.reconstructible() {
|
||||||
return DepKindStruct {
|
return DepKindStruct {
|
||||||
|
@ -424,8 +437,8 @@ macro_rules! define_queries {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn recover<'tcx>(tcx: TyCtxt<'tcx>, dep_node: DepNode) -> Option<query_keys::$name<'tcx>> {
|
fn recover<'tcx>(tcx: TyCtxt<'tcx>, dep_node: DepNode) -> Option<<queries::$name<'tcx> as QueryConfig>::Key> {
|
||||||
<query_keys::$name<'_> as DepNodeParams<TyCtxt<'_>>>::recover(tcx, &dep_node)
|
<<queries::$name<'_> as QueryConfig>::Key as DepNodeParams<TyCtxt<'_>>>::recover(tcx, &dep_node)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn force_from_dep_node(tcx: TyCtxt<'_>, dep_node: DepNode) -> bool {
|
fn force_from_dep_node(tcx: TyCtxt<'_>, dep_node: DepNode) -> bool {
|
||||||
|
@ -465,28 +478,25 @@ macro_rules! define_queries {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME(eddyb) this macro (and others?) use `$tcx` and `'tcx` interchangeably.
|
|
||||||
// We should either not take `$tcx` at all and use `'tcx` everywhere, or use
|
|
||||||
// `$tcx` everywhere (even if that isn't necessary due to lack of hygiene).
|
|
||||||
macro_rules! define_queries_struct {
|
macro_rules! define_queries_struct {
|
||||||
(tcx: $tcx:tt,
|
(
|
||||||
input: ($(([$($modifiers:tt)*] [$($attr:tt)*] [$name:ident]))*)) => {
|
input: ($(([$($modifiers:tt)*] [$($attr:tt)*] [$name:ident]))*)) => {
|
||||||
pub struct Queries<$tcx> {
|
pub struct Queries<'tcx> {
|
||||||
local_providers: Box<Providers>,
|
local_providers: Box<Providers>,
|
||||||
extern_providers: Box<ExternProviders>,
|
extern_providers: Box<ExternProviders>,
|
||||||
|
|
||||||
pub on_disk_cache: Option<OnDiskCache<$tcx>>,
|
pub on_disk_cache: Option<OnDiskCache<'tcx>>,
|
||||||
|
|
||||||
jobs: AtomicU64,
|
jobs: AtomicU64,
|
||||||
|
|
||||||
$($(#[$attr])* $name: QueryState<query_keys::$name<$tcx>>,)*
|
$($(#[$attr])* $name: QueryState<<queries::$name<'tcx> as QueryConfig>::Key>,)*
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<$tcx> Queries<$tcx> {
|
impl<'tcx> Queries<'tcx> {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
local_providers: Providers,
|
local_providers: Providers,
|
||||||
extern_providers: ExternProviders,
|
extern_providers: ExternProviders,
|
||||||
on_disk_cache: Option<OnDiskCache<$tcx>>,
|
on_disk_cache: Option<OnDiskCache<'tcx>>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Queries {
|
Queries {
|
||||||
local_providers: Box::new(local_providers),
|
local_providers: Box::new(local_providers),
|
||||||
|
@ -498,8 +508,8 @@ macro_rules! define_queries_struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn try_collect_active_jobs(
|
pub(crate) fn try_collect_active_jobs(
|
||||||
&$tcx self,
|
&'tcx self,
|
||||||
tcx: TyCtxt<$tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
) -> Option<QueryMap> {
|
) -> Option<QueryMap> {
|
||||||
let tcx = QueryCtxt { tcx, queries: self };
|
let tcx = QueryCtxt { tcx, queries: self };
|
||||||
let mut jobs = QueryMap::default();
|
let mut jobs = QueryMap::default();
|
||||||
|
@ -532,13 +542,13 @@ macro_rules! define_queries_struct {
|
||||||
#[tracing::instrument(level = "trace", skip(self, tcx))]
|
#[tracing::instrument(level = "trace", skip(self, tcx))]
|
||||||
fn $name(
|
fn $name(
|
||||||
&'tcx self,
|
&'tcx self,
|
||||||
tcx: TyCtxt<$tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
span: Span,
|
span: Span,
|
||||||
key: query_keys::$name<$tcx>,
|
key: <queries::$name<'tcx> as QueryConfig>::Key,
|
||||||
mode: QueryMode,
|
mode: QueryMode,
|
||||||
) -> Option<query_stored::$name<$tcx>> {
|
) -> Option<query_stored::$name<'tcx>> {
|
||||||
let qcx = QueryCtxt { tcx, queries: self };
|
let qcx = QueryCtxt { tcx, queries: self };
|
||||||
get_query::<queries::$name<$tcx>, _>(qcx, span, key, mode)
|
get_query::<queries::$name<'tcx>, _>(qcx, span, key, mode)
|
||||||
})*
|
})*
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -306,7 +306,7 @@ pub fn alloc_self_profile_query_strings(tcx: TyCtxt<'_>) {
|
||||||
let mut string_cache = QueryKeyStringCache::new();
|
let mut string_cache = QueryKeyStringCache::new();
|
||||||
|
|
||||||
macro_rules! alloc_once {
|
macro_rules! alloc_once {
|
||||||
(<$tcx:tt>
|
(
|
||||||
$($(#[$attr:meta])* [$($modifiers:tt)*] fn $name:ident($K:ty) -> $V:ty,)*
|
$($(#[$attr:meta])* [$($modifiers:tt)*] fn $name:ident($K:ty) -> $V:ty,)*
|
||||||
) => {
|
) => {
|
||||||
$({
|
$({
|
||||||
|
@ -320,5 +320,5 @@ pub fn alloc_self_profile_query_strings(tcx: TyCtxt<'_>) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rustc_query_append! { [alloc_once!][<'tcx>] }
|
rustc_query_append! { [alloc_once!] }
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue