]> git.lizzy.rs Git - rust.git/commitdiff
Unpack type arguments for QueryState.
authorCamille GILLOT <gillot.camille@gmail.com>
Fri, 6 Mar 2020 19:05:05 +0000 (20:05 +0100)
committerCamille GILLOT <gillot.camille@gmail.com>
Mon, 16 Mar 2020 08:39:11 +0000 (09:39 +0100)
src/librustc/ty/query/plumbing.rs

index 67f0fdfcd5488aea9e21828bfa543fa213dbeb23..37fc339ee6395dd3bc1484712f144e6d07343f58 100644 (file)
@@ -56,15 +56,25 @@ fn default() -> QueryStateShardImpl<'tcx, K, C> {
     }
 }
 
-pub(crate) struct QueryState<'tcx, D: QueryAccessors<'tcx> + ?Sized> {
-    pub(super) cache: D::Cache,
-    pub(super) shards: Sharded<QueryStateShard<'tcx, D>>,
+pub(crate) type QueryState<'tcx, Q> = QueryStateImpl<
+    'tcx,
+    <Q as QueryConfig<'tcx>>::Key,
+    <Q as QueryConfig<'tcx>>::Value,
+    <Q as QueryAccessors<'tcx>>::Cache,
+>;
+
+pub(crate) struct QueryStateImpl<'tcx, K, V, C: QueryCache<K, V>> {
+    pub(super) cache: C,
+    pub(super) shards: Sharded<QueryStateShardImpl<'tcx, K, C::Sharded>>,
     #[cfg(debug_assertions)]
     pub(super) cache_hits: AtomicUsize,
 }
 
-impl<'tcx, Q: QueryAccessors<'tcx>> QueryState<'tcx, Q> {
-    pub(super) fn get_lookup<K: Hash>(&'tcx self, key: &K) -> QueryLookup<'tcx, Q> {
+impl<'tcx, K, V, C: QueryCache<K, V>> QueryStateImpl<'tcx, K, V, C> {
+    pub(super) fn get_lookup<K2: Hash>(
+        &'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<K, V>> QueryStateImpl<'tcx, K, V, C> {
     pub fn iter_results<R>(
         &self,
-        f: impl for<'a> FnOnce(
-            Box<dyn Iterator<Item = (&'a M::Key, &'a M::Value, DepNodeIndex)> + 'a>,
-        ) -> R,
+        f: impl for<'a> FnOnce(Box<dyn Iterator<Item = (&'a K, &'a V, DepNodeIndex)> + 'a>) -> R,
     ) -> R {
         self.cache.iter(&self.shards, |shard| &mut shard.cache, f)
     }
@@ -103,10 +111,10 @@ pub fn all_inactive(&self) -> bool {
     }
 }
 
-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<K, V>> 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 @@ fn try_get_cached<Q, R, OnHit, OnMiss>(
     {
         let state = Q::query_state(self);
 
-        state.cache.lookup(
+        state.cache.lookup::<_, _, _, _, Q>(
             state,
             QueryStateShard::<Q>::get_cache,
             key,
@@ -1035,7 +1043,7 @@ pub fn alloc_self_profile_query_strings(self) {
                 let mut string_cache = QueryKeyStringCache::new();
 
                 $({
-                    alloc_self_profile_query_strings_for_query_cache(
+                    alloc_self_profile_query_strings_for_query_cache::<queries::$name<'_>>(
                         self,
                         stringify!($name),
                         &self.queries.$name,