Skip to content

Commit d4411dc

Browse files
committed
Remove QueryInfo.
`CycleError` has one field containing a `(Span, QueryStackFrame<I>)` and another field containing a `QueryInfo`, which is a struct containing just a `Span` and a `QueryStackFrame<I>`. We already have the `Spanned` type for adding a span to something. This commit uses it for both fields in `CycleError`, removing the need for `QueryInfo`. Which is good for the following reasons. - Any type with `Info` in the name is suspect, IMO. - `QueryInfo` can no longer be confused with the similar `QueryJobInfo`. - The doc comment on `QueryInfo` was wrong; it didn't contain a query key.
1 parent b49ecc9 commit d4411dc

6 files changed

Lines changed: 44 additions & 56 deletions

File tree

compiler/rustc_middle/src/query/job.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,9 @@ use parking_lot::{Condvar, Mutex};
77
use rustc_span::Span;
88

99
use crate::query::plumbing::CycleError;
10-
use crate::query::stack::{QueryStackDeferred, QueryStackFrame, QueryStackFrameExtra};
10+
use crate::query::stack::QueryStackDeferred;
1111
use crate::ty::TyCtxt;
1212

13-
/// Represents a span and a query key.
14-
#[derive(Clone, Debug)]
15-
pub struct QueryInfo<I> {
16-
/// The span corresponding to the reason for which this query was required.
17-
pub span: Span,
18-
pub frame: QueryStackFrame<I>,
19-
}
20-
21-
impl<'tcx> QueryInfo<QueryStackDeferred<'tcx>> {
22-
pub(crate) fn lift(&self) -> QueryInfo<QueryStackFrameExtra> {
23-
QueryInfo { span: self.span, frame: self.frame.lift() }
24-
}
25-
}
26-
2713
/// A value uniquely identifying an active query job.
2814
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
2915
pub struct QueryJobId(pub NonZero<u64>);

compiler/rustc_middle/src/query/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use rustc_hir::def_id::LocalDefId;
22

