Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4534,9 +4534,11 @@ version = "0.0.0"
dependencies = [
"measureme",
"rustc_data_structures",
"rustc_errors",
"rustc_hashes",
"rustc_hir",
"rustc_index",
"rustc_macros",
"rustc_middle",
"rustc_query_system",
"rustc_serialize",
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_middle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ pub mod thir;
pub mod traits;
pub mod ty;
pub mod util;
mod values;

#[macro_use]
pub mod query;
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ mod keys;
pub mod on_disk_cache;
#[macro_use]
pub mod plumbing;
pub mod values;

pub fn describe_as_module(def_id: impl Into<LocalDefId>, tcx: TyCtxt<'_>) -> String {
let def_id = def_id.into();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use rustc_errors::codes::*;
use rustc_errors::{Applicability, MultiSpan, pluralize, struct_span_code_err};
use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res};
use rustc_query_system::Value;
use rustc_query_system::query::{CycleError, report_cycle};
use rustc_span::def_id::LocalDefId;
use rustc_span::{ErrorGuaranteed, Span};
Expand All @@ -16,21 +15,41 @@ use crate::dep_graph::dep_kinds;
use crate::query::plumbing::CyclePlaceholder;
use crate::ty::{self, Representability, Ty, TyCtxt};

impl<'tcx> Value<TyCtxt<'tcx>> for Ty<'_> {
pub trait Value<'tcx>: Sized {
fn from_cycle_error(tcx: TyCtxt<'tcx>, cycle_error: &CycleError, guar: ErrorGuaranteed)
-> Self;
}

impl<'tcx, T> Value<'tcx> for T {
default fn from_cycle_error(
tcx: TyCtxt<'tcx>,
cycle_error: &CycleError,
_guar: ErrorGuaranteed,
) -> T {
tcx.sess.dcx().abort_if_errors();
bug!(
"<{} as Value>::from_cycle_error called without errors: {:#?}",
std::any::type_name::<T>(),
cycle_error.cycle,
);
}
}

impl<'tcx> Value<'tcx> for Ty<'_> {
fn from_cycle_error(tcx: TyCtxt<'tcx>, _: &CycleError, guar: ErrorGuaranteed) -> Self {
// SAFETY: This is never called when `Self` is not `Ty<'tcx>`.
// FIXME: Represent the above fact in the trait system somehow.
unsafe { std::mem::transmute::<Ty<'tcx>, Ty<'_>>(Ty::new_error(tcx, guar)) }
}
}

impl<'tcx> Value<TyCtxt<'tcx>> for Result<ty::EarlyBinder<'_, Ty<'_>>, CyclePlaceholder> {
impl<'tcx> Value<'tcx> for Result<ty::EarlyBinder<'_, Ty<'_>>, CyclePlaceholder> {
fn from_cycle_error(_tcx: TyCtxt<'tcx>, _: &CycleError, guar: ErrorGuaranteed) -> Self {
Err(CyclePlaceholder(guar))
}
}

impl<'tcx> Value<TyCtxt<'tcx>> for ty::SymbolName<'_> {
impl<'tcx> Value<'tcx> for ty::SymbolName<'_> {
fn from_cycle_error(tcx: TyCtxt<'tcx>, _: &CycleError, _guar: ErrorGuaranteed) -> Self {
// SAFETY: This is never called when `Self` is not `SymbolName<'tcx>`.
// FIXME: Represent the above fact in the trait system somehow.
Expand All @@ -42,7 +61,7 @@ impl<'tcx> Value<TyCtxt<'tcx>> for ty::SymbolName<'_> {
}
}

impl<'tcx> Value<TyCtxt<'tcx>> for ty::Binder<'_, ty::FnSig<'_>> {
impl<'tcx> Value<'tcx> for ty::Binder<'_, ty::FnSig<'_>> {
fn from_cycle_error(
tcx: TyCtxt<'tcx>,
cycle_error: &CycleError,
Expand Down Expand Up @@ -76,7 +95,7 @@ impl<'tcx> Value<TyCtxt<'tcx>> for ty::Binder<'_, ty::FnSig<'_>> {
}
}

impl<'tcx> Value<TyCtxt<'tcx>> for Representability {
impl<'tcx> Value<'tcx> for Representability {
fn from_cycle_error(
tcx: TyCtxt<'tcx>,
cycle_error: &CycleError,
Expand Down Expand Up @@ -112,7 +131,7 @@ impl<'tcx> Value<TyCtxt<'tcx>> for Representability {
}
}

impl<'tcx> Value<TyCtxt<'tcx>> for ty::EarlyBinder<'_, Ty<'_>> {
impl<'tcx> Value<'tcx> for ty::EarlyBinder<'_, Ty<'_>> {
fn from_cycle_error(
tcx: TyCtxt<'tcx>,
cycle_error: &CycleError,
Expand All @@ -122,7 +141,7 @@ impl<'tcx> Value<TyCtxt<'tcx>> for ty::EarlyBinder<'_, Ty<'_>> {
}
}

impl<'tcx> Value<TyCtxt<'tcx>> for ty::EarlyBinder<'_, ty::Binder<'_, ty::FnSig<'_>>> {
impl<'tcx> Value<'tcx> for ty::EarlyBinder<'_, ty::Binder<'_, ty::FnSig<'_>>> {
fn from_cycle_error(
tcx: TyCtxt<'tcx>,
cycle_error: &CycleError,
Expand All @@ -132,7 +151,7 @@ impl<'tcx> Value<TyCtxt<'tcx>> for ty::EarlyBinder<'_, ty::Binder<'_, ty::FnSig<
}
}

impl<'tcx> Value<TyCtxt<'tcx>> for &[ty::Variance] {
impl<'tcx> Value<'tcx> for &[ty::Variance] {
fn from_cycle_error(
tcx: TyCtxt<'tcx>,
cycle_error: &CycleError,
Expand Down Expand Up @@ -180,7 +199,7 @@ fn search_for_cycle_permutation<Q, T>(
otherwise()
}

impl<'tcx, T> Value<TyCtxt<'tcx>> for Result<T, &'_ ty::layout::LayoutError<'_>> {
impl<'tcx, T> Value<'tcx> for Result<T, &'_ ty::layout::LayoutError<'_>> {
fn from_cycle_error(
tcx: TyCtxt<'tcx>,
cycle_error: &CycleError,
Expand Down Expand Up @@ -273,7 +292,7 @@ impl<'tcx, T> Value<TyCtxt<'tcx>> for Result<T, &'_ ty::layout::LayoutError<'_>>

// item_and_field_ids should form a cycle where each field contains the
// type in the next element in the list
pub fn recursive_type_error(
fn recursive_type_error(
tcx: TyCtxt<'_>,
mut item_and_field_ids: Vec<(LocalDefId, LocalDefId)>,
representable_ids: &FxHashSet<LocalDefId>,
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_query_impl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ edition = "2024"
# tidy-alphabetical-start
measureme = "12.0.1"
rustc_data_structures = { path = "../rustc_data_structures" }
rustc_errors = { path = "../rustc_errors" }
rustc_hashes = { path = "../rustc_hashes" }
rustc_hir = { path = "../rustc_hir" }
rustc_index = { path = "../rustc_index" }
rustc_macros = { path = "../rustc_macros" }
rustc_middle = { path = "../rustc_middle" }
rustc_query_system = { path = "../rustc_query_system" }
rustc_serialize = { path = "../rustc_serialize" }
Expand Down
24 changes: 24 additions & 0 deletions compiler/rustc_query_impl/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use rustc_hir::limit::Limit;
use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_span::{Span, Symbol};

#[derive(Diagnostic)]
#[help(
"consider increasing the recursion limit by adding a `#![recursion_limit = \"{$suggested_limit}\"]` attribute to your crate (`{$crate_name}`)"
)]
#[diag("queries overflow the depth limit!")]
pub(crate) struct QueryOverflow {
#[primary_span]
pub span: Span,
#[subdiagnostic]
pub note: QueryOverflowNote,
pub suggested_limit: Limit,
pub crate_name: Symbol,
}

#[derive(Subdiagnostic)]
#[note("query depth increased by {$depth} when {$desc}")]
pub(crate) struct QueryOverflowNote {
pub desc: String,
pub depth: usize,
}
4 changes: 3 additions & 1 deletion compiler/rustc_query_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ use rustc_middle::queries::{
use rustc_middle::query::AsLocalKey;
use rustc_middle::query::on_disk_cache::{CacheEncoder, EncodedDepNodeIndex, OnDiskCache};
use rustc_middle::query::plumbing::{QuerySystem, QuerySystemFns, QueryVTable};
use rustc_middle::query::values::Value;
use rustc_middle::ty::TyCtxt;
use rustc_query_system::Value;
use rustc_query_system::dep_graph::SerializedDepNodeIndex;
use rustc_query_system::ich::StableHashingContext;
use rustc_query_system::query::{
Expand All @@ -39,6 +39,8 @@ pub use crate::plumbing::{QueryCtxt, query_key_hash_verify_all};
mod profiling_support;
pub use self::profiling_support::alloc_self_profile_query_strings;

mod error;

#[derive(ConstParamTy)] // Allow this struct to be used for const-generic values.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
struct QueryFlags {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_query_impl/src/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ use rustc_query_system::query::{
QueryCache, QueryContext, QueryDispatcher, QueryJobId, QueryMap, QuerySideEffect,
QueryStackDeferred, QueryStackFrame, QueryStackFrameExtra, force_query,
};
use rustc_query_system::{QueryOverflow, QueryOverflowNote};
use rustc_serialize::{Decodable, Encodable};
use rustc_span::def_id::LOCAL_CRATE;

use crate::QueryDispatcherUnerased;
use crate::error::{QueryOverflow, QueryOverflowNote};

/// Implements [`QueryContext`] for use by [`rustc_query_system`], since that
/// crate does not have direct access to [`TyCtxt`].
Expand Down
7 changes: 0 additions & 7 deletions compiler/rustc_query_system/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@ impl<Key, Value> Default for Cache<Key, Value> {
}
}

impl<Key, Value> Cache<Key, Value> {
/// Actually frees the underlying memory in contrast to what stdlib containers do on `clear`
pub fn clear(&self) {
*self.hashmap.borrow_mut() = Default::default();
}
}

impl<Key: Eq + Hash, Value: Clone> Cache<Key, Value> {
pub fn get<Tcx: DepContext>(&self, key: &Key, tcx: Tcx) -> Option<Value> {
Some(self.hashmap.borrow().get(key)?.get(tcx))
Expand Down
24 changes: 1 addition & 23 deletions compiler/rustc_query_system/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use rustc_errors::codes::*;
use rustc_hir::limit::Limit;
use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_span::{Span, Symbol};
use rustc_span::Span;

#[derive(Subdiagnostic)]
#[note("...which requires {$desc}...")]
Expand Down Expand Up @@ -75,24 +74,3 @@ pub(crate) struct IncrementCompilation {
pub run_cmd: String,
pub dep_node: String,
}

#[derive(Diagnostic)]
#[help(
"consider increasing the recursion limit by adding a `#![recursion_limit = \"{$suggested_limit}\"]` attribute to your crate (`{$crate_name}`)"
)]
#[diag("queries overflow the depth limit!")]
pub struct QueryOverflow {
#[primary_span]
pub span: Span,
#[subdiagnostic]
pub note: QueryOverflowNote,
pub suggested_limit: Limit,
pub crate_name: Symbol,
}

#[derive(Subdiagnostic)]
#[note("query depth increased by {$depth} when {$desc}")]
pub struct QueryOverflowNote {
pub desc: String,
pub depth: usize,
}
4 changes: 0 additions & 4 deletions compiler/rustc_query_system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,3 @@ pub mod dep_graph;
mod error;
pub mod ich;
pub mod query;
mod values;

pub use error::{QueryOverflow, QueryOverflowNote};
pub use values::Value;
21 changes: 0 additions & 21 deletions compiler/rustc_query_system/src/values.rs

This file was deleted.

Loading