about summary refs log tree commit diff
path: root/compiler/rustc_query_system/src
diff options
context:
space:
mode:
authorCamille GILLOT <gillot.camille@gmail.com>2022-10-31 23:16:24 +0000
committerCamille GILLOT <gillot.camille@gmail.com>2022-11-01 17:07:55 +0000
commitbc9a202a222da3d421f63d3960a871f239dae609 (patch)
treec7175fa5a01becf65502c95e4f8dcf224d9c8838 /compiler/rustc_query_system/src
parentade5cffc2ba4a238030aca3386532fdf20c9d26d (diff)
downloadrust-bc9a202a222da3d421f63d3960a871f239dae609.tar.gz
rust-bc9a202a222da3d421f63d3960a871f239dae609.zip
Use Key impl to select cache.
Diffstat (limited to 'compiler/rustc_query_system/src')
-rw-r--r--compiler/rustc_query_system/src/query/caches.rs26
-rw-r--r--compiler/rustc_query_system/src/query/mod.rs2
2 files changed, 27 insertions, 1 deletions
diff --git a/compiler/rustc_query_system/src/query/caches.rs b/compiler/rustc_query_system/src/query/caches.rs
index 0a473f91267..cdd43572422 100644
--- a/compiler/rustc_query_system/src/query/caches.rs
+++ b/compiler/rustc_query_system/src/query/caches.rs
@@ -12,6 +12,14 @@ use rustc_index::vec::{Idx, IndexVec};
 use std::default::Default;
 use std::fmt::Debug;
 use std::hash::Hash;
+use std::marker::PhantomData;
+
+pub trait CacheSelector<'tcx, V> {
+    type Cache
+    where
+        V: Clone;
+    type ArenaCache;
+}
 
 pub trait QueryStorage {
     type Value: Debug;
@@ -43,6 +51,15 @@ pub trait QueryCache: QueryStorage + Sized {
     fn iter(&self, f: &mut dyn FnMut(&Self::Key, &Self::Value, DepNodeIndex));
 }
 
+pub struct DefaultCacheSelector<K>(PhantomData<K>);
+
+impl<'tcx, K: Eq + Hash, V: 'tcx> CacheSelector<'tcx, V> for DefaultCacheSelector<K> {
+    type Cache = DefaultCache<K, V>
+    where
+        V: Clone;
+    type ArenaCache = ArenaCache<'tcx, K, V>;
+}
+
 pub struct DefaultCache<K, V> {
     #[cfg(parallel_compiler)]
     cache: Sharded<FxHashMap<K, (V, DepNodeIndex)>>,
@@ -209,6 +226,15 @@ where
     }
 }
 
+pub struct VecCacheSelector<K>(PhantomData<K>);
+
+impl<'tcx, K: Idx, V: 'tcx> CacheSelector<'tcx, V> for VecCacheSelector<K> {
+    type Cache = VecCache<K, V>
+    where
+        V: Clone;
+    type ArenaCache = VecArenaCache<'tcx, K, V>;
+}
+
 pub struct VecCache<K: Idx, V> {
     #[cfg(parallel_compiler)]
     cache: Sharded<IndexVec<K, Option<(V, DepNodeIndex)>>>,
diff --git a/compiler/rustc_query_system/src/query/mod.rs b/compiler/rustc_query_system/src/query/mod.rs
index bf14cd8de37..1d3b46aad7b 100644
--- a/compiler/rustc_query_system/src/query/mod.rs
+++ b/compiler/rustc_query_system/src/query/mod.rs
@@ -8,7 +8,7 @@ pub use self::job::{print_query_stack, QueryInfo, QueryJob, QueryJobId, QueryJob
 
 mod caches;
 pub use self::caches::{
-    ArenaCache, DefaultCache, QueryCache, QueryStorage, VecArenaCache, VecCache,
+    CacheSelector, DefaultCacheSelector, QueryCache, QueryStorage, VecCacheSelector,
 };
 
 mod config;