Skip to content

Commit fd26499

Browse files
committed
Auto merge of #153690 - nnethercote:find_dep_kind_root, r=petrochenkov
`find_dep_kind_root` tweaks Two minor changes relating to `find_dep_kind_root`. r? @SparrowLii
2 parents 620e36a + ddd1a69 commit fd26499

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

compiler/rustc_query_impl/src/job.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl<'tcx> QueryJobMap<'tcx> {
4646
}
4747
}
4848

49-
#[derive(Clone, Debug)]
49+
#[derive(Debug)]
5050
pub(crate) struct QueryJobInfo<'tcx> {
5151
pub(crate) frame: QueryStackFrame<'tcx>,
5252
pub(crate) job: QueryJob<'tcx>,
@@ -88,27 +88,28 @@ pub(crate) fn find_cycle_in_stack<'tcx>(
8888
panic!("did not find a cycle")
8989
}
9090

91+
/// Finds the job closest to the root with a `DepKind` matching the `DepKind` of `id` and returns
92+
/// information about it.
9193
#[cold]
9294
#[inline(never)]
9395
pub(crate) fn find_dep_kind_root<'tcx>(
96+
tcx: TyCtxt<'tcx>,
9497
id: QueryJobId,
9598
job_map: QueryJobMap<'tcx>,
96-
) -> (QueryJobInfo<'tcx>, usize) {
99+
) -> (Span, String, usize) {
97100
let mut depth = 1;
98-
let info = &job_map.map[&id];
101+
let mut info = &job_map.map[&id];
99102
let dep_kind = info.frame.dep_kind;
100-
let mut current_id = info.job.parent;
101-
let mut last_layout = (info.clone(), depth);
103+
let mut last_info = info;
102104

103-
while let Some(id) = current_id {
104-
let info = &job_map.map[&id];
105+
while let Some(id) = info.job.parent {
106+
info = &job_map.map[&id];
105107
if info.frame.dep_kind == dep_kind {
106108
depth += 1;
107-
last_layout = (info.clone(), depth);
109+
last_info = info;
108110
}
109-
current_id = info.job.parent;
110111
}
111-
last_layout
112+
(last_info.job.span, last_info.frame.tagged_key.description(tcx), depth)
112113
}
113114

114115
/// The locaton of a resumable waiter. The usize is the index into waiters in the query's latch.

compiler/rustc_query_impl/src/plumbing.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,16 @@ use crate::{CollectActiveJobsKind, GetQueryVTable, collect_active_jobs_from_all_
3030

3131
fn depth_limit_error<'tcx>(tcx: TyCtxt<'tcx>, job: QueryJobId) {
3232
let job_map = collect_active_jobs_from_all_queries(tcx, CollectActiveJobsKind::Full);
33-
let (info, depth) = find_dep_kind_root(job, job_map);
33+
let (span, desc, depth) = find_dep_kind_root(tcx, job, job_map);
3434

3535
let suggested_limit = match tcx.recursion_limit() {
3636
Limit(0) => Limit(2),
3737
limit => limit * 2,
3838
};
3939

40-
tcx.sess.dcx().emit_fatal(QueryOverflow {
41-
span: info.job.span,
42-
note: QueryOverflowNote { desc: info.frame.tagged_key.description(tcx), depth },
40+
tcx.dcx().emit_fatal(QueryOverflow {
41+
span,
42+
note: QueryOverflowNote { desc, depth },
4343
suggested_limit,
4444
crate_name: tcx.crate_name(LOCAL_CRATE),
4545
});

0 commit comments

Comments
 (0)