Skip to content

Commit 75ef068

Browse files
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.
1 parent 9deed6f commit 75ef068

File tree

4 files changed

+24
-45
lines changed

4 files changed

+24
-45
lines changed

compiler/rustc_middle/src/ty/query.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -222,12 +222,12 @@ macro_rules! define_callbacks {
222222

223223
let cached = try_get_cached(self.tcx, &self.tcx.query_caches.$name, &key, noop);
224224

225-
let lookup = match cached {
225+
match cached {
226226
Ok(()) => return,
227-
Err(lookup) => lookup,
228-
};
227+
Err(()) => (),
228+
}
229229

230-
self.tcx.queries.$name(self.tcx, DUMMY_SP, key, lookup, QueryMode::Ensure);
230+
self.tcx.queries.$name(self.tcx, DUMMY_SP, key, QueryMode::Ensure);
231231
})*
232232
}
233233

@@ -251,12 +251,12 @@ macro_rules! define_callbacks {
251251

252252
let cached = try_get_cached(self.tcx, &self.tcx.query_caches.$name, &key, copy);
253253

254-
let lookup = match cached {
254+
match cached {
255255
Ok(value) => return value,
256-
Err(lookup) => lookup,
257-
};
256+
Err(()) => (),
257+
}
258258

259-
self.tcx.queries.$name(self.tcx, self.span, key, lookup, QueryMode::Get).unwrap()
259+
self.tcx.queries.$name(self.tcx, self.span, key, QueryMode::Get).unwrap()
260260
})*
261261
}
262262

@@ -314,7 +314,6 @@ macro_rules! define_callbacks {
314314
tcx: TyCtxt<$tcx>,
315315
span: Span,
316316
key: query_keys::$name<$tcx>,
317-
lookup: QueryLookup,
318317
mode: QueryMode,
319318
) -> Option<query_stored::$name<$tcx>>;)*
320319
}

compiler/rustc_query_impl/src/plumbing.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -538,12 +538,11 @@ macro_rules! define_queries_struct {
538538
tcx: TyCtxt<$tcx>,
539539
span: Span,
540540
key: query_keys::$name<$tcx>,
541-
lookup: QueryLookup,
542541
mode: QueryMode,
543542
) -> Option<query_stored::$name<$tcx>> {
544543
opt_remap_env_constness!([$($modifiers)*][key]);
545544
let qcx = QueryCtxt { tcx, queries: self };
546-
get_query::<queries::$name<$tcx>, _>(qcx, span, key, lookup, mode)
545+
get_query::<queries::$name<$tcx>, _>(qcx, span, key, mode)
547546
})*
548547
}
549548
};

compiler/rustc_query_system/src/query/caches.rs

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::dep_graph::DepNodeIndex;
2-
use crate::query::plumbing::QueryLookup;
32

43
use rustc_arena::TypedArena;
54
use rustc_data_structures::fx::FxHashMap;
@@ -35,7 +34,7 @@ pub trait QueryCache: QueryStorage + Sized {
3534
key: &Self::Key,
3635
// `on_hit` can be called while holding a lock to the query state shard.
3736
on_hit: OnHit,
38-
) -> Result<R, QueryLookup>
37+
) -> Result<R, ()>
3938
where
4039
OnHit: FnOnce(&Self::Stored, DepNodeIndex) -> R;
4140

@@ -79,21 +78,20 @@ where
7978
type Key = K;
8079

8180
#[inline(always)]
82-
fn lookup<R, OnHit>(&self, key: &K, on_hit: OnHit) -> Result<R, QueryLookup>
81+
fn lookup<R, OnHit>(&self, key: &K, on_hit: OnHit) -> Result<R, ()>
8382
where
8483
OnHit: FnOnce(&V, DepNodeIndex) -> R,
8584
{
8685
let key_hash = sharded::make_hash(key);
8786
let shard = sharded::get_shard_index_by_hash(key_hash);
8887
let lock = self.shards.get_shard_by_index(shard).lock();
89-
let lookup = QueryLookup { key_hash, shard };
90-
let result = lock.raw_entry().from_key_hashed_nocheck(lookup.key_hash, key);
88+
let result = lock.raw_entry().from_key_hashed_nocheck(key_hash, key);
9189

9290
if let Some((_, value)) = result {
9391
let hit_result = on_hit(&value.0, value.1);
9492
Ok(hit_result)
9593
} else {
96-
Err(lookup)
94+
Err(())
9795
}
9896
}
9997

@@ -153,21 +151,20 @@ where
153151
type Key = K;
154152

