2 pub use self::plumbing::*;
5 #[cfg(parallel_compiler)]
6 pub use self::job::deadlock;
7 pub use self::job::{print_query_stack, QueryInfo, QueryJob, QueryJobId, QueryJobInfo, QueryMap};
10 pub use self::caches::{
11 ArenaCacheSelector, CacheSelector, DefaultCacheSelector, QueryCache, QueryStorage,
15 pub use self::config::{QueryConfig, QueryDescription, QueryVTable};
17 use crate::dep_graph::{DepNodeIndex, HasDepContext, SerializedDepNodeIndex};
18 use rustc_data_structures::sync::Lock;
19 use rustc_errors::Diagnostic;
20 use rustc_hir::def::DefKind;
22 use thin_vec::ThinVec;
24 /// Description of a frame in the query stack.
26 /// This is mostly used in case of cycles for error reporting.
27 #[derive(Clone, Debug)]
28 pub struct QueryStackFrame {
29 pub name: &'static str,
30 pub description: String,
32 def_kind: Option<DefKind>,
33 /// This hash is used to deterministically pick
34 /// a query to remove cycles in the parallel compiler.
35 #[cfg(parallel_compiler)]
39 impl QueryStackFrame {
45 def_kind: Option<DefKind>,
46 _hash: impl FnOnce() -> u64,
53 #[cfg(parallel_compiler)]
58 // FIXME(eddyb) Get more valid `Span`s on queries.
60 pub fn default_span(&self, span: Span) -> Span {
64 self.span.unwrap_or(span)
68 /// Tracks 'side effects' for a particular query.
69 /// This struct is saved to disk along with the query result,
70 /// and loaded from disk if we mark the query as green.
71 /// This allows us to 'replay' changes to global state
72 /// that would otherwise only occur if we actually
73 /// executed the query method.
74 #[derive(Debug, Clone, Default, Encodable, Decodable)]
75 pub struct QuerySideEffects {
76 /// Stores any diagnostics emitted during query execution.
77 /// These diagnostics will be re-emitted if we mark
78 /// the query as green.
79 pub(super) diagnostics: ThinVec<Diagnostic>,
82 impl QuerySideEffects {
84 pub fn is_empty(&self) -> bool {
85 let QuerySideEffects { diagnostics } = self;
86 diagnostics.is_empty()
88 pub fn append(&mut self, other: QuerySideEffects) {
89 let QuerySideEffects { diagnostics } = self;
90 diagnostics.extend(other.diagnostics);
94 pub trait QueryContext: HasDepContext {
95 fn next_job_id(&self) -> QueryJobId;
97 /// Get the query information from the TLS context.
98 fn current_query_job(&self) -> Option<QueryJobId>;
100 fn try_collect_active_jobs(&self) -> Option<QueryMap>;
102 /// Load side effects associated to the node in the previous session.
103 fn load_side_effects(&self, prev_dep_node_index: SerializedDepNodeIndex) -> QuerySideEffects;
105 /// Register diagnostics for the given node, for use in next session.
106 fn store_side_effects(&self, dep_node_index: DepNodeIndex, side_effects: QuerySideEffects);
108 /// Register diagnostics for the given node, for use in next session.
109 fn store_side_effects_for_anon_node(
111 dep_node_index: DepNodeIndex,
112 side_effects: QuerySideEffects,
115 /// Executes a job by changing the `ImplicitCtxt` to point to the
116 /// new query job while it executes. It returns the diagnostics
117 /// captured during execution and the actual result.
122 diagnostics: Option<&Lock<ThinVec<Diagnostic>>>,
123 compute: impl FnOnce() -> R,
126 fn depth_limit_error(&self, job: QueryJobId);