33
pub use self::caches::{DefIdCache, DefaultCache, QueryCache, SingleCache, VecCache};
4-
pub use self::job::{QueryInfo, QueryJob, QueryJobId, QueryLatch, QueryWaiter};
4+
pub use self::job::{QueryJob, QueryJobId, QueryLatch, QueryWaiter};
55
pub use self::keys::{AsLocalQueryKey, LocalCrate, QueryKey};
66
pub use self::plumbing::{
77
ActiveKeyStatus, CycleError, CycleErrorHandling, EnsureMode, IntoQueryParam, QueryMode,

compiler/rustc_middle/src/query/plumbing.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use rustc_data_structures::sync::{AtomicU64, WorkerLocal};
88
use rustc_hir::def_id::{DefId, LocalDefId};
99
use rustc_hir::hir_id::OwnerId;
1010
use rustc_macros::HashStable;
11+
use rustc_span::source_map::{Spanned, respan};
1112
use rustc_span::{ErrorGuaranteed, Span};
1213
pub use sealed::IntoQueryParam;
1314

@@ -16,7 +17,7 @@ use crate::ich::StableHashingContext;
1617
use crate::queries::{ExternProviders, Providers, QueryArenas, QueryVTables};
1718
use crate::query::on_disk_cache::OnDiskCache;
1819
use crate::query::stack::{QueryStackDeferred, QueryStackFrame, QueryStackFrameExtra};
19-
use crate::query::{QueryCache, QueryInfo, QueryJob};
20+
use crate::query::{QueryCache, QueryJob};
2021
use crate::ty::TyCtxt;
2122

2223
/// For a particular query, keeps track of "active" keys, i.e. keys whose
@@ -64,15 +65,15 @@ pub enum CycleErrorHandling {
6465
#[derive(Clone, Debug)]
6566
pub struct CycleError<I = QueryStackFrameExtra> {
6667
/// The query and related span that uses the cycle.
67-
pub usage: Option<(Span, QueryStackFrame<I>)>,
68-
pub cycle: Vec<QueryInfo<I>>,
68+
pub usage: Option<Spanned<QueryStackFrame<I>>>,
69+
pub cycle: Vec<Spanned<QueryStackFrame<I>>>,
6970
}
7071

7172
impl<'tcx> CycleError<QueryStackDeferred<'tcx>> {
7273
pub fn lift(&self) -> CycleError<QueryStackFrameExtra> {
7374
CycleError {
74-
usage: self.usage.as_ref().map(|(span, frame)| (*span, frame.lift())),
75-
cycle: self.cycle.iter().map(|info| info.lift()).collect(),
75+
usage: self.usage.as_ref().map(|usage| respan(usage.span, usage.node.lift())),
76+
cycle: self.cycle.iter().map(|frame| respan(frame.span, frame.node.lift())).collect(),
7677
}
7778
}
7879
}

compiler/rustc_query_impl/src/execution.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ fn mk_cycle<'tcx, C: QueryCache>(
112112
}
113113
CycleErrorHandling::Stash => {
114114
let guar = if let Some(root) = cycle_error.cycle.first()
115-
&& let Some(span) = root.frame.info.span
115+
&& let Some(span) = root.node.info.span
116116
{
117117
error.stash(span, StashKey::Cycle).unwrap()
118118
} else {

compiler/rustc_query_impl/src/from_cycle_error.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ impl<'tcx> FromCycleError<'tcx> for ty::Binder<'_, ty::FnSig<'_>> {
6060
fn from_cycle_error(tcx: TyCtxt<'tcx>, cycle_error: CycleError, guar: ErrorGuaranteed) -> Self {
6161
let err = Ty::new_error(tcx, guar);
6262

63-
let arity = if let Some(info) = cycle_error.cycle.get(0)
64-
&& info.frame.dep_kind == DepKind::fn_sig
65-
&& let Some(def_id) = info.frame.def_id
63+
let arity = if let Some(frame) = cycle_error.cycle.get(0)
64+
&& frame.node.dep_kind == DepKind::fn_sig
65+
&& let Some(def_id) = frame.node.def_id
6666
&& let Some(node) = tcx.hir_get_if_local(def_id)
6767
&& let Some(sig) = node.fn_sig()
6868
{
@@ -94,11 +94,11 @@ impl<'tcx> FromCycleError<'tcx> for Representability {
9494
) -> Self {
9595
let mut item_and_field_ids = Vec::new();
9696
let mut representable_ids = FxHashSet::default();
97-
for info in &cycle_error.cycle {
98-
if info.frame.dep_kind == DepKind::check_representability
99-
&& let Some(field_id) = info.frame.def_id
97+
for frame in &cycle_error.cycle {
98+
if frame.node.dep_kind == DepKind::check_representability
99+
&& let Some(field_id) = frame.node.def_id
100100
&& let Some(field_id) = field_id.as_local()
101-
&& let Some(DefKind::Field) = info.frame.info.def_kind
101+
&& let Some(DefKind::Field) = frame.node.info.def_kind
102102
{
103103
let parent_id = tcx.parent(field_id.to_def_id());
104104
let item_id = match tcx.def_kind(parent_id) {
@@ -108,9 +108,9 @@ impl<'tcx> FromCycleError<'tcx> for Representability {
108108
item_and_field_ids.push((item_id.expect_local(), field_id));
109109
}
110110
}
111-
for info in &cycle_error.cycle {
112-
if info.frame.dep_kind == DepKind::check_representability_adt_ty
113-
&& let Some(def_id) = info.frame.def_id_for_ty_in_cycle
111+
for frame in &cycle_error.cycle {
112+
if frame.node.dep_kind == DepKind::check_representability_adt_ty
113+
&& let Some(def_id) = frame.node.def_id_for_ty_in_cycle
114114
&& let Some(def_id) = def_id.as_local()
115115
&& !item_and_field_ids.iter().any(|&(id, _)| id == def_id)
116116
{
@@ -145,9 +145,9 @@ impl<'tcx> FromCycleError<'tcx> for &[ty::Variance] {
145145
search_for_cycle_permutation(
146146
&cycle_error.cycle,
147147
|cycle| {
148-
if let Some(info) = cycle.get(0)
149-
&& info.frame.dep_kind == DepKind::variances_of
150-
&& let Some(def_id) = info.frame.def_id
148+
if let Some(frame) = cycle.get(0)
149+
&& frame.node.dep_kind == DepKind::variances_of
150+
&& let Some(def_id) = frame.node.def_id
151151
{
152152
let n = tcx.generics_of(def_id).own_params.len();
153153
ControlFlow::Break(vec![ty::Bivariant; n].leak())
@@ -157,7 +157,7 @@ impl<'tcx> FromCycleError<'tcx> for &[ty::Variance] {
157157
},
158158
|| {
159159
span_bug!(
160-
cycle_error.usage.as_ref().unwrap().0,
160+
cycle_error.usage.as_ref().unwrap().span,
161161
"only `variances_of` returns `&[ty::Variance]`"
162162
)
163163
},
@@ -193,8 +193,8 @@ impl<'tcx, T> FromCycleError<'tcx> for Result<T, &'_ ty::layout::LayoutError<'_>
193193
let diag = search_for_cycle_permutation(
194194
&cycle_error.cycle,
195195
|cycle| {
196-
if cycle[0].frame.dep_kind == DepKind::layout_of
197-
&& let Some(def_id) = cycle[0].frame.def_id_for_ty_in_cycle
196+
if cycle[0].node.dep_kind == DepKind::layout_of
197+
&& let Some(def_id) = cycle[0].node.def_id_for_ty_in_cycle
198198
&& let Some(def_id) = def_id.as_local()
199199
&& let def_kind = tcx.def_kind(def_id)
200200
&& matches!(def_kind, DefKind::Closure)
@@ -217,18 +217,18 @@ impl<'tcx, T> FromCycleError<'tcx> for Result<T, &'_ ty::layout::LayoutError<'_>
217217
tcx.def_kind_descr_article(def_kind, def_id.to_def_id()),
218218
tcx.def_kind_descr(def_kind, def_id.to_def_id()),
219219
);
220-
for (i, info) in cycle.iter().enumerate() {
221-
if info.frame.dep_kind != DepKind::layout_of {
220+
for (i, frame) in cycle.iter().enumerate() {
221+
if frame.node.dep_kind != DepKind::layout_of {
222222
continue;
223223
}
224-
let Some(frame_def_id) = info.frame.def_id_for_ty_in_cycle else {
224+
let Some(frame_def_id) = frame.node.def_id_for_ty_in_cycle else {
225225
continue;
226226
};
227227
let Some(frame_coroutine_kind) = tcx.coroutine_kind(frame_def_id) else {
228228
continue;
229229
};
230230
let frame_span =
231-
info.frame.info.default_span(cycle[(i + 1) % cycle.len()].span);
231+
frame.node.info.default_span(cycle[(i + 1) % cycle.len()].span);
232232
if frame_span.is_dummy() {
233233
continue;
234234
}

compiler/rustc_query_impl/src/job.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
77
use rustc_errors::{Diag, DiagCtxtHandle};
88
use rustc_hir::def::DefKind;
99
use rustc_middle::query::{
10-
CycleError, QueryInfo, QueryJob, QueryJobId, QueryLatch, QueryStackDeferred, QueryStackFrame,
11-
QueryWaiter,
10+
CycleError, QueryJob, QueryJobId, QueryLatch, QueryStackDeferred, QueryStackFrame, QueryWaiter,
1211
};
1312
use rustc_middle::ty::TyCtxt;
1413
use rustc_session::Session;
14+
use rustc_span::source_map::respan;
1515
use rustc_span::{DUMMY_SP, Span};
1616

1717
use crate::collect_active_jobs_from_all_queries;
@@ -66,7 +66,7 @@ pub(crate) fn find_cycle_in_stack<'tcx>(
6666

6767
while let Some(job) = current_job {
6868
let info = &job_map.map[&job];
69-
cycle.push(QueryInfo { span: info.job.span, frame: info.frame.clone() });
69+
cycle.push(respan(info.job.span, info.frame.clone()));
7070

7171
if job == id {
7272
cycle.reverse();
@@ -79,7 +79,7 @@ pub(crate) fn find_cycle_in_stack<'tcx>(
7979
// Find out why the cycle itself was used
8080
let usage = try {
8181
let parent = info.job.parent?;
82-
(info.job.span, job_map.frame_of(parent).clone())
82+
respan(info.job.span, job_map.frame_of(parent).clone())
8383
};
8484
return CycleError { usage, cycle };
8585
}
@@ -291,14 +291,15 @@ fn remove_cycle<'tcx>(
291291
stack.rotate_left(pos);
292292
}
293293

294-
let usage = entry_point.waiter.map(|(span, job)| (span, job_map.frame_of(job).clone()));
294+
let usage =
295+
entry_point.waiter.map(|(span, job)| respan(span, job_map.frame_of(job).clone()));
295296

296297
// Create the cycle error
297298
let error = CycleError {
298299
usage,
299300
cycle: stack
300301
.iter()
301-
.map(|&(span, job)| QueryInfo { span, frame: job_map.frame_of(job).clone() })
302+
.map(|&(span, job)| respan(span, job_map.frame_of(job).clone()))
302303
.collect(),
303304
};
304305

@@ -433,37 +434,37 @@ pub(crate) fn report_cycle<'a>(
433434
) -> Diag<'a> {
434435
assert!(!stack.is_empty());
435436

436-
let span = stack[0].frame.info.default_span(stack[1 % stack.len()].span);
437+
let span = stack[0].node.info.default_span(stack[1 % stack.len()].span);
437438

438439
let mut cycle_stack = Vec::new();
439440

440441
use crate::error::StackCount;
441-
let stack_bottom = stack[0].frame.info.description.to_owned();
442+
let stack_bottom = stack[0].node.info.description.to_owned();
442443
let stack_count = if stack.len() == 1 {
443444
StackCount::Single { stack_bottom: stack_bottom.clone() }
444445
} else {
445446
StackCount::Multiple { stack_bottom: stack_bottom.clone() }
446447
};
447448

448449
for i in 1..stack.len() {
449-
let frame = &stack[i].frame;
450+
let frame = &stack[i].node;
450451
let span = frame.info.default_span(stack[(i + 1) % stack.len()].span);
451452
cycle_stack
452453
.push(crate::error::CycleStack { span, desc: frame.info.description.to_owned() });
453454
}
454455

455456
let mut cycle_usage = None;
456-
if let Some((span, ref query)) = *usage {
457+
if let Some(usage) = usage {
457458
cycle_usage = Some(crate::error::CycleUsage {
458-
span: query.info.default_span(span),
459-
usage: query.info.description.to_string(),
459+
span: usage.node.info.default_span(usage.span),
460+
usage: usage.node.info.description.to_string(),
460461
});
461462
}
462463

463464
let alias =
464-
if stack.iter().all(|entry| matches!(entry.frame.info.def_kind, Some(DefKind::TyAlias))) {
465+
if stack.iter().all(|entry| matches!(entry.node.info.def_kind, Some(DefKind::TyAlias))) {
465466
Some(crate::error::Alias::Ty)
466-
} else if stack.iter().all(|entry| entry.frame.info.def_kind == Some(DefKind::TraitAlias)) {
467+
} else if stack.iter().all(|entry| entry.node.info.def_kind == Some(DefKind::TraitAlias)) {
467468
Some(crate::error::Alias::Trait)
468469
} else {
469470
None

0 commit comments

Comments
 (0)