rust/compiler/rustc_query_system/src/dep_graph/mod.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

111 lines
3.2 KiB
Rust
Raw Normal View History

pub mod debug;
mod dep_node;
mod graph;
mod query;
mod serialized;
2020-03-18 09:25:22 +00:00
pub use dep_node::{DepNode, DepNodeParams, WorkProductId};
pub use graph::{
hash_result, DepGraph, DepNodeColor, DepNodeIndex, TaskDeps, TaskDepsRef, WorkProduct,
};
2020-03-18 09:25:22 +00:00
pub use query::DepGraphQuery;
pub use serialized::{SerializedDepGraph, SerializedDepNodeIndex};
use crate::ich::StableHashingContext;
2020-03-18 09:25:22 +00:00
use rustc_data_structures::profiling::SelfProfilerRef;
2021-03-02 21:38:49 +00:00
use rustc_serialize::{opaque::FileEncoder, Encodable};
use rustc_session::Session;
2020-03-18 09:25:22 +00:00
use std::fmt;
use std::hash::Hash;
pub trait DepContext: Copy {
2020-03-18 09:25:22 +00:00
type DepKind: self::DepKind;
/// Create a hashing context for hashing new results.
fn with_stable_hashing_context<R>(&self, f: impl FnOnce(StableHashingContext<'_>) -> R) -> R;
2020-03-18 09:25:22 +00:00
/// Access the DepGraph.
fn dep_graph(&self) -> &DepGraph<Self::DepKind>;
2020-03-18 09:25:22 +00:00
/// Access the profiler.
fn profiler(&self) -> &SelfProfilerRef;
/// Access the compiler session.
fn sess(&self) -> &Session;
2021-10-16 18:10:23 +00:00
/// Return whether this kind always require evaluation.
fn is_eval_always(&self, kind: Self::DepKind) -> bool;
fn fingerprint_style(&self, kind: Self::DepKind) -> FingerprintStyle;
2021-10-16 18:24:08 +00:00
/// Try to force a dep node to execute and see if it's green.
2021-10-16 19:12:34 +00:00
fn try_force_from_dep_node(&self, dep_node: DepNode<Self::DepKind>) -> bool;
2021-10-16 18:24:08 +00:00
/// Load data from the on-disk cache.
2021-10-16 19:12:34 +00:00
fn try_load_from_on_disk_cache(&self, dep_node: DepNode<Self::DepKind>);
2020-03-18 09:25:22 +00:00
}
2020-10-18 19:01:36 +00:00
pub trait HasDepContext: Copy {
type DepKind: self::DepKind;
type DepContext: self::DepContext<DepKind = Self::DepKind>;
2020-10-18 19:01:36 +00:00
fn dep_context(&self) -> &Self::DepContext;
}
impl<T: DepContext> HasDepContext for T {
type DepKind = T::DepKind;
type DepContext = Self;
fn dep_context(&self) -> &Self::DepContext {
self
}
}
/// Describes the contents of the fingerprint generated by a given query.
2021-10-16 19:24:10 +00:00
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
pub enum FingerprintStyle {
/// The fingerprint is actually a DefPathHash.
DefPathHash,
2022-09-09 10:05:01 +00:00
/// The fingerprint is actually a HirId.
HirId,
/// Query key was `()` or equivalent, so fingerprint is just zero.
Unit,
/// Some opaque hash.
Opaque,
}
impl FingerprintStyle {
#[inline]
pub fn reconstructible(self) -> bool {
match self {
2022-09-09 10:05:01 +00:00
FingerprintStyle::DefPathHash | FingerprintStyle::Unit | FingerprintStyle::HirId => {
true
}
FingerprintStyle::Opaque => false,
}
}
}
2020-03-18 09:25:22 +00:00
/// Describe the different families of dependency nodes.
2021-03-02 21:38:49 +00:00
pub trait DepKind: Copy + fmt::Debug + Eq + Hash + Send + Encodable<FileEncoder> + 'static {
/// DepKind to use when incr. comp. is turned off.
2020-03-18 20:02:02 +00:00
const NULL: Self;
/// DepKind to use to create the initial forever-red node.
const RED: Self;
2020-03-18 09:25:22 +00:00
/// Implementation of `std::fmt::Debug` for `DepNode`.
fn debug_node(node: &DepNode<Self>, f: &mut fmt::Formatter<'_>) -> fmt::Result;
/// Execute the operation with provided dependencies.
fn with_deps<OP, R>(deps: TaskDepsRef<'_, Self>, op: OP) -> R
2020-03-18 09:25:22 +00:00
where
OP: FnOnce() -> R;
/// Access dependencies from current implicit context.
fn read_deps<OP>(op: OP)
2020-03-18 09:25:22 +00:00
where
OP: for<'a> FnOnce(TaskDepsRef<'a, Self>);
2020-03-18 09:25:22 +00:00
}