From: Camille GILLOT Date: Sat, 7 Mar 2020 16:56:59 +0000 (+0100) Subject: Simplify type aliases. X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=7309b3cd8be928a0ec9e3219d9562ddeb54ff994;p=rust.git Simplify type aliases. --- diff --git a/src/librustc/ty/query/caches.rs b/src/librustc/ty/query/caches.rs index ae01dcb364b..17639545d12 100644 --- a/src/librustc/ty/query/caches.rs +++ b/src/librustc/ty/query/caches.rs @@ -1,5 +1,5 @@ use crate::dep_graph::DepNodeIndex; -use crate::ty::query::plumbing::{QueryLookupImpl, QueryStateImpl, QueryStateShardImpl}; +use crate::ty::query::plumbing::{QueryLookup, QueryStateImpl, QueryStateShard}; use crate::ty::TyCtxt; use rustc_data_structures::fx::FxHashMap; @@ -28,11 +28,10 @@ fn lookup<'tcx, R, GetCache, OnHit, OnMiss>( on_miss: OnMiss, ) -> R where - GetCache: for<'a> Fn( - &'a mut QueryStateShardImpl<'tcx, K, Self::Sharded>, - ) -> &'a mut Self::Sharded, + GetCache: + for<'a> Fn(&'a mut QueryStateShard<'tcx, K, Self::Sharded>) -> &'a mut Self::Sharded, OnHit: FnOnce(&V, DepNodeIndex) -> R, - OnMiss: FnOnce(K, QueryLookupImpl<'tcx, QueryStateShardImpl<'tcx, K, Self::Sharded>>) -> R; + OnMiss: FnOnce(K, QueryLookup<'tcx, K, Self::Sharded>) -> R; fn complete( &self, @@ -73,11 +72,10 @@ fn lookup<'tcx, R, GetCache, OnHit, OnMiss>( on_miss: OnMiss, ) -> R where - GetCache: for<'a> Fn( - &'a mut QueryStateShardImpl<'tcx, K, Self::Sharded>, - ) -> &'a mut Self::Sharded, + GetCache: + for<'a> Fn(&'a mut QueryStateShard<'tcx, K, Self::Sharded>) -> &'a mut Self::Sharded, OnHit: FnOnce(&V, DepNodeIndex) -> R, - OnMiss: FnOnce(K, QueryLookupImpl<'tcx, QueryStateShardImpl<'tcx, K, Self::Sharded>>) -> R, + OnMiss: FnOnce(K, QueryLookup<'tcx, K, Self::Sharded>) -> R, { let mut lookup = state.get_lookup(&key); let lock = &mut *lookup.lock; diff --git a/src/librustc/ty/query/plumbing.rs b/src/librustc/ty/query/plumbing.rs index 406ca18b591..467b1a7e4a1 100644 --- a/src/librustc/ty/query/plumbing.rs +++ b/src/librustc/ty/query/plumbing.rs @@ -29,16 +29,7 @@ #[cfg(debug_assertions)] use std::sync::atomic::{AtomicUsize, Ordering}; -pub(crate) type QueryStateShard<'tcx, Q> = QueryStateShardImpl< - 'tcx, - >::Key, - <>::Cache as QueryCache< - >::Key, - >::Value, - >>::Sharded, ->; - -pub(crate) struct QueryStateShardImpl<'tcx, K, C> { +pub(crate) struct QueryStateShard<'tcx, K, C> { pub(super) cache: C, pub(super) active: FxHashMap>, @@ -46,15 +37,15 @@ pub(crate) struct QueryStateShardImpl<'tcx, K, C> { pub(super) jobs: u32, } -impl<'tcx, K, C> QueryStateShardImpl<'tcx, K, C> { +impl<'tcx, K, C> QueryStateShard<'tcx, K, C> { fn get_cache(&mut self) -> &mut C { &mut self.cache } } -impl<'tcx, K, C: Default> Default for QueryStateShardImpl<'tcx, K, C> { - fn default() -> QueryStateShardImpl<'tcx, K, C> { - QueryStateShardImpl { cache: Default::default(), active: Default::default(), jobs: 0 } +impl<'tcx, K, C: Default> Default for QueryStateShard<'tcx, K, C> { + fn default() -> QueryStateShard<'tcx, K, C> { + QueryStateShard { cache: Default::default(), active: Default::default(), jobs: 0 } } } @@ -67,16 +58,13 @@ fn default() -> QueryStateShardImpl<'tcx, K, C> { pub(crate) struct QueryStateImpl<'tcx, K, V, C: QueryCache> { pub(super) cache: C, - pub(super) shards: Sharded>, + pub(super) shards: Sharded>, #[cfg(debug_assertions)] pub(super) cache_hits: AtomicUsize, } impl<'tcx, K, V, C: QueryCache> QueryStateImpl<'tcx, K, V, C> { - pub(super) fn get_lookup( - &'tcx self, - key: &K2, - ) -> QueryLookupImpl<'tcx, QueryStateShardImpl<'tcx, K, C::Sharded>> { + pub(super) fn get_lookup(&'tcx self, key: &K2) -> QueryLookup<'tcx, K, C::Sharded> { // We compute the key's hash once and then use it for both the // shard lookup and the hashmap lookup. This relies on the fact // that both of them use `FxHasher`. @@ -86,7 +74,7 @@ pub(super) fn get_lookup( let shard = self.shards.get_shard_index_by_hash(key_hash); let lock = self.shards.get_shard_by_index(shard).lock(); - QueryLookupImpl { key_hash, shard, lock } + QueryLookup { key_hash, shard, lock } } } @@ -154,11 +142,10 @@ fn default() -> QueryStateImpl<'tcx, K, V, C> { } /// Values used when checking a query cache which can be reused on a cache-miss to execute the query. -pub(crate) type QueryLookup<'tcx, Q> = QueryLookupImpl<'tcx, QueryStateShard<'tcx, Q>>; -pub(crate) struct QueryLookupImpl<'tcx, QSS> { +pub(crate) struct QueryLookup<'tcx, K, C> { pub(super) key_hash: u64, pub(super) shard: usize, - pub(super) lock: LockGuard<'tcx, QSS>, + pub(super) lock: LockGuard<'tcx, QueryStateShard<'tcx, K, C>>, } /// A type representing the responsibility to execute the job in the `job` field. @@ -198,7 +185,7 @@ pub(super) fn try_start( tcx: TyCtxt<'tcx>, span: Span, key: &K, - mut lookup: QueryLookup<'tcx, Q>, + mut lookup: QueryLookup<'tcx, K, C::Sharded>, ) -> TryGetJob<'tcx, Q> where K: Eq + Hash + Clone + Debug, @@ -502,11 +489,11 @@ fn try_get_cached( where C: QueryCache, OnHit: FnOnce(&V, DepNodeIndex) -> R, - OnMiss: FnOnce(K, QueryLookupImpl<'tcx, QueryStateShardImpl<'tcx, K, C::Sharded>>) -> R, + OnMiss: FnOnce(K, QueryLookup<'tcx, K, C::Sharded>) -> R, { state.cache.lookup( state, - QueryStateShardImpl::::get_cache, + QueryStateShard::::get_cache, key, |value, index| { if unlikely!(self.prof.enabled()) { @@ -546,7 +533,7 @@ pub(super) fn try_execute_query + 'tcx>( self, span: Span, key: Q::Key, - lookup: QueryLookup<'tcx, Q>, + lookup: QueryLookup<'tcx, Q::Key, >::Sharded>, ) -> Q::Value { let job = match JobOwnerImpl::try_start::(self, span, &key, lookup) { TryGetJob::NotYetStarted(job) => job,