]> git.lizzy.rs Git - rust.git/commitdiff
Delete QueryLookup
authorMark Rousskov <mark.simulacrum@gmail.com>
Sun, 20 Feb 2022 03:56:56 +0000 (22:56 -0500)
committerMark Rousskov <mark.simulacrum@gmail.com>
Sun, 20 Feb 2022 17:11:28 +0000 (12:11 -0500)
This was largely just caching the shard value at this point, which is not
particularly useful -- in the use sites the key was being hashed nearby anyway.

compiler/rustc_middle/src/ty/query.rs
compiler/rustc_query_impl/src/plumbing.rs
compiler/rustc_query_system/src/query/caches.rs
compiler/rustc_query_system/src/query/plumbing.rs

index c72b823d8499aaa775a5e654c56fbdc4400430ce..f2e1d129e9ba791ac765b65b1135fad46a6ee6f4 100644 (file)
@@ -222,12 +222,12 @@ pub fn $name(self, key: query_helper_param_ty!($($K)*)) {
 
                 let cached = try_get_cached(self.tcx, &self.tcx.query_caches.$name, &key, noop);
 
-                let lookup = match cached {
+                match cached {
                     Ok(()) => return,
-                    Err(lookup) => lookup,
-                };
+                    Err(()) => (),
+                }
 
-                self.tcx.queries.$name(self.tcx, DUMMY_SP, key, lookup, QueryMode::Ensure);
+                self.tcx.queries.$name(self.tcx, DUMMY_SP, key, QueryMode::Ensure);
             })*
         }
 
@@ -251,12 +251,12 @@ pub fn $name(self, key: query_helper_param_ty!($($K)*)) -> query_stored::$name<$
 
                 let cached = try_get_cached(self.tcx, &self.tcx.query_caches.$name, &key, copy);
 
-                let lookup = match cached {
+                match cached {
                     Ok(value) => return value,
-                    Err(lookup) => lookup,
-                };
+                    Err(()) => (),
+                }
 
-                self.tcx.queries.$name(self.tcx, self.span, key, lookup, QueryMode::Get).unwrap()
+                self.tcx.queries.$name(self.tcx, self.span, key, QueryMode::Get).unwrap()
             })*
         }
 
@@ -314,7 +314,6 @@ fn $name(
                 tcx: TyCtxt<$tcx>,
                 span: Span,
                 key: query_keys::$name<$tcx>,
-                lookup: QueryLookup,
                 mode: QueryMode,
             ) -> Option<query_stored::$name<$tcx>>;)*
         }
index 1eaf5ee0c05849baf8f5b2398bd4d595f15ad8a0..684b2e248c85fbf6a7781aca49aa060de2e47d6a 100644 (file)
@@ -538,12 +538,11 @@ fn $name(
                 tcx: TyCtxt<$tcx>,
                 span: Span,
                 key: query_keys::$name<$tcx>,
-                lookup: QueryLookup,
                 mode: QueryMode,
             ) -> Option<query_stored::$name<$tcx>> {
                 opt_remap_env_constness!([$($modifiers)*][key]);
                 let qcx = QueryCtxt { tcx, queries: self };
-                get_query::<queries::$name<$tcx>, _>(qcx, span, key, lookup, mode)
+                get_query::<queries::$name<$tcx>, _>(qcx, span, key, mode)
             })*
         }
     };
index 05cc61c83aab98d5ac913136c20965ff836bf1d0..c5fa4c9ee6fc1e2d25d344a00c19ecb87f219a72 100644 (file)
@@ -1,5 +1,4 @@
 use crate::dep_graph::DepNodeIndex;
-use crate::query::plumbing::QueryLookup;
 
 use rustc_arena::TypedArena;
 use rustc_data_structures::fx::FxHashMap;
@@ -35,7 +34,7 @@ fn lookup<R, OnHit>(
         key: &Self::Key,
         // `on_hit` can be called while holding a lock to the query state shard.
         on_hit: OnHit,
-    ) -> Result<R, QueryLookup>
+    ) -> Result<R, ()>
     where
         OnHit: FnOnce(&Self::Stored, DepNodeIndex) -> R;
 
@@ -79,21 +78,20 @@ impl<K, V> QueryCache for DefaultCache<K, V>
     type Key = K;
 
     #[inline(always)]
-    fn lookup<R, OnHit>(&self, key: &K, on_hit: OnHit) -> Result<R, QueryLookup>
+    fn lookup<R, OnHit>(&self, key: &K, on_hit: OnHit) -> Result<R, ()>
     where
         OnHit: FnOnce(&V, DepNodeIndex) -> R,
     {
         let key_hash = sharded::make_hash(key);
         let shard = sharded::get_shard_index_by_hash(key_hash);
         let lock = self.shards.get_shard_by_index(shard).lock();
-        let lookup = QueryLookup { key_hash, shard };
-        let result = lock.raw_entry().from_key_hashed_nocheck(lookup.key_hash, key);
+        let result = lock.raw_entry().from_key_hashed_nocheck(key_hash, key);
 
         if let Some((_, value)) = result {
             let hit_result = on_hit(&value.0, value.1);
             Ok(hit_result)
         } else {
-            Err(lookup)
+            Err(())
         }
     }
 
@@ -153,21 +151,20 @@ impl<'tcx, K, V: 'tcx> QueryCache for ArenaCache<'tcx, K, V>
     type Key = K;
 
     #[inline(always)]
-    fn lookup<R, OnHit>(&self, key: &K, on_hit: OnHit) -> Result<R, QueryLookup>
+    fn lookup<R, OnHit>(&self, key: &K, on_hit: OnHit) -> Result<R, ()>
     where
         OnHit: FnOnce(&&'tcx V, DepNodeIndex) -> R,
     {
         let key_hash = sharded::make_hash(key);
         let shard = sharded::get_shard_index_by_hash(key_hash);
         let lock = self.shards.get_shard_by_index(shard).lock();
-        let lookup = QueryLookup { key_hash, shard };
-        let result = lock.raw_entry().from_key_hashed_nocheck(lookup.key_hash, key);
+        let result = lock.raw_entry().from_key_hashed_nocheck(key_hash, key);
 
         if let Some((_, value)) = result {
             let hit_result = on_hit(&&value.0, value.1);
             Ok(hit_result)
         } else {
-            Err(lookup)
+            Err(())
         }
     }
 
index 9278bb602e11d6f9742873bd118c8ce100cc35eb..d55afaa0cb00ee117527b4ac93b58f2a6070932d 100644 (file)
 use std::mem;
 use std::ptr;
 
-/// Values used when checking a query cache which can be reused on a cache-miss to execute the query.
-pub struct QueryLookup {
-    pub(super) key_hash: u64,
-    pub(super) shard: usize,
-}
-
 // 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`.
@@ -147,13 +141,11 @@ fn try_start<'b, CTX>(
         state: &'b QueryState<K>,
         span: Span,
         key: K,
-        lookup: QueryLookup,
     ) -> TryGetJob<'b, K>
     where
         CTX: QueryContext,
     {
-        let shard = lookup.shard;
-        let mut state_lock = state.shards.get_shard_by_index(shard).lock();
+        let mut state_lock = state.shards.get_shard_by_value(&key).lock();
         let lock = &mut *state_lock;
 
         match lock.active.entry(key) {
@@ -303,7 +295,7 @@ pub fn try_get_cached<'a, CTX, C, R, OnHit>(
     key: &C::Key,
     // `on_hit` can be called while holding a lock to the query cache
     on_hit: OnHit,
-) -> Result<R, QueryLookup>
+) -> Result<R, ()>
 where
     C: QueryCache,
     CTX: DepContext,
@@ -324,7 +316,6 @@ fn try_execute_query<CTX, C>(
     cache: &C,
     span: Span,
     key: C::Key,
-    lookup: QueryLookup,
     dep_node: Option<DepNode<CTX::DepKind>>,
     query: &QueryVtable<CTX, C::Key, C::Value>,
 ) -> (C::Stored, Option<DepNodeIndex>)
@@ -333,7 +324,7 @@ fn try_execute_query<CTX, C>(
     C::Key: Clone + DepNodeParams<CTX::DepContext>,
     CTX: QueryContext,
 {
-    match JobOwner::<'_, C::Key>::try_start(&tcx, state, span, key.clone(), lookup) {
+    match JobOwner::<'_, C::Key>::try_start(&tcx, state, span, key.clone()) {
         TryGetJob::NotYetStarted(job) => {
             let (result, dep_node_index) = execute_job(tcx, key, dep_node, query, job.id);
             let result = job.complete(cache, result, dep_node_index);
@@ -675,13 +666,7 @@ pub enum QueryMode {
     Ensure,
 }
 
-pub fn get_query<Q, CTX>(
-    tcx: CTX,
-    span: Span,
-    key: Q::Key,
-    lookup: QueryLookup,
-    mode: QueryMode,
-) -> Option<Q::Stored>
+pub fn get_query<Q, CTX>(tcx: CTX, span: Span, key: Q::Key, mode: QueryMode) -> Option<Q::Stored>
 where
     Q: QueryDescription<CTX>,
     Q::Key: DepNodeParams<CTX::DepContext>,
@@ -705,7 +690,6 @@ pub fn get_query<Q, CTX>(
         Q::query_cache(tcx),
         span,
         key,
-        lookup,
         dep_node,
         &query,
     );
@@ -730,14 +714,14 @@ pub fn force_query<Q, CTX>(tcx: CTX, key: Q::Key, dep_node: DepNode<CTX::DepKind
         }
     });
 
-    let lookup = match cached {
+    match cached {
         Ok(()) => return,
-        Err(lookup) => lookup,
-    };
+        Err(()) => {}
+    }
 
     let query = Q::make_vtable(tcx, &key);
     let state = Q::query_state(tcx);
     debug_assert!(!query.anon);
 
-    try_execute_query(tcx, state, cache, DUMMY_SP, key, lookup, Some(dep_node), &query);
+    try_execute_query(tcx, state, cache, DUMMY_SP, key, Some(dep_node), &query);
 }