Skip to content

Commit 9f0615c

Browse files
committed
Auto merge of #153867 - Zoxc:rem-def_id_for_ty_in_cycle, r=nnethercote
Remove `def_id_for_ty_in_cycle` This removes `QueryKey::def_id_for_ty_in_cycle` and `QueryStackFrame.def_id_for_ty_in_cycle` by computing it instead from `TaggedQueryKey`.
2 parents 03749d6 + 1a30924 commit 9f0615c

File tree

4 files changed

+9
-37
lines changed

4 files changed

+9
-37
lines changed

compiler/rustc_middle/src/query/keys.rs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,6 @@ pub trait QueryKey: Sized + QueryKeyBounds {
4545
fn key_as_def_id(&self) -> Option<DefId> {
4646
None
4747
}
48-
49-
/// Used to detect when ADT def ids are used as keys in a cycle for better error reporting.
50-
fn def_id_for_ty_in_cycle(&self) -> Option<DefId> {
51-
None
52-
}
5348
}
5449

5550
pub trait AsLocalQueryKey: QueryKey {
@@ -265,14 +260,6 @@ impl<'tcx> QueryKey for Ty<'tcx> {
265260
fn default_span(&self, _: TyCtxt<'_>) -> Span {
266261
DUMMY_SP
267262
}
268-
269-
fn def_id_for_ty_in_cycle(&self) -> Option<DefId> {
270-
match *self.kind() {
271-
ty::Adt(adt, _) => Some(adt.did()),
272-
ty::Coroutine(def_id, ..) => Some(def_id),
273-
_ => None,
274-
}
275-
}
276263
}
277264

278265
impl<'tcx> QueryKey for (Ty<'tcx>, Ty<'tcx>) {
@@ -291,10 +278,6 @@ impl<'tcx, T: QueryKey> QueryKey for ty::PseudoCanonicalInput<'tcx, T> {
291278
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
292279
self.value.default_span(tcx)
293280
}
294-
295-
fn def_id_for_ty_in_cycle(&self) -> Option<DefId> {
296-
self.value.def_id_for_ty_in_cycle()
297-
}
298281
}
299282

300283
impl QueryKey for Symbol {
@@ -371,13 +354,6 @@ impl<'tcx> QueryKey for (ValidityRequirement, ty::PseudoCanonicalInput<'tcx, Ty<
371354
fn default_span(&self, _: TyCtxt<'_>) -> Span {
372355
DUMMY_SP
373356
}
374-
375-
fn def_id_for_ty_in_cycle(&self) -> Option<DefId> {
376-
match self.1.value.kind() {
377-
ty::Adt(adt, _) => Some(adt.did()),
378-
_ => None,
379-
}
380-
}
381357
}
382358

383359
impl<'tcx> QueryKey for (ty::Instance<'tcx>, CollectionMode) {

compiler/rustc_middle/src/query/stack.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,4 @@ pub struct QueryStackFrame<'tcx> {
1313
pub tagged_key: TaggedQueryKey<'tcx>,
1414
pub dep_kind: DepKind,
1515
pub def_id: Option<DefId>,
16-
/// A def-id that is extracted from a `Ty` in a query key
17-
pub def_id_for_ty_in_cycle: Option<DefId>,
1816
}

compiler/rustc_query_impl/src/from_cycle_error.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_errors::{Applicability, Diag, MultiSpan, pluralize, struct_span_code_e
99
use rustc_hir as hir;
1010
use rustc_hir::def::{DefKind, Res};
1111
use rustc_middle::dep_graph::DepKind;
12-
use rustc_middle::queries::QueryVTables;
12+
use rustc_middle::queries::{QueryVTables, TaggedQueryKey};
1313
use rustc_middle::query::CycleError;
1414
use rustc_middle::query::erase::erase_val;
1515
use rustc_middle::ty::layout::LayoutError;
@@ -91,9 +91,9 @@ fn check_representability<'tcx>(tcx: TyCtxt<'tcx>, cycle_error: CycleError<'tcx>
9191
}
9292
}
9393
for info in &cycle_error.cycle {
94-
if info.frame.dep_kind == DepKind::check_representability_adt_ty
95-
&& let Some(def_id) = info.frame.def_id_for_ty_in_cycle
96-
&& let Some(def_id) = def_id.as_local()
94+
if let TaggedQueryKey::check_representability_adt_ty(key) = info.frame.tagged_key
95+
&& let Some(adt) = key.ty_adt_def()
96+
&& let Some(def_id) = adt.did().as_local()
9797
&& !item_and_field_ids.iter().any(|&(id, _)| id == def_id)
9898
{
9999
representable_ids.insert(def_id);
@@ -154,8 +154,8 @@ fn layout_of<'tcx>(
154154
let diag = search_for_cycle_permutation(
155155
&cycle_error.cycle,
156156
|cycle| {
157-
if cycle[0].frame.dep_kind == DepKind::layout_of
158-
&& let Some(def_id) = cycle[0].frame.def_id_for_ty_in_cycle
157+
if let TaggedQueryKey::layout_of(key) = cycle[0].frame.tagged_key
158+
&& let ty::Coroutine(def_id, _) = key.value.kind()
159159
&& let Some(def_id) = def_id.as_local()
160160
&& let def_kind = tcx.def_kind(def_id)
161161
&& matches!(def_kind, DefKind::Closure)
@@ -179,10 +179,10 @@ fn layout_of<'tcx>(
179179
tcx.def_kind_descr(def_kind, def_id.to_def_id()),
180180
);
181181
for (i, info) in cycle.iter().enumerate() {
182-
if info.frame.dep_kind != DepKind::layout_of {
182+
let TaggedQueryKey::layout_of(frame_key) = info.frame.tagged_key else {
183183
continue;
184-
}
185-
let Some(frame_def_id) = info.frame.def_id_for_ty_in_cycle else {
184+
};
185+
let &ty::Coroutine(frame_def_id, _) = frame_key.value.kind() else {
186186
continue;
187187
};
188188
let Some(frame_coroutine_kind) = tcx.coroutine_kind(frame_def_id) else {

compiler/rustc_query_impl/src/plumbing.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,11 @@ where
9191
QueryVTable<'tcx, C>: DynSync,
9292
{
9393
let def_id: Option<DefId> = key.key_as_def_id();
94-
let def_id_for_ty_in_cycle: Option<DefId> = key.def_id_for_ty_in_cycle();
9594

9695
QueryStackFrame {
9796
tagged_key: (vtable.create_tagged_key)(key),
9897
dep_kind: vtable.dep_kind,
9998
def_id,
100-
def_id_for_ty_in_cycle,
10199
}
102100
}
103101

0 commit comments

Comments
 (0)