1
Fork 0

Note that type aliases cannot be recursive

This commit is contained in:
Noah Lev 2021-08-19 20:30:33 -07:00
parent 2f48bfa88c
commit cd0fc444fb
7 changed files with 84 additions and 2 deletions

View file

@ -29,24 +29,53 @@ pub struct QueryStackFrame {
pub name: &'static str,
pub description: String,
span: Option<Span>,
/// The `DefKind` this query frame is associated with, if applicable.
///
/// 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
/// a query to remove cycles in the parallel compiler.
#[cfg(parallel_compiler)]
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 {
#[inline]
pub fn new(
name: &'static str,
description: String,
span: Option<Span>,
def_kind: Option<SimpleDefKind>,
_hash: impl FnOnce() -> u64,
) -> Self {
Self {
name,
description,
span,
def_kind,
#[cfg(parallel_compiler)]
hash: _hash(),
}