2016-05-06 09:02:05 +00:00
|
|
|
pub mod debug;
|
2016-03-28 21:37:34 +00:00
|
|
|
mod dep_node;
|
|
|
|
mod graph;
|
2016-01-05 18:02:57 +00:00
|
|
|
mod query;
|
2017-09-22 11:00:42 +00:00
|
|
|
mod serialized;
|
2016-01-05 18:02:57 +00:00
|
|
|
|
2022-09-12 02:10:53 +00:00
|
|
|
pub use dep_node::{DepKindStruct, DepNode, DepNodeParams, WorkProductId};
|
2022-01-08 23:22:06 +00:00
|
|
|
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};
|
|
|
|
|
2021-09-25 23:40:17 +00:00
|
|
|
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};
|
2020-11-12 19:48:37 +00:00
|
|
|
use rustc_session::Session;
|
2020-03-18 09:25:22 +00:00
|
|
|
|
|
|
|
use std::fmt;
|
|
|
|
use std::hash::Hash;
|
|
|
|
|
2020-03-24 19:09:06 +00:00
|
|
|
pub trait DepContext: Copy {
|
2020-03-18 09:25:22 +00:00
|
|
|
type DepKind: self::DepKind;
|
|
|
|
|
|
|
|
/// Create a hashing context for hashing new results.
|
2023-02-13 23:18:46 +00:00
|
|
|
fn with_stable_hashing_context<R>(self, f: impl FnOnce(StableHashingContext<'_>) -> R) -> R;
|
2020-03-18 09:25:22 +00:00
|
|
|
|
2020-10-11 08:34:50 +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;
|
2020-11-12 19:48:37 +00:00
|
|
|
|
|
|
|
/// Access the compiler session.
|
|
|
|
fn sess(&self) -> &Session;
|
2021-10-16 18:10:23 +00:00
|
|
|
|
2022-09-12 04:18:08 +00:00
|
|
|
fn dep_kind_info(&self, dep_node: Self::DepKind) -> &DepKindStruct<Self>;
|
|
|
|
|
|
|
|
#[inline(always)]
|
2023-02-13 23:18:46 +00:00
|
|
|
fn fingerprint_style(self, kind: Self::DepKind) -> FingerprintStyle {
|
2022-09-12 04:18:08 +00:00
|
|
|
let data = self.dep_kind_info(kind);
|
|
|
|
if data.is_anon {
|
|
|
|
return FingerprintStyle::Opaque;
|
|
|
|
}
|
|
|
|
data.fingerprint_style
|
|
|
|
}
|
2021-10-16 18:10:23 +00:00
|
|
|
|
2022-09-12 04:18:08 +00:00
|
|
|
#[inline(always)]
|
|
|
|
/// Return whether this kind always require evaluation.
|
2023-02-13 23:18:46 +00:00
|
|
|
fn is_eval_always(self, kind: Self::DepKind) -> bool {
|
2022-09-12 04:18:08 +00:00
|
|
|
self.dep_kind_info(kind).is_eval_always
|
|
|
|
}
|
2021-10-16 18:24:08 +00:00
|
|
|
|
|
|
|
/// Try to force a dep node to execute and see if it's green.
|
2022-11-05 19:40:42 +00:00
|
|
|
#[instrument(skip(self), level = "debug")]
|
2022-09-12 04:18:08 +00:00
|
|
|
fn try_force_from_dep_node(self, dep_node: DepNode<Self::DepKind>) -> bool {
|
|
|
|
let cb = self.dep_kind_info(dep_node.kind);
|
|
|
|
if let Some(f) = cb.force_from_dep_node {
|
|
|
|
f(self, dep_node);
|
|
|
|
true
|
|
|
|
} else {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
2021-10-16 18:24:08 +00:00
|
|
|
|
|
|
|
/// Load data from the on-disk cache.
|
2022-09-12 04:18:08 +00:00
|
|
|
fn try_load_from_on_disk_cache(self, dep_node: DepNode<Self::DepKind>) {
|
|
|
|
let cb = self.dep_kind_info(dep_node.kind);
|
|
|
|
if let Some(f) = cb.try_load_from_on_disk_cache {
|
|
|
|
f(self, dep_node)
|
|
|
|
}
|
|
|
|
}
|
2020-03-18 09:25:22 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 19:01:36 +00:00
|
|
|
pub trait HasDepContext: Copy {
|
|
|
|
type DepKind: self::DepKind;
|
2021-09-25 23:40:17 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-02 16:06:42 +00:00
|
|
|
/// 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)]
|
2021-10-02 16:06:42 +00:00
|
|
|
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,
|
2021-10-02 16:06:42 +00:00
|
|
|
/// 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
|
|
|
|
}
|
2021-10-02 16:06:42 +00:00
|
|
|
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 {
|
2022-05-03 20:04:49 +00:00
|
|
|
/// DepKind to use when incr. comp. is turned off.
|
2020-03-18 20:02:02 +00:00
|
|
|
const NULL: Self;
|
|
|
|
|
2022-05-03 20:04:49 +00:00
|
|
|
/// 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.
|
2022-01-08 23:22:06 +00:00
|
|
|
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.
|
Fix clippy warnings
Fixes clippy::{cone_on_copy, filter_next, redundant_closure, single_char_pattern, len_zero,redundant_field_names, useless_format, identity_conversion, map_clone, into_iter_on_ref, needless_return, option_as_ref_deref, unused_unit, unnecessary_mut_passed}
2020-05-11 11:01:37 +00:00
|
|
|
fn read_deps<OP>(op: OP)
|
2020-03-18 09:25:22 +00:00
|
|
|
where
|
2022-01-08 23:22:06 +00:00
|
|
|
OP: for<'a> FnOnce(TaskDepsRef<'a, Self>);
|
2020-03-18 09:25:22 +00:00
|
|
|
}
|