diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:18:32 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:18:32 +0000 |
commit | 4547b622d8d29df964fa2914213088b148c498fc (patch) | |
tree | 9fc6b25f3c3add6b745be9a2400a6e96140046e9 /compiler/rustc_query_impl/src | |
parent | Releasing progress-linux version 1.66.0+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-4547b622d8d29df964fa2914213088b148c498fc.tar.xz rustc-4547b622d8d29df964fa2914213088b148c498fc.zip |
Merging upstream version 1.67.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | compiler/rustc_middle/src/query/keys.rs (renamed from compiler/rustc_query_impl/src/keys.rs) | 23 | ||||
-rw-r--r-- | compiler/rustc_query_impl/src/lib.rs | 6 | ||||
-rw-r--r-- | compiler/rustc_query_impl/src/on_disk_cache.rs | 6 | ||||
-rw-r--r-- | compiler/rustc_query_impl/src/plumbing.rs | 46 | ||||
-rw-r--r-- | compiler/rustc_query_impl/src/profiling_support.rs | 51 |
5 files changed, 64 insertions, 68 deletions
diff --git a/compiler/rustc_query_impl/src/keys.rs b/compiler/rustc_middle/src/query/keys.rs index 8be2e2be8..880632561 100644 --- a/compiler/rustc_query_impl/src/keys.rs +++ b/compiler/rustc_middle/src/query/keys.rs @@ -1,19 +1,22 @@ //! Defines the set of legal keys that can be used in queries. +use crate::infer::canonical::Canonical; +use crate::mir; +use crate::traits; +use crate::ty::fast_reject::SimplifiedType; +use crate::ty::subst::{GenericArg, SubstsRef}; +use crate::ty::{self, layout::TyAndLayout, Ty, TyCtxt}; use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE}; use rustc_hir::hir_id::{HirId, OwnerId}; -use rustc_middle::infer::canonical::Canonical; -use rustc_middle::mir; -use rustc_middle::traits; -use rustc_middle::ty::fast_reject::SimplifiedType; -use rustc_middle::ty::subst::{GenericArg, SubstsRef}; -use rustc_middle::ty::{self, layout::TyAndLayout, Ty, TyCtxt}; +use rustc_query_system::query::{DefaultCacheSelector, VecCacheSelector}; use rustc_span::symbol::{Ident, Symbol}; use rustc_span::{Span, DUMMY_SP}; /// The `Key` trait controls what types can legally be used as the key /// for a query. -pub trait Key { +pub trait Key: Sized { + type CacheSelector = DefaultCacheSelector<Self>; + /// Given an instance of this key, what crate is it referring to? /// This is used to find the provider. fn query_crate_is_local(&self) -> bool; @@ -100,6 +103,8 @@ impl<'tcx> Key for mir::interpret::LitToConstInput<'tcx> { } impl Key for CrateNum { + type CacheSelector = VecCacheSelector<Self>; + #[inline(always)] fn query_crate_is_local(&self) -> bool { *self == LOCAL_CRATE @@ -110,6 +115,8 @@ impl Key for CrateNum { } impl Key for OwnerId { + type CacheSelector = VecCacheSelector<Self>; + #[inline(always)] fn query_crate_is_local(&self) -> bool { true @@ -123,6 +130,8 @@ impl Key for OwnerId { } impl Key for LocalDefId { + type CacheSelector = VecCacheSelector<Self>; + #[inline(always)] fn query_crate_is_local(&self) -> bool { true diff --git a/compiler/rustc_query_impl/src/lib.rs b/compiler/rustc_query_impl/src/lib.rs index 11d4c97e7..d426a2b6b 100644 --- a/compiler/rustc_query_impl/src/lib.rs +++ b/compiler/rustc_query_impl/src/lib.rs @@ -20,6 +20,7 @@ extern crate rustc_middle; use rustc_data_structures::sync::AtomicU64; use rustc_middle::arena::Arena; use rustc_middle::dep_graph::{self, DepKindStruct}; +use rustc_middle::query::Key; use rustc_middle::ty::query::{query_keys, query_storage, query_stored, query_values}; use rustc_middle::ty::query::{ExternProviders, Providers, QueryEngine}; use rustc_middle::ty::TyCtxt; @@ -32,11 +33,8 @@ use rustc_query_system::query::*; #[cfg(parallel_compiler)] pub use rustc_query_system::query::{deadlock, QueryContext}; -mod keys; -use keys::Key; - pub use rustc_query_system::query::QueryConfig; -pub(crate) use rustc_query_system::query::{QueryDescription, QueryVTable}; +pub(crate) use rustc_query_system::query::QueryVTable; mod on_disk_cache; pub use on_disk_cache::OnDiskCache; diff --git a/compiler/rustc_query_impl/src/on_disk_cache.rs b/compiler/rustc_query_impl/src/on_disk_cache.rs index 9000f81d9..ac9653b90 100644 --- a/compiler/rustc_query_impl/src/on_disk_cache.rs +++ b/compiler/rustc_query_impl/src/on_disk_cache.rs @@ -812,13 +812,13 @@ impl<'a, 'tcx> Decodable<CacheDecoder<'a, 'tcx>> } } -impl<'a, 'tcx> Decodable<CacheDecoder<'a, 'tcx>> for &'tcx [ty::abstract_const::Node<'tcx>] { +impl<'a, 'tcx> Decodable<CacheDecoder<'a, 'tcx>> for &'tcx [(ty::Predicate<'tcx>, Span)] { fn decode(d: &mut CacheDecoder<'a, 'tcx>) -> Self { RefDecodable::decode(d) } } -impl<'a, 'tcx> Decodable<CacheDecoder<'a, 'tcx>> for &'tcx [(ty::Predicate<'tcx>, Span)] { +impl<'a, 'tcx> Decodable<CacheDecoder<'a, 'tcx>> for &'tcx [(ty::Clause<'tcx>, Span)] { fn decode(d: &mut CacheDecoder<'a, 'tcx>) -> Self { RefDecodable::decode(d) } @@ -1062,7 +1062,7 @@ pub fn encode_query_results<'a, 'tcx, CTX, Q>( query_result_index: &mut EncodedDepNodeIndex, ) where CTX: QueryContext + 'tcx, - Q: super::QueryDescription<CTX>, + Q: super::QueryConfig<CTX>, Q::Value: Encodable<CacheEncoder<'a, 'tcx>>, { let _timer = tcx diff --git a/compiler/rustc_query_impl/src/plumbing.rs b/compiler/rustc_query_impl/src/plumbing.rs index 1d17f4221..8d5d84c5d 100644 --- a/compiler/rustc_query_impl/src/plumbing.rs +++ b/compiler/rustc_query_impl/src/plumbing.rs @@ -2,7 +2,6 @@ //! generate the actual methods on tcx which find and execute the provider, //! manage the caches, and so forth. -use crate::keys::Key; use crate::on_disk_cache::{CacheDecoder, CacheEncoder, EncodedDepNodeIndex}; use crate::profiling_support::QueryKeyStringCache; use crate::{on_disk_cache, Queries}; @@ -12,13 +11,13 @@ use rustc_errors::{Diagnostic, Handler}; use rustc_middle::dep_graph::{ self, DepKind, DepKindStruct, DepNode, DepNodeIndex, SerializedDepNodeIndex, }; +use rustc_middle::query::Key; use rustc_middle::ty::tls::{self, ImplicitCtxt}; use rustc_middle::ty::{self, TyCtxt}; use rustc_query_system::dep_graph::{DepNodeParams, HasDepContext}; use rustc_query_system::ich::StableHashingContext; use rustc_query_system::query::{ - force_query, QueryConfig, QueryContext, QueryDescription, QueryJobId, QueryMap, - QuerySideEffects, QueryStackFrame, + force_query, QueryConfig, QueryContext, QueryJobId, QueryMap, QuerySideEffects, QueryStackFrame, }; use rustc_query_system::{LayoutOfDepth, QueryOverflow, Value}; use rustc_serialize::Decodable; @@ -253,6 +252,18 @@ macro_rules! depth_limit { }; } +macro_rules! feedable { + ([]) => {{ + false + }}; + ([(feedable) $($rest:tt)*]) => {{ + true + }}; + ([$other:tt $($modifiers:tt)*]) => { + feedable!([$($modifiers)*]) + }; +} + macro_rules! hash_result { ([]) => {{ Some(dep_graph::hash_result) @@ -310,7 +321,7 @@ pub(crate) fn create_query_frame< ty::print::with_forced_impl_filename_line!(do_describe(tcx.tcx, key)) ); let description = - if tcx.sess.verbose() { format!("{} [{}]", description, name) } else { description }; + if tcx.sess.verbose() { format!("{} [{:?}]", description, name) } else { description }; let span = if kind == dep_graph::DepKind::def_span { // The `def_span` query is used to calculate `default_span`, // so exit to avoid infinite recursion. @@ -340,7 +351,7 @@ pub(crate) fn create_query_frame< fn try_load_from_on_disk_cache<'tcx, Q>(tcx: TyCtxt<'tcx>, dep_node: DepNode) where - Q: QueryDescription<QueryCtxt<'tcx>>, + Q: QueryConfig<QueryCtxt<'tcx>>, Q::Key: DepNodeParams<TyCtxt<'tcx>>, { debug_assert!(tcx.dep_graph.is_green(&dep_node)); @@ -365,7 +376,7 @@ where fn force_from_dep_node<'tcx, Q>(tcx: TyCtxt<'tcx>, dep_node: DepNode) -> bool where - Q: QueryDescription<QueryCtxt<'tcx>>, + Q: QueryConfig<QueryCtxt<'tcx>>, Q::Key: DepNodeParams<TyCtxt<'tcx>>, Q::Value: Value<TyCtxt<'tcx>>, { @@ -398,12 +409,9 @@ where } } -pub(crate) fn query_callback<'tcx, Q: QueryConfig>( - is_anon: bool, - is_eval_always: bool, -) -> DepKindStruct<'tcx> +pub(crate) fn query_callback<'tcx, Q>(is_anon: bool, is_eval_always: bool) -> DepKindStruct<'tcx> where - Q: QueryDescription<QueryCtxt<'tcx>>, + Q: QueryConfig<QueryCtxt<'tcx>>, Q::Key: DepNodeParams<TyCtxt<'tcx>>, { let fingerprint_style = Q::Key::fingerprint_style(); @@ -458,14 +466,12 @@ macro_rules! define_queries { })* } - $(impl<'tcx> QueryConfig for queries::$name<'tcx> { + $(impl<'tcx> QueryConfig<QueryCtxt<'tcx>> for queries::$name<'tcx> { type Key = query_keys::$name<'tcx>; type Value = query_values::$name<'tcx>; type Stored = query_stored::$name<'tcx>; const NAME: &'static str = stringify!($name); - } - impl<'tcx> QueryDescription<QueryCtxt<'tcx>> for queries::$name<'tcx> { #[inline] fn cache_on_disk(tcx: TyCtxt<'tcx>, key: &Self::Key) -> bool { ::rustc_middle::query::cached::$name(tcx, key) @@ -497,6 +503,7 @@ macro_rules! define_queries { anon: is_anon!([$($modifiers)*]), eval_always: is_eval_always!([$($modifiers)*]), depth_limit: depth_limit!([$($modifiers)*]), + feedable: feedable!([$($modifiers)*]), dep_kind: dep_graph::DepKind::$name, hash_result: hash_result!([$($modifiers)*]), handle_cycle_error: handle_cycle_error!([$($modifiers)*]), @@ -662,12 +669,15 @@ macro_rules! define_queries_struct { local_providers: Box<Providers>, extern_providers: Box<ExternProviders>, query_structs: Vec<$crate::plumbing::QueryStruct<'tcx>>, - pub on_disk_cache: Option<OnDiskCache<'tcx>>, - jobs: AtomicU64, - $($(#[$attr])* $name: QueryState<<queries::$name<'tcx> as QueryConfig>::Key>,)* + $( + $(#[$attr])* + $name: QueryState< + <queries::$name<'tcx> as QueryConfig<QueryCtxt<'tcx>>>::Key + >, + )* } impl<'tcx> Queries<'tcx> { @@ -704,7 +714,7 @@ macro_rules! define_queries_struct { &'tcx self, tcx: TyCtxt<'tcx>, span: Span, - key: <queries::$name<'tcx> as QueryConfig>::Key, + key: <queries::$name<'tcx> as QueryConfig<QueryCtxt<'tcx>>>::Key, mode: QueryMode, ) -> Option<query_stored::$name<'tcx>> { let qcx = QueryCtxt { tcx, queries: self }; diff --git a/compiler/rustc_query_impl/src/profiling_support.rs b/compiler/rustc_query_impl/src/profiling_support.rs index 2cc311d48..81114f2cd 100644 --- a/compiler/rustc_query_impl/src/profiling_support.rs +++ b/compiler/rustc_query_impl/src/profiling_support.rs @@ -19,18 +19,18 @@ impl QueryKeyStringCache { } } -struct QueryKeyStringBuilder<'p, 'c, 'tcx> { +struct QueryKeyStringBuilder<'p, 'tcx> { profiler: &'p SelfProfiler, tcx: TyCtxt<'tcx>, - string_cache: &'c mut QueryKeyStringCache, + string_cache: &'p mut QueryKeyStringCache, } -impl<'p, 'c, 'tcx> QueryKeyStringBuilder<'p, 'c, 'tcx> { +impl<'p, 'tcx> QueryKeyStringBuilder<'p, 'tcx> { fn new( profiler: &'p SelfProfiler, tcx: TyCtxt<'tcx>, - string_cache: &'c mut QueryKeyStringCache, - ) -> QueryKeyStringBuilder<'p, 'c, 'tcx> { + string_cache: &'p mut QueryKeyStringCache, + ) -> QueryKeyStringBuilder<'p, 'tcx> { QueryKeyStringBuilder { profiler, tcx, string_cache } } @@ -99,7 +99,7 @@ impl<'p, 'c, 'tcx> QueryKeyStringBuilder<'p, 'c, 'tcx> { } trait IntoSelfProfilingString { - fn to_self_profile_string(&self, builder: &mut QueryKeyStringBuilder<'_, '_, '_>) -> StringId; + fn to_self_profile_string(&self, builder: &mut QueryKeyStringBuilder<'_, '_>) -> StringId; } // The default implementation of `IntoSelfProfilingString` just uses `Debug` @@ -109,7 +109,7 @@ trait IntoSelfProfilingString { impl<T: Debug> IntoSelfProfilingString for T { default fn to_self_profile_string( &self, - builder: &mut QueryKeyStringBuilder<'_, '_, '_>, + builder: &mut QueryKeyStringBuilder<'_, '_>, ) -> StringId { let s = format!("{:?}", self); builder.profiler.alloc_string(&s[..]) @@ -117,60 +117,42 @@ impl<T: Debug> IntoSelfProfilingString for T { } impl<T: SpecIntoSelfProfilingString> IntoSelfProfilingString for T { - fn to_self_profile_string(&self, builder: &mut QueryKeyStringBuilder<'_, '_, '_>) -> StringId { + fn to_self_profile_string(&self, builder: &mut QueryKeyStringBuilder<'_, '_>) -> StringId { self.spec_to_self_profile_string(builder) } } #[rustc_specialization_trait] trait SpecIntoSelfProfilingString: Debug { - fn spec_to_self_profile_string( - &self, - builder: &mut QueryKeyStringBuilder<'_, '_, '_>, - ) -> StringId; + fn spec_to_self_profile_string(&self, builder: &mut QueryKeyStringBuilder<'_, '_>) -> StringId; } impl SpecIntoSelfProfilingString for DefId { - fn spec_to_self_profile_string( - &self, - builder: &mut QueryKeyStringBuilder<'_, '_, '_>, - ) -> StringId { + fn spec_to_self_profile_string(&self, builder: &mut QueryKeyStringBuilder<'_, '_>) -> StringId { builder.def_id_to_string_id(*self) } } impl SpecIntoSelfProfilingString for CrateNum { - fn spec_to_self_profile_string( - &self, - builder: &mut QueryKeyStringBuilder<'_, '_, '_>, - ) -> StringId { + fn spec_to_self_profile_string(&self, builder: &mut QueryKeyStringBuilder<'_, '_>) -> StringId { builder.def_id_to_string_id(self.as_def_id()) } } impl SpecIntoSelfProfilingString for DefIndex { - fn spec_to_self_profile_string( - &self, - builder: &mut QueryKeyStringBuilder<'_, '_, '_>, - ) -> StringId { + fn spec_to_self_profile_string(&self, builder: &mut QueryKeyStringBuilder<'_, '_>) -> StringId { builder.def_id_to_string_id(DefId { krate: LOCAL_CRATE, index: *self }) } } impl SpecIntoSelfProfilingString for LocalDefId { - fn spec_to_self_profile_string( - &self, - builder: &mut QueryKeyStringBuilder<'_, '_, '_>, - ) -> StringId { + fn spec_to_self_profile_string(&self, builder: &mut QueryKeyStringBuilder<'_, '_>) -> StringId { builder.def_id_to_string_id(DefId { krate: LOCAL_CRATE, index: self.local_def_index }) } } impl<T: SpecIntoSelfProfilingString> SpecIntoSelfProfilingString for WithOptConstParam<T> { - fn spec_to_self_profile_string( - &self, - builder: &mut QueryKeyStringBuilder<'_, '_, '_>, - ) -> StringId { + fn spec_to_self_profile_string(&self, builder: &mut QueryKeyStringBuilder<'_, '_>) -> StringId { // We print `WithOptConstParam` values as tuples to make them shorter // and more readable, without losing information: // @@ -205,10 +187,7 @@ where T0: SpecIntoSelfProfilingString, T1: SpecIntoSelfProfilingString, { - fn spec_to_self_profile_string( - &self, - builder: &mut QueryKeyStringBuilder<'_, '_, '_>, - ) -> StringId { + fn spec_to_self_profile_string(&self, builder: &mut QueryKeyStringBuilder<'_, '_>) -> StringId { let val0 = self.0.to_self_profile_string(builder); let val1 = self.1.to_self_profile_string(builder); |