Rename some query-related things.

Various `QueryStackFrame` variables are called `query`; `frame` is a
better name. And various `QueryInfo` variables are called `frame`;
`info` is a better name.

This eliminates some confusing `query.query()` occurrences, which is a
good sign, and some `frame.query` occurrences become `info.frame`.
This commit is contained in:
Nicholas Nethercote 2026-01-30 14:50:45 +11:00
parent cd1c773661
commit 4ff360e997
4 changed files with 47 additions and 47 deletions

View file

@ -50,9 +50,9 @@ impl<'tcx> Value<TyCtxt<'tcx>> for ty::Binder<'_, ty::FnSig<'_>> {
) -> Self {
let err = Ty::new_error(tcx, guar);
let arity = if let Some(frame) = cycle_error.cycle.get(0)
&& frame.query.dep_kind == dep_kinds::fn_sig
&& let Some(def_id) = frame.query.def_id
let arity = if let Some(info) = cycle_error.cycle.get(0)
&& info.frame.dep_kind == dep_kinds::fn_sig
&& let Some(def_id) = info.frame.def_id
&& let Some(node) = tcx.hir_get_if_local(def_id)
&& let Some(sig) = node.fn_sig()
{
@ -85,10 +85,10 @@ impl<'tcx> Value<TyCtxt<'tcx>> for Representability {
let mut item_and_field_ids = Vec::new();
let mut representable_ids = FxHashSet::default();
for info in &cycle_error.cycle {
if info.query.dep_kind == dep_kinds::representability
&& let Some(field_id) = info.query.def_id
if info.frame.dep_kind == dep_kinds::representability
&& let Some(field_id) = info.frame.def_id
&& let Some(field_id) = field_id.as_local()
&& let Some(DefKind::Field) = info.query.info.def_kind
&& let Some(DefKind::Field) = info.frame.info.def_kind
{
let parent_id = tcx.parent(field_id.to_def_id());
let item_id = match tcx.def_kind(parent_id) {
@ -99,8 +99,8 @@ impl<'tcx> Value<TyCtxt<'tcx>> for Representability {
}
}
for info in &cycle_error.cycle {
if info.query.dep_kind == dep_kinds::representability_adt_ty
&& let Some(def_id) = info.query.def_id_for_ty_in_cycle
if info.frame.dep_kind == dep_kinds::representability_adt_ty
&& let Some(def_id) = info.frame.def_id_for_ty_in_cycle
&& let Some(def_id) = def_id.as_local()
&& !item_and_field_ids.iter().any(|&(id, _)| id == def_id)
{
@ -141,9 +141,9 @@ impl<'tcx> Value<TyCtxt<'tcx>> for &[ty::Variance] {
search_for_cycle_permutation(
&cycle_error.cycle,
|cycle| {
if let Some(frame) = cycle.get(0)
&& frame.query.dep_kind == dep_kinds::variances_of
&& let Some(def_id) = frame.query.def_id
if let Some(info) = cycle.get(0)
&& info.frame.dep_kind == dep_kinds::variances_of
&& let Some(def_id) = info.frame.def_id
{
let n = tcx.generics_of(def_id).own_params.len();
ControlFlow::Break(vec![ty::Bivariant; n].leak())
@ -189,8 +189,8 @@ impl<'tcx, T> Value<TyCtxt<'tcx>> for Result<T, &'_ ty::layout::LayoutError<'_>>
let diag = search_for_cycle_permutation(
&cycle_error.cycle,
|cycle| {
if cycle[0].query.dep_kind == dep_kinds::layout_of
&& let Some(def_id) = cycle[0].query.def_id_for_ty_in_cycle
if cycle[0].frame.dep_kind == dep_kinds::layout_of
&& let Some(def_id) = cycle[0].frame.def_id_for_ty_in_cycle
&& let Some(def_id) = def_id.as_local()
&& let def_kind = tcx.def_kind(def_id)
&& matches!(def_kind, DefKind::Closure)
@ -213,18 +213,18 @@ impl<'tcx, T> Value<TyCtxt<'tcx>> for Result<T, &'_ ty::layout::LayoutError<'_>>
tcx.def_kind_descr_article(def_kind, def_id.to_def_id()),
tcx.def_kind_descr(def_kind, def_id.to_def_id()),
);
for (i, frame) in cycle.iter().enumerate() {
if frame.query.dep_kind != dep_kinds::layout_of {
for (i, info) in cycle.iter().enumerate() {
if info.frame.dep_kind != dep_kinds::layout_of {
continue;
}
let Some(frame_def_id) = frame.query.def_id_for_ty_in_cycle else {
let Some(frame_def_id) = info.frame.def_id_for_ty_in_cycle else {
continue;
};
let Some(frame_coroutine_kind) = tcx.coroutine_kind(frame_def_id) else {
continue;
};
let frame_span =
frame.query.info.default_span(cycle[(i + 1) % cycle.len()].span);
info.frame.info.default_span(cycle[(i + 1) % cycle.len()].span);
if frame_span.is_dummy() {
continue;
}

View file

@ -167,7 +167,7 @@ impl<'tcx> QueryContext<'tcx> for QueryCtxt<'tcx> {
self.tcx.sess.dcx().emit_fatal(QueryOverflow {
span: info.job.span,
note: QueryOverflowNote { desc: info.query.info.extract().description, depth },
note: QueryOverflowNote { desc: info.frame.info.extract().description, depth },
suggested_limit,
crate_name: self.tcx.crate_name(LOCAL_CRATE),
});
@ -728,14 +728,14 @@ macro_rules! define_queries {
qmap: &mut QueryMap<'tcx>,
require_complete: bool,
) -> Option<()> {
let make_query = |tcx, key| {
let make_frame = |tcx, key| {
let kind = rustc_middle::dep_graph::dep_kinds::$name;
let name = stringify!($name);
$crate::plumbing::create_query_frame(tcx, rustc_middle::query::descs::$name, key, kind, name)
};
let res = tcx.query_system.states.$name.collect_active_jobs(
tcx,
make_query,
make_frame,
qmap,
require_complete,
);

View file

@ -23,12 +23,12 @@ use crate::query::{QueryContext, QueryStackFrame};
pub struct QueryInfo<I> {
/// The span corresponding to the reason for which this query was required.
pub span: Span,
pub query: QueryStackFrame<I>,
pub frame: QueryStackFrame<I>,
}
impl<'tcx> QueryInfo<QueryStackDeferred<'tcx>> {
pub(crate) fn lift(&self) -> QueryInfo<QueryStackFrameExtra> {
QueryInfo { span: self.span, query: self.query.lift() }
QueryInfo { span: self.span, frame: self.frame.lift() }
}
}
@ -39,8 +39,8 @@ pub type QueryMap<'tcx> = FxHashMap<QueryJobId, QueryJobInfo<'tcx>>;
pub struct QueryJobId(pub NonZero<u64>);
impl QueryJobId {
fn query<'a, 'tcx>(self, map: &'a QueryMap<'tcx>) -> QueryStackFrame<QueryStackDeferred<'tcx>> {
map.get(&self).unwrap().query.clone()
fn frame<'a, 'tcx>(self, map: &'a QueryMap<'tcx>) -> QueryStackFrame<QueryStackDeferred<'tcx>> {
map.get(&self).unwrap().frame.clone()
}
fn span<'a, 'tcx>(self, map: &'a QueryMap<'tcx>) -> Span {
@ -58,7 +58,7 @@ impl QueryJobId {
#[derive(Clone, Debug)]
pub struct QueryJobInfo<'tcx> {
pub query: QueryStackFrame<QueryStackDeferred<'tcx>>,
pub frame: QueryStackFrame<QueryStackDeferred<'tcx>>,
pub job: QueryJob<'tcx>,
}
@ -122,7 +122,7 @@ impl QueryJobId {
while let Some(job) = current_job {
let info = query_map.get(&job).unwrap();
cycle.push(QueryInfo { span: info.job.span, query: info.query.clone() });
cycle.push(QueryInfo { span: info.job.span, frame: info.frame.clone() });
if job == *self {
cycle.reverse();
@ -137,7 +137,7 @@ impl QueryJobId {
.job
.parent
.as_ref()
.map(|parent| (info.job.span, parent.query(&query_map)));
.map(|parent| (info.job.span, parent.frame(&query_map)));
return CycleError { usage, cycle };
}
@ -155,13 +155,13 @@ impl QueryJobId {
) -> (QueryJobInfo<'tcx>, usize) {
let mut depth = 1;
let info = query_map.get(&self).unwrap();
let dep_kind = info.query.dep_kind;
let dep_kind = info.frame.dep_kind;
let mut current_id = info.job.parent;
let mut last_layout = (info.clone(), depth);
while let Some(id) = current_id {
let info = query_map.get(&id).unwrap();
if info.query.dep_kind == dep_kind {
if info.frame.dep_kind == dep_kind {
depth += 1;
last_layout = (info.clone(), depth);
}
@ -386,7 +386,7 @@ where
.iter()
.min_by_key(|v| {
let (span, query) = f(v);
let hash = query.query(query_map).hash;
let hash = query.frame(query_map).hash;
// Prefer entry points which have valid spans for nicer error messages
// We add an integer to the tuple ensuring that entry points
// with valid spans are picked first
@ -470,14 +470,14 @@ fn remove_cycle<'tcx>(
stack.rotate_left(pos);
}
let usage = usage.as_ref().map(|(span, query)| (*span, query.query(query_map)));
let usage = usage.as_ref().map(|(span, query)| (*span, query.frame(query_map)));
// Create the cycle error
let error = CycleError {
usage,
cycle: stack
.iter()
.map(|&(s, ref q)| QueryInfo { span: s, query: q.query(query_map) })
.map(|&(s, ref q)| QueryInfo { span: s, frame: q.frame(query_map) })
.collect(),
};
@ -556,7 +556,7 @@ pub fn report_cycle<'a>(
) -> Diag<'a> {
assert!(!stack.is_empty());
let span = stack[0].query.info.default_span(stack[1 % stack.len()].span);
let span = stack[0].frame.info.default_span(stack[1 % stack.len()].span);
let mut cycle_stack = Vec::new();
@ -564,9 +564,9 @@ pub fn report_cycle<'a>(
let stack_count = if stack.len() == 1 { StackCount::Single } else { StackCount::Multiple };
for i in 1..stack.len() {
let query = &stack[i].query;
let span = query.info.default_span(stack[(i + 1) % stack.len()].span);
cycle_stack.push(CycleStack { span, desc: query.info.description.to_owned() });
let frame = &stack[i].frame;
let span = frame.info.default_span(stack[(i + 1) % stack.len()].span);
cycle_stack.push(CycleStack { span, desc: frame.info.description.to_owned() });
}
let mut cycle_usage = None;
@ -578,9 +578,9 @@ pub fn report_cycle<'a>(
}
let alias =
if stack.iter().all(|entry| matches!(entry.query.info.def_kind, Some(DefKind::TyAlias))) {
if stack.iter().all(|entry| matches!(entry.frame.info.def_kind, Some(DefKind::TyAlias))) {
Some(crate::error::Alias::Ty)
} else if stack.iter().all(|entry| entry.query.info.def_kind == Some(DefKind::TraitAlias)) {
} else if stack.iter().all(|entry| entry.frame.info.def_kind == Some(DefKind::TraitAlias)) {
Some(crate::error::Alias::Trait)
} else {
None
@ -589,7 +589,7 @@ pub fn report_cycle<'a>(
let cycle_diag = crate::error::Cycle {
span,
cycle_stack,
stack_bottom: stack[0].query.info.description.to_owned(),
stack_bottom: stack[0].frame.info.description.to_owned(),
alias,
cycle_usage,
stack_count,
@ -625,12 +625,12 @@ pub fn print_query_stack<'tcx, Qcx: QueryContext<'tcx>>(
let Some(query_info) = query_map.get(&query) else {
break;
};
let query_extra = query_info.query.info.extract();
let query_extra = query_info.frame.info.extract();
if Some(count_printed) < limit_frames || limit_frames.is_none() {
// Only print to stderr as many stack frames as `num_frames` when present.
dcx.struct_failure_note(format!(
"#{} [{:?}] {}",
count_printed, query_info.query.dep_kind, query_extra.description
count_printed, query_info.frame.dep_kind, query_extra.description
))
.with_span(query_info.job.span)
.emit();
@ -642,7 +642,7 @@ pub fn print_query_stack<'tcx, Qcx: QueryContext<'tcx>>(
file,
"#{} [{}] {}",
count_total,
qcx.dep_context().dep_kind_vtable(query_info.query.dep_kind).name,
qcx.dep_context().dep_kind_vtable(query_info.frame.dep_kind).name,
query_extra.description
);
}

View file

@ -82,7 +82,7 @@ where
pub fn collect_active_jobs<Qcx: Copy>(
&self,
qcx: Qcx,
make_query: fn(Qcx, K) -> QueryStackFrame<QueryStackDeferred<'tcx>>,
make_frame: fn(Qcx, K) -> QueryStackFrame<QueryStackDeferred<'tcx>>,
jobs: &mut QueryMap<'tcx>,
require_complete: bool,
) -> Option<()> {
@ -108,11 +108,11 @@ where
}
}
// Call `make_query` while we're not holding a `self.active` lock as `make_query` may call
// Call `make_frame` while we're not holding a `self.active` lock as `make_frame` may call
// queries leading to a deadlock.
for (key, job) in active {
let query = make_query(qcx, key);
jobs.insert(job.id, QueryJobInfo { query, job });
let frame = make_frame(qcx, key);
jobs.insert(job.id, QueryJobInfo { frame, job });
}
Some(())
@ -170,7 +170,7 @@ where
}
CycleErrorHandling::Stash => {
let guar = if let Some(root) = cycle_error.cycle.first()
&& let Some(span) = root.query.info.span
&& let Some(span) = root.frame.info.span
{
error.stash(span, StashKey::Cycle).unwrap()
} else {