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::{ArenaCache, DefaultCache, QueryCache, QueryStorage};
13 pub use self::config::{QueryConfig, QueryDescription, QueryVTable};
15 use crate::dep_graph::{DepNodeIndex, HasDepContext, SerializedDepNodeIndex};
16 use rustc_data_structures::sync::Lock;
17 use rustc_errors::Diagnostic;
18 use rustc_hir::def::DefKind;
19 use rustc_span::def_id::DefId;
21 use thin_vec::ThinVec;
23 /// Description of a frame in the query stack.
25 /// This is mostly used in case of cycles for error reporting.
26 #[derive(Clone, Debug)]
27 pub struct QueryStackFrame {
28 pub name: &'static str,
29 pub description: String,
31 pub def_id: Option<DefId>,
32 pub def_kind: Option<DefKind>,
33 pub ty_adt_id: Option<DefId>,
34 /// This hash is used to deterministically pick
35 /// a query to remove cycles in the parallel compiler.
36 #[cfg(parallel_compiler)]
40 impl QueryStackFrame {
46 def_id: Option<DefId>,
47 def_kind: Option<DefKind>,
48 ty_adt_id: Option<DefId>,
49 _hash: impl FnOnce() -> u64,
58 #[cfg(parallel_compiler)]
63 // FIXME(eddyb) Get more valid `Span`s on queries.
65 pub fn default_span(&self, span: Span) -> Span {
69 self.span.unwrap_or(span)
73 /// Tracks 'side effects' for a particular query.
74 /// This struct is saved to disk along with the query result,
75 /// and loaded from disk if we mark the query as green.
76 /// This allows us to 'replay' changes to global state
77 /// that would otherwise only occur if we actually
78 /// executed the query method.
79 #[derive(Debug, Clone, Default, Encodable, Decodable)]
80 pub struct QuerySideEffects {
81 /// Stores any diagnostics emitted during query execution.
82 /// These diagnostics will be re-emitted if we mark
83 /// the query as green.
84 pub(super) diagnostics: ThinVec<Diagnostic>,
87 impl QuerySideEffects {
89 pub fn is_empty(&self) -> bool {
90 let QuerySideEffects { diagnostics } = self;
91 diagnostics.is_empty()
93 pub fn append(&mut self, other: QuerySideEffects) {
94 let QuerySideEffects { diagnostics } = self;
95 diagnostics.extend(other.diagnostics);
99 pub trait QueryContext: HasDepContext {
100 fn next_job_id(&self) -> QueryJobId;
102 /// Get the query information from the TLS context.
103 fn current_query_job(&self) -> Option<QueryJobId>;
105 fn try_collect_active_jobs(&self) -> Option<QueryMap>;
107 /// Load side effects associated to the node in the previous session.
108 fn load_side_effects(&self, prev_dep_node_index: SerializedDepNodeIndex) -> QuerySideEffects;
110 /// Register diagnostics for the given node, for use in next session.
111 fn store_side_effects(&self, dep_node_index: DepNodeIndex, side_effects: QuerySideEffects);
113 /// Register diagnostics for the given node, for use in next session.
114 fn store_side_effects_for_anon_node(
116 dep_node_index: DepNodeIndex,
117 side_effects: QuerySideEffects,
120 /// Executes a job by changing the `ImplicitCtxt` to point to the
121 /// new query job while it executes. It returns the diagnostics
122 /// captured during execution and the actual result.
127 diagnostics: Option<&Lock<ThinVec<Diagnostic>>>,
128 compute: impl FnOnce() -> R,
131 fn depth_limit_error(&self, job: QueryJobId);