Skip to content

Commit 82df68e

Browse files
authored
Unrolled build for #151626
Rollup merge of #151626 - Zalathar:qcx-deref, r=tiif Remove `Deref<Target = TyCtxt>` from `QueryCtxt` Explicitly writing `self.tcx` is easy enough, and lets us remove a bit of non-essential deref magic.
2 parents 4742769 + 4b8fc13 commit 82df68e

File tree

1 file changed

+18
-21
lines changed

1 file changed

+18
-21
lines changed

compiler/rustc_query_impl/src/plumbing.rs

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ use rustc_span::def_id::LOCAL_CRATE;
3535

3636
use crate::QueryConfigRestored;
3737

38+
/// Implements [`QueryContext`] for use by [`rustc_query_system`], since that
39+
/// crate does not have direct access to [`TyCtxt`].
3840
#[derive(Copy, Clone)]
3941
pub struct QueryCtxt<'tcx> {
4042
pub tcx: TyCtxt<'tcx>,
@@ -47,15 +49,6 @@ impl<'tcx> QueryCtxt<'tcx> {
4749
}
4850
}
4951

50-
impl<'tcx> std::ops::Deref for QueryCtxt<'tcx> {
51-
type Target = TyCtxt<'tcx>;
52-
53-
#[inline]
54-
fn deref(&self) -> &Self::Target {
55-
&self.tcx
56-
}
57-
}
58-
5952
impl<'tcx> HasDepContext for QueryCtxt<'tcx> {
6053
type Deps = rustc_middle::dep_graph::DepsType;
6154
type DepContext = TyCtxt<'tcx>;
@@ -69,14 +62,16 @@ impl<'tcx> HasDepContext for QueryCtxt<'tcx> {
6962
impl QueryContext for QueryCtxt<'_> {
7063
#[inline]
7164
fn jobserver_proxy(&self) -> &Proxy {
72-
&*self.jobserver_proxy
65+
&self.tcx.jobserver_proxy
7366
}
7467

7568
#[inline]
7669
fn next_job_id(self) -> QueryJobId {
7770
QueryJobId(
78-
NonZero::new(self.query_system.jobs.fetch_add(1, std::sync::atomic::Ordering::Relaxed))
79-
.unwrap(),
71+
NonZero::new(
72+
self.tcx.query_system.jobs.fetch_add(1, std::sync::atomic::Ordering::Relaxed),
73+
)
74+
.unwrap(),
8075
)
8176
}
8277

@@ -113,7 +108,8 @@ impl QueryContext for QueryCtxt<'_> {
113108
self,
114109
prev_dep_node_index: SerializedDepNodeIndex,
115110
) -> Option<QuerySideEffect> {
116-
self.query_system
111+
self.tcx
112+
.query_system
117113
.on_disk_cache
118114
.as_ref()
119115
.and_then(|c| c.load_side_effect(self.tcx, prev_dep_node_index))
@@ -122,7 +118,7 @@ impl QueryContext for QueryCtxt<'_> {
122118
#[inline(never)]
123119
#[cold]
124120
fn store_side_effect(self, dep_node_index: DepNodeIndex, side_effect: QuerySideEffect) {
125-
if let Some(c) = self.query_system.on_disk_cache.as_ref() {
121+
if let Some(c) = self.tcx.query_system.on_disk_cache.as_ref() {
126122
c.store_side_effect(dep_node_index, side_effect)
127123
}
128124
}
@@ -140,7 +136,9 @@ impl QueryContext for QueryCtxt<'_> {
140136
// as `self`, so we use `with_related_context` to relate the 'tcx lifetimes
141137
// when accessing the `ImplicitCtxt`.
142138
tls::with_related_context(self.tcx, move |current_icx| {
143-
if depth_limit && !self.recursion_limit().value_within_limit(current_icx.query_depth) {
139+
if depth_limit
140+
&& !self.tcx.recursion_limit().value_within_limit(current_icx.query_depth)
141+
{
144142
self.depth_limit_error(token);
145143
}
146144

@@ -161,16 +159,16 @@ impl QueryContext for QueryCtxt<'_> {
161159
let query_map = self.collect_active_jobs(true).expect("failed to collect active queries");
162160
let (info, depth) = job.find_dep_kind_root(query_map);
163161

164-
let suggested_limit = match self.recursion_limit() {
162+
let suggested_limit = match self.tcx.recursion_limit() {
165163
Limit(0) => Limit(2),
166164
limit => limit * 2,
167165
};
168166

169-
self.sess.dcx().emit_fatal(QueryOverflow {
167+
self.tcx.sess.dcx().emit_fatal(QueryOverflow {
170168
span: info.job.span,
171169
note: QueryOverflowNote { desc: info.query.description, depth },
172170
suggested_limit,
173-
crate_name: self.crate_name(LOCAL_CRATE),
171+
crate_name: self.tcx.crate_name(LOCAL_CRATE),
174172
});
175173
}
176174
}
@@ -367,7 +365,7 @@ pub(crate) fn encode_query_results<'a, 'tcx, Q>(
367365
Q: super::QueryConfigRestored<'tcx>,
368366
Q::RestoredValue: Encodable<CacheEncoder<'a, 'tcx>>,
369367
{
370-
let _timer = qcx.profiler().generic_activity_with_arg("encode_query_results_for", query.name());
368+
let _timer = qcx.tcx.prof.generic_activity_with_arg("encode_query_results_for", query.name());
371369

372370
assert!(query.query_state(qcx).all_inactive());
373371
let cache = query.query_cache(qcx);
@@ -389,8 +387,7 @@ pub(crate) fn query_key_hash_verify<'tcx>(
389387
query: impl QueryConfig<QueryCtxt<'tcx>>,
390388
qcx: QueryCtxt<'tcx>,
391389
) {
392-
let _timer =
393-
qcx.profiler().generic_activity_with_arg("query_key_hash_verify_for", query.name());
390+
let _timer = qcx.tcx.prof.generic_activity_with_arg("query_key_hash_verify_for", query.name());
394391

395392
let mut map = UnordMap::default();
396393

0 commit comments

Comments
 (0)