Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6b23a7e

Browse files
committedNov 8, 2022
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

Lines changed: 15 additions & 36 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 18 additions & 18 deletions
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

‎compiler/rustc_query_system/src/dep_graph/graph.rs

Lines changed: 38 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -377,9 +377,9 @@ impl<K: DepKind> DepGraph<K> {
377377

378378
/// Executes something within an "anonymous" task, that is, a task the
379379
/// `DepNode` of which is determined by the list of inputs it read from.
380-
pub fn with_anon_task<Ctxt: DepContext<DepKind = K>, OP, R>(
380+
pub fn with_anon_task<Tcx: DepContext<DepKind = K>, OP, R>(
381381
&self,
382-
cx: Ctxt,
382+
cx: Tcx,
383383
dep_kind: K,
384384
op: OP,
385385
) -> (R, DepNodeIndex)
@@ -571,12 +571,12 @@ impl<K: DepKind> DepGraph<K> {
571571
/// A node will have an index, when it's already been marked green, or when we can mark it
572572
/// green. This function will mark the current task as a reader of the specified node, when
573573
/// a node index can be found for that node.
574-
pub fn try_mark_green<Ctxt: QueryContext<DepKind = K>>(
574+
pub fn try_mark_green<Qcx: QueryContext<DepKind = K>>(
575575
&self,
576-
tcx: Ctxt,
576+
qcx: Qcx,
577577
dep_node: &DepNode<K>,
578578
) -> Option<(SerializedDepNodeIndex, DepNodeIndex)> {
579-
debug_assert!(!tcx.dep_context().is_eval_always(dep_node.kind));
579+
debug_assert!(!qcx.dep_context().is_eval_always(dep_node.kind));
580580

581581
// Return None if the dep graph is disabled
582582
let data = self.data.as_ref()?;
@@ -592,15 +592,16 @@ impl<K: DepKind> DepGraph<K> {
592592
// in the previous compilation session too, so we can try to
593593
// mark it as green by recursively marking all of its
594594
// dependencies green.
595-
self.try_mark_previous_green(tcx, data, prev_index, &dep_node)
595+
self.try_mark_previous_green(qcx, data, prev_index, &dep_node)
596596
.map(|dep_node_index| (prev_index, dep_node_index))
597597
}
598598
}
599599
}
600600

601-
fn try_mark_parent_green<Ctxt: QueryContext<DepKind = K>>(
601+
#[instrument(skip(self, qcx, data, parent_dep_node_index), level = "debug")]
602+
fn try_mark_parent_green<Qcx: QueryContext<DepKind = K>>(
602603
&self,
603-
tcx: Ctxt,
604+
qcx: Qcx,
604605
data: &DepGraphData<K>,
605606
parent_dep_node_index: SerializedDepNodeIndex,
606607
dep_node: &DepNode<K>,
@@ -613,82 +614,60 @@ impl<K: DepKind> DepGraph<K> {
613614
// This dependency has been marked as green before, we are
614615
// still fine and can continue with checking the other
615616
// dependencies.
616-
debug!(
617-
"try_mark_previous_green({:?}) --- found dependency {:?} to \
618-
be immediately green",
619-
dep_node, dep_dep_node,
620-
);
617+
debug!("dependency {dep_dep_node:?} was immediately green");
621618
return Some(());
622619
}
623620
Some(DepNodeColor::Red) => {
624621
// We found a dependency the value of which has changed
625622
// compared to the previous compilation session. We cannot
626623
// mark the DepNode as green and also don't need to bother
627624
// with checking any of the other dependencies.
628-
debug!(
629-
"try_mark_previous_green({:?}) - END - dependency {:?} was immediately red",
630-
dep_node, dep_dep_node,
631-
);
625+
debug!("dependency {dep_dep_node:?} was immediately red");
632626
return None;
633627
}
634628
None => {}
635629
}
636630

637631
// We don't know the state of this dependency. If it isn't
638632
// an eval_always node, let's try to mark it green recursively.
639-
if !tcx.dep_context().is_eval_always(dep_dep_node.kind) {
633+
if !qcx.dep_context().is_eval_always(dep_dep_node.kind) {
640634
debug!(
641-
"try_mark_previous_green({:?}) --- state of dependency {:?} ({}) \
642-
is unknown, trying to mark it green",
643-
dep_node, dep_dep_node, dep_dep_node.hash,
635+
"state of dependency {:?} ({}) is unknown, trying to mark it green",
636+
dep_dep_node, dep_dep_node.hash,
644637
);
645638

646639
let node_index =
647-
self.try_mark_previous_green(tcx, data, parent_dep_node_index, dep_dep_node);
640+
self.try_mark_previous_green(qcx, data, parent_dep_node_index, dep_dep_node);
641+
648642
if node_index.is_some() {
649-
debug!(
650-
"try_mark_previous_green({:?}) --- managed to MARK dependency {:?} as green",
651-
dep_node, dep_dep_node
652-
);
643+
debug!("managed to MARK dependency {dep_dep_node:?} as green",);
653644
return Some(());
654645
}
655646
}
656647

657648
// We failed to mark it green, so we try to force the query.
658-
debug!(
659-
"try_mark_previous_green({:?}) --- trying to force dependency {:?}",
660-
dep_node, dep_dep_node
661-
);
662-
if !tcx.dep_context().try_force_from_dep_node(*dep_dep_node) {
649+
debug!("trying to force dependency {dep_dep_node:?}");
650+
if !qcx.dep_context().try_force_from_dep_node(*dep_dep_node) {
663651
// The DepNode could not be forced.
664-
debug!(
665-
"try_mark_previous_green({:?}) - END - dependency {:?} could not be forced",
666-
dep_node, dep_dep_node
667-
);
652+
debug!("dependency {dep_dep_node:?} could not be forced");
668653
return None;
669654
}
670655

671656
let dep_dep_node_color = data.colors.get(parent_dep_node_index);
672657

673658
match dep_dep_node_color {
674659
Some(DepNodeColor::Green(_)) => {
675-
debug!(
676-
"try_mark_previous_green({:?}) --- managed to FORCE dependency {:?} to green",
677-
dep_node, dep_dep_node
678-
);
660+
debug!("managed to FORCE dependency {dep_dep_node:?} to green");
679661
return Some(());
680662
}
681663
Some(DepNodeColor::Red) => {
682-
debug!(
683-
"try_mark_previous_green({:?}) - END - dependency {:?} was red after forcing",
684-
dep_node, dep_dep_node
685-
);
664+
debug!("dependency {dep_dep_node:?} was red after forcing",);
686665
return None;
687666
}
688667
None => {}
689668
}
690669

691-
if !tcx.dep_context().sess().has_errors_or_delayed_span_bugs() {
670+
if !qcx.dep_context().sess().has_errors_or_delayed_span_bugs() {
692671
panic!("try_mark_previous_green() - Forcing the DepNode should have set its color")
693672
}
694673

@@ -702,38 +681,34 @@ impl<K: DepKind> DepGraph<K> {
702681
// invalid state will not be persisted to the
703682
// incremental compilation cache because of
704683
// compilation errors being present.
705-
debug!(
706-
"try_mark_previous_green({:?}) - END - dependency {:?} resulted in compilation error",
707-
dep_node, dep_dep_node
708-
);
684+
debug!("dependency {dep_dep_node:?} resulted in compilation error",);
709685
return None;
710686
}
711687

712688
/// Try to mark a dep-node which existed in the previous compilation session as green.
713-
fn try_mark_previous_green<Ctxt: QueryContext<DepKind = K>>(
689+
#[instrument(skip(self, qcx, data, prev_dep_node_index), level = "debug")]
690+
fn try_mark_previous_green<Qcx: QueryContext<DepKind = K>>(
714691
&self,
715-
tcx: Ctxt,
692+
qcx: Qcx,
716693
data: &DepGraphData<K>,
717694
prev_dep_node_index: SerializedDepNodeIndex,
718695
dep_node: &DepNode<K>,
719696
) -> Option<DepNodeIndex> {
720-
debug!("try_mark_previous_green({:?}) - BEGIN", dep_node);
721-
722697
#[cfg(not(parallel_compiler))]
723698
{
724699
debug_assert!(!self.dep_node_exists(dep_node));
725700
debug_assert!(data.colors.get(prev_dep_node_index).is_none());
726701
}
727702

728703
// We never try to mark eval_always nodes as green
729-
debug_assert!(!tcx.dep_context().is_eval_always(dep_node.kind));
704+
debug_assert!(!qcx.dep_context().is_eval_always(dep_node.kind));
730705

731706
debug_assert_eq!(data.previous.index_to_node(prev_dep_node_index), *dep_node);
732707

733708
let prev_deps = data.previous.edge_targets_from(prev_dep_node_index);
734709

735710
for &dep_dep_node_index in prev_deps {
736-
self.try_mark_parent_green(tcx, data, dep_dep_node_index, dep_node)?
711+
self.try_mark_parent_green(qcx, data, dep_dep_node_index, dep_node)?
737712
}
738713

739714
// If we got here without hitting a `return` that means that all
@@ -745,7 +720,7 @@ impl<K: DepKind> DepGraph<K> {
745720
// We allocating an entry for the node in the current dependency graph and
746721
// adding all the appropriate edges imported from the previous graph
747722
let dep_node_index = data.current.promote_node_and_deps_to_current(
748-
tcx.dep_context().profiler(),
723+
qcx.dep_context().profiler(),
749724
&data.previous,
750725
prev_dep_node_index,
751726
);
@@ -754,7 +729,7 @@ impl<K: DepKind> DepGraph<K> {
754729

755730
// FIXME: Store the fact that a node has diagnostics in a bit in the dep graph somewhere
756731
// Maybe store a list on disk and encode this fact in the DepNodeState
757-
let side_effects = tcx.load_side_effects(prev_dep_node_index);
732+
let side_effects = qcx.load_side_effects(prev_dep_node_index);
758733

759734
#[cfg(not(parallel_compiler))]
760735
debug_assert!(
@@ -765,24 +740,24 @@ impl<K: DepKind> DepGraph<K> {
765740
);
766741

767742
if !side_effects.is_empty() {
768-
self.emit_side_effects(tcx, data, dep_node_index, side_effects);
743+
self.emit_side_effects(qcx, data, dep_node_index, side_effects);
769744
}
770745

771746
// ... and finally storing a "Green" entry in the color map.
772747
// Multiple threads can all write the same color here
773748
data.colors.insert(prev_dep_node_index, DepNodeColor::Green(dep_node_index));
774749

775-
debug!("try_mark_previous_green({:?}) - END - successfully marked as green", dep_node);
750+
debug!("successfully marked {dep_node:?} as green");
776751
Some(dep_node_index)
777752
}
778753

779754
/// Atomically emits some loaded diagnostics.
780755
/// This may be called concurrently on multiple threads for the same dep node.
781756
#[cold]
782757
#[inline(never)]
783-
fn emit_side_effects<Ctxt: QueryContext<DepKind = K>>(
758+
fn emit_side_effects<Qcx: QueryContext<DepKind = K>>(
784759
&self,
785-
tcx: Ctxt,
760+
qcx: Qcx,
786761
data: &DepGraphData<K>,
787762
dep_node_index: DepNodeIndex,
788763
side_effects: QuerySideEffects,
@@ -794,9 +769,9 @@ impl<K: DepKind> DepGraph<K> {
794769
// must process side effects
795770

796771
// Promote the previous diagnostics to the current session.
797-
tcx.store_side_effects(dep_node_index, side_effects.clone());
772+
qcx.store_side_effects(dep_node_index, side_effects.clone());
798773

799-
let handle = tcx.dep_context().sess().diagnostic();
774+
let handle = qcx.dep_context().sess().diagnostic();
800775

801776
for mut diagnostic in side_effects.diagnostics {
802777
handle.emit_diagnostic(&mut diagnostic);
@@ -824,7 +799,7 @@ impl<K: DepKind> DepGraph<K> {
824799
//
825800
// This method will only load queries that will end up in the disk cache.
826801
// Other queries will not be executed.
827-
pub fn exec_cache_promotions<Ctxt: DepContext<DepKind = K>>(&self, tcx: Ctxt) {
802+
pub fn exec_cache_promotions<Tcx: DepContext<DepKind = K>>(&self, tcx: Tcx) {
828803
let _prof_timer = tcx.profiler().generic_activity("incr_comp_query_cache_promotion");
829804

830805
let data = self.data.as_ref().unwrap();

‎compiler/rustc_query_system/src/dep_graph/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,8 @@ pub trait DepContext: Copy {
5252
}
5353

5454
/// Try to force a dep node to execute and see if it's green.
55+
#[instrument(skip(self), level = "debug")]
5556
fn try_force_from_dep_node(self, dep_node: DepNode<Self::DepKind>) -> bool {
56-
debug!("try_force_from_dep_node({:?}) --- trying to force", dep_node);
57-
5857
let cb = self.dep_kind_info(dep_node.kind);
5958
if let Some(f) = cb.force_from_dep_node {
6059
f(self, dep_node);

‎compiler/rustc_query_system/src/query/config.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_data_structures::fingerprint::Fingerprint;
1111
use std::fmt::Debug;
1212
use std::hash::Hash;
1313

14-
pub trait QueryConfig<CTX: QueryContext> {
14+
pub trait QueryConfig<Qcx: QueryContext> {
1515
const NAME: &'static str;
1616

1717
type Key: Eq + Hash + Clone + Debug;
@@ -21,47 +21,47 @@ pub trait QueryConfig<CTX: QueryContext> {
2121
type Cache: QueryCache<Key = Self::Key, Stored = Self::Stored, Value = Self::Value>;
2222

2323
// Don't use this method to access query results, instead use the methods on TyCtxt
24-
fn query_state<'a>(tcx: CTX) -> &'a QueryState<Self::Key>
24+
fn query_state<'a>(tcx: Qcx) -> &'a QueryState<Self::Key>
2525
where
26-
CTX: 'a;
26+
Qcx: 'a;
2727

2828
// Don't use this method to access query results, instead use the methods on TyCtxt
29-
fn query_cache<'a>(tcx: CTX) -> &'a Self::Cache
29+
fn query_cache<'a>(tcx: Qcx) -> &'a Self::Cache
3030
where
31-
CTX: 'a;
31+
Qcx: 'a;
3232

3333
// Don't use this method to compute query results, instead use the methods on TyCtxt
34-
fn make_vtable(tcx: CTX, key: &Self::Key) -> QueryVTable<CTX, Self::Key, Self::Value>;
34+
fn make_vtable(tcx: Qcx, key: &Self::Key) -> QueryVTable<Qcx, Self::Key, Self::Value>;
3535

36-
fn cache_on_disk(tcx: CTX::DepContext, key: &Self::Key) -> bool;
36+
fn cache_on_disk(tcx: Qcx::DepContext, key: &Self::Key) -> bool;
3737

3838
// Don't use this method to compute query results, instead use the methods on TyCtxt
39-
fn execute_query(tcx: CTX::DepContext, k: Self::Key) -> Self::Stored;
39+
fn execute_query(tcx: Qcx::DepContext, k: Self::Key) -> Self::Stored;
4040
}
4141

4242
#[derive(Copy, Clone)]
43-
pub struct QueryVTable<CTX: QueryContext, K, V> {
43+
pub struct QueryVTable<Qcx: QueryContext, K, V> {
4444
pub anon: bool,
45-
pub dep_kind: CTX::DepKind,
45+
pub dep_kind: Qcx::DepKind,
4646
pub eval_always: bool,
4747
pub depth_limit: bool,
4848

49-
pub compute: fn(CTX::DepContext, K) -> V,
49+
pub compute: fn(Qcx::DepContext, K) -> V,
5050
pub hash_result: Option<fn(&mut StableHashingContext<'_>, &V) -> Fingerprint>,
5151
pub handle_cycle_error: HandleCycleError,
5252
// NOTE: this is also `None` if `cache_on_disk()` returns false, not just if it's unsupported by the query
53-
pub try_load_from_disk: Option<fn(CTX, SerializedDepNodeIndex) -> Option<V>>,
53+
pub try_load_from_disk: Option<fn(Qcx, SerializedDepNodeIndex) -> Option<V>>,
5454
}
5555

56-
impl<CTX: QueryContext, K, V> QueryVTable<CTX, K, V> {
57-
pub(crate) fn to_dep_node(&self, tcx: CTX::DepContext, key: &K) -> DepNode<CTX::DepKind>
56+
impl<Qcx: QueryContext, K, V> QueryVTable<Qcx, K, V> {
57+
pub(crate) fn to_dep_node(&self, tcx: Qcx::DepContext, key: &K) -> DepNode<Qcx::DepKind>
5858
where
59-
K: crate::dep_graph::DepNodeParams<CTX::DepContext>,
59+
K: crate::dep_graph::DepNodeParams<Qcx::DepContext>,
6060
{
6161
DepNode::construct(tcx, self.dep_kind, key)
6262
}
6363

64-
pub(crate) fn compute(&self, tcx: CTX::DepContext, key: K) -> V {
64+
pub(crate) fn compute(&self, tcx: Qcx::DepContext, key: K) -> V {
6565
(self.compute)(tcx, key)
6666
}
6767
}

‎compiler/rustc_query_system/src/query/job.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -596,8 +596,8 @@ pub(crate) fn report_cycle<'a>(
596596
cycle_diag.into_diagnostic(&sess.parse_sess.span_diagnostic)
597597
}
598598

599-
pub fn print_query_stack<CTX: QueryContext>(
600-
tcx: CTX,
599+
pub fn print_query_stack<Qcx: QueryContext>(
600+
qcx: Qcx,
601601
mut current_query: Option<QueryJobId>,
602602
handler: &Handler,
603603
num_frames: Option<usize>,
@@ -606,7 +606,7 @@ pub fn print_query_stack<CTX: QueryContext>(
606606
// a panic hook, which means that the global `Handler` may be in a weird
607607
// state if it was responsible for triggering the panic.
608608
let mut i = 0;
609-
let query_map = tcx.try_collect_active_jobs();
609+
let query_map = qcx.try_collect_active_jobs();
610610

611611
while let Some(query) = current_query {
612612
if Some(i) == num_frames {

‎compiler/rustc_query_system/src/query/plumbing.rs

Lines changed: 131 additions & 127 deletions
Large diffs are not rendered by default.

‎compiler/rustc_query_system/src/values.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use crate::dep_graph::DepContext;
22
use crate::query::QueryInfo;
33

4-
pub trait Value<CTX: DepContext>: Sized {
5-
fn from_cycle_error(tcx: CTX, cycle: &[QueryInfo]) -> Self;
4+
pub trait Value<Tcx: DepContext>: Sized {
5+
fn from_cycle_error(tcx: Tcx, cycle: &[QueryInfo]) -> Self;
66
}
77

8-
impl<CTX: DepContext, T> Value<CTX> for T {
9-
default fn from_cycle_error(tcx: CTX, _: &[QueryInfo]) -> T {
8+
impl<Tcx: DepContext, T> Value<Tcx> for T {
9+
default fn from_cycle_error(tcx: Tcx, _: &[QueryInfo]) -> T {
1010
tcx.sess().abort_if_errors();
1111
// Ideally we would use `bug!` here. But bug! is only defined in rustc_middle, and it's
1212
// non-trivial to define it earlier.

0 commit comments

Comments
 (0)
Please sign in to comment.