Move generics on QueryCache.
This commit is contained in:
parent
0e8b59a2f4
commit
fa06cfd25b
6 changed files with 23 additions and 23 deletions
|
@ -208,7 +208,7 @@ macro_rules! is_eval_always {
|
||||||
|
|
||||||
macro_rules! query_storage {
|
macro_rules! query_storage {
|
||||||
(<$tcx:tt>[][$K:ty, $V:ty]) => {
|
(<$tcx:tt>[][$K:ty, $V:ty]) => {
|
||||||
<<$K as Key>::CacheSelector as CacheSelector<TyCtxt<$tcx>, $K, $V>>::Cache
|
<<$K as Key>::CacheSelector as CacheSelector<$K, $V>>::Cache
|
||||||
};
|
};
|
||||||
(<$tcx:tt>[storage($ty:ty) $($rest:tt)*][$K:ty, $V:ty]) => {
|
(<$tcx:tt>[storage($ty:ty) $($rest:tt)*][$K:ty, $V:ty]) => {
|
||||||
$ty
|
$ty
|
||||||
|
|
|
@ -163,7 +163,7 @@ pub(super) fn alloc_self_profile_query_strings_for_query_cache<'tcx, C>(
|
||||||
query_state: &QueryState<TyCtxt<'tcx>, C>,
|
query_state: &QueryState<TyCtxt<'tcx>, C>,
|
||||||
string_cache: &mut QueryKeyStringCache,
|
string_cache: &mut QueryKeyStringCache,
|
||||||
) where
|
) where
|
||||||
C: QueryCache<TyCtxt<'tcx>>,
|
C: QueryCache,
|
||||||
C::Key: Debug + Clone,
|
C::Key: Debug + Clone,
|
||||||
{
|
{
|
||||||
tcx.prof.with_profiler(|profiler| {
|
tcx.prof.with_profiler(|profiler| {
|
||||||
|
|
|
@ -38,7 +38,7 @@ struct QueryStats {
|
||||||
local_def_id_keys: Option<usize>,
|
local_def_id_keys: Option<usize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn stats<CTX: QueryContext, C: QueryCache<CTX>>(
|
fn stats<CTX: QueryContext, C: QueryCache>(
|
||||||
name: &'static str,
|
name: &'static str,
|
||||||
map: &QueryState<CTX, C>,
|
map: &QueryState<CTX, C>,
|
||||||
) -> QueryStats {
|
) -> QueryStats {
|
||||||
|
|
|
@ -8,11 +8,11 @@ use std::default::Default;
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
pub trait CacheSelector<CTX: QueryContext, K: Hash, V> {
|
pub trait CacheSelector<K: Hash, V> {
|
||||||
type Cache: QueryCache<CTX, Key = K, Value = V>;
|
type Cache: QueryCache<Key = K, Value = V>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait QueryCache<CTX: QueryContext>: Default {
|
pub trait QueryCache: Default {
|
||||||
type Key: Hash;
|
type Key: Hash;
|
||||||
type Value;
|
type Value;
|
||||||
type Sharded: Default;
|
type Sharded: Default;
|
||||||
|
@ -21,7 +21,7 @@ pub trait QueryCache<CTX: QueryContext>: Default {
|
||||||
/// It returns the shard index and a lock guard to the shard,
|
/// It returns the shard index and a lock guard to the shard,
|
||||||
/// which will be used if the query is not in the cache and we need
|
/// which will be used if the query is not in the cache and we need
|
||||||
/// to compute it.
|
/// to compute it.
|
||||||
fn lookup<R, OnHit, OnMiss>(
|
fn lookup<CTX: QueryContext, R, OnHit, OnMiss>(
|
||||||
&self,
|
&self,
|
||||||
state: &QueryState<CTX, Self>,
|
state: &QueryState<CTX, Self>,
|
||||||
key: Self::Key,
|
key: Self::Key,
|
||||||
|
@ -33,7 +33,7 @@ pub trait QueryCache<CTX: QueryContext>: Default {
|
||||||
OnHit: FnOnce(&Self::Value, DepNodeIndex) -> R,
|
OnHit: FnOnce(&Self::Value, DepNodeIndex) -> R,
|
||||||
OnMiss: FnOnce(Self::Key, QueryLookup<'_, CTX, Self::Key, Self::Sharded>) -> R;
|
OnMiss: FnOnce(Self::Key, QueryLookup<'_, CTX, Self::Key, Self::Sharded>) -> R;
|
||||||
|
|
||||||
fn complete(
|
fn complete<CTX: QueryContext>(
|
||||||
&self,
|
&self,
|
||||||
tcx: CTX,
|
tcx: CTX,
|
||||||
lock_sharded_storage: &mut Self::Sharded,
|
lock_sharded_storage: &mut Self::Sharded,
|
||||||
|
@ -54,7 +54,7 @@ pub trait QueryCache<CTX: QueryContext>: Default {
|
||||||
|
|
||||||
pub struct DefaultCacheSelector;
|
pub struct DefaultCacheSelector;
|
||||||
|
|
||||||
impl<CTX: QueryContext, K: Eq + Hash, V: Clone> CacheSelector<CTX, K, V> for DefaultCacheSelector {
|
impl<K: Eq + Hash, V: Clone> CacheSelector<K, V> for DefaultCacheSelector {
|
||||||
type Cache = DefaultCache<K, V>;
|
type Cache = DefaultCache<K, V>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,13 +66,13 @@ impl<K, V> Default for DefaultCache<K, V> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<CTX: QueryContext, K: Eq + Hash, V: Clone> QueryCache<CTX> for DefaultCache<K, V> {
|
impl<K: Eq + Hash, V: Clone> QueryCache for DefaultCache<K, V> {
|
||||||
type Key = K;
|
type Key = K;
|
||||||
type Value = V;
|
type Value = V;
|
||||||
type Sharded = FxHashMap<K, (V, DepNodeIndex)>;
|
type Sharded = FxHashMap<K, (V, DepNodeIndex)>;
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn lookup<R, OnHit, OnMiss>(
|
fn lookup<CTX: QueryContext, R, OnHit, OnMiss>(
|
||||||
&self,
|
&self,
|
||||||
state: &QueryState<CTX, Self>,
|
state: &QueryState<CTX, Self>,
|
||||||
key: K,
|
key: K,
|
||||||
|
@ -92,7 +92,7 @@ impl<CTX: QueryContext, K: Eq + Hash, V: Clone> QueryCache<CTX> for DefaultCache
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn complete(
|
fn complete<CTX: QueryContext>(
|
||||||
&self,
|
&self,
|
||||||
_: CTX,
|
_: CTX,
|
||||||
lock_sharded_storage: &mut Self::Sharded,
|
lock_sharded_storage: &mut Self::Sharded,
|
||||||
|
|
|
@ -63,7 +63,7 @@ pub trait QueryAccessors<CTX: QueryContext>: QueryConfig<CTX> {
|
||||||
const EVAL_ALWAYS: bool;
|
const EVAL_ALWAYS: bool;
|
||||||
const DEP_KIND: CTX::DepKind;
|
const DEP_KIND: CTX::DepKind;
|
||||||
|
|
||||||
type Cache: QueryCache<CTX, Key = Self::Key, Value = Self::Value>;
|
type Cache: QueryCache<Key = Self::Key, Value = Self::Value>;
|
||||||
|
|
||||||
// Don't use this method to access query results, instead use the methods on TyCtxt
|
// Don't use this method to access query results, instead use the methods on TyCtxt
|
||||||
fn query_state<'a>(tcx: CTX) -> &'a QueryState<CTX, Self::Cache>;
|
fn query_state<'a>(tcx: CTX) -> &'a QueryState<CTX, Self::Cache>;
|
||||||
|
|
|
@ -42,14 +42,14 @@ impl<CTX: QueryContext, K, C: Default> Default for QueryStateShard<CTX, K, C> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct QueryState<CTX: QueryContext, C: QueryCache<CTX>> {
|
pub struct QueryState<CTX: QueryContext, C: QueryCache> {
|
||||||
cache: C,
|
cache: C,
|
||||||
shards: Sharded<QueryStateShard<CTX, C::Key, C::Sharded>>,
|
shards: Sharded<QueryStateShard<CTX, C::Key, C::Sharded>>,
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
pub cache_hits: AtomicUsize,
|
pub cache_hits: AtomicUsize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<CTX: QueryContext, C: QueryCache<CTX>> QueryState<CTX, C> {
|
impl<CTX: QueryContext, C: QueryCache> QueryState<CTX, C> {
|
||||||
pub(super) fn get_lookup<'tcx>(
|
pub(super) fn get_lookup<'tcx>(
|
||||||
&'tcx self,
|
&'tcx self,
|
||||||
key: &C::Key,
|
key: &C::Key,
|
||||||
|
@ -77,7 +77,7 @@ enum QueryResult<CTX: QueryContext> {
|
||||||
Poisoned,
|
Poisoned,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<CTX: QueryContext, C: QueryCache<CTX>> QueryState<CTX, C> {
|
impl<CTX: QueryContext, C: QueryCache> QueryState<CTX, C> {
|
||||||
pub fn iter_results<R>(
|
pub fn iter_results<R>(
|
||||||
&self,
|
&self,
|
||||||
f: impl for<'a> FnOnce(
|
f: impl for<'a> FnOnce(
|
||||||
|
@ -122,7 +122,7 @@ impl<CTX: QueryContext, C: QueryCache<CTX>> QueryState<CTX, C> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<CTX: QueryContext, C: QueryCache<CTX>> Default for QueryState<CTX, C> {
|
impl<CTX: QueryContext, C: QueryCache> Default for QueryState<CTX, C> {
|
||||||
fn default() -> QueryState<CTX, C> {
|
fn default() -> QueryState<CTX, C> {
|
||||||
QueryState {
|
QueryState {
|
||||||
cache: C::default(),
|
cache: C::default(),
|
||||||
|
@ -144,7 +144,7 @@ pub struct QueryLookup<'tcx, CTX: QueryContext, K, C> {
|
||||||
/// This will poison the relevant query if dropped.
|
/// This will poison the relevant query if dropped.
|
||||||
struct JobOwner<'tcx, CTX: QueryContext, C>
|
struct JobOwner<'tcx, CTX: QueryContext, C>
|
||||||
where
|
where
|
||||||
C: QueryCache<CTX>,
|
C: QueryCache,
|
||||||
C::Key: Eq + Hash + Clone + Debug,
|
C::Key: Eq + Hash + Clone + Debug,
|
||||||
C::Value: Clone,
|
C::Value: Clone,
|
||||||
{
|
{
|
||||||
|
@ -155,7 +155,7 @@ where
|
||||||
|
|
||||||
impl<'tcx, CTX: QueryContext, C> JobOwner<'tcx, CTX, C>
|
impl<'tcx, CTX: QueryContext, C> JobOwner<'tcx, CTX, C>
|
||||||
where
|
where
|
||||||
C: QueryCache<CTX>,
|
C: QueryCache,
|
||||||
C::Key: Eq + Hash + Clone + Debug,
|
C::Key: Eq + Hash + Clone + Debug,
|
||||||
C::Value: Clone,
|
C::Value: Clone,
|
||||||
{
|
{
|
||||||
|
@ -292,7 +292,7 @@ where
|
||||||
(result, diagnostics.into_inner())
|
(result, diagnostics.into_inner())
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx, CTX: QueryContext, C: QueryCache<CTX>> Drop for JobOwner<'tcx, CTX, C>
|
impl<'tcx, CTX: QueryContext, C: QueryCache> Drop for JobOwner<'tcx, CTX, C>
|
||||||
where
|
where
|
||||||
C::Key: Eq + Hash + Clone + Debug,
|
C::Key: Eq + Hash + Clone + Debug,
|
||||||
C::Value: Clone,
|
C::Value: Clone,
|
||||||
|
@ -326,7 +326,7 @@ pub struct CycleError<Q> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The result of `try_start`.
|
/// The result of `try_start`.
|
||||||
enum TryGetJob<'tcx, CTX: QueryContext, C: QueryCache<CTX>>
|
enum TryGetJob<'tcx, CTX: QueryContext, C: QueryCache>
|
||||||
where
|
where
|
||||||
C::Key: Eq + Hash + Clone + Debug,
|
C::Key: Eq + Hash + Clone + Debug,
|
||||||
C::Value: Clone,
|
C::Value: Clone,
|
||||||
|
@ -358,7 +358,7 @@ fn try_get_cached<CTX, C, R, OnHit, OnMiss>(
|
||||||
on_miss: OnMiss,
|
on_miss: OnMiss,
|
||||||
) -> R
|
) -> R
|
||||||
where
|
where
|
||||||
C: QueryCache<CTX>,
|
C: QueryCache,
|
||||||
CTX: QueryContext,
|
CTX: QueryContext,
|
||||||
OnHit: FnOnce(&C::Value, DepNodeIndex) -> R,
|
OnHit: FnOnce(&C::Value, DepNodeIndex) -> R,
|
||||||
OnMiss: FnOnce(C::Key, QueryLookup<'_, CTX, C::Key, C::Sharded>) -> R,
|
OnMiss: FnOnce(C::Key, QueryLookup<'_, CTX, C::Key, C::Sharded>) -> R,
|
||||||
|
@ -385,7 +385,7 @@ fn try_execute_query<Q, CTX>(
|
||||||
tcx: CTX,
|
tcx: CTX,
|
||||||
span: Span,
|
span: Span,
|
||||||
key: Q::Key,
|
key: Q::Key,
|
||||||
lookup: QueryLookup<'_, CTX, Q::Key, <Q::Cache as QueryCache<CTX>>::Sharded>,
|
lookup: QueryLookup<'_, CTX, Q::Key, <Q::Cache as QueryCache>::Sharded>,
|
||||||
) -> Q::Value
|
) -> Q::Value
|
||||||
where
|
where
|
||||||
Q: QueryDescription<CTX>,
|
Q: QueryDescription<CTX>,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue