1
Fork 0

Rewrite representability

This commit is contained in:
Cameron Steffen 2022-08-15 14:11:11 -05:00
parent e42c4d7218
commit ff940db666
61 changed files with 537 additions and 744 deletions

View file

@ -551,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());
@ -569,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(),
});
}

View file

@ -18,6 +18,7 @@ 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(),
}

View file

@ -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)
}
}
}

View file

@ -1,11 +1,12 @@
use crate::dep_graph::DepContext;
use crate::query::QueryInfo;
pub trait Value<CTX: DepContext>: Sized {
fn from_cycle_error(tcx: CTX) -> Self;
fn from_cycle_error(tcx: CTX, cycle: &[QueryInfo]) -> Self;
}
impl<CTX: DepContext, T> Value<CTX> for T {
default fn from_cycle_error(tcx: CTX) -> T {
default fn from_cycle_error(tcx: CTX, _: &[QueryInfo]) -> T {
tcx.sess().abort_if_errors();
// Ideally we would use `bug!` here. But bug! is only defined in rustc_middle, and it's
// non-trivial to define it earlier.