Skip to content

Commit

Permalink
Rollup merge of #117963 - nnethercote:rustc_query_system, r=compiler-…
Browse files Browse the repository at this point in the history
…errors

`rustc_query_system` cleanups

Minor cleanups.

r? `@compiler-errors`
  • Loading branch information
TaKO8Ki authored Nov 17, 2023
2 parents c77cb7a + 8f669f5 commit 68f5762
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 34 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/dep_graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ mod dep_node;

pub use rustc_query_system::dep_graph::debug::EdgeFilter;
pub use rustc_query_system::dep_graph::{
debug::DepNodeFilter, hash_result, DepContext, DepGraphQuery, DepNodeColor, DepNodeIndex, Deps,
SerializedDepGraph, SerializedDepNodeIndex, TaskDeps, TaskDepsRef, WorkProduct, WorkProductId,
debug::DepNodeFilter, hash_result, DepContext, DepGraphQuery, DepNodeIndex, Deps,
SerializedDepGraph, SerializedDepNodeIndex, TaskDepsRef, WorkProduct, WorkProductId,
WorkProductMap,
};

Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_query_system/src/dep_graph/edges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ 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]>,
}
Expand All @@ -18,21 +18,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
}
}
Expand Down
36 changes: 18 additions & 18 deletions compiler/rustc_query_system/src/dep_graph/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand All @@ -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);
}

Expand All @@ -53,28 +52,28 @@ 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,
}
}
}

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
Expand Down Expand Up @@ -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()
}

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand All @@ -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()
}

Expand All @@ -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);
}
}
Expand All @@ -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,
{
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 2 additions & 5 deletions compiler/rustc_query_system/src/dep_graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_query_system/src/dep_graph/serialized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_query_system/src/ich/hcx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub struct StableHashingContext<'a> {
// `CachingSourceMapView`, so we initialize it lazily.
raw_source_map: &'a SourceMap,
caching_source_map: Option<CachingSourceMapView<'a>>,
pub(super) hashing_controls: HashingControls,
hashing_controls: HashingControls,
}

/// The `BodyResolver` allows mapping a `BodyId` to the corresponding `hir::Body`.
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_query_system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
#![feature(core_intrinsics)]
#![feature(hash_raw_entry)]
#![feature(min_specialization)]
#![feature(extern_types)]
#![feature(let_chains)]
#![feature(inline_const)]
#![allow(rustc::potential_query_instability)]
#![deny(rustc::untranslatable_diagnostic)]
#![deny(rustc::diagnostic_outside_of_impl)]
Expand Down

0 comments on commit 68f5762

Please sign in to comment.