Skip to content

Commit 52cedca

Browse files
author
Julian Wollersberger
committed
Remove <CTX: QueryContext> in a bunch of places.
It was only needed by `find_cycle_in_stack()` in job.rs, but needed to be forwarded through dozens of types.
1 parent 39b0e79 commit 52cedca

File tree

8 files changed

+211
-167
lines changed

8 files changed

+211
-167
lines changed

compiler/rustc_middle/src/ty/query/plumbing.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ impl QueryContext for TyCtxt<'tcx> {
4040

4141
fn try_collect_active_jobs(
4242
&self,
43-
) -> Option<FxHashMap<QueryJobId<Self::DepKind>, QueryJobInfo<Self>>> {
43+
) -> Option<FxHashMap<QueryJobId<Self::DepKind>, QueryJobInfo<Self::DepKind, Self::Query>>>
44+
{
4445
self.queries.try_collect_active_jobs()
4546
}
4647

@@ -365,7 +366,7 @@ macro_rules! define_queries_inner {
365366
type Cache = query_storage!([$($modifiers)*][$($K)*, $V]);
366367

367368
#[inline(always)]
368-
fn query_state<'a>(tcx: TyCtxt<$tcx>) -> &'a QueryState<TyCtxt<$tcx>, Self::Cache> {
369+
fn query_state<'a>(tcx: TyCtxt<$tcx>) -> &'a QueryState<crate::dep_graph::DepKind, <TyCtxt<$tcx> as QueryContext>::Query, Self::Cache> {
369370
&tcx.queries.$name
370371
}
371372

@@ -520,7 +521,8 @@ macro_rules! define_queries_struct {
520521
fallback_extern_providers: Box<Providers>,
521522

522523
$($(#[$attr])* $name: QueryState<
523-
TyCtxt<$tcx>,
524+
crate::dep_graph::DepKind,
525+
<TyCtxt<$tcx> as QueryContext>::Query,
524526
<queries::$name<$tcx> as QueryAccessors<TyCtxt<'tcx>>>::Cache,
525527
>,)*
526528
}
@@ -541,7 +543,7 @@ macro_rules! define_queries_struct {
541543

542544
pub(crate) fn try_collect_active_jobs(
543545
&self
544-
) -> Option<FxHashMap<QueryJobId<crate::dep_graph::DepKind>, QueryJobInfo<TyCtxt<'tcx>>>> {
546+
) -> Option<FxHashMap<QueryJobId<crate::dep_graph::DepKind>, QueryJobInfo<crate::dep_graph::DepKind, <TyCtxt<$tcx> as QueryContext>::Query>>> {
545547
let mut jobs = FxHashMap::default();
546548

547549
$(

compiler/rustc_middle/src/ty/query/profiling_support.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ use rustc_data_structures::fx::FxHashMap;
55
use rustc_data_structures::profiling::SelfProfiler;
66
use rustc_hir::def_id::{CrateNum, DefId, DefIndex, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
77
use rustc_hir::definitions::DefPathData;
8-
use rustc_query_system::query::QueryCache;
9-
use rustc_query_system::query::QueryState;
8+
use rustc_query_system::query::{QueryCache, QueryContext, QueryState};
109
use std::fmt::Debug;
1110
use std::io::Write;
1211

@@ -231,7 +230,7 @@ where
231230
pub(super) fn alloc_self_profile_query_strings_for_query_cache<'tcx, C>(
232231
tcx: TyCtxt<'tcx>,
233232
query_name: &'static str,
234-
query_state: &QueryState<TyCtxt<'tcx>, C>,
233+
query_state: &QueryState<crate::dep_graph::DepKind, <TyCtxt<'tcx> as QueryContext>::Query, C>,
235234
string_cache: &mut QueryKeyStringCache,
236235
) where
237236
C: QueryCache,

compiler/rustc_middle/src/ty/query/stats.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
use crate::ty::query::queries;
22
use crate::ty::TyCtxt;
33
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
4-
use rustc_query_system::query::QueryCache;
5-
use rustc_query_system::query::QueryState;
6-
use rustc_query_system::query::{QueryAccessors, QueryContext};
4+
use rustc_query_system::query::{QueryAccessors, QueryCache, QueryContext, QueryState};
75

86
use std::any::type_name;
7+
use std::hash::Hash;
98
use std::mem;
109
#[cfg(debug_assertions)]
1110
use std::sync::atomic::Ordering;
@@ -38,10 +37,12 @@ struct QueryStats {
3837
local_def_id_keys: Option<usize>,
3938
}
4039

41-
fn stats<CTX: QueryContext, C: QueryCache>(
42-
name: &'static str,
43-
map: &QueryState<CTX, C>,
44-
) -> QueryStats {
40+
fn stats<D, Q, C>(name: &'static str, map: &QueryState<D, Q, C>) -> QueryStats
41+
where
42+
D: Copy + Clone + Eq + Hash,
43+
Q: Clone,
44+
C: QueryCache,
45+
{
4546
let mut stats = QueryStats {
4647
name,
4748
#[cfg(debug_assertions)]
@@ -127,7 +128,8 @@ macro_rules! print_stats {
127128

128129
$($(
129130
queries.push(stats::<
130-
TyCtxt<'_>,
131+
crate::dep_graph::DepKind,
132+
<TyCtxt<'_> as QueryContext>::Query,
131133
<queries::$name<'_> as QueryAccessors<TyCtxt<'_>>>::Cache,
132134
>(
133135
stringify!($name),

compiler/rustc_query_system/src/query/caches.rs

+20-13
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use crate::dep_graph::DepNodeIndex;
22
use crate::query::plumbing::{QueryLookup, QueryState};
3-
use crate::query::QueryContext;
43

54
use rustc_arena::TypedArena;
65
use rustc_data_structures::fx::FxHashMap;
76
use rustc_data_structures::sharded::Sharded;
87
use rustc_data_structures::sync::WorkerLocal;
98
use std::default::Default;
9+
use std::fmt::Debug;
1010
use std::hash::Hash;
1111
use std::marker::PhantomData;
1212

@@ -24,24 +24,24 @@ pub trait QueryStorage: Default {
2424
}
2525

2626
pub trait QueryCache: QueryStorage {
27-
type Key: Hash;
27+
type Key: Hash + Eq + Clone + Debug;
2828
type Sharded: Default;
2929

3030
/// Checks if the query is already computed and in the cache.
3131
/// It returns the shard index and a lock guard to the shard,
3232
/// which will be used if the query is not in the cache and we need
3333
/// to compute it.
34-
fn lookup<CTX: QueryContext, R, OnHit, OnMiss>(
34+
fn lookup<D, Q, R, OnHit, OnMiss>(
3535
&self,
36-
state: &QueryState<CTX, Self>,
36+
state: &QueryState<D, Q, Self>,
3737
key: Self::Key,
3838
// `on_hit` can be called while holding a lock to the query state shard.
3939
on_hit: OnHit,
4040
on_miss: OnMiss,
4141
) -> R
4242
where
4343
OnHit: FnOnce(&Self::Stored, DepNodeIndex) -> R,
44-
OnMiss: FnOnce(Self::Key, QueryLookup<'_, CTX, Self::Key, Self::Sharded>) -> R;
44+
OnMiss: FnOnce(Self::Key, QueryLookup<'_, D, Q, Self::Key, Self::Sharded>) -> R;
4545

4646
fn complete(
4747
&self,
@@ -86,21 +86,25 @@ impl<K: Eq + Hash, V: Clone> QueryStorage for DefaultCache<K, V> {
8686
}
8787
}
8888

89-
impl<K: Eq + Hash, V: Clone> QueryCache for DefaultCache<K, V> {
89+
impl<K, V> QueryCache for DefaultCache<K, V>
90+
where
91+
K: Eq + Hash + Clone + Debug,
92+
V: Clone,
93+
{
9094
type Key = K;
9195
type Sharded = FxHashMap<K, (V, DepNodeIndex)>;
9296

9397
#[inline(always)]
94-
fn lookup<CTX: QueryContext, R, OnHit, OnMiss>(
98+
fn lookup<D, Q, R, OnHit, OnMiss>(
9599
&self,
96-
state: &QueryState<CTX, Self>,
100+
state: &QueryState<D, Q, Self>,
97101
key: K,
98102
on_hit: OnHit,
99103
on_miss: OnMiss,
100104
) -> R
101105
where
102106
OnHit: FnOnce(&V, DepNodeIndex) -> R,
103-
OnMiss: FnOnce(K, QueryLookup<'_, CTX, K, Self::Sharded>) -> R,
107+
OnMiss: FnOnce(K, QueryLookup<'_, D, Q, K, Self::Sharded>) -> R,
104108
{
105109
let mut lookup = state.get_lookup(&key);
106110
let lock = &mut *lookup.lock;
@@ -164,21 +168,24 @@ impl<'tcx, K: Eq + Hash, V: 'tcx> QueryStorage for ArenaCache<'tcx, K, V> {
164168
}
165169
}
166170

167-
impl<'tcx, K: Eq + Hash, V: 'tcx> QueryCache for ArenaCache<'tcx, K, V> {
171+
impl<'tcx, K, V: 'tcx> QueryCache for ArenaCache<'tcx, K, V>
172+
where
173+
K: Eq + Hash + Clone + Debug,
174+
{
168175
type Key = K;
169176
type Sharded = FxHashMap<K, &'tcx (V, DepNodeIndex)>;
170177

171178
#[inline(always)]
172-
fn lookup<CTX: QueryContext, R, OnHit, OnMiss>(
179+
fn lookup<D, Q, R, OnHit, OnMiss>(
173180
&self,
174-
state: &QueryState<CTX, Self>,
181+
state: &QueryState<D, Q, Self>,
175182
key: K,
176183
on_hit: OnHit,
177184
on_miss: OnMiss,
178185
) -> R
179186
where
180187
OnHit: FnOnce(&&'tcx V, DepNodeIndex) -> R,
181-
OnMiss: FnOnce(K, QueryLookup<'_, CTX, K, Self::Sharded>) -> R,
188+
OnMiss: FnOnce(K, QueryLookup<'_, D, Q, K, Self::Sharded>) -> R,
182189
{
183190
let mut lookup = state.get_lookup(&key);
184191
let lock = &mut *lookup.lock;

compiler/rustc_query_system/src/query/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ pub trait QueryAccessors<CTX: QueryContext>: QueryConfig {
7676
type Cache: QueryCache<Key = Self::Key, Stored = Self::Stored, Value = Self::Value>;
7777

7878
// Don't use this method to access query results, instead use the methods on TyCtxt
79-
fn query_state<'a>(tcx: CTX) -> &'a QueryState<CTX, Self::Cache>;
79+
fn query_state<'a>(tcx: CTX) -> &'a QueryState<CTX::DepKind, CTX::Query, Self::Cache>;
8080

8181
fn to_dep_node(tcx: CTX, key: &Self::Key) -> DepNode<CTX::DepKind>
8282
where

0 commit comments

Comments
 (0)