Tweak query key trait bounds.
Query keys must be stably hashable. Currently this requirement is expressed as a where-clause on `impl QueryDispatcher for SemiDynamicQueryDispatcher` and a where-clause on `create_deferred_query_stack_frame`. This commit removes those where-clause bounds and adds a single bound to `QueryCache::Key`, which already has some other bounds. I.e. it consolidates the bounds. It also gives them a name (`QueryCacheKey`) to avoid repeating them. There is also a related `Key` trait in `rustc_middle`; it should probably be merged with `QueryCacheKey` in the future, but not today. This cleanup helps with the next two commits, which do bigger rearrangements, and where the where-clauses caused me some difficulties.
This commit is contained in:
parent
286fbe5d84
commit
d3d4fd9312
5 changed files with 13 additions and 10 deletions
|
|
@ -10,7 +10,6 @@
|
|||
|
||||
use std::marker::ConstParamTy;
|
||||
|
||||
use rustc_data_structures::stable_hasher::HashStable;
|
||||
use rustc_data_structures::sync::AtomicU64;
|
||||
use rustc_middle::arena::Arena;
|
||||
use rustc_middle::dep_graph::{self, DepKind, DepKindVTable, DepNodeIndex};
|
||||
|
|
@ -23,7 +22,6 @@ use rustc_middle::query::plumbing::{QuerySystem, QuerySystemFns, QueryVTable};
|
|||
use rustc_middle::query::values::Value;
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_query_system::dep_graph::SerializedDepNodeIndex;
|
||||
use rustc_query_system::ich::StableHashingContext;
|
||||
use rustc_query_system::query::{
|
||||
CycleError, CycleErrorHandling, HashResult, QueryCache, QueryDispatcher, QueryMap, QueryMode,
|
||||
QueryState,
|
||||
|
|
@ -78,8 +76,6 @@ impl<'tcx, C: QueryCache, const FLAGS: QueryFlags> Clone
|
|||
// This is `impl QueryDispatcher for SemiDynamicQueryDispatcher`.
|
||||
impl<'tcx, C: QueryCache, const FLAGS: QueryFlags> QueryDispatcher<'tcx>
|
||||
for SemiDynamicQueryDispatcher<'tcx, C, FLAGS>
|
||||
where
|
||||
for<'a> C::Key: HashStable<StableHashingContext<'a>>,
|
||||
{
|
||||
type Qcx = QueryCtxt<'tcx>;
|
||||
type Key = C::Key;
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@ use rustc_middle::ty::print::with_reduced_queries;
|
|||
use rustc_middle::ty::tls::{self, ImplicitCtxt};
|
||||
use rustc_middle::ty::{self, TyCtxt};
|
||||
use rustc_query_system::dep_graph::{DepNodeKey, FingerprintStyle, HasDepContext};
|
||||
use rustc_query_system::ich::StableHashingContext;
|
||||
use rustc_query_system::query::{
|
||||
QueryCache, QueryContext, QueryDispatcher, QueryJobId, QueryMap, QuerySideEffect,
|
||||
QueryStackDeferred, QueryStackFrame, QueryStackFrameExtra,
|
||||
|
|
@ -360,7 +359,7 @@ pub(crate) fn create_deferred_query_stack_frame<'tcx, Cache>(
|
|||
) -> QueryStackFrame<QueryStackDeferred<'tcx>>
|
||||
where
|
||||
Cache: QueryCache,
|
||||
Cache::Key: Key + DynSend + DynSync + for<'a> HashStable<StableHashingContext<'a>> + 'tcx,
|
||||
Cache::Key: Key + DynSend + DynSync,
|
||||
{
|
||||
let kind = vtable.dep_kind;
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#![allow(internal_features)]
|
||||
#![feature(assert_matches)]
|
||||
#![feature(min_specialization)]
|
||||
#![feature(trait_alias)]
|
||||
// tidy-alphabetical-end
|
||||
|
||||
pub mod dep_graph;
|
||||
|
|
|
|||
|
|
@ -3,12 +3,17 @@ use std::hash::Hash;
|
|||
use std::sync::OnceLock;
|
||||
|
||||
use rustc_data_structures::sharded::ShardedHashMap;
|
||||
use rustc_data_structures::stable_hasher::HashStable;
|
||||
pub use rustc_data_structures::vec_cache::VecCache;
|
||||
use rustc_hir::def_id::LOCAL_CRATE;
|
||||
use rustc_index::Idx;
|
||||
use rustc_span::def_id::{DefId, DefIndex};
|
||||
|
||||
use crate::dep_graph::DepNodeIndex;
|
||||
use crate::ich::StableHashingContext;
|
||||
|
||||
/// Traits that all query keys must satisfy.
|
||||
pub trait QueryCacheKey = Hash + Eq + Copy + Debug + for<'a> HashStable<StableHashingContext<'a>>;
|
||||
|
||||
/// Trait for types that serve as an in-memory cache for query results,
|
||||
/// for a given key (argument) type and value (return) type.
|
||||
|
|
@ -16,7 +21,7 @@ use crate::dep_graph::DepNodeIndex;
|
|||
/// Types implementing this trait are associated with actual key/value types
|
||||
/// by the `Cache` associated type of the `rustc_middle::query::Key` trait.
|
||||
pub trait QueryCache: Sized {
|
||||
type Key: Hash + Eq + Copy + Debug;
|
||||
type Key: QueryCacheKey;
|
||||
type Value: Copy;
|
||||
|
||||
/// Returns the cached value (and other information) associated with the
|
||||
|
|
@ -48,7 +53,7 @@ impl<K, V> Default for DefaultCache<K, V> {
|
|||
|
||||
impl<K, V> QueryCache for DefaultCache<K, V>
|
||||
where
|
||||
K: Eq + Hash + Copy + Debug,
|
||||
K: QueryCacheKey,
|
||||
V: Copy,
|
||||
{
|
||||
type Key = K;
|
||||
|
|
@ -175,7 +180,7 @@ where
|
|||
|
||||
impl<K, V> QueryCache for VecCache<K, V, DepNodeIndex>
|
||||
where
|
||||
K: Idx + Eq + Hash + Copy + Debug,
|
||||
K: Idx + QueryCacheKey,
|
||||
V: Copy,
|
||||
{
|
||||
type Key = K;
|
||||
|
|
|
|||
|
|
@ -12,7 +12,9 @@ use rustc_macros::{Decodable, Encodable};
|
|||
use rustc_span::Span;
|
||||
use rustc_span::def_id::DefId;
|
||||
|
||||
pub use self::caches::{DefIdCache, DefaultCache, QueryCache, SingleCache, VecCache};
|
||||
pub use self::caches::{
|
||||
DefIdCache, DefaultCache, QueryCache, QueryCacheKey, SingleCache, VecCache,
|
||||
};
|
||||
pub use self::dispatcher::{HashResult, QueryDispatcher};
|
||||
pub use self::job::{
|
||||
QueryInfo, QueryJob, QueryJobId, QueryJobInfo, QueryLatch, QueryMap, break_query_cycles,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue