summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_query_system/src/query
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--compiler/rustc_query_system/src/query/config.rs2
-rw-r--r--compiler/rustc_query_system/src/query/job.rs33
-rw-r--r--compiler/rustc_query_system/src/query/mod.rs15
-rw-r--r--compiler/rustc_query_system/src/query/plumbing.rs11
4 files changed, 43 insertions, 18 deletions
diff --git a/compiler/rustc_query_system/src/query/config.rs b/compiler/rustc_query_system/src/query/config.rs
index c4549cc9e..0a1cffa3b 100644
--- a/compiler/rustc_query_system/src/query/config.rs
+++ b/compiler/rustc_query_system/src/query/config.rs
@@ -49,8 +49,6 @@ impl<CTX: QueryContext, K, V> QueryVTable<CTX, K, V> {
pub trait QueryDescription<CTX: QueryContext>: QueryConfig {
type Cache: QueryCache<Key = Self::Key, Stored = Self::Stored, Value = Self::Value>;
- fn describe(tcx: CTX, key: Self::Key) -> String;
-
// Don't use this method to access query results, instead use the methods on TyCtxt
fn query_state<'a>(tcx: CTX) -> &'a QueryState<Self::Key>
where
diff --git a/compiler/rustc_query_system/src/query/job.rs b/compiler/rustc_query_system/src/query/job.rs
index 45b4079fb..ed65393f5 100644
--- a/compiler/rustc_query_system/src/query/job.rs
+++ b/compiler/rustc_query_system/src/query/job.rs
@@ -3,9 +3,11 @@ use crate::query::plumbing::CycleError;
use crate::query::{QueryContext, QueryStackFrame};
use rustc_data_structures::fx::FxHashMap;
-use rustc_errors::{Diagnostic, DiagnosticBuilder, ErrorGuaranteed, Handler, Level};
+use rustc_errors::{
+ Diagnostic, DiagnosticBuilder, ErrorGuaranteed, Handler, IntoDiagnostic, Level,
+};
use rustc_hir::def::DefKind;
-use rustc_session::{Session, SessionDiagnostic};
+use rustc_session::Session;
use rustc_span::Span;
use std::hash::Hash;
@@ -59,6 +61,7 @@ impl QueryJobId {
}
}
+#[derive(Clone)]
pub struct QueryJobInfo {
pub query: QueryStackFrame,
pub job: QueryJob,
@@ -116,10 +119,10 @@ impl QueryJob {
}
}
-#[cfg(not(parallel_compiler))]
impl QueryJobId {
#[cold]
#[inline(never)]
+ #[cfg(not(parallel_compiler))]
pub(super) fn find_cycle_in_stack(
&self,
query_map: QueryMap,
@@ -156,6 +159,24 @@ impl QueryJobId {
panic!("did not find a cycle")
}
+
+ #[cold]
+ #[inline(never)]
+ pub fn try_find_layout_root(&self, query_map: QueryMap) -> Option<(QueryJobInfo, usize)> {
+ let mut last_layout = None;
+ let mut current_id = Some(*self);
+ let mut depth = 0;
+
+ while let Some(id) = current_id {
+ let info = query_map.get(&id).unwrap();
+ if info.query.name == "layout_of" {
+ depth += 1;
+ last_layout = Some((info.clone(), depth));
+ }
+ current_id = info.job.parent;
+ }
+ last_layout
+ }
}
#[cfg(parallel_compiler)]
@@ -530,7 +551,7 @@ pub fn deadlock(query_map: QueryMap, registry: &rayon_core::Registry) {
#[cold]
pub(crate) fn report_cycle<'a>(
sess: &'a Session,
- CycleError { usage, cycle: stack }: CycleError,
+ CycleError { usage, cycle: stack }: &CycleError,
) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
assert!(!stack.is_empty());
@@ -548,10 +569,10 @@ pub(crate) fn report_cycle<'a>(
}
let mut cycle_usage = None;
- if let Some((span, query)) = usage {
+ if let Some((span, ref query)) = *usage {
cycle_usage = Some(crate::error::CycleUsage {
span: query.default_span(span),
- usage: query.description,
+ usage: query.description.to_string(),
});
}
diff --git a/compiler/rustc_query_system/src/query/mod.rs b/compiler/rustc_query_system/src/query/mod.rs
index 0b07bb64b..118703fc0 100644
--- a/compiler/rustc_query_system/src/query/mod.rs
+++ b/compiler/rustc_query_system/src/query/mod.rs
@@ -14,10 +14,11 @@ pub use self::caches::{
mod config;
pub use self::config::{QueryConfig, QueryDescription, QueryVTable};
-use crate::dep_graph::{DepContext, DepNodeIndex, HasDepContext, SerializedDepNodeIndex};
+use crate::dep_graph::{DepNodeIndex, HasDepContext, SerializedDepNodeIndex};
use rustc_data_structures::sync::Lock;
use rustc_errors::Diagnostic;
use rustc_hir::def::DefKind;
+use rustc_span::def_id::DefId;
use rustc_span::Span;
use thin_vec::ThinVec;
@@ -29,7 +30,9 @@ pub struct QueryStackFrame {
pub name: &'static str,
pub description: String,
span: Option<Span>,
- def_kind: Option<DefKind>,
+ pub def_id: Option<DefId>,
+ pub def_kind: Option<DefKind>,
+ pub ty_adt_id: Option<DefId>,
/// This hash is used to deterministically pick
/// a query to remove cycles in the parallel compiler.
#[cfg(parallel_compiler)]
@@ -42,14 +45,18 @@ impl QueryStackFrame {
name: &'static str,
description: String,
span: Option<Span>,
+ def_id: Option<DefId>,
def_kind: Option<DefKind>,
+ ty_adt_id: Option<DefId>,
_hash: impl FnOnce() -> u64,
) -> Self {
Self {
name,
description,
span,
+ def_id,
def_kind,
+ ty_adt_id,
#[cfg(parallel_compiler)]
hash: _hash(),
}
@@ -123,7 +130,5 @@ pub trait QueryContext: HasDepContext {
compute: impl FnOnce() -> R,
) -> R;
- fn depth_limit_error(&self) {
- self.dep_context().sess().emit_fatal(crate::error::QueryOverflow);
- }
+ fn depth_limit_error(&self, job: QueryJobId);
}
diff --git a/compiler/rustc_query_system/src/query/plumbing.rs b/compiler/rustc_query_system/src/query/plumbing.rs
index 8179a674a..15b89daa6 100644
--- a/compiler/rustc_query_system/src/query/plumbing.rs
+++ b/compiler/rustc_query_system/src/query/plumbing.rs
@@ -119,7 +119,7 @@ where
#[inline(never)]
fn mk_cycle<CTX, V, R>(
tcx: CTX,
- error: CycleError,
+ cycle_error: CycleError,
handler: HandleCycleError,
cache: &dyn crate::query::QueryStorage<Value = V, Stored = R>,
) -> R
@@ -128,13 +128,14 @@ where
V: std::fmt::Debug + Value<CTX::DepContext>,
R: Clone,
{
- let error = report_cycle(tcx.dep_context().sess(), error);
- let value = handle_cycle_error(*tcx.dep_context(), error, handler);
+ let error = report_cycle(tcx.dep_context().sess(), &cycle_error);
+ let value = handle_cycle_error(*tcx.dep_context(), &cycle_error, error, handler);
cache.store_nocache(value)
}
fn handle_cycle_error<CTX, V>(
tcx: CTX,
+ cycle_error: &CycleError,
mut error: DiagnosticBuilder<'_, ErrorGuaranteed>,
handler: HandleCycleError,
) -> V
@@ -146,7 +147,7 @@ where
match handler {
Error => {
error.emit();
- Value::from_cycle_error(tcx)
+ Value::from_cycle_error(tcx, &cycle_error.cycle)
}
Fatal => {
error.emit();
@@ -155,7 +156,7 @@ where
}
DelayBug => {
error.delay_as_bug();
- Value::from_cycle_error(tcx)
+ Value::from_cycle_error(tcx, &cycle_error.cycle)
}
}
}