Skip to content

Commit a0f57e2

Browse files
committed
Unpack type arguments for QueryState.
1 parent 486a082 commit a0f57e2

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

src/librustc/ty/query/plumbing.rs

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,25 @@ impl<'tcx, K, C: Default> Default for QueryStateShardImpl<'tcx, K, C> {
5656
}
5757
}
5858

59-
pub(crate) struct QueryState<'tcx, D: QueryAccessors<'tcx> + ?Sized> {
60-
pub(super) cache: D::Cache,
61-
pub(super) shards: Sharded<QueryStateShard<'tcx, D>>,
59+
pub(crate) type QueryState<'tcx, Q> = QueryStateImpl<
60+
'tcx,
61+
<Q as QueryConfig<'tcx>>::Key,
62+
<Q as QueryConfig<'tcx>>::Value,
63+
<Q as QueryAccessors<'tcx>>::Cache,
64+
>;
65+
66+
pub(crate) struct QueryStateImpl<'tcx, K, V, C: QueryCache<K, V>> {
67+
pub(super) cache: C,
68+
pub(super) shards: Sharded<QueryStateShardImpl<'tcx, K, C::Sharded>>,
6269
#[cfg(debug_assertions)]
6370
pub(super) cache_hits: AtomicUsize,
6471
}
6572

66-
impl<'tcx, Q: QueryAccessors<'tcx>> QueryState<'tcx, Q> {
67-
pub(super) fn get_lookup<K: Hash>(&'tcx self, key: &K) -> QueryLookup<'tcx, Q> {
73+
impl<'tcx, K, V, C: QueryCache<K, V>> QueryStateImpl<'tcx, K, V, C> {
74+
pub(super) fn get_lookup<K2: Hash>(
75+
&'tcx self,
76+
key: &K2,
77+
) -> QueryLookupImpl<'tcx, QueryStateShardImpl<'tcx, K, C::Sharded>> {
6878
// We compute the key's hash once and then use it for both the
6979
// shard lookup and the hashmap lookup. This relies on the fact
7080
// that both of them use `FxHasher`.
@@ -88,12 +98,10 @@ pub(super) enum QueryResult<'tcx> {
8898
Poisoned,
8999
}
90100

91-
impl<'tcx, M: QueryAccessors<'tcx>> QueryState<'tcx, M> {
101+
impl<'tcx, K, V, C: QueryCache<K, V>> QueryStateImpl<'tcx, K, V, C> {
92102
pub fn iter_results<R>(
93103
&self,
94-
f: impl for<'a> FnOnce(
95-
Box<dyn Iterator<Item = (&'a M::Key, &'a M::Value, DepNodeIndex)> + 'a>,
96-
) -> R,
104+
f: impl for<'a> FnOnce(Box<dyn Iterator<Item = (&'a K, &'a V, DepNodeIndex)> + 'a>) -> R,
97105
) -> R {
98106
self.cache.iter(&self.shards, |shard| &mut shard.cache, f)
99107
}
@@ -103,10 +111,10 @@ impl<'tcx, M: QueryAccessors<'tcx>> QueryState<'tcx, M> {
103111
}
104112
}
105113

106-
impl<'tcx, M: QueryAccessors<'tcx>> Default for QueryState<'tcx, M> {
107-
fn default() -> QueryState<'tcx, M> {
108-
QueryState {
109-
cache: M::Cache::default(),
114+
impl<'tcx, K, V, C: QueryCache<K, V>> Default for QueryStateImpl<'tcx, K, V, C> {
115+
fn default() -> QueryStateImpl<'tcx, K, V, C> {
116+
QueryStateImpl {
117+
cache: C::default(),
110118
shards: Default::default(),
111119
#[cfg(debug_assertions)]
112120
cache_hits: AtomicUsize::new(0),
@@ -441,7 +449,7 @@ impl<'tcx> TyCtxt<'tcx> {
441449
{
442450
let state = Q::query_state(self);
443451

444-
state.cache.lookup(
452+
state.cache.lookup::<_, _, _, _, Q>(
445453
state,
446454
QueryStateShard::<Q>::get_cache,
447455
key,
@@ -1035,7 +1043,7 @@ macro_rules! define_queries_inner {
10351043
let mut string_cache = QueryKeyStringCache::new();
10361044

10371045
$({
1038-
alloc_self_profile_query_strings_for_query_cache(
1046+
alloc_self_profile_query_strings_for_query_cache::<queries::$name<'_>>(
10391047
self,
10401048
stringify!($name),
10411049
&self.queries.$name,

0 commit comments

Comments
 (0)