Skip to content

Commit 303246c

Browse files
committed
Simplify type aliases.
1 parent c7c5f42 commit 303246c

File tree

2 files changed

+21
-36
lines changed

2 files changed

+21
-36
lines changed

src/librustc/ty/query/caches.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::dep_graph::DepNodeIndex;
2-
use crate::ty::query::plumbing::{QueryLookupImpl, QueryStateImpl, QueryStateShardImpl};
2+
use crate::ty::query::plumbing::{QueryLookup, QueryStateImpl, QueryStateShard};
33
use crate::ty::TyCtxt;
44

55
use rustc_data_structures::fx::FxHashMap;
@@ -28,11 +28,10 @@ pub(crate) trait QueryCache<K, V>: Default {
2828
on_miss: OnMiss,
2929
) -> R
3030
where
31-
GetCache: for<'a> Fn(
32-
&'a mut QueryStateShardImpl<'tcx, K, Self::Sharded>,
33-
) -> &'a mut Self::Sharded,
31+
GetCache:
32+
for<'a> Fn(&'a mut QueryStateShard<'tcx, K, Self::Sharded>) -> &'a mut Self::Sharded,
3433
OnHit: FnOnce(&V, DepNodeIndex) -> R,
35-
OnMiss: FnOnce(K, QueryLookupImpl<'tcx, QueryStateShardImpl<'tcx, K, Self::Sharded>>) -> R;
34+
OnMiss: FnOnce(K, QueryLookup<'tcx, K, Self::Sharded>) -> R;
3635

3736
fn complete(
3837
&self,
@@ -73,11 +72,10 @@ impl<K: Eq + Hash, V: Clone> QueryCache<K, V> for DefaultCache {
7372
on_miss: OnMiss,
7473
) -> R
7574
where
76-
GetCache: for<'a> Fn(
77-
&'a mut QueryStateShardImpl<'tcx, K, Self::Sharded>,
78-
) -> &'a mut Self::Sharded,
75+
GetCache:
76+
for<'a> Fn(&'a mut QueryStateShard<'tcx, K, Self::Sharded>) -> &'a mut Self::Sharded,
7977
OnHit: FnOnce(&V, DepNodeIndex) -> R,
80-
OnMiss: FnOnce(K, QueryLookupImpl<'tcx, QueryStateShardImpl<'tcx, K, Self::Sharded>>) -> R,
78+
OnMiss: FnOnce(K, QueryLookup<'tcx, K, Self::Sharded>) -> R,
8179
{
8280
let mut lookup = state.get_lookup(&key);
8381
let lock = &mut *lookup.lock;

src/librustc/ty/query/plumbing.rs

+14-27
Original file line numberDiff line numberDiff line change
@@ -29,32 +29,23 @@ use std::ptr;
2929
#[cfg(debug_assertions)]
3030
use std::sync::atomic::{AtomicUsize, Ordering};
3131

32-
pub(crate) type QueryStateShard<'tcx, Q> = QueryStateShardImpl<
33-
'tcx,
34-
<Q as QueryConfig<'tcx>>::Key,
35-
<<Q as QueryAccessors<'tcx>>::Cache as QueryCache<
36-
<Q as QueryConfig<'tcx>>::Key,
37-
<Q as QueryConfig<'tcx>>::Value,
38-
>>::Sharded,
39-
>;
40-
41-
pub(crate) struct QueryStateShardImpl<'tcx, K, C> {
32+
pub(crate) struct QueryStateShard<'tcx, K, C> {
4233
pub(super) cache: C,
4334
pub(super) active: FxHashMap<K, QueryResult<'tcx>>,
4435

4536
/// Used to generate unique ids for active jobs.
4637
pub(super) jobs: u32,
4738
}
4839

49-
impl<'tcx, K, C> QueryStateShardImpl<'tcx, K, C> {
40+
impl<'tcx, K, C> QueryStateShard<'tcx, K, C> {
5041
fn get_cache(&mut self) -> &mut C {
5142
&mut self.cache
5243
}
5344
}
5445

55-
impl<'tcx, K, C: Default> Default for QueryStateShardImpl<'tcx, K, C> {
56-
fn default() -> QueryStateShardImpl<'tcx, K, C> {
57-
QueryStateShardImpl { cache: Default::default(), active: Default::default(), jobs: 0 }
46+
impl<'tcx, K, C: Default> Default for QueryStateShard<'tcx, K, C> {
47+
fn default() -> QueryStateShard<'tcx, K, C> {
48+
QueryStateShard { cache: Default::default(), active: Default::default(), jobs: 0 }
5849
}
5950
}
6051

@@ -67,16 +58,13 @@ pub(crate) type QueryState<'tcx, Q> = QueryStateImpl<
6758

6859
pub(crate) struct QueryStateImpl<'tcx, K, V, C: QueryCache<K, V>> {
6960
pub(super) cache: C,
70-
pub(super) shards: Sharded<QueryStateShardImpl<'tcx, K, C::Sharded>>,
61+
pub(super) shards: Sharded<QueryStateShard<'tcx, K, C::Sharded>>,
7162
#[cfg(debug_assertions)]
7263
pub(super) cache_hits: AtomicUsize,
7364
}
7465

7566
impl<'tcx, K, V, C: QueryCache<K, V>> QueryStateImpl<'tcx, K, V, C> {
76-
pub(super) fn get_lookup<K2: Hash>(
77-
&'tcx self,
78-
key: &K2,
79-
) -> QueryLookupImpl<'tcx, QueryStateShardImpl<'tcx, K, C::Sharded>> {
67+
pub(super) fn get_lookup<K2: Hash>(&'tcx self, key: &K2) -> QueryLookup<'tcx, K, C::Sharded> {
8068
// We compute the key's hash once and then use it for both the
8169
// shard lookup and the hashmap lookup. This relies on the fact
8270
// that both of them use `FxHasher`.
@@ -86,7 +74,7 @@ impl<'tcx, K, V, C: QueryCache<K, V>> QueryStateImpl<'tcx, K, V, C> {
8674

8775
let shard = self.shards.get_shard_index_by_hash(key_hash);
8876
let lock = self.shards.get_shard_by_index(shard).lock();
89-
QueryLookupImpl { key_hash, shard, lock }
77+
QueryLookup { key_hash, shard, lock }
9078
}
9179
}
9280

@@ -155,11 +143,10 @@ impl<'tcx, K, V, C: QueryCache<K, V>> Default for QueryStateImpl<'tcx, K, V, C>
155143
}
156144

157145
/// Values used when checking a query cache which can be reused on a cache-miss to execute the query.
158-
pub(crate) type QueryLookup<'tcx, Q> = QueryLookupImpl<'tcx, QueryStateShard<'tcx, Q>>;
159-
pub(crate) struct QueryLookupImpl<'tcx, QSS> {
146+
pub(crate) struct QueryLookup<'tcx, K, C> {
160147
pub(super) key_hash: u64,
161148
pub(super) shard: usize,
162-
pub(super) lock: LockGuard<'tcx, QSS>,
149+
pub(super) lock: LockGuard<'tcx, QueryStateShard<'tcx, K, C>>,
163150
}
164151

165152
/// A type representing the responsibility to execute the job in the `job` field.
@@ -199,7 +186,7 @@ where
199186
tcx: TyCtxt<'tcx>,
200187
span: Span,
201188
key: &K,
202-
mut lookup: QueryLookup<'tcx, Q>,
189+
mut lookup: QueryLookup<'tcx, K, C::Sharded>,
203190
) -> TryGetJob<'tcx, Q>
204191
where
205192
K: Eq + Hash + Clone + Debug,
@@ -503,11 +490,11 @@ impl<'tcx> TyCtxt<'tcx> {
503490
where
504491
C: QueryCache<K, V>,
505492
OnHit: FnOnce(&V, DepNodeIndex) -> R,
506-
OnMiss: FnOnce(K, QueryLookupImpl<'tcx, QueryStateShardImpl<'tcx, K, C::Sharded>>) -> R,
493+
OnMiss: FnOnce(K, QueryLookup<'tcx, K, C::Sharded>) -> R,
507494
{
508495
state.cache.lookup(
509496
state,
510-
QueryStateShardImpl::<K, C::Sharded>::get_cache,
497+
QueryStateShard::<K, C::Sharded>::get_cache,
511498
key,
512499
|value, index| {
513500
if unlikely!(self.prof.enabled()) {
@@ -547,7 +534,7 @@ impl<'tcx> TyCtxt<'tcx> {
547534
self,
548535
span: Span,
549536
key: Q::Key,
550-
lookup: QueryLookup<'tcx, Q>,
537+
lookup: QueryLookup<'tcx, Q::Key, <Q::Cache as QueryCache<Q::Key, Q::Value>>::Sharded>,
551538
) -> Q::Value {
552539
let job = match JobOwnerImpl::try_start::<Q>(self, span, &key, lookup) {
553540
TryGetJob::NotYetStarted(job) => job,

0 commit comments

Comments
 (0)