Auto merge of #94066 - Mark-Simulacrum:factor-out-simple-def-kind, r=davidtwco
Remove SimpleDefKind Now that rustc_query_system depends on rustc_hir, we can just directly make use of the regular DefKind.
This commit is contained in:
commit
026d8ce7f5
|
@ -44,8 +44,6 @@ pub use on_disk_cache::OnDiskCache;
|
||||||
mod profiling_support;
|
mod profiling_support;
|
||||||
pub use self::profiling_support::alloc_self_profile_query_strings;
|
pub use self::profiling_support::alloc_self_profile_query_strings;
|
||||||
|
|
||||||
mod util;
|
|
||||||
|
|
||||||
fn describe_as_module(def_id: LocalDefId, tcx: TyCtxt<'_>) -> String {
|
fn describe_as_module(def_id: LocalDefId, tcx: TyCtxt<'_>) -> String {
|
||||||
if def_id.is_top_level_module() {
|
if def_id.is_top_level_module() {
|
||||||
"top-level module".to_string()
|
"top-level module".to_string()
|
||||||
|
|
|
@ -290,13 +290,11 @@ macro_rules! define_queries {
|
||||||
} else {
|
} else {
|
||||||
Some(key.default_span(*tcx))
|
Some(key.default_span(*tcx))
|
||||||
};
|
};
|
||||||
let def_id = key.key_as_def_id();
|
|
||||||
let def_kind = def_id
|
|
||||||
.and_then(|def_id| def_id.as_local())
|
|
||||||
// Use `tcx.hir().opt_def_kind()` to reduce the chance of
|
// Use `tcx.hir().opt_def_kind()` to reduce the chance of
|
||||||
// accidentally triggering an infinite query loop.
|
// accidentally triggering an infinite query loop.
|
||||||
.and_then(|def_id| tcx.hir().opt_def_kind(def_id))
|
let def_kind = key.key_as_def_id()
|
||||||
.map(|def_kind| $crate::util::def_kind_to_simple_def_kind(def_kind));
|
.and_then(|def_id| def_id.as_local())
|
||||||
|
.and_then(|def_id| tcx.hir().opt_def_kind(def_id));
|
||||||
let hash = || {
|
let hash = || {
|
||||||
let mut hcx = tcx.create_stable_hashing_context();
|
let mut hcx = tcx.create_stable_hashing_context();
|
||||||
let mut hasher = StableHasher::new();
|
let mut hasher = StableHasher::new();
|
||||||
|
|
|
@ -1,18 +0,0 @@
|
||||||
use rustc_hir::def::DefKind;
|
|
||||||
use rustc_query_system::query::SimpleDefKind;
|
|
||||||
|
|
||||||
/// Convert a [`DefKind`] to a [`SimpleDefKind`].
|
|
||||||
///
|
|
||||||
/// *See [`SimpleDefKind`]'s docs for more information.*
|
|
||||||
pub(crate) fn def_kind_to_simple_def_kind(def_kind: DefKind) -> SimpleDefKind {
|
|
||||||
match def_kind {
|
|
||||||
DefKind::Struct => SimpleDefKind::Struct,
|
|
||||||
DefKind::Enum => SimpleDefKind::Enum,
|
|
||||||
DefKind::Union => SimpleDefKind::Union,
|
|
||||||
DefKind::Trait => SimpleDefKind::Trait,
|
|
||||||
DefKind::TyAlias => SimpleDefKind::TyAlias,
|
|
||||||
DefKind::TraitAlias => SimpleDefKind::TraitAlias,
|
|
||||||
|
|
||||||
_ => SimpleDefKind::Other,
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,6 +1,7 @@
|
||||||
use crate::dep_graph::DepContext;
|
use crate::dep_graph::DepContext;
|
||||||
use crate::query::plumbing::CycleError;
|
use crate::query::plumbing::CycleError;
|
||||||
use crate::query::{QueryContext, QueryStackFrame, SimpleDefKind};
|
use crate::query::{QueryContext, QueryStackFrame};
|
||||||
|
use rustc_hir::def::DefKind;
|
||||||
|
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
use rustc_errors::{struct_span_err, Diagnostic, DiagnosticBuilder, Handler, Level};
|
use rustc_errors::{struct_span_err, Diagnostic, DiagnosticBuilder, Handler, Level};
|
||||||
|
@ -555,16 +556,14 @@ pub(crate) fn report_cycle<'a>(
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
if stack.iter().all(|entry| {
|
|
||||||
entry.query.def_kind.map_or(false, |def_kind| {
|
|
||||||
matches!(def_kind, SimpleDefKind::TyAlias | SimpleDefKind::TraitAlias)
|
|
||||||
})
|
|
||||||
}) {
|
|
||||||
if stack.iter().all(|entry| {
|
if stack.iter().all(|entry| {
|
||||||
entry
|
entry
|
||||||
.query
|
.query
|
||||||
.def_kind
|
.def_kind
|
||||||
.map_or(false, |def_kind| matches!(def_kind, SimpleDefKind::TyAlias))
|
.map_or(false, |def_kind| matches!(def_kind, DefKind::TyAlias | DefKind::TraitAlias))
|
||||||
|
}) {
|
||||||
|
if stack.iter().all(|entry| {
|
||||||
|
entry.query.def_kind.map_or(false, |def_kind| matches!(def_kind, DefKind::TyAlias))
|
||||||
}) {
|
}) {
|
||||||
err.note("type aliases cannot be recursive");
|
err.note("type aliases cannot be recursive");
|
||||||
err.help("consider using a struct, enum, or union instead to break the cycle");
|
err.help("consider using a struct, enum, or union instead to break the cycle");
|
||||||
|
|
|
@ -19,6 +19,7 @@ use crate::dep_graph::{DepNodeIndex, HasDepContext, SerializedDepNodeIndex};
|
||||||
use rustc_data_structures::sync::Lock;
|
use rustc_data_structures::sync::Lock;
|
||||||
use rustc_data_structures::thin_vec::ThinVec;
|
use rustc_data_structures::thin_vec::ThinVec;
|
||||||
use rustc_errors::Diagnostic;
|
use rustc_errors::Diagnostic;
|
||||||
|
use rustc_hir::def::DefKind;
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
|
|
||||||
/// Description of a frame in the query stack.
|
/// Description of a frame in the query stack.
|
||||||
|
@ -29,46 +30,20 @@ pub struct QueryStackFrame {
|
||||||
pub name: &'static str,
|
pub name: &'static str,
|
||||||
pub description: String,
|
pub description: String,
|
||||||
span: Option<Span>,
|
span: Option<Span>,
|
||||||
/// The `DefKind` this query frame is associated with, if applicable.
|
def_kind: Option<DefKind>,
|
||||||
///
|
|
||||||
/// We can't use `rustc_hir::def::DefKind` because `rustc_hir` is not
|
|
||||||
/// available in `rustc_query_system`. Instead, we have a simplified
|
|
||||||
/// custom version of it, called [`SimpleDefKind`].
|
|
||||||
def_kind: Option<SimpleDefKind>,
|
|
||||||
/// This hash is used to deterministically pick
|
/// This hash is used to deterministically pick
|
||||||
/// a query to remove cycles in the parallel compiler.
|
/// a query to remove cycles in the parallel compiler.
|
||||||
#[cfg(parallel_compiler)]
|
#[cfg(parallel_compiler)]
|
||||||
hash: u64,
|
hash: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A simplified version of `rustc_hir::def::DefKind`.
|
|
||||||
///
|
|
||||||
/// It was added to help improve cycle errors caused by recursive type aliases.
|
|
||||||
/// As of August 2021, `rustc_query_system` cannot depend on `rustc_hir`
|
|
||||||
/// because it would create a dependency cycle. So, instead, a simplified
|
|
||||||
/// version of `DefKind` was added to `rustc_query_system`.
|
|
||||||
///
|
|
||||||
/// `DefKind`s are converted to `SimpleDefKind`s in `rustc_query_impl`.
|
|
||||||
#[derive(Debug, Copy, Clone)]
|
|
||||||
pub enum SimpleDefKind {
|
|
||||||
Struct,
|
|
||||||
Enum,
|
|
||||||
Union,
|
|
||||||
Trait,
|
|
||||||
TyAlias,
|
|
||||||
TraitAlias,
|
|
||||||
|
|
||||||
// FIXME: add more from `rustc_hir::def::DefKind` and then remove `Other`
|
|
||||||
Other,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl QueryStackFrame {
|
impl QueryStackFrame {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new(
|
pub fn new(
|
||||||
name: &'static str,
|
name: &'static str,
|
||||||
description: String,
|
description: String,
|
||||||
span: Option<Span>,
|
span: Option<Span>,
|
||||||
def_kind: Option<SimpleDefKind>,
|
def_kind: Option<DefKind>,
|
||||||
_hash: impl FnOnce() -> u64,
|
_hash: impl FnOnce() -> u64,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
|
Loading…
Reference in a new issue