From 9918693037dce8aa4bb6f08741b6812923486c18 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 19 Jun 2024 11:26:03 +0200 Subject: Merging upstream version 1.76.0+dfsg1. Signed-off-by: Daniel Baumann --- compiler/rustc_query_system/src/dep_graph/edges.rs | 11 +++-- compiler/rustc_query_system/src/dep_graph/graph.rs | 48 +++++++++++----------- compiler/rustc_query_system/src/dep_graph/mod.rs | 7 +--- .../rustc_query_system/src/dep_graph/serialized.rs | 17 ++------ compiler/rustc_query_system/src/ich/hcx.rs | 2 +- .../rustc_query_system/src/ich/impls_syntax.rs | 10 ++--- compiler/rustc_query_system/src/lib.rs | 9 +--- compiler/rustc_query_system/src/query/job.rs | 31 ++++++++------ compiler/rustc_query_system/src/query/mod.rs | 2 +- compiler/rustc_query_system/src/query/plumbing.rs | 23 +++++------ 10 files changed, 70 insertions(+), 90 deletions(-) (limited to 'compiler/rustc_query_system') diff --git a/compiler/rustc_query_system/src/dep_graph/edges.rs b/compiler/rustc_query_system/src/dep_graph/edges.rs index 6ba3924f6..63d46f47f 100644 --- a/compiler/rustc_query_system/src/dep_graph/edges.rs +++ b/compiler/rustc_query_system/src/dep_graph/edges.rs @@ -1,11 +1,10 @@ use crate::dep_graph::DepNodeIndex; use smallvec::SmallVec; use std::hash::{Hash, Hasher}; -use std::iter::Extend; use std::ops::Deref; #[derive(Default, Debug)] -pub struct EdgesVec { +pub(crate) struct EdgesVec { max: u32, edges: SmallVec<[DepNodeIndex; EdgesVec::INLINE_CAPACITY]>, } @@ -18,21 +17,21 @@ impl Hash for EdgesVec { } impl EdgesVec { - pub const INLINE_CAPACITY: usize = 8; + pub(crate) const INLINE_CAPACITY: usize = 8; #[inline] - pub fn new() -> Self { + pub(crate) fn new() -> Self { Self::default() } #[inline] - pub fn push(&mut self, edge: DepNodeIndex) { + pub(crate) fn push(&mut self, edge: DepNodeIndex) { self.max = self.max.max(edge.as_u32()); self.edges.push(edge); } #[inline] - pub fn max_index(&self) -> u32 { + pub(crate) fn max_index(&self) -> u32 { self.max } } diff --git a/compiler/rustc_query_system/src/dep_graph/graph.rs b/compiler/rustc_query_system/src/dep_graph/graph.rs index 6cace0195..3556a5ec1 100644 --- a/compiler/rustc_query_system/src/dep_graph/graph.rs +++ b/compiler/rustc_query_system/src/dep_graph/graph.rs @@ -18,7 +18,7 @@ use std::sync::atomic::Ordering::Relaxed; use super::query::DepGraphQuery; use super::serialized::{GraphEncoder, SerializedDepGraph, SerializedDepNodeIndex}; use super::{DepContext, DepKind, DepNode, Deps, HasDepContext, WorkProductId}; -use crate::dep_graph::EdgesVec; +use crate::dep_graph::edges::EdgesVec; use crate::ich::StableHashingContext; use crate::query::{QueryContext, QuerySideEffects}; @@ -41,8 +41,7 @@ rustc_index::newtype_index! { } impl DepNodeIndex { - pub const INVALID: DepNodeIndex = DepNodeIndex::MAX; - pub const SINGLETON_DEPENDENCYLESS_ANON_NODE: DepNodeIndex = DepNodeIndex::from_u32(0); + const SINGLETON_DEPENDENCYLESS_ANON_NODE: DepNodeIndex = DepNodeIndex::from_u32(0); pub const FOREVER_RED_NODE: DepNodeIndex = DepNodeIndex::from_u32(1); } @@ -53,20 +52,20 @@ impl From for QueryInvocationId { } } -pub struct MarkFrame<'a> { +pub(crate) struct MarkFrame<'a> { index: SerializedDepNodeIndex, parent: Option<&'a MarkFrame<'a>>, } #[derive(PartialEq)] -pub enum DepNodeColor { +enum DepNodeColor { Red, Green(DepNodeIndex), } impl DepNodeColor { #[inline] - pub fn is_green(self) -> bool { + fn is_green(self) -> bool { match self { DepNodeColor::Red => false, DepNodeColor::Green(_) => true, @@ -74,7 +73,7 @@ impl DepNodeColor { } } -pub struct DepGraphData { +pub(crate) struct DepGraphData { /// The new encoding of the dependency graph, optimized for red/green /// tracking. The `current` field is the dependency graph of only the /// current compilation session: We don't merge the previous dep-graph into @@ -185,7 +184,7 @@ impl DepGraph { } #[inline] - pub fn data(&self) -> Option<&DepGraphData> { + pub(crate) fn data(&self) -> Option<&DepGraphData> { self.data.as_deref() } @@ -333,7 +332,7 @@ impl DepGraphData { /// /// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/queries/incremental-compilation.html #[inline(always)] - pub fn with_task, A: Debug, R>( + pub(crate) fn with_task, A: Debug, R>( &self, key: DepNode, cx: Ctxt, @@ -398,7 +397,7 @@ impl DepGraphData { /// Executes something within an "anonymous" task, that is, a task the /// `DepNode` of which is determined by the list of inputs it read from. - pub fn with_anon_task, OP, R>( + pub(crate) fn with_anon_task, OP, R>( &self, cx: Tcx, dep_kind: DepKind, @@ -618,7 +617,7 @@ impl DepGraph { impl DepGraphData { #[inline] - pub fn dep_node_index_of_opt(&self, dep_node: &DepNode) -> Option { + fn dep_node_index_of_opt(&self, dep_node: &DepNode) -> Option { if let Some(prev_index) = self.previous.node_to_index_opt(dep_node) { self.current.prev_index_to_index.lock()[prev_index] } else { @@ -627,7 +626,7 @@ impl DepGraphData { } #[inline] - pub fn dep_node_exists(&self, dep_node: &DepNode) -> bool { + fn dep_node_exists(&self, dep_node: &DepNode) -> bool { self.dep_node_index_of_opt(dep_node).is_some() } @@ -643,21 +642,21 @@ impl DepGraphData { /// Returns true if the given node has been marked as green during the /// current compilation session. Used in various assertions #[inline] - pub fn is_index_green(&self, prev_index: SerializedDepNodeIndex) -> bool { + pub(crate) fn is_index_green(&self, prev_index: SerializedDepNodeIndex) -> bool { self.colors.get(prev_index).is_some_and(|c| c.is_green()) } #[inline] - pub fn prev_fingerprint_of(&self, prev_index: SerializedDepNodeIndex) -> Fingerprint { + pub(crate) fn prev_fingerprint_of(&self, prev_index: SerializedDepNodeIndex) -> Fingerprint { self.previous.fingerprint_by_index(prev_index) } #[inline] - pub fn prev_node_of(&self, prev_index: SerializedDepNodeIndex) -> DepNode { + pub(crate) fn prev_node_of(&self, prev_index: SerializedDepNodeIndex) -> DepNode { self.previous.index_to_node(prev_index) } - pub fn mark_debug_loaded_from_disk(&self, dep_node: DepNode) { + pub(crate) fn mark_debug_loaded_from_disk(&self, dep_node: DepNode) { self.debug_loaded_from_disk.lock().insert(dep_node); } } @@ -684,8 +683,9 @@ impl DepGraph { self.data.as_ref().unwrap().debug_loaded_from_disk.lock().contains(&dep_node) } + #[cfg(debug_assertions)] #[inline(always)] - pub fn register_dep_node_debug_str(&self, dep_node: DepNode, debug_str_gen: F) + pub(crate) fn register_dep_node_debug_str(&self, dep_node: DepNode, debug_str_gen: F) where F: FnOnce() -> String, { @@ -725,7 +725,7 @@ impl DepGraphData { /// A node will have an index, when it's already been marked green, or when we can mark it /// green. This function will mark the current task as a reader of the specified node, when /// a node index can be found for that node. - pub fn try_mark_green>( + pub(crate) fn try_mark_green>( &self, qcx: Qcx, dep_node: &DepNode, @@ -743,7 +743,7 @@ impl DepGraphData { // in the previous compilation session too, so we can try to // mark it as green by recursively marking all of its // dependencies green. - self.try_mark_previous_green(qcx, prev_index, &dep_node, None) + self.try_mark_previous_green(qcx, prev_index, dep_node, None) .map(|dep_node_index| (prev_index, dep_node_index)) } } @@ -818,7 +818,7 @@ impl DepGraphData { None => {} } - if let None = qcx.dep_context().sess().has_errors_or_delayed_span_bugs() { + if let None = qcx.dep_context().sess().has_errors_or_span_delayed_bugs() { panic!("try_mark_previous_green() - Forcing the DepNode should have set its color") } @@ -924,10 +924,10 @@ impl DepGraphData { // Promote the previous diagnostics to the current session. qcx.store_side_effects(dep_node_index, side_effects.clone()); - let handle = qcx.dep_context().sess().diagnostic(); + let dcx = qcx.dep_context().sess().dcx(); - for mut diagnostic in side_effects.diagnostics { - handle.emit_diagnostic(&mut diagnostic); + for diagnostic in side_effects.diagnostics { + dcx.emit_diagnostic(diagnostic); } } } @@ -982,7 +982,7 @@ impl DepGraph { } } - pub fn encode(&self, profiler: &SelfProfilerRef) -> FileEncodeResult { + pub fn finish_encoding(&self, profiler: &SelfProfilerRef) -> FileEncodeResult { if let Some(data) = &self.data { data.current.encoder.steal().finish(profiler) } else { diff --git a/compiler/rustc_query_system/src/dep_graph/mod.rs b/compiler/rustc_query_system/src/dep_graph/mod.rs index 624ae680a..feb69ecd0 100644 --- a/compiler/rustc_query_system/src/dep_graph/mod.rs +++ b/compiler/rustc_query_system/src/dep_graph/mod.rs @@ -6,11 +6,8 @@ mod query; mod serialized; pub use dep_node::{DepKind, DepKindStruct, DepNode, DepNodeParams, WorkProductId}; -pub use edges::EdgesVec; -pub use graph::{ - hash_result, DepGraph, DepGraphData, DepNodeColor, DepNodeIndex, TaskDeps, TaskDepsRef, - WorkProduct, WorkProductMap, -}; +pub(crate) use graph::DepGraphData; +pub use graph::{hash_result, DepGraph, DepNodeIndex, TaskDepsRef, WorkProduct, WorkProductMap}; pub use query::DepGraphQuery; pub use serialized::{SerializedDepGraph, SerializedDepNodeIndex}; diff --git a/compiler/rustc_query_system/src/dep_graph/serialized.rs b/compiler/rustc_query_system/src/dep_graph/serialized.rs index fcf46be6e..504763f6c 100644 --- a/compiler/rustc_query_system/src/dep_graph/serialized.rs +++ b/compiler/rustc_query_system/src/dep_graph/serialized.rs @@ -37,7 +37,7 @@ use super::query::DepGraphQuery; use super::{DepKind, DepNode, DepNodeIndex, Deps}; -use crate::dep_graph::EdgesVec; +use crate::dep_graph::edges::EdgesVec; use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fingerprint::PackedFingerprint; use rustc_data_structures::fx::FxHashMap; @@ -54,6 +54,7 @@ use std::marker::PhantomData; // unused so that we can store multiple index types in `CompressedHybridIndex`, // and use those bits to encode which index type it contains. rustc_index::newtype_index! { + #[encodable] #[max = 0x7FFF_FFFF] pub struct SerializedDepNodeIndex {} } @@ -69,7 +70,7 @@ const DEP_NODE_PAD: usize = DEP_NODE_SIZE - 1; const DEP_NODE_WIDTH_BITS: usize = DEP_NODE_SIZE / 2; /// Data for use when recompiling the **current crate**. -#[derive(Debug)] +#[derive(Debug, Default)] pub struct SerializedDepGraph { /// The set of all DepNodes in the graph nodes: IndexVec, @@ -88,18 +89,6 @@ pub struct SerializedDepGraph { index: Vec>, } -impl Default for SerializedDepGraph { - fn default() -> Self { - SerializedDepGraph { - nodes: Default::default(), - fingerprints: Default::default(), - edge_list_indices: Default::default(), - edge_list_data: Default::default(), - index: Default::default(), - } - } -} - impl SerializedDepGraph { #[inline] pub fn edge_targets_from( diff --git a/compiler/rustc_query_system/src/ich/hcx.rs b/compiler/rustc_query_system/src/ich/hcx.rs index 5593a1541..eec0433ae 100644 --- a/compiler/rustc_query_system/src/ich/hcx.rs +++ b/compiler/rustc_query_system/src/ich/hcx.rs @@ -28,7 +28,7 @@ pub struct StableHashingContext<'a> { // `CachingSourceMapView`, so we initialize it lazily. raw_source_map: &'a SourceMap, caching_source_map: Option>, - pub(super) hashing_controls: HashingControls, + hashing_controls: HashingControls, } /// The `BodyResolver` allows mapping a `BodyId` to the corresponding `hir::Body`. diff --git a/compiler/rustc_query_system/src/ich/impls_syntax.rs b/compiler/rustc_query_system/src/ich/impls_syntax.rs index b2177be0e..f2387017c 100644 --- a/compiler/rustc_query_system/src/ich/impls_syntax.rs +++ b/compiler/rustc_query_system/src/ich/impls_syntax.rs @@ -117,11 +117,9 @@ impl<'tcx> HashStable> for rustc_feature::Features { self.declared_lang_features.hash_stable(hcx, hasher); self.declared_lib_features.hash_stable(hcx, hasher); - self.walk_feature_fields(|feature_name, value| { - feature_name.hash_stable(hcx, hasher); - value.hash_stable(hcx, hasher); - }); + self.all_features()[..].hash_stable(hcx, hasher); + for feature in rustc_feature::UNSTABLE_FEATURES.iter() { + feature.feature.name.hash_stable(hcx, hasher); + } } } - -impl<'ctx> rustc_type_ir::HashStableContext for StableHashingContext<'ctx> {} diff --git a/compiler/rustc_query_system/src/lib.rs b/compiler/rustc_query_system/src/lib.rs index 1944ac443..9b66b9a48 100644 --- a/compiler/rustc_query_system/src/lib.rs +++ b/compiler/rustc_query_system/src/lib.rs @@ -2,10 +2,8 @@ #![feature(core_intrinsics)] #![feature(hash_raw_entry)] #![feature(min_specialization)] -#![feature(extern_types)] #![feature(let_chains)] -#![feature(inline_const)] -#![allow(rustc::potential_query_instability)] +#![allow(rustc::potential_query_instability, internal_features)] #![deny(rustc::untranslatable_diagnostic)] #![deny(rustc::diagnostic_outside_of_impl)] @@ -16,9 +14,6 @@ extern crate rustc_data_structures; #[macro_use] extern crate rustc_macros; -use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage}; -use rustc_fluent_macro::fluent_messages; - pub mod cache; pub mod dep_graph; mod error; @@ -31,4 +26,4 @@ pub use error::LayoutOfDepth; pub use error::QueryOverflow; pub use values::Value; -fluent_messages! { "../messages.ftl" } +rustc_fluent_macro::fluent_messages! { "../messages.ftl" } diff --git a/compiler/rustc_query_system/src/query/job.rs b/compiler/rustc_query_system/src/query/job.rs index f2c1f84fc..2a34ffb75 100644 --- a/compiler/rustc_query_system/src/query/job.rs +++ b/compiler/rustc_query_system/src/query/job.rs @@ -5,7 +5,7 @@ use crate::query::DepKind; use crate::query::{QueryContext, QueryStackFrame}; use rustc_data_structures::fx::FxHashMap; use rustc_errors::{ - Diagnostic, DiagnosticBuilder, ErrorGuaranteed, Handler, IntoDiagnostic, Level, + DiagCtxt, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, IntoDiagnostic, Level, }; use rustc_hir::def::DefKind; use rustc_session::Session; @@ -18,7 +18,6 @@ use std::num::NonZeroU64; #[cfg(parallel_compiler)] use { parking_lot::{Condvar, Mutex}, - rayon_core, rustc_data_structures::fx::FxHashSet, rustc_data_structures::{defer, jobserver}, rustc_span::DUMMY_SP, @@ -38,7 +37,7 @@ pub struct QueryInfo { pub type QueryMap = FxHashMap; /// A value uniquely identifying an active query job. -#[derive(Copy, Clone, Eq, PartialEq, Hash)] +#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct QueryJobId(pub NonZeroU64); impl QueryJobId { @@ -62,14 +61,14 @@ impl QueryJobId { } } -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct QueryJobInfo { pub query: QueryStackFrame, pub job: QueryJob, } /// Represents an active query job. -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct QueryJob { pub id: QueryJobId, @@ -182,6 +181,7 @@ impl QueryJobId { } #[cfg(parallel_compiler)] +#[derive(Debug)] struct QueryWaiter { query: Option, condvar: Condvar, @@ -198,13 +198,14 @@ impl QueryWaiter { } #[cfg(parallel_compiler)] +#[derive(Debug)] struct QueryLatchInfo { complete: bool, waiters: Vec>, } #[cfg(parallel_compiler)] -#[derive(Clone)] +#[derive(Clone, Debug)] pub(super) struct QueryLatch { info: Arc>, } @@ -540,7 +541,11 @@ pub fn deadlock(query_map: QueryMap, registry: &rayon_core::Registry) { // X to Y due to Rayon waiting and a true dependency from Y to X. The algorithm here // only considers the true dependency and won't detect a cycle. if !found_cycle { - panic!("deadlock detected"); + if query_map.len() == 0 { + panic!("deadlock detected without any query!") + } else { + panic!("deadlock detected! current query map:\n{:#?}", query_map); + } } // FIXME: Ensure this won't cause a deadlock before we return @@ -599,28 +604,28 @@ pub(crate) fn report_cycle<'a>( note_span: (), }; - cycle_diag.into_diagnostic(&sess.parse_sess.span_diagnostic) + cycle_diag.into_diagnostic(sess.dcx()) } pub fn print_query_stack( qcx: Qcx, mut current_query: Option, - handler: &Handler, + dcx: &DiagCtxt, num_frames: Option, mut file: Option, ) -> usize { // Be careful relying on global state here: this code is called from - // a panic hook, which means that the global `Handler` may be in a weird + // a panic hook, which means that the global `DiagCtxt` may be in a weird // state if it was responsible for triggering the panic. let mut count_printed = 0; let mut count_total = 0; - let query_map = qcx.try_collect_active_jobs(); + let query_map = qcx.collect_active_jobs(); if let Some(ref mut file) = file { let _ = writeln!(file, "\n\nquery stack during panic:"); } while let Some(query) = current_query { - let Some(query_info) = query_map.as_ref().and_then(|map| map.get(&query)) else { + let Some(query_info) = query_map.get(&query) else { break; }; if Some(count_printed) < num_frames || num_frames.is_none() { @@ -633,7 +638,7 @@ pub fn print_query_stack( ), ); diag.span = query_info.job.span.into(); - handler.force_print_diagnostic(diag); + dcx.force_print_diagnostic(diag); count_printed += 1; } diff --git a/compiler/rustc_query_system/src/query/mod.rs b/compiler/rustc_query_system/src/query/mod.rs index 05dee9f12..96a0c7a03 100644 --- a/compiler/rustc_query_system/src/query/mod.rs +++ b/compiler/rustc_query_system/src/query/mod.rs @@ -106,7 +106,7 @@ pub trait QueryContext: HasDepContext { /// Get the query information from the TLS context. fn current_query_job(self) -> Option; - fn try_collect_active_jobs(self) -> Option; + fn collect_active_jobs(self) -> QueryMap; /// Load side effects associated to the node in the previous session. fn load_side_effects(self, prev_dep_node_index: SerializedDepNodeIndex) -> QuerySideEffects; diff --git a/compiler/rustc_query_system/src/query/plumbing.rs b/compiler/rustc_query_system/src/query/plumbing.rs index 1f3403d09..41638b38c 100644 --- a/compiler/rustc_query_system/src/query/plumbing.rs +++ b/compiler/rustc_query_system/src/query/plumbing.rs @@ -138,7 +138,7 @@ where && let Some(span) = root.query.span { error.stash(span, StashKey::Cycle); - qcx.dep_context().sess().delay_span_bug(span, "delayed cycle error") + qcx.dep_context().sess().span_delayed_bug(span, "delayed cycle error") } else { error.emit() }; @@ -203,7 +203,7 @@ where } } -#[derive(Clone)] +#[derive(Clone, Debug)] pub(crate) struct CycleError { /// The query and related span that uses the cycle. pub usage: Option<(Span, QueryStackFrame)>, @@ -220,7 +220,7 @@ where C: QueryCache, Tcx: DepContext, { - match cache.lookup(&key) { + match cache.lookup(key) { Some((value, index)) => { tcx.profiler().query_cache_hit(index.into()); tcx.dep_graph().read_index(index); @@ -242,11 +242,8 @@ where Q: QueryConfig, Qcx: QueryContext, { - let error = try_execute.find_cycle_in_stack( - qcx.try_collect_active_jobs().unwrap(), - &qcx.current_query_job(), - span, - ); + let error = + try_execute.find_cycle_in_stack(qcx.collect_active_jobs(), &qcx.current_query_job(), span); (mk_cycle(query, qcx, error), None) } @@ -424,7 +421,7 @@ where // We have an inconsistency. This can happen if one of the two // results is tainted by errors. In this case, delay a bug to // ensure compilation is doomed. - qcx.dep_context().sess().delay_span_bug( + qcx.dep_context().sess().span_delayed_bug( DUMMY_SP, format!( "Computed query value for {:?}({:?}) is inconsistent with fed value,\n\ @@ -502,7 +499,7 @@ where // The diagnostics for this query will be promoted to the current session during // `try_mark_green()`, so we can ignore them here. if let Some(ret) = qcx.start_query(job_id, false, None, || { - try_load_from_disk_and_cache_in_memory(query, dep_graph_data, qcx, &key, &dep_node) + try_load_from_disk_and_cache_in_memory(query, dep_graph_data, qcx, &key, dep_node) }) { return ret; } @@ -563,7 +560,7 @@ where // Note this function can be called concurrently from the same query // We must ensure that this is handled correctly. - let (prev_dep_node_index, dep_node_index) = dep_graph_data.try_mark_green(qcx, &dep_node)?; + let (prev_dep_node_index, dep_node_index) = dep_graph_data.try_mark_green(qcx, dep_node)?; debug_assert!(dep_graph_data.is_index_green(prev_dep_node_index)); @@ -610,7 +607,7 @@ where // Sanity check for the logic in `ensure`: if the node is green and the result loadable, // we should actually be able to load it. debug_assert!( - !query.loadable_from_disk(qcx, &key, prev_dep_node_index), + !query.loadable_from_disk(qcx, key, prev_dep_node_index), "missing on-disk cache entry for loadable {dep_node:?}" ); @@ -667,7 +664,7 @@ pub(crate) fn incremental_verify_ich( let old_hash = dep_graph_data.prev_fingerprint_of(prev_index); if new_hash != old_hash { - incremental_verify_ich_failed(tcx, prev_index, &|| format_value(&result)); + incremental_verify_ich_failed(tcx, prev_index, &|| format_value(result)); } } -- cgit v1.2.3