Skip to content

Commit 6b23a7e

Browse files
committed
Auto merge of #104023 - Nilstrieb:cleanup-query, r=cjgillot
Several query cleanups A few cleanups, mostly about naming in `rustc_query_system`. r? `@cjgillot`
2 parents 6184a96 + 6d26ea8 commit 6b23a7e

File tree

9 files changed

+228
-271
lines changed

9 files changed

+228
-271
lines changed

compiler/rustc_query_impl/src/profiling_support.rs

+15-36
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@ impl QueryKeyStringCache {
1919
}
2020
}
2121

22-
struct QueryKeyStringBuilder<'p, 'c, 'tcx> {
22+
struct QueryKeyStringBuilder<'p, 'tcx> {
2323
profiler: &'p SelfProfiler,
2424
tcx: TyCtxt<'tcx>,
25-
string_cache: &'c mut QueryKeyStringCache,
25+
string_cache: &'p mut QueryKeyStringCache,
2626
}
2727

28-
impl<'p, 'c, 'tcx> QueryKeyStringBuilder<'p, 'c, 'tcx> {
28+
impl<'p, 'tcx> QueryKeyStringBuilder<'p, 'tcx> {
2929
fn new(
3030
profiler: &'p SelfProfiler,
3131
tcx: TyCtxt<'tcx>,
32-
string_cache: &'c mut QueryKeyStringCache,
33-
) -> QueryKeyStringBuilder<'p, 'c, 'tcx> {
32+
string_cache: &'p mut QueryKeyStringCache,
33+
) -> QueryKeyStringBuilder<'p, 'tcx> {
3434
QueryKeyStringBuilder { profiler, tcx, string_cache }
3535
}
3636

@@ -99,7 +99,7 @@ impl<'p, 'c, 'tcx> QueryKeyStringBuilder<'p, 'c, 'tcx> {
9999
}
100100

101101
trait IntoSelfProfilingString {
102-
fn to_self_profile_string(&self, builder: &mut QueryKeyStringBuilder<'_, '_, '_>) -> StringId;
102+
fn to_self_profile_string(&self, builder: &mut QueryKeyStringBuilder<'_, '_>) -> StringId;
103103
}
104104

105105
// The default implementation of `IntoSelfProfilingString` just uses `Debug`
@@ -109,68 +109,50 @@ trait IntoSelfProfilingString {
109109
impl<T: Debug> IntoSelfProfilingString for T {
110110
default fn to_self_profile_string(
111111
&self,
112-
builder: &mut QueryKeyStringBuilder<'_, '_, '_>,
112+
builder: &mut QueryKeyStringBuilder<'_, '_>,
113113
) -> StringId {
114114
let s = format!("{:?}", self);
115115
builder.profiler.alloc_string(&s[..])
116116
}
117117
}
118118

119119
impl<T: SpecIntoSelfProfilingString> IntoSelfProfilingString for T {
120-
fn to_self_profile_string(&self, builder: &mut QueryKeyStringBuilder<'_, '_, '_>) -> StringId {
120+
fn to_self_profile_string(&self, builder: &mut QueryKeyStringBuilder<'_, '_>) -> StringId {
121121
self.spec_to_self_profile_string(builder)
122122
}
123123
}
124124

125125
#[rustc_specialization_trait]
126126
trait SpecIntoSelfProfilingString: Debug {
127-
fn spec_to_self_profile_string(
128-
&self,
129-
builder: &mut QueryKeyStringBuilder<'_, '_, '_>,
130-
) -> StringId;
127+
fn spec_to_self_profile_string(&self, builder: &mut QueryKeyStringBuilder<'_, '_>) -> StringId;
131128
}
132129

133130
impl SpecIntoSelfProfilingString for DefId {
134-
fn spec_to_self_profile_string(
135-
&self,
136-
builder: &mut QueryKeyStringBuilder<'_, '_, '_>,
137-
) -> StringId {
131+
fn spec_to_self_profile_string(&self, builder: &mut QueryKeyStringBuilder<'_, '_>) -> StringId {
138132
builder.def_id_to_string_id(*self)
139133
}
140134
}
141135

142136
impl SpecIntoSelfProfilingString for CrateNum {
143-
fn spec_to_self_profile_string(
144-
&self,
145-
builder: &mut QueryKeyStringBuilder<'_, '_, '_>,
146-
) -> StringId {
137+
fn spec_to_self_profile_string(&self, builder: &mut QueryKeyStringBuilder<'_, '_>) -> StringId {
147138
builder.def_id_to_string_id(self.as_def_id())
148139
}
149140
}
150141

151142
impl SpecIntoSelfProfilingString for DefIndex {
152-
fn spec_to_self_profile_string(
153-
&self,
154-
builder: &mut QueryKeyStringBuilder<'_, '_, '_>,
155-
) -> StringId {
143+
fn spec_to_self_profile_string(&self, builder: &mut QueryKeyStringBuilder<'_, '_>) -> StringId {
156144
builder.def_id_to_string_id(DefId { krate: LOCAL_CRATE, index: *self })
157145
}
158146
}
159147

160148
impl SpecIntoSelfProfilingString for LocalDefId {
161-
fn spec_to_self_profile_string(
162-
&self,
163-
builder: &mut QueryKeyStringBuilder<'_, '_, '_>,
164-
) -> StringId {
149+
fn spec_to_self_profile_string(&self, builder: &mut QueryKeyStringBuilder<'_, '_>) -> StringId {
165150
builder.def_id_to_string_id(DefId { krate: LOCAL_CRATE, index: self.local_def_index })
166151
}
167152
}
168153

169154
impl<T: SpecIntoSelfProfilingString> SpecIntoSelfProfilingString for WithOptConstParam<T> {
170-
fn spec_to_self_profile_string(
171-
&self,
172-
builder: &mut QueryKeyStringBuilder<'_, '_, '_>,
173-
) -> StringId {
155+
fn spec_to_self_profile_string(&self, builder: &mut QueryKeyStringBuilder<'_, '_>) -> StringId {
174156
// We print `WithOptConstParam` values as tuples to make them shorter
175157
// and more readable, without losing information:
176158
//
@@ -205,10 +187,7 @@ where
205187
T0: SpecIntoSelfProfilingString,
206188
T1: SpecIntoSelfProfilingString,
207189
{
208-
fn spec_to_self_profile_string(
209-
&self,
210-
builder: &mut QueryKeyStringBuilder<'_, '_, '_>,
211-
) -> StringId {
190+
fn spec_to_self_profile_string(&self, builder: &mut QueryKeyStringBuilder<'_, '_>) -> StringId {
212191
let val0 = self.0.to_self_profile_string(builder);
213192
let val1 = self.1.to_self_profile_string(builder);
214193

compiler/rustc_query_system/src/cache.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl<Key, Value> Cache<Key, Value> {
2626
}
2727

2828
impl<Key: Eq + Hash, Value: Clone> Cache<Key, Value> {
29-
pub fn get<CTX: DepContext>(&self, key: &Key, tcx: CTX) -> Option<Value> {
29+
pub fn get<Tcx: DepContext>(&self, key: &Key, tcx: Tcx) -> Option<Value> {
3030
Some(self.hashmap.borrow().get(key)?.get(tcx))
3131
}
3232

@@ -46,7 +46,7 @@ impl<T: Clone> WithDepNode<T> {
4646
WithDepNode { dep_node, cached_value }
4747
}
4848

49-
pub fn get<CTX: DepContext>(&self, tcx: CTX) -> T {
49+
pub fn get<Tcx: DepContext>(&self, tcx: Tcx) -> T {
5050
tcx.dep_graph().read_index(self.dep_node);
5151
self.cached_value.clone()
5252
}

compiler/rustc_query_system/src/dep_graph/dep_node.rs

+18-18
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,18 @@ impl<K: DepKind> DepNode<K> {
6161
/// Creates a new, parameterless DepNode. This method will assert
6262
/// that the DepNode corresponding to the given DepKind actually
6363
/// does not require any parameters.
64-
pub fn new_no_params<Ctxt>(tcx: Ctxt, kind: K) -> DepNode<K>
64+
pub fn new_no_params<Tcx>(tcx: Tcx, kind: K) -> DepNode<K>
6565
where
66-
Ctxt: super::DepContext<DepKind = K>,
66+
Tcx: super::DepContext<DepKind = K>,
6767
{
6868
debug_assert_eq!(tcx.fingerprint_style(kind), FingerprintStyle::Unit);
6969
DepNode { kind, hash: Fingerprint::ZERO.into() }
7070
}
7171

72-
pub fn construct<Ctxt, Key>(tcx: Ctxt, kind: K, arg: &Key) -> DepNode<K>
72+
pub fn construct<Tcx, Key>(tcx: Tcx, kind: K, arg: &Key) -> DepNode<K>
7373
where
74-
Ctxt: super::DepContext<DepKind = K>,
75-
Key: DepNodeParams<Ctxt>,
74+
Tcx: super::DepContext<DepKind = K>,
75+
Key: DepNodeParams<Tcx>,
7676
{
7777
let hash = arg.to_fingerprint(tcx);
7878
let dep_node = DepNode { kind, hash: hash.into() };
@@ -93,9 +93,9 @@ impl<K: DepKind> DepNode<K> {
9393
/// Construct a DepNode from the given DepKind and DefPathHash. This
9494
/// method will assert that the given DepKind actually requires a
9595
/// single DefId/DefPathHash parameter.
96-
pub fn from_def_path_hash<Ctxt>(tcx: Ctxt, def_path_hash: DefPathHash, kind: K) -> Self
96+
pub fn from_def_path_hash<Tcx>(tcx: Tcx, def_path_hash: DefPathHash, kind: K) -> Self
9797
where
98-
Ctxt: super::DepContext<DepKind = K>,
98+
Tcx: super::DepContext<DepKind = K>,
9999
{
100100
debug_assert!(tcx.fingerprint_style(kind) == FingerprintStyle::DefPathHash);
101101
DepNode { kind, hash: def_path_hash.0.into() }
@@ -108,18 +108,18 @@ impl<K: DepKind> fmt::Debug for DepNode<K> {
108108
}
109109
}
110110

111-
pub trait DepNodeParams<Ctxt: DepContext>: fmt::Debug + Sized {
111+
pub trait DepNodeParams<Tcx: DepContext>: fmt::Debug + Sized {
112112
fn fingerprint_style() -> FingerprintStyle;
113113

114114
/// This method turns the parameters of a DepNodeConstructor into an opaque
115115
/// Fingerprint to be used in DepNode.
116116
/// Not all DepNodeParams support being turned into a Fingerprint (they
117117
/// don't need to if the corresponding DepNode is anonymous).
118-
fn to_fingerprint(&self, _: Ctxt) -> Fingerprint {
118+
fn to_fingerprint(&self, _: Tcx) -> Fingerprint {
119119
panic!("Not implemented. Accidentally called on anonymous node?")
120120
}
121121

122-
fn to_debug_str(&self, _: Ctxt) -> String {
122+
fn to_debug_str(&self, _: Tcx) -> String {
123123
format!("{:?}", self)
124124
}
125125

@@ -129,10 +129,10 @@ pub trait DepNodeParams<Ctxt: DepContext>: fmt::Debug + Sized {
129129
/// `fingerprint_style()` is not `FingerprintStyle::Opaque`.
130130
/// It is always valid to return `None` here, in which case incremental
131131
/// compilation will treat the query as having changed instead of forcing it.
132-
fn recover(tcx: Ctxt, dep_node: &DepNode<Ctxt::DepKind>) -> Option<Self>;
132+
fn recover(tcx: Tcx, dep_node: &DepNode<Tcx::DepKind>) -> Option<Self>;
133133
}
134134

135-
impl<Ctxt: DepContext, T> DepNodeParams<Ctxt> for T
135+
impl<Tcx: DepContext, T> DepNodeParams<Tcx> for T
136136
where
137137
T: for<'a> HashStable<StableHashingContext<'a>> + fmt::Debug,
138138
{
@@ -142,7 +142,7 @@ where
142142
}
143143

144144
#[inline(always)]
145-
default fn to_fingerprint(&self, tcx: Ctxt) -> Fingerprint {
145+
default fn to_fingerprint(&self, tcx: Tcx) -> Fingerprint {
146146
tcx.with_stable_hashing_context(|mut hcx| {
147147
let mut hasher = StableHasher::new();
148148
self.hash_stable(&mut hcx, &mut hasher);
@@ -151,12 +151,12 @@ where
151151
}
152152

153153
#[inline(always)]
154-
default fn to_debug_str(&self, _: Ctxt) -> String {
154+
default fn to_debug_str(&self, _: Tcx) -> String {
155155
format!("{:?}", *self)
156156
}
157157

158158
#[inline(always)]
159-
default fn recover(_: Ctxt, _: &DepNode<Ctxt::DepKind>) -> Option<Self> {
159+
default fn recover(_: Tcx, _: &DepNode<Tcx::DepKind>) -> Option<Self> {
160160
None
161161
}
162162
}
@@ -166,7 +166,7 @@ where
166166
/// Information is retrieved by indexing the `DEP_KINDS` array using the integer value
167167
/// of the `DepKind`. Overall, this allows to implement `DepContext` using this manual
168168
/// jump table instead of large matches.
169-
pub struct DepKindStruct<CTX: DepContext> {
169+
pub struct DepKindStruct<Tcx: DepContext> {
170170
/// Anonymous queries cannot be replayed from one compiler invocation to the next.
171171
/// When their result is needed, it is recomputed. They are useful for fine-grained
172172
/// dependency tracking, and caching within one compiler invocation.
@@ -216,10 +216,10 @@ pub struct DepKindStruct<CTX: DepContext> {
216216
/// with kind `MirValidated`, we know that the GUID/fingerprint of the `DepNode`
217217
/// is actually a `DefPathHash`, and can therefore just look up the corresponding
218218
/// `DefId` in `tcx.def_path_hash_to_def_id`.
219-
pub force_from_dep_node: Option<fn(tcx: CTX, dep_node: DepNode<CTX::DepKind>) -> bool>,
219+
pub force_from_dep_node: Option<fn(tcx: Tcx, dep_node: DepNode<Tcx::DepKind>) -> bool>,
220220

221221
/// Invoke a query to put the on-disk cached value in memory.
222-
pub try_load_from_on_disk_cache: Option<fn(CTX, DepNode<CTX::DepKind>)>,
222+
pub try_load_from_on_disk_cache: Option<fn(Tcx, DepNode<Tcx::DepKind>)>,
223223
}
224224

225225
/// A "work product" corresponds to a `.o` (or other) file that we

0 commit comments

Comments
 (0)