]> git.lizzy.rs Git - rust.git/blobdiff - compiler/rustc_middle/src/ty/query/plumbing.rs
Separate the query cache from the query state.
[rust.git] / compiler / rustc_middle / src / ty / query / plumbing.rs
index dcfc116585b9ebb14b50038d0cdd9347df2f18f2..9a011846fd62df686c50cf0dbea6ac9d8250d49a 100644 (file)
@@ -355,6 +355,11 @@ pub mod query_stored {
             $(pub type $name<$tcx> = <query_storage::$name<$tcx> as QueryStorage>::Stored;)*
         }
 
+        #[derive(Default)]
+        pub struct QueryCaches<$tcx> {
+            $($(#[$attr])* $name: QueryCacheStore<query_storage::$name<$tcx>>,)*
+        }
+
         $(impl<$tcx> QueryConfig for queries::$name<$tcx> {
             type Key = $($K)*;
             type Value = $V;
@@ -370,10 +375,17 @@ impl<$tcx> QueryAccessors<TyCtxt<$tcx>> for queries::$name<$tcx> {
             type Cache = query_storage::$name<$tcx>;
 
             #[inline(always)]
-            fn query_state<'a>(tcx: TyCtxt<$tcx>) -> &'a QueryState<crate::dep_graph::DepKind, <TyCtxt<$tcx> as QueryContext>::Query, Self::Cache> {
+            fn query_state<'a>(tcx: TyCtxt<$tcx>) -> &'a QueryState<crate::dep_graph::DepKind, Query<$tcx>, Self::Key> {
                 &tcx.queries.$name
             }
 
+            #[inline(always)]
+            fn query_cache<'a>(tcx: TyCtxt<$tcx>) -> &'a QueryCacheStore<Self::Cache>
+                where 'tcx:'a
+            {
+                &tcx.query_caches.$name
+            }
+
             #[inline]
             fn compute(tcx: TyCtxt<'tcx>, key: Self::Key) -> Self::Value {
                 let provider = tcx.queries.providers.get(key.query_crate())
@@ -479,7 +491,7 @@ pub fn alloc_self_profile_query_strings(self) {
                     alloc_self_profile_query_strings_for_query_cache(
                         self,
                         stringify!($name),
-                        &self.queries.$name,
+                        &self.query_caches.$name,
                         &mut string_cache,
                     );
                 })*
@@ -525,8 +537,8 @@ pub struct Queries<$tcx> {
 
             $($(#[$attr])*  $name: QueryState<
                 crate::dep_graph::DepKind,
-                <TyCtxt<$tcx> as QueryContext>::Query,
-                query_storage::$name<$tcx>,
+                Query<$tcx>,
+                query_keys::$name<$tcx>,
             >,)*
         }