155153
#[inline(always)]
156-
fn lookup<R, OnHit>(&self, key: &K, on_hit: OnHit) -> Result<R, QueryLookup>
154+
fn lookup<R, OnHit>(&self, key: &K, on_hit: OnHit) -> Result<R, ()>
157155
where
158156
OnHit: FnOnce(&&'tcx V, DepNodeIndex) -> R,
159157
{
160158
let key_hash = sharded::make_hash(key);
161159
let shard = sharded::get_shard_index_by_hash(key_hash);
162160
let lock = self.shards.get_shard_by_index(shard).lock();
163-
let lookup = QueryLookup { key_hash, shard };
164-
let result = lock.raw_entry().from_key_hashed_nocheck(lookup.key_hash, key);
161+
let result = lock.raw_entry().from_key_hashed_nocheck(key_hash, key);
165162

166163
if let Some((_, value)) = result {
167164
let hit_result = on_hit(&&value.0, value.1);
168165
Ok(hit_result)
169166
} else {
170-
Err(lookup)
167+
Err(())
171168
}
172169
}
173170

compiler/rustc_query_system/src/query/plumbing.rs

+8-24
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@ use std::hash::{Hash, Hasher};
2424
use std::mem;
2525
use std::ptr;
2626

27-
/// Values used when checking a query cache which can be reused on a cache-miss to execute the query.
28-
pub struct QueryLookup {
29-
pub(super) key_hash: u64,
30-
pub(super) shard: usize,
31-
}
32-
3327
// We compute the key's hash once and then use it for both the
3428
// shard lookup and the hashmap lookup. This relies on the fact
3529
// that both of them use `FxHasher`.
@@ -147,13 +141,11 @@ where
147141
state: &'b QueryState<K>,
148142
span: Span,
149143
key: K,
150-
lookup: QueryLookup,
151144
) -> TryGetJob<'b, K>
152145
where
153146
CTX: QueryContext,
154147
{
155-
let shard = lookup.shard;
156-
let mut state_lock = state.shards.get_shard_by_index(shard).lock();
148+
let mut state_lock = state.shards.get_shard_by_value(&key).lock();
157149
let lock = &mut *state_lock;
158150

159151
match lock.active.entry(key) {
@@ -303,7 +295,7 @@ pub fn try_get_cached<'a, CTX, C, R, OnHit>(
303295
key: &C::Key,
304296
// `on_hit` can be called while holding a lock to the query cache
305297
on_hit: OnHit,
306-
) -> Result<R, QueryLookup>
298+
) -> Result<R, ()>
307299
where
308300
C: QueryCache,
309301
CTX: DepContext,
@@ -324,7 +316,6 @@ fn try_execute_query<CTX, C>(
324316
cache: &C,
325317
span: Span,
326318
key: C::Key,
327-
lookup: QueryLookup,
328319
dep_node: Option<DepNode<CTX::DepKind>>,
329320
query: &QueryVtable<CTX, C::Key, C::Value>,
330321
) -> (C::Stored, Option<DepNodeIndex>)
@@ -333,7 +324,7 @@ where
333324
C::Key: Clone + DepNodeParams<CTX::DepContext>,
334325
CTX: QueryContext,
335326
{
336-
match JobOwner::<'_, C::Key>::try_start(&tcx, state, span, key.clone(), lookup) {
327+
match JobOwner::<'_, C::Key>::try_start(&tcx, state, span, key.clone()) {
337328
TryGetJob::NotYetStarted(job) => {
338329
let (result, dep_node_index) = execute_job(tcx, key, dep_node, query, job.id);
339330
let result = job.complete(cache, result, dep_node_index);
@@ -675,13 +666,7 @@ pub enum QueryMode {
675666
Ensure,
676667
}
677668

678-
pub fn get_query<Q, CTX>(
679-
tcx: CTX,
680-
span: Span,
681-
key: Q::Key,
682-
lookup: QueryLookup,
683-
mode: QueryMode,
684-
) -> Option<Q::Stored>
669+
pub fn get_query<Q, CTX>(tcx: CTX, span: Span, key: Q::Key, mode: QueryMode) -> Option<Q::Stored>
685670
where
686671
Q: QueryDescription<CTX>,
687672
Q::Key: DepNodeParams<CTX::DepContext>,
@@ -705,7 +690,6 @@ where
705690
Q::query_cache(tcx),
706691
span,
707692
key,
708-
lookup,
709693
dep_node,
710694
&query,
711695
);
@@ -730,14 +714,14 @@ where
730714
}
731715
});
732716

733-
let lookup = match cached {
717+
match cached {
734718
Ok(()) => return,
735-
Err(lookup) => lookup,
736-
};
719+
Err(()) => {}
720+
}
737721

738722
let query = Q::make_vtable(tcx, &key);
739723
let state = Q::query_state(tcx);
740724
debug_assert!(!query.anon);
741725

742-
try_execute_query(tcx, state, cache, DUMMY_SP, key, lookup, Some(dep_node), &query);
726+
try_execute_query(tcx, state, cache, DUMMY_SP, key, Some(dep_node), &query);
743727
}

0 commit comments

Comments
 (0)