Skip to content

Commit c2ff8ad

Browse files
committed
Auto merge of rust-lang#105550 - gimbles:master, r=Nilstrieb
Use `DepKind` instead of `&'static str` in `QueryStackFrame` `@rustbot` author Fixes rust-lang#105168
2 parents 62cc869 + f8b3008 commit c2ff8ad

File tree

7 files changed

+141
-114
lines changed

7 files changed

+141
-114
lines changed

compiler/rustc_middle/src/values.rs

+12-11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::dep_graph::DepKind;
12
use rustc_data_structures::fx::FxHashSet;
23
use rustc_errors::{pluralize, struct_span_err, Applicability, MultiSpan};
34
use rustc_hir as hir;
@@ -11,16 +12,16 @@ use rustc_span::Span;
1112

1213
use std::fmt::Write;
1314

14-
impl<'tcx> Value<TyCtxt<'tcx>> for Ty<'_> {
15-
fn from_cycle_error(tcx: TyCtxt<'tcx>, _: &[QueryInfo]) -> Self {
15+
impl<'tcx> Value<TyCtxt<'tcx>, DepKind> for Ty<'_> {
16+
fn from_cycle_error(tcx: TyCtxt<'tcx>, _: &[QueryInfo<DepKind>]) -> Self {
1617
// SAFETY: This is never called when `Self` is not `Ty<'tcx>`.
1718
// FIXME: Represent the above fact in the trait system somehow.
1819
unsafe { std::mem::transmute::<Ty<'tcx>, Ty<'_>>(tcx.ty_error()) }
1920
}
2021
}
2122

22-
impl<'tcx> Value<TyCtxt<'tcx>> for ty::SymbolName<'_> {
23-
fn from_cycle_error(tcx: TyCtxt<'tcx>, _: &[QueryInfo]) -> Self {
23+
impl<'tcx> Value<TyCtxt<'tcx>, DepKind> for ty::SymbolName<'_> {
24+
fn from_cycle_error(tcx: TyCtxt<'tcx>, _: &[QueryInfo<DepKind>]) -> Self {
2425
// SAFETY: This is never called when `Self` is not `SymbolName<'tcx>`.
2526
// FIXME: Represent the above fact in the trait system somehow.
2627
unsafe {
@@ -31,12 +32,12 @@ impl<'tcx> Value<TyCtxt<'tcx>> for ty::SymbolName<'_> {
3132
}
3233
}
3334

34-
impl<'tcx> Value<TyCtxt<'tcx>> for ty::Binder<'_, ty::FnSig<'_>> {
35-
fn from_cycle_error(tcx: TyCtxt<'tcx>, stack: &[QueryInfo]) -> Self {
35+
impl<'tcx> Value<TyCtxt<'tcx>, DepKind> for ty::Binder<'_, ty::FnSig<'_>> {
36+
fn from_cycle_error(tcx: TyCtxt<'tcx>, stack: &[QueryInfo<DepKind>]) -> Self {
3637
let err = tcx.ty_error();
3738

3839
let arity = if let Some(frame) = stack.get(0)
39-
&& frame.query.name == "fn_sig"
40+
&& frame.query.dep_kind == DepKind::fn_sig
4041
&& let Some(def_id) = frame.query.def_id
4142
&& let Some(node) = tcx.hir().get_if_local(def_id)
4243
&& let Some(sig) = node.fn_sig()
@@ -61,12 +62,12 @@ impl<'tcx> Value<TyCtxt<'tcx>> for ty::Binder<'_, ty::FnSig<'_>> {
6162
}
6263
}
6364

64-
impl<'tcx> Value<TyCtxt<'tcx>> for Representability {
65-
fn from_cycle_error(tcx: TyCtxt<'tcx>, cycle: &[QueryInfo]) -> Self {
65+
impl<'tcx> Value<TyCtxt<'tcx>, DepKind> for Representability {
66+
fn from_cycle_error(tcx: TyCtxt<'tcx>, cycle: &[QueryInfo<DepKind>]) -> Self {
6667
let mut item_and_field_ids = Vec::new();
6768
let mut representable_ids = FxHashSet::default();
6869
for info in cycle {
69-
if info.query.name == "representability"
70+
if info.query.dep_kind == DepKind::representability
7071
&& let Some(field_id) = info.query.def_id
7172
&& let Some(field_id) = field_id.as_local()
7273
&& let Some(DefKind::Field) = info.query.def_kind
@@ -80,7 +81,7 @@ impl<'tcx> Value<TyCtxt<'tcx>> for Representability {
8081
}
8182
}
8283
for info in cycle {
83-
if info.query.name == "representability_adt_ty"
84+
if info.query.dep_kind == DepKind::representability_adt_ty
8485
&& let Some(def_id) = info.query.ty_adt_id
8586
&& let Some(def_id) = def_id.as_local()
8687
&& !item_and_field_ids.iter().any(|&(id, _)| id == def_id)

compiler/rustc_query_impl/src/plumbing.rs

+13-11
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl QueryContext for QueryCtxt<'_> {
6666
tls::with_related_context(**self, |icx| icx.query)
6767
}
6868

69-
fn try_collect_active_jobs(&self) -> Option<QueryMap> {
69+
fn try_collect_active_jobs(&self) -> Option<QueryMap<DepKind>> {
7070
self.queries.try_collect_active_jobs(**self)
7171
}
7272

@@ -195,7 +195,7 @@ impl<'tcx> QueryCtxt<'tcx> {
195195

196196
#[derive(Clone, Copy)]
197197
pub(crate) struct QueryStruct<'tcx> {
198-
pub try_collect_active_jobs: fn(QueryCtxt<'tcx>, &mut QueryMap) -> Option<()>,
198+
pub try_collect_active_jobs: fn(QueryCtxt<'tcx>, &mut QueryMap<DepKind>) -> Option<()>,
199199
pub alloc_self_profile_query_strings: fn(TyCtxt<'tcx>, &mut QueryKeyStringCache),
200200
pub encode_query_results:
201201
Option<fn(QueryCtxt<'tcx>, &mut CacheEncoder<'_, 'tcx>, &mut EncodedDepNodeIndex)>,
@@ -313,7 +313,7 @@ pub(crate) fn create_query_frame<
313313
key: K,
314314
kind: DepKind,
315315
name: &'static str,
316-
) -> QueryStackFrame {
316+
) -> QueryStackFrame<DepKind> {
317317
// Disable visible paths printing for performance reasons.
318318
// Showing visible path instead of any path is not that important in production.
319319
let description = ty::print::with_no_visible_paths!(
@@ -346,7 +346,7 @@ pub(crate) fn create_query_frame<
346346
};
347347
let ty_adt_id = key.ty_adt_id();
348348

349-
QueryStackFrame::new(name, description, span, def_id, def_kind, ty_adt_id, hash)
349+
QueryStackFrame::new(description, span, def_id, def_kind, kind, ty_adt_id, hash)
350350
}
351351

352352
fn try_load_from_on_disk_cache<'tcx, Q>(tcx: TyCtxt<'tcx>, dep_node: DepNode)
@@ -378,7 +378,7 @@ fn force_from_dep_node<'tcx, Q>(tcx: TyCtxt<'tcx>, dep_node: DepNode) -> bool
378378
where
379379
Q: QueryConfig<QueryCtxt<'tcx>>,
380380
Q::Key: DepNodeParams<TyCtxt<'tcx>>,
381-
Q::Value: Value<TyCtxt<'tcx>>,
381+
Q::Value: Value<TyCtxt<'tcx>, DepKind>,
382382
{
383383
// We must avoid ever having to call `force_from_dep_node()` for a
384384
// `DepNode::codegen_unit`:
@@ -402,7 +402,7 @@ where
402402
#[cfg(debug_assertions)]
403403
let _guard = tracing::span!(tracing::Level::TRACE, stringify!($name), ?key).entered();
404404
let tcx = QueryCtxt::from_tcx(tcx);
405-
force_query::<Q, _>(tcx, key, dep_node);
405+
force_query::<Q, _, DepKind>(tcx, key, dep_node);
406406
true
407407
} else {
408408
false
@@ -480,7 +480,7 @@ macro_rules! define_queries {
480480
type Cache = query_storage::$name<'tcx>;
481481

482482
#[inline(always)]
483-
fn query_state<'a>(tcx: QueryCtxt<'tcx>) -> &'a QueryState<Self::Key>
483+
fn query_state<'a>(tcx: QueryCtxt<'tcx>) -> &'a QueryState<Self::Key, crate::dep_graph::DepKind>
484484
where QueryCtxt<'tcx>: 'a
485485
{
486486
&tcx.queries.$name
@@ -587,9 +587,10 @@ macro_rules! define_queries {
587587
use $crate::plumbing::{QueryStruct, QueryCtxt};
588588
use $crate::profiling_support::QueryKeyStringCache;
589589
use rustc_query_system::query::QueryMap;
590+
use rustc_middle::dep_graph::DepKind;
590591

591592
pub(super) const fn dummy_query_struct<'tcx>() -> QueryStruct<'tcx> {
592-
fn noop_try_collect_active_jobs(_: QueryCtxt<'_>, _: &mut QueryMap) -> Option<()> {
593+
fn noop_try_collect_active_jobs(_: QueryCtxt<'_>, _: &mut QueryMap<DepKind>) -> Option<()> {
593594
None
594595
}
595596
fn noop_alloc_self_profile_query_strings(_: TyCtxt<'_>, _: &mut QueryKeyStringCache) {}
@@ -675,7 +676,8 @@ macro_rules! define_queries_struct {
675676
$(
676677
$(#[$attr])*
677678
$name: QueryState<
678-
<queries::$name<'tcx> as QueryConfig<QueryCtxt<'tcx>>>::Key
679+
<queries::$name<'tcx> as QueryConfig<QueryCtxt<'tcx>>>::Key,
680+
rustc_middle::dep_graph::DepKind,
679681
>,
680682
)*
681683
}
@@ -684,7 +686,7 @@ macro_rules! define_queries_struct {
684686
pub(crate) fn try_collect_active_jobs(
685687
&'tcx self,
686688
tcx: TyCtxt<'tcx>,
687-
) -> Option<QueryMap> {
689+
) -> Option<QueryMap<rustc_middle::dep_graph::DepKind>> {
688690
let tcx = QueryCtxt { tcx, queries: self };
689691
let mut jobs = QueryMap::default();
690692

@@ -718,7 +720,7 @@ macro_rules! define_queries_struct {
718720
mode: QueryMode,
719721
) -> Option<query_stored::$name<'tcx>> {
720722
let qcx = QueryCtxt { tcx, queries: self };
721-
get_query::<queries::$name<'tcx>, _>(qcx, span, key, mode)
723+
get_query::<queries::$name<'tcx>, _, rustc_middle::dep_graph::DepKind>(qcx, span, key, mode)
722724
})*
723725
}
724726
};

compiler/rustc_query_system/src/query/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub trait QueryConfig<Qcx: QueryContext> {
2121
type Cache: QueryCache<Key = Self::Key, Stored = Self::Stored, Value = Self::Value>;
2222

2323
// Don't use this method to access query results, instead use the methods on TyCtxt
24-
fn query_state<'a>(tcx: Qcx) -> &'a QueryState<Self::Key>
24+
fn query_state<'a>(tcx: Qcx) -> &'a QueryState<Self::Key, Qcx::DepKind>
2525
where
2626
Qcx: 'a;
2727

0 commit comments

Comments
 (0)