diff --git a/src/librustc/ty/query/plumbing.rs b/src/librustc/ty/query/plumbing.rs index 67f0fdfcd5488..37fc339ee6395 100644 --- a/src/librustc/ty/query/plumbing.rs +++ b/src/librustc/ty/query/plumbing.rs @@ -56,15 +56,25 @@ impl<'tcx, K, C: Default> Default for QueryStateShardImpl<'tcx, K, C> { } } -pub(crate) struct QueryState<'tcx, D: QueryAccessors<'tcx> + ?Sized> { - pub(super) cache: D::Cache, - pub(super) shards: Sharded>, +pub(crate) type QueryState<'tcx, Q> = QueryStateImpl< + 'tcx, + >::Key, + >::Value, + >::Cache, +>; + +pub(crate) struct QueryStateImpl<'tcx, K, V, C: QueryCache> { + pub(super) cache: C, + pub(super) shards: Sharded>, #[cfg(debug_assertions)] pub(super) cache_hits: AtomicUsize, } -impl<'tcx, Q: QueryAccessors<'tcx>> QueryState<'tcx, Q> { - pub(super) fn get_lookup(&'tcx self, key: &K) -> QueryLookup<'tcx, Q> { +impl<'tcx, K, V, C: QueryCache> QueryStateImpl<'tcx, K, V, C> { + pub(super) fn get_lookup( + &'tcx self, + key: &K2, + ) -> QueryLookupImpl<'tcx, QueryStateShardImpl<'tcx, K, C::Sharded>> { // We compute the key's hash once and then use it for both the // shard lookup and the hashmap lookup. This relies on the fact // that both of them use `FxHasher`. @@ -88,12 +98,10 @@ pub(super) enum QueryResult<'tcx> { Poisoned, } -impl<'tcx, M: QueryAccessors<'tcx>> QueryState<'tcx, M> { +impl<'tcx, K, V, C: QueryCache> QueryStateImpl<'tcx, K, V, C> { pub fn iter_results( &self, - f: impl for<'a> FnOnce( - Box + 'a>, - ) -> R, + f: impl for<'a> FnOnce(Box + 'a>) -> R, ) -> R { self.cache.iter(&self.shards, |shard| &mut shard.cache, f) } @@ -103,10 +111,10 @@ impl<'tcx, M: QueryAccessors<'tcx>> QueryState<'tcx, M> { } } -impl<'tcx, M: QueryAccessors<'tcx>> Default for QueryState<'tcx, M> { - fn default() -> QueryState<'tcx, M> { - QueryState { - cache: M::Cache::default(), +impl<'tcx, K, V, C: QueryCache> Default for QueryStateImpl<'tcx, K, V, C> { + fn default() -> QueryStateImpl<'tcx, K, V, C> { + QueryStateImpl { + cache: C::default(), shards: Default::default(), #[cfg(debug_assertions)] cache_hits: AtomicUsize::new(0), @@ -441,7 +449,7 @@ impl<'tcx> TyCtxt<'tcx> { { let state = Q::query_state(self); - state.cache.lookup( + state.cache.lookup::<_, _, _, _, Q>( state, QueryStateShard::::get_cache, key, @@ -1035,7 +1043,7 @@ macro_rules! define_queries_inner { let mut string_cache = QueryKeyStringCache::new(); $({ - alloc_self_profile_query_strings_for_query_cache( + alloc_self_profile_query_strings_for_query_cache::>( self, stringify!($name), &self.queries.$name,