Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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
10 changes: 6 additions & 4 deletions compiler/rustc_interface/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use rustc_data_structures::sync;
use rustc_metadata::{DylibError, EncodedMetadata, load_symbol_from_dylib};
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
use rustc_middle::ty::{CurrentGcx, TyCtxt};
use rustc_query_impl::collect_active_jobs_from_all_queries;
use rustc_query_impl::{CollectActiveJobsKind, collect_active_jobs_from_all_queries};
use rustc_session::config::{
Cfg, CrateType, OutFileName, OutputFilenames, OutputTypes, Sysroot, host_tuple,
};
Expand Down Expand Up @@ -253,9 +253,11 @@ internal compiler error: query cycle handler thread panicked, aborting process";
unsafe { &*(session_globals as *const SessionGlobals) },
|| {
// Ensure there were no errors collecting all active jobs.
// We need the complete map to ensure we find a cycle to break.
collect_active_jobs_from_all_queries(tcx, false).expect(
"failed to collect active queries in deadlock handler",
// We need the complete map to ensure we find a cycle to
// break.
collect_active_jobs_from_all_queries(
tcx,
CollectActiveJobsKind::FullNoContention,
)
},
);
Expand Down
16 changes: 5 additions & 11 deletions compiler/rustc_lint/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ pub trait LintContext {
///
/// [`emit_lint_base`]: rustc_middle::lint::emit_lint_base#decorate-signature
#[track_caller]
fn opt_span_diag_lint<S: Into<MultiSpan>>(
fn opt_span_lint<S: Into<MultiSpan>>(
&self,
lint: &'static Lint,
span: Option<S>,
Expand All @@ -532,13 +532,7 @@ pub trait LintContext {
span: S,
decorator: impl for<'a> Diagnostic<'a, ()>,
) {
self.opt_span_diag_lint(lint, Some(span), decorator);
}

/// Emit a lint from a lint struct (some type that implements `Diagnostic`, typically
/// generated by `#[derive(Diagnostic)]`).
fn emit_diag_lint(&self, lint: &'static Lint, decorator: impl for<'a> Diagnostic<'a, ()>) {
self.opt_span_diag_lint(lint, None as Option<Span>, decorator);
self.opt_span_lint(lint, Some(span), decorator);
}

/// This returns the lint level for the given lint at the current location.
Expand Down Expand Up @@ -594,7 +588,7 @@ impl<'tcx> LintContext for LateContext<'tcx> {
self.tcx.sess
}

fn opt_span_diag_lint<S: Into<MultiSpan>>(
fn opt_span_lint<S: Into<MultiSpan>>(
&self,
lint: &'static Lint,
span: Option<S>,
Expand All @@ -619,13 +613,13 @@ impl LintContext for EarlyContext<'_> {
self.builder.sess()
}

fn opt_span_diag_lint<S: Into<MultiSpan>>(
fn opt_span_lint<S: Into<MultiSpan>>(
&self,
lint: &'static Lint,
span: Option<S>,
decorator: impl for<'a> Diagnostic<'a, ()>,
) {
self.builder.opt_span_diag_lint(lint, span.map(|s| s.into()), decorator)
self.builder.opt_span_lint(lint, span.map(|s| s.into()), decorator)
}

fn get_lint_level(&self, lint: &'static Lint) -> LevelAndSource {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_lint/src/early.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl<'ecx, 'tcx, T: EarlyLintPass> EarlyContextAndPass<'ecx, 'tcx, T> {
let BufferedEarlyLint { span, node_id: _, lint_id, diagnostic } = early_lint;
match diagnostic {
DecorateDiagCompat::Builtin(b) => {
self.context.opt_span_diag_lint(
self.context.opt_span_lint(
lint_id.lint,
span,
DecorateBuiltinLint {
Expand All @@ -50,7 +50,7 @@ impl<'ecx, 'tcx, T: EarlyLintPass> EarlyContextAndPass<'ecx, 'tcx, T> {
);
}
DecorateDiagCompat::Dynamic(d) => {
self.context.opt_span_diag_lint(lint_id.lint, span, d);
self.context.opt_span_lint(lint_id.lint, span, d);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/levels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
/// Used to emit a lint-related diagnostic based on the current state of
/// this lint context.
#[track_caller]
pub(crate) fn opt_span_diag_lint(
pub(crate) fn opt_span_lint(
&self,
lint: &'static Lint,
span: Option<MultiSpan>,
Expand Down
15 changes: 0 additions & 15 deletions compiler/rustc_macros/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ struct QueryModifiers {
anon: Option<Ident>,
arena_cache: Option<Ident>,
cache_on_disk_if: Option<CacheOnDiskIf>,
cycle_delay_bug: Option<Ident>,
depth_limit: Option<Ident>,
desc: Desc,
eval_always: Option<Ident>,
Expand All @@ -157,7 +156,6 @@ fn parse_query_modifiers(input: ParseStream<'_>) -> Result<QueryModifiers> {
let mut arena_cache = None;
let mut cache_on_disk_if = None;
let mut desc = None;
let mut cycle_delay_bug = None;
let mut no_hash = None;
let mut anon = None;
let mut eval_always = None;
Expand Down Expand Up @@ -191,8 +189,6 @@ fn parse_query_modifiers(input: ParseStream<'_>) -> Result<QueryModifiers> {
try_insert!(cache_on_disk_if = CacheOnDiskIf { modifier, block });
} else if modifier == "arena_cache" {
try_insert!(arena_cache = modifier);
} else if modifier == "cycle_delay_bug" {
try_insert!(cycle_delay_bug = modifier);
} else if modifier == "no_hash" {
try_insert!(no_hash = modifier);
} else if modifier == "anon" {
Expand All @@ -216,7 +212,6 @@ fn parse_query_modifiers(input: ParseStream<'_>) -> Result<QueryModifiers> {
arena_cache,
cache_on_disk_if,
desc,
cycle_delay_bug,
no_hash,
anon,
eval_always,
Expand Down Expand Up @@ -251,7 +246,6 @@ fn make_modifiers_stream(query: &Query) -> proc_macro2::TokenStream {
anon,
arena_cache,
cache_on_disk_if,
cycle_delay_bug,
depth_limit,
desc: _,
eval_always,
Expand All @@ -264,13 +258,6 @@ fn make_modifiers_stream(query: &Query) -> proc_macro2::TokenStream {
let anon = anon.is_some();
let arena_cache = arena_cache.is_some();
let cache_on_disk = cache_on_disk_if.is_some();

let cycle_error_handling = if cycle_delay_bug.is_some() {
quote! { DelayBug }
} else {
quote! { Error }
};

let depth_limit = depth_limit.is_some();
let eval_always = eval_always.is_some();
let feedable = feedable.is_some();
Expand All @@ -289,7 +276,6 @@ fn make_modifiers_stream(query: &Query) -> proc_macro2::TokenStream {
anon: #anon,
arena_cache: #arena_cache,
cache_on_disk: #cache_on_disk,
cycle_error_handling: #cycle_error_handling,
depth_limit: #depth_limit,
eval_always: #eval_always,
feedable: #feedable,
Expand Down Expand Up @@ -402,7 +388,6 @@ fn add_to_analyzer_stream(query: &Query, analyzer_stream: &mut proc_macro2::Toke

doc_link!(
arena_cache,
cycle_delay_bug,
no_hash,
anon,
eval_always,
Expand Down
19 changes: 7 additions & 12 deletions compiler/rustc_middle/src/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -564,13 +564,13 @@ rustc_queries! {
}

/// Checks whether a type is representable or infinitely sized
query check_representability(key: LocalDefId) -> rustc_middle::ty::Representability {
//
// Infinitely sized types will cause a cycle. The `value_from_cycle_error` impl will print
// a custom error about the infinite size and then abort compilation. (In the past we
// recovered and continued, but in practice that leads to confusing subsequent error
// messages about cycles that then abort.)
query check_representability(key: LocalDefId) {
desc { "checking if `{}` is representable", tcx.def_path_str(key) }
// Infinitely sized types will cause a cycle. The custom `FromCycleError` impl for
// `Representability` will print a custom error about the infinite size and then abort
// compilation. (In the past we recovered and continued, but in practice that leads to
// confusing subsequent error messages about cycles that then abort.)
cycle_delay_bug
// We don't want recursive representability calls to be forced with
// incremental compilation because, if a cycle occurs, we need the
// entire cycle to be in memory for diagnostics. This means we can't
Expand All @@ -580,9 +580,8 @@ rustc_queries! {

/// An implementation detail for the `check_representability` query. See that query for more
/// details, particularly on the modifiers.
query check_representability_adt_ty(key: Ty<'tcx>) -> rustc_middle::ty::Representability {
query check_representability_adt_ty(key: Ty<'tcx>) {
desc { "checking if `{}` is representable", key }
cycle_delay_bug
anon
}

Expand Down Expand Up @@ -1027,7 +1026,6 @@ rustc_queries! {
desc { "computing the variances of `{}`", tcx.def_path_str(def_id) }
cache_on_disk_if { def_id.is_local() }
separate_provide_extern
cycle_delay_bug
}

/// Gets a map with the inferred outlives-predicates of every item in the local crate.
Expand Down Expand Up @@ -1160,7 +1158,6 @@ rustc_queries! {
desc { "computing function signature of `{}`", tcx.def_path_str(key) }
cache_on_disk_if { key.is_local() }
separate_provide_extern
cycle_delay_bug
}

/// Performs lint checking for the module.
Expand Down Expand Up @@ -1751,8 +1748,6 @@ rustc_queries! {
) -> Result<ty::layout::TyAndLayout<'tcx>, &'tcx ty::layout::LayoutError<'tcx>> {
depth_limit
desc { "computing layout of `{}`", key.value }
// we emit our own error during query cycle handling
cycle_delay_bug
}

/// Compute a `FnAbi` suitable for indirect calls, i.e. to `fn` pointers.
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_middle/src/query/erase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,6 @@ impl_erasable_for_simple_types! {
rustc_middle::ty::Destructor,
rustc_middle::ty::fast_reject::SimplifiedType,
rustc_middle::ty::ImplPolarity,
rustc_middle::ty::Representability,
rustc_middle::ty::UnusedGenericParams,
rustc_middle::ty::util::AlwaysRequiresDrop,
rustc_middle::ty::Visibility<rustc_span::def_id::DefId>,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ pub use self::caches::{DefIdCache, DefaultCache, QueryCache, SingleCache, VecCac
pub use self::job::{QueryInfo, QueryJob, QueryJobId, QueryLatch, QueryWaiter};
pub use self::keys::{AsLocalQueryKey, LocalCrate, QueryKey};
pub use self::plumbing::{
ActiveKeyStatus, CycleError, CycleErrorHandling, EnsureMode, IntoQueryParam, QueryMode,
QueryState, TyCtxtAt, TyCtxtEnsureDone, TyCtxtEnsureOk, TyCtxtEnsureResult,
ActiveKeyStatus, CycleError, EnsureMode, IntoQueryParam, QueryMode, QueryState, TyCtxtAt,
TyCtxtEnsureDone, TyCtxtEnsureOk, TyCtxtEnsureResult,
};
pub use self::stack::QueryStackFrame;
pub use crate::queries::Providers;
Expand Down
5 changes: 0 additions & 5 deletions compiler/rustc_middle/src/query/modifiers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ pub(crate) struct arena_cache;
/// identifier is available for use within the block, as is `tcx`.
pub(crate) struct cache_on_disk_if;

/// # `cycle_delay_bug` query modifier
///
/// If a dependency cycle is detected, emit a delayed bug instead of a normal error.
pub(crate) struct cycle_delay_bug;

/// # `depth_limit` query modifier
///
/// Impose a recursion call depth limit on the query to prevent stack overflow.
Expand Down
22 changes: 7 additions & 15 deletions compiler/rustc_middle/src/query/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ use rustc_data_structures::fingerprint::Fingerprint;
use rustc_data_structures::hash_table::HashTable;
use rustc_data_structures::sharded::Sharded;
use rustc_data_structures::sync::{AtomicU64, WorkerLocal};
use rustc_errors::Diag;
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::hir_id::OwnerId;
use rustc_span::{ErrorGuaranteed, Span};
use rustc_span::Span;
pub use sealed::IntoQueryParam;

use crate::dep_graph::{DepKind, DepNodeIndex, SerializedDepNodeIndex};
Expand Down Expand Up @@ -49,16 +50,6 @@ pub enum ActiveKeyStatus<'tcx> {
Poisoned,
}

/// How a particular query deals with query cycle errors.
///
/// Inspected by the code that actually handles cycle errors, to decide what
/// approach to use.
#[derive(Copy, Clone)]
pub enum CycleErrorHandling {
Error,
DelayBug,
}

#[derive(Clone, Debug)]
pub struct CycleError<'tcx> {
/// The query and related span that uses the cycle.
Expand Down Expand Up @@ -98,8 +89,6 @@ pub struct QueryVTable<'tcx, C: QueryCache> {
pub feedable: bool,

pub dep_kind: DepKind,
/// How this query deals with query cycle errors.
pub cycle_error_handling: CycleErrorHandling,
pub state: QueryState<'tcx, C::Key>,
pub cache: C,

Expand Down Expand Up @@ -127,12 +116,16 @@ pub struct QueryVTable<'tcx, C: QueryCache> {
/// For `no_hash` queries, this function pointer is None.
pub hash_value_fn: Option<fn(&mut StableHashingContext<'_>, &C::Value) -> Fingerprint>,

/// Function pointer that handles a cycle error. `error` must be consumed, e.g. with `emit` (if
/// it should be emitted) or `delay_as_bug` (if it need not be emitted because an alternative
/// error is created and emitted).
pub value_from_cycle_error: fn(
tcx: TyCtxt<'tcx>,
key: C::Key,
cycle_error: CycleError<'tcx>,
guar: ErrorGuaranteed,
error: Diag<'_>,
) -> C::Value,

pub format_value: fn(&C::Value) -> String,

pub create_tagged_key: fn(C::Key) -> TaggedQueryKey<'tcx>,
Expand Down Expand Up @@ -295,7 +288,6 @@ macro_rules! define_callbacks {
anon: $anon:literal,
arena_cache: $arena_cache:literal,
cache_on_disk: $cache_on_disk:literal,
cycle_error_handling: $cycle_error_handling:ident,
depth_limit: $depth_limit:literal,
eval_always: $eval_always:literal,
feedable: $feedable:literal,
Expand Down
5 changes: 0 additions & 5 deletions compiler/rustc_middle/src/ty/adt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -751,8 +751,3 @@ impl<'tcx> AdtDef<'tcx> {
if self.is_struct() { tcx.adt_sizedness_constraint((self.did(), sizedness)) } else { None }
}
}

/// This type exists just so a `FromCycleError` impl can be made for the `check_representability`
/// query.
#[derive(Clone, Copy, Debug, HashStable)]
pub struct Representability;
1 change: 0 additions & 1 deletion compiler/rustc_query_impl/src/dep_kind_vtables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ macro_rules! define_dep_kind_vtables {
anon: $anon:literal,
arena_cache: $arena_cache:literal,
cache_on_disk: $cache_on_disk:literal,
cycle_error_handling: $cycle_error_handling:ident,
depth_limit: $depth_limit:literal,
eval_always: $eval_always:literal,
feedable: $feedable:literal,
Expand Down
Loading
Loading