From: Mark Rousskov Date: Sun, 20 Feb 2022 03:56:56 +0000 (-0500) Subject: Delete QueryLookup X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=75ef06892089e0cf53b4a86419c7ff3b3c1f3c4c;hp=9deed6f74ea2df0ba08fb72342bef4eb303d0777;p=rust.git Delete QueryLookup 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. --- diff --git a/compiler/rustc_middle/src/ty/query.rs b/compiler/rustc_middle/src/ty/query.rs index c72b823d849..f2e1d129e9b 100644 --- a/compiler/rustc_middle/src/ty/query.rs +++ b/compiler/rustc_middle/src/ty/query.rs @@ -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>;)* } diff --git a/compiler/rustc_query_impl/src/plumbing.rs b/compiler/rustc_query_impl/src/plumbing.rs index 1eaf5ee0c05..684b2e248c8 100644 --- a/compiler/rustc_query_impl/src/plumbing.rs +++ b/compiler/rustc_query_impl/src/plumbing.rs @@ -538,12 +538,11 @@ fn $name( tcx: TyCtxt<$tcx>, span: Span, key: query_keys::$name<$tcx>, - lookup: QueryLookup, mode: QueryMode, ) -> Option> { opt_remap_env_constness!([$($modifiers)*][key]); let qcx = QueryCtxt { tcx, queries: self }; - get_query::, _>(qcx, span, key, lookup, mode) + get_query::, _>(qcx, span, key, mode) })* } }; diff --git a/compiler/rustc_query_system/src/query/caches.rs b/compiler/rustc_query_system/src/query/caches.rs index 05cc61c83aa..c5fa4c9ee6f 100644 --- a/compiler/rustc_query_system/src/query/caches.rs +++ b/compiler/rustc_query_system/src/query/caches.rs @@ -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( key: &Self::Key, // `on_hit` can be called while holding a lock to the query state shard. on_hit: OnHit, - ) -> Result + ) -> Result where OnHit: FnOnce(&Self::Stored, DepNodeIndex) -> R; @@ -79,21 +78,20 @@ impl QueryCache for DefaultCache type Key = K; #[inline(always)] - fn lookup(&self, key: &K, on_hit: OnHit) -> Result + fn lookup(&self, key: &K, on_hit: OnHit) -> Result 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(&self, key: &K, on_hit: OnHit) -> Result + fn lookup(&self, key: &K, on_hit: OnHit) -> Result 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(()) } } diff --git a/compiler/rustc_query_system/src/query/plumbing.rs b/compiler/rustc_query_system/src/query/plumbing.rs index 9278bb602e1..d55afaa0cb0 100644 --- a/compiler/rustc_query_system/src/query/plumbing.rs +++ b/compiler/rustc_query_system/src/query/plumbing.rs @@ -24,12 +24,6 @@ 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, 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 +) -> Result where C: QueryCache, CTX: DepContext, @@ -324,7 +316,6 @@ fn try_execute_query( cache: &C, span: Span, key: C::Key, - lookup: QueryLookup, dep_node: Option>, query: &QueryVtable, ) -> (C::Stored, Option) @@ -333,7 +324,7 @@ fn try_execute_query( C::Key: Clone + DepNodeParams, 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( - tcx: CTX, - span: Span, - key: Q::Key, - lookup: QueryLookup, - mode: QueryMode, -) -> Option +pub fn get_query(tcx: CTX, span: Span, key: Q::Key, mode: QueryMode) -> Option where Q: QueryDescription, Q::Key: DepNodeParams, @@ -705,7 +690,6 @@ pub fn get_query( Q::query_cache(tcx), span, key, - lookup, dep_node, &query, ); @@ -730,14 +714,14 @@ pub fn force_query(tcx: CTX, key: Q::Key, dep_node: DepNode 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); }