Skip to content

Commit 228ca8e

Browse files
committed
Access QueryStateShard directly.
1 parent d305b2c commit 228ca8e

File tree

2 files changed

+5
-19
lines changed

2 files changed

+5
-19
lines changed

src/librustc_query_system/query/caches.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::dep_graph::DepNodeIndex;
22
use crate::query::config::QueryContext;
3-
use crate::query::plumbing::{QueryLookup, QueryState, QueryStateShard};
3+
use crate::query::plumbing::{QueryLookup, QueryState};
44

55
use rustc_data_structures::fx::FxHashMap;
66
use rustc_data_structures::sharded::Sharded;
@@ -21,19 +21,15 @@ pub trait QueryCache<CTX: QueryContext>: Default {
2121
/// It returns the shard index and a lock guard to the shard,
2222
/// which will be used if the query is not in the cache and we need
2323
/// to compute it.
24-
fn lookup<R, GetCache, OnHit, OnMiss>(
24+
fn lookup<R, OnHit, OnMiss>(
2525
&self,
2626
state: &QueryState<CTX, Self>,
27-
get_cache: GetCache,
2827
key: Self::Key,
2928
// `on_hit` can be called while holding a lock to the query state shard.
3029
on_hit: OnHit,
3130
on_miss: OnMiss,
3231
) -> R
3332
where
34-
GetCache: for<'a> Fn(
35-
&'a mut QueryStateShard<CTX, Self::Key, Self::Sharded>,
36-
) -> &'a mut Self::Sharded,
3733
OnHit: FnOnce(&Self::Value, DepNodeIndex) -> R,
3834
OnMiss: FnOnce(Self::Key, QueryLookup<'_, CTX, Self::Key, Self::Sharded>) -> R;
3935

@@ -76,24 +72,21 @@ impl<CTX: QueryContext, K: Eq + Hash, V: Clone> QueryCache<CTX> for DefaultCache
7672
type Sharded = FxHashMap<K, (V, DepNodeIndex)>;
7773

7874
#[inline(always)]
79-
fn lookup<R, GetCache, OnHit, OnMiss>(
75+
fn lookup<R, OnHit, OnMiss>(
8076
&self,
8177
state: &QueryState<CTX, Self>,
82-
get_cache: GetCache,
8378
key: K,
8479
on_hit: OnHit,
8580
on_miss: OnMiss,
8681
) -> R
8782
where
88-
GetCache:
89-
for<'a> Fn(&'a mut QueryStateShard<CTX, K, Self::Sharded>) -> &'a mut Self::Sharded,
9083
OnHit: FnOnce(&V, DepNodeIndex) -> R,
9184
OnMiss: FnOnce(K, QueryLookup<'_, CTX, K, Self::Sharded>) -> R,
9285
{
9386
let mut lookup = state.get_lookup(&key);
9487
let lock = &mut *lookup.lock;
9588

96-
let result = get_cache(lock).raw_entry().from_key_hashed_nocheck(lookup.key_hash, &key);
89+
let result = lock.cache.raw_entry().from_key_hashed_nocheck(lookup.key_hash, &key);
9790

9891
if let Some((_, value)) = result { on_hit(&value.0, value.1) } else { on_miss(key, lookup) }
9992
}

src/librustc_query_system/query/plumbing.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,13 @@ use std::ptr;
3030
use std::sync::atomic::{AtomicUsize, Ordering};
3131

3232
pub struct QueryStateShard<CTX: QueryContext, K, C> {
33-
cache: C,
33+
pub(super) cache: C,
3434
active: FxHashMap<K, QueryResult<CTX>>,
3535

3636
/// Used to generate unique ids for active jobs.
3737
jobs: u32,
3838
}
3939

40-
impl<CTX: QueryContext, K, C> QueryStateShard<CTX, K, C> {
41-
fn get_cache(&mut self) -> &mut C {
42-
&mut self.cache
43-
}
44-
}
45-
4640
impl<CTX: QueryContext, K, C: Default> Default for QueryStateShard<CTX, K, C> {
4741
fn default() -> QueryStateShard<CTX, K, C> {
4842
QueryStateShard { cache: Default::default(), active: Default::default(), jobs: 0 }
@@ -372,7 +366,6 @@ where
372366
{
373367
state.cache.lookup(
374368
state,
375-
QueryStateShard::<CTX, C::Key, C::Sharded>::get_cache,
376369
key,
377370
|value, index| {
378371
if unlikely!(tcx.profiler().enabled()) {

0 commit comments

Comments
 (0)