From 698f8c2f01ea549d77d7dc3338a12e04c11057b9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:02:58 +0200 Subject: Adding upstream version 1.64.0+dfsg1. Signed-off-by: Daniel Baumann --- compiler/rustc_query_system/src/dep_graph/mod.rs | 106 +++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 compiler/rustc_query_system/src/dep_graph/mod.rs (limited to 'compiler/rustc_query_system/src/dep_graph/mod.rs') diff --git a/compiler/rustc_query_system/src/dep_graph/mod.rs b/compiler/rustc_query_system/src/dep_graph/mod.rs new file mode 100644 index 000000000..342d95ca4 --- /dev/null +++ b/compiler/rustc_query_system/src/dep_graph/mod.rs @@ -0,0 +1,106 @@ +pub mod debug; +mod dep_node; +mod graph; +mod query; +mod serialized; + +pub use dep_node::{DepNode, DepNodeParams, WorkProductId}; +pub use graph::{ + hash_result, DepGraph, DepNodeColor, DepNodeIndex, TaskDeps, TaskDepsRef, WorkProduct, +}; +pub use query::DepGraphQuery; +pub use serialized::{SerializedDepGraph, SerializedDepNodeIndex}; + +use crate::ich::StableHashingContext; +use rustc_data_structures::profiling::SelfProfilerRef; +use rustc_serialize::{opaque::FileEncoder, Encodable}; +use rustc_session::Session; + +use std::fmt; +use std::hash::Hash; + +pub trait DepContext: Copy { + type DepKind: self::DepKind; + + /// Create a hashing context for hashing new results. + fn with_stable_hashing_context(&self, f: impl FnOnce(StableHashingContext<'_>) -> R) -> R; + + /// Access the DepGraph. + fn dep_graph(&self) -> &DepGraph; + + /// Access the profiler. + fn profiler(&self) -> &SelfProfilerRef; + + /// Access the compiler session. + fn sess(&self) -> &Session; + + /// Return whether this kind always require evaluation. + fn is_eval_always(&self, kind: Self::DepKind) -> bool; + + fn fingerprint_style(&self, kind: Self::DepKind) -> FingerprintStyle; + + /// Try to force a dep node to execute and see if it's green. + fn try_force_from_dep_node(&self, dep_node: DepNode) -> bool; + + /// Load data from the on-disk cache. + fn try_load_from_on_disk_cache(&self, dep_node: DepNode); +} + +pub trait HasDepContext: Copy { + type DepKind: self::DepKind; + type DepContext: self::DepContext; + + fn dep_context(&self) -> &Self::DepContext; +} + +impl 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. +#[derive(Debug, PartialEq, Eq, Copy, Clone)] +pub enum FingerprintStyle { + /// The fingerprint is actually a DefPathHash. + DefPathHash, + /// 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 { + FingerprintStyle::DefPathHash | FingerprintStyle::Unit => true, + FingerprintStyle::Opaque => false, + } + } +} + +/// Describe the different families of dependency nodes. +pub trait DepKind: Copy + fmt::Debug + Eq + Hash + Send + Encodable + 'static { + /// DepKind to use when incr. comp. is turned off. + const NULL: Self; + + /// DepKind to use to create the initial forever-red node. + const RED: Self; + + /// Implementation of `std::fmt::Debug` for `DepNode`. + fn debug_node(node: &DepNode, f: &mut fmt::Formatter<'_>) -> fmt::Result; + + /// Execute the operation with provided dependencies. + fn with_deps(deps: TaskDepsRef<'_, Self>, op: OP) -> R + where + OP: FnOnce() -> R; + + /// Access dependencies from current implicit context. + fn read_deps(op: OP) + where + OP: for<'a> FnOnce(TaskDepsRef<'a, Self>); +} -- cgit v1.2.3