diff options
Diffstat (limited to 'compiler/rustc_query_system/src/dep_graph')
4 files changed, 34 insertions, 49 deletions
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<DepNodeIndex> 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<D: Deps> { +pub(crate) struct DepGraphData<D: Deps> { /// 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<D: Deps> DepGraph<D> { } #[inline] - pub fn data(&self) -> Option<&DepGraphData<D>> { + pub(crate) fn data(&self) -> Option<&DepGraphData<D>> { self.data.as_deref() } @@ -333,7 +332,7 @@ impl<D: Deps> DepGraphData<D> { /// /// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/queries/incremental-compilation.html #[inline(always)] - pub fn with_task<Ctxt: HasDepContext<Deps = D>, A: Debug, R>( + pub(crate) fn with_task<Ctxt: HasDepContext<Deps = D>, A: Debug, R>( &self, key: DepNode, cx: Ctxt, @@ -398,7 +397,7 @@ impl<D: Deps> DepGraphData<D> { /// 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<Tcx: DepContext<Deps = D>, OP, R>( + pub(crate) fn with_anon_task<Tcx: DepContext<Deps = D>, OP, R>( &self, cx: Tcx, dep_kind: DepKind, @@ -618,7 +617,7 @@ impl<D: Deps> DepGraph<D> { impl<D: Deps> DepGraphData<D> { #[inline] - pub fn dep_node_index_of_opt(&self, dep_node: &DepNode) -> Option<DepNodeIndex> { + fn dep_node_index_of_opt(&self, dep_node: &DepNode) -> Option<DepNodeIndex> { 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<D: Deps> DepGraphData<D> { } #[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<D: Deps> DepGraphData<D> { /// 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<D: Deps> DepGraph<D> { 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<F>(&self, dep_node: DepNode, debug_str_gen: F) + pub(crate) fn register_dep_node_debug_str<F>(&self, dep_node: DepNode, debug_str_gen: F) where F: FnOnce() -> String, { @@ -725,7 +725,7 @@ impl<D: Deps> DepGraphData<D> { /// 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<Qcx: QueryContext<Deps = D>>( + pub(crate) fn try_mark_green<Qcx: QueryContext<Deps = D>>( &self, qcx: Qcx, dep_node: &DepNode, @@ -743,7 +743,7 @@ impl<D: Deps> DepGraphData<D> { // 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<D: Deps> DepGraphData<D> { 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<D: Deps> DepGraphData<D> { // 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<D: Deps> DepGraph<D> { } } - 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<SerializedDepNodeIndex, DepNode>, @@ -88,18 +89,6 @@ pub struct SerializedDepGraph { index: Vec<UnhashMap<PackedFingerprint, SerializedDepNodeIndex>>, } -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( |