]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_query_system/src/dep_graph/mod.rs
rustc_query_system: explicitly register reused dep nodes
[rust.git] / compiler / rustc_query_system / src / dep_graph / mod.rs
1 pub mod debug;
2 mod dep_node;
3 mod graph;
4 mod prev;
5 mod query;
6 mod serialized;
7
8 pub use dep_node::{DepNode, DepNodeParams, WorkProductId};
9 pub use graph::{hash_result, DepGraph, DepNodeColor, DepNodeIndex, TaskDeps, WorkProduct};
10 pub use prev::PreviousDepGraph;
11 pub use query::DepGraphQuery;
12 pub use serialized::{SerializedDepGraph, SerializedDepNodeIndex};
13
14 use rustc_data_structures::profiling::SelfProfilerRef;
15 use rustc_data_structures::sync::Lock;
16 use rustc_data_structures::thin_vec::ThinVec;
17 use rustc_errors::Diagnostic;
18
19 use std::fmt;
20 use std::hash::Hash;
21
22 pub trait DepContext: Copy {
23     type DepKind: self::DepKind;
24     type StableHashingContext;
25
26     /// Create a hashing context for hashing new results.
27     fn create_stable_hashing_context(&self) -> Self::StableHashingContext;
28
29     fn debug_dep_tasks(&self) -> bool;
30     fn debug_dep_node(&self) -> bool;
31
32     /// Try to force a dep node to execute and see if it's green.
33     fn try_force_from_dep_node(&self, dep_node: &DepNode<Self::DepKind>) -> bool;
34
35     fn register_reused_dep_node(&self, dep_node: &DepNode<Self::DepKind>);
36
37     /// Return whether the current session is tainted by errors.
38     fn has_errors_or_delayed_span_bugs(&self) -> bool;
39
40     /// Return the diagnostic handler.
41     fn diagnostic(&self) -> &rustc_errors::Handler;
42
43     /// Load data from the on-disk cache.
44     fn try_load_from_on_disk_cache(&self, dep_node: &DepNode<Self::DepKind>);
45
46     /// Load diagnostics associated to the node in the previous session.
47     fn load_diagnostics(&self, prev_dep_node_index: SerializedDepNodeIndex) -> Vec<Diagnostic>;
48
49     /// Register diagnostics for the given node, for use in next session.
50     fn store_diagnostics(&self, dep_node_index: DepNodeIndex, diagnostics: ThinVec<Diagnostic>);
51
52     /// Register diagnostics for the given node, for use in next session.
53     fn store_diagnostics_for_anon_node(
54         &self,
55         dep_node_index: DepNodeIndex,
56         diagnostics: ThinVec<Diagnostic>,
57     );
58
59     /// Access the profiler.
60     fn profiler(&self) -> &SelfProfilerRef;
61 }
62
63 /// Describe the different families of dependency nodes.
64 pub trait DepKind: Copy + fmt::Debug + Eq + Ord + Hash {
65     const NULL: Self;
66
67     /// Return whether this kind always require evaluation.
68     fn is_eval_always(&self) -> bool;
69
70     /// Return whether this kind requires additional parameters to be executed.
71     fn has_params(&self) -> bool;
72
73     /// Implementation of `std::fmt::Debug` for `DepNode`.
74     fn debug_node(node: &DepNode<Self>, f: &mut fmt::Formatter<'_>) -> fmt::Result;
75
76     /// Execute the operation with provided dependencies.
77     fn with_deps<OP, R>(deps: Option<&Lock<TaskDeps<Self>>>, op: OP) -> R
78     where
79         OP: FnOnce() -> R;
80
81     /// Access dependencies from current implicit context.
82     fn read_deps<OP>(op: OP)
83     where
84         OP: for<'a> FnOnce(Option<&'a Lock<TaskDeps<Self>>>);
85
86     fn can_reconstruct_query_key(&self) -> bool;
87 }