Skip to content

Commit 7309b3c

Browse files
committed
Simplify type aliases.
1 parent 7d84f4f commit 7309b3c

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

@@ -154,11 +142,10 @@ impl<'tcx, K, V, C: QueryCache<K, V>> Default for QueryStateImpl<'tcx, K, V, C>
154142
}
155143

156144
/// Values used when checking a query cache which can be reused on a cache-miss to execute the query.
157-
pub(crate) type QueryLookup<'tcx, Q> = QueryLookupImpl<'tcx, QueryStateShard<'tcx, Q>>;
158-
pub(crate) struct QueryLookupImpl<'tcx, QSS> {
145+
pub(crate) struct QueryLookup<'tcx, K, C> {
159146
pub(super) key_hash: u64,
160147
pub(super) shard: usize,
161-
pub(super) lock: LockGuard<'tcx, QSS>,
148+
pub(super) lock: LockGuard<'tcx, QueryStateShard<'tcx, K, C>>,
162149
}
163150

164151
/// A type representing the responsibility to execute the job in the `job` field.
@@ -198,7 +185,7 @@ where
198185
tcx: TyCtxt<'tcx>,
199186
span: Span,
200187
key: &K,
201-
mut lookup: QueryLookup<'tcx, Q>,
188+
mut lookup: QueryLookup<'tcx, K, C::Sharded>,
202189
) -> TryGetJob<'tcx, Q>
203190
where
204191
K: Eq + Hash + Clone + Debug,
@@ -502,11 +489,11 @@ impl<'tcx> TyCtxt<'tcx> {
502489
where
503490
C: QueryCache<K, V>,
504491
OnHit: FnOnce(&V, DepNodeIndex) -> R,
505-
OnMiss: FnOnce(K, QueryLookupImpl<'tcx, QueryStateShardImpl<'tcx, K, C::Sharded>>) -> R,
492+
OnMiss: FnOnce(K, QueryLookup<'tcx, K, C::Sharded>) -> R,
506493
{
507494
state.cache.lookup(
508495
state,
509-
QueryStateShardImpl::<K, C::Sharded>::get_cache,
496+
QueryStateShard::<K, C::Sharded>::get_cache,
510497
key,
511498
|value, index| {
512499
if unlikely!(self.prof.enabled()) {
@@ -546,7 +533,7 @@ impl<'tcx> TyCtxt<'tcx> {
546533
self,
547534
span: Span,
548535
key: Q::Key,
549-
lookup: QueryLookup<'tcx, Q>,
536+
lookup: QueryLookup<'tcx, Q::Key, <Q::Cache as QueryCache<Q::Key, Q::Value>>::Sharded>,
550537
) -> Q::Value {
551538
let job = match JobOwnerImpl::try_start::<Q>(self, span, &key, lookup) {
552539
TryGetJob::NotYetStarted(job) => job,

0 commit comments

Comments
 (0)