From 228ca8ef0a2087d5000aa28f821f31c0d675be1f Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Tue, 24 Mar 2020 09:30:13 +0100 Subject: [PATCH] Access QueryStateShard directly. --- src/librustc_query_system/query/caches.rs | 15 ++++----------- src/librustc_query_system/query/plumbing.rs | 9 +-------- 2 files changed, 5 insertions(+), 19 deletions(-) diff --git a/src/librustc_query_system/query/caches.rs b/src/librustc_query_system/query/caches.rs index 400e6fe84a8..f79aa992fd2 100644 --- a/src/librustc_query_system/query/caches.rs +++ b/src/librustc_query_system/query/caches.rs @@ -1,6 +1,6 @@ use crate::dep_graph::DepNodeIndex; use crate::query::config::QueryContext; -use crate::query::plumbing::{QueryLookup, QueryState, QueryStateShard}; +use crate::query::plumbing::{QueryLookup, QueryState}; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::sharded::Sharded; @@ -21,19 +21,15 @@ pub trait QueryCache: Default { /// It returns the shard index and a lock guard to the shard, /// which will be used if the query is not in the cache and we need /// to compute it. - fn lookup( + fn lookup( &self, state: &QueryState, - get_cache: GetCache, key: Self::Key, // `on_hit` can be called while holding a lock to the query state shard. on_hit: OnHit, on_miss: OnMiss, ) -> R where - GetCache: for<'a> Fn( - &'a mut QueryStateShard, - ) -> &'a mut Self::Sharded, OnHit: FnOnce(&Self::Value, DepNodeIndex) -> R, OnMiss: FnOnce(Self::Key, QueryLookup<'_, CTX, Self::Key, Self::Sharded>) -> R; @@ -76,24 +72,21 @@ impl QueryCache for DefaultCache type Sharded = FxHashMap; #[inline(always)] - fn lookup( + fn lookup( &self, state: &QueryState, - get_cache: GetCache, key: K, on_hit: OnHit, on_miss: OnMiss, ) -> R where - GetCache: - for<'a> Fn(&'a mut QueryStateShard) -> &'a mut Self::Sharded, OnHit: FnOnce(&V, DepNodeIndex) -> R, OnMiss: FnOnce(K, QueryLookup<'_, CTX, K, Self::Sharded>) -> R, { let mut lookup = state.get_lookup(&key); let lock = &mut *lookup.lock; - let result = get_cache(lock).raw_entry().from_key_hashed_nocheck(lookup.key_hash, &key); + let result = lock.cache.raw_entry().from_key_hashed_nocheck(lookup.key_hash, &key); if let Some((_, value)) = result { on_hit(&value.0, value.1) } else { on_miss(key, lookup) } } diff --git a/src/librustc_query_system/query/plumbing.rs b/src/librustc_query_system/query/plumbing.rs index dbe7b9c385d..cf23467cf99 100644 --- a/src/librustc_query_system/query/plumbing.rs +++ b/src/librustc_query_system/query/plumbing.rs @@ -30,19 +30,13 @@ use std::ptr; use std::sync::atomic::{AtomicUsize, Ordering}; pub struct QueryStateShard { - cache: C, + pub(super) cache: C, active: FxHashMap>, /// Used to generate unique ids for active jobs. jobs: u32, } -impl QueryStateShard { - fn get_cache(&mut self) -> &mut C { - &mut self.cache - } -} - impl Default for QueryStateShard { fn default() -> QueryStateShard { QueryStateShard { cache: Default::default(), active: Default::default(), jobs: 0 } @@ -372,7 +366,6 @@ where { state.cache.lookup( state, - QueryStateShard::::get_cache, key, |value, index| { if unlikely!(tcx.profiler().enabled()) {