]>
Commit | Line | Data |
---|---|---|
ba9703b0 XL |
1 | mod plumbing; |
2 | pub use self::plumbing::*; | |
3 | ||
4 | mod job; | |
5 | #[cfg(parallel_compiler)] | |
6 | pub use self::job::deadlock; | |
6a06907d | 7 | pub use self::job::{print_query_stack, QueryInfo, QueryJob, QueryJobId, QueryJobInfo, QueryMap}; |
ba9703b0 XL |
8 | |
9 | mod caches; | |
f9f354fc | 10 | pub use self::caches::{ |
353b0b11 | 11 | CacheSelector, DefaultCacheSelector, QueryCache, SingleCacheSelector, VecCacheSelector, |
f9f354fc | 12 | }; |
ba9703b0 XL |
13 | |
14 | mod config; | |
9c376795 | 15 | pub use self::config::{HashResult, QueryConfig, TryLoadFromDisk}; |
ba9703b0 | 16 | |
9c376795 | 17 | use crate::dep_graph::DepKind; |
2b03887a | 18 | use crate::dep_graph::{DepNodeIndex, HasDepContext, SerializedDepNodeIndex}; |
ba9703b0 | 19 | use rustc_data_structures::sync::Lock; |
ba9703b0 | 20 | use rustc_errors::Diagnostic; |
5e7ed085 | 21 | use rustc_hir::def::DefKind; |
2b03887a | 22 | use rustc_span::def_id::DefId; |
6a06907d | 23 | use rustc_span::Span; |
f2b60f7d | 24 | use thin_vec::ThinVec; |
ba9703b0 | 25 | |
6a06907d XL |
26 | /// Description of a frame in the query stack. |
27 | /// | |
28 | /// This is mostly used in case of cycles for error reporting. | |
29 | #[derive(Clone, Debug)] | |
9c376795 | 30 | pub struct QueryStackFrame<D: DepKind> { |
6a06907d XL |
31 | pub description: String, |
32 | span: Option<Span>, | |
2b03887a FG |
33 | pub def_id: Option<DefId>, |
34 | pub def_kind: Option<DefKind>, | |
35 | pub ty_adt_id: Option<DefId>, | |
9c376795 | 36 | pub dep_kind: D, |
6a06907d XL |
37 | /// This hash is used to deterministically pick |
38 | /// a query to remove cycles in the parallel compiler. | |
39 | #[cfg(parallel_compiler)] | |
40 | hash: u64, | |
41 | } | |
42 | ||
9c376795 | 43 | impl<D: DepKind> QueryStackFrame<D> { |
6a06907d XL |
44 | #[inline] |
45 | pub fn new( | |
6a06907d XL |
46 | description: String, |
47 | span: Option<Span>, | |
2b03887a | 48 | def_id: Option<DefId>, |
5e7ed085 | 49 | def_kind: Option<DefKind>, |
9c376795 | 50 | dep_kind: D, |
2b03887a | 51 | ty_adt_id: Option<DefId>, |
6a06907d XL |
52 | _hash: impl FnOnce() -> u64, |
53 | ) -> Self { | |
54 | Self { | |
6a06907d XL |
55 | description, |
56 | span, | |
2b03887a | 57 | def_id, |
94222f64 | 58 | def_kind, |
2b03887a | 59 | ty_adt_id, |
9c376795 | 60 | dep_kind, |
6a06907d XL |
61 | #[cfg(parallel_compiler)] |
62 | hash: _hash(), | |
63 | } | |
64 | } | |
ba9703b0 | 65 | |
6a06907d XL |
66 | // FIXME(eddyb) Get more valid `Span`s on queries. |
67 | #[inline] | |
68 | pub fn default_span(&self, span: Span) -> Span { | |
69 | if !span.is_dummy() { | |
70 | return span; | |
71 | } | |
72 | self.span.unwrap_or(span) | |
73 | } | |
74 | } | |
ba9703b0 | 75 | |
94222f64 XL |
76 | /// Tracks 'side effects' for a particular query. |
77 | /// This struct is saved to disk along with the query result, | |
78 | /// and loaded from disk if we mark the query as green. | |
79 | /// This allows us to 'replay' changes to global state | |
80 | /// that would otherwise only occur if we actually | |
81 | /// executed the query method. | |
82 | #[derive(Debug, Clone, Default, Encodable, Decodable)] | |
83 | pub struct QuerySideEffects { | |
84 | /// Stores any diagnostics emitted during query execution. | |
85 | /// These diagnostics will be re-emitted if we mark | |
86 | /// the query as green. | |
87 | pub(super) diagnostics: ThinVec<Diagnostic>, | |
88 | } | |
89 | ||
90 | impl QuerySideEffects { | |
064997fb | 91 | #[inline] |
94222f64 XL |
92 | pub fn is_empty(&self) -> bool { |
93 | let QuerySideEffects { diagnostics } = self; | |
94 | diagnostics.is_empty() | |
95 | } | |
96 | pub fn append(&mut self, other: QuerySideEffects) { | |
97 | let QuerySideEffects { diagnostics } = self; | |
98 | diagnostics.extend(other.diagnostics); | |
99 | } | |
100 | } | |
101 | ||
6a06907d | 102 | pub trait QueryContext: HasDepContext { |
9ffffee4 | 103 | fn next_job_id(self) -> QueryJobId; |
5099ac24 | 104 | |
ba9703b0 | 105 | /// Get the query information from the TLS context. |
9ffffee4 | 106 | fn current_query_job(self) -> Option<QueryJobId>; |
ba9703b0 | 107 | |
9ffffee4 | 108 | fn try_collect_active_jobs(self) -> Option<QueryMap<Self::DepKind>>; |
6a06907d | 109 | |
94222f64 | 110 | /// Load side effects associated to the node in the previous session. |
9ffffee4 | 111 | fn load_side_effects(self, prev_dep_node_index: SerializedDepNodeIndex) -> QuerySideEffects; |
6a06907d XL |
112 | |
113 | /// Register diagnostics for the given node, for use in next session. | |
9ffffee4 | 114 | fn store_side_effects(self, dep_node_index: DepNodeIndex, side_effects: QuerySideEffects); |
6a06907d XL |
115 | |
116 | /// Register diagnostics for the given node, for use in next session. | |
94222f64 | 117 | fn store_side_effects_for_anon_node( |
9ffffee4 | 118 | self, |
6a06907d | 119 | dep_node_index: DepNodeIndex, |
94222f64 | 120 | side_effects: QuerySideEffects, |
6a06907d | 121 | ); |
ba9703b0 XL |
122 | |
123 | /// Executes a job by changing the `ImplicitCtxt` to point to the | |
124 | /// new query job while it executes. It returns the diagnostics | |
125 | /// captured during execution and the actual result. | |
126 | fn start_query<R>( | |
9ffffee4 | 127 | self, |
5099ac24 | 128 | token: QueryJobId, |
f2b60f7d | 129 | depth_limit: bool, |
ba9703b0 | 130 | diagnostics: Option<&Lock<ThinVec<Diagnostic>>>, |
6a06907d | 131 | compute: impl FnOnce() -> R, |
ba9703b0 | 132 | ) -> R; |
f2b60f7d | 133 | |
9ffffee4 | 134 | fn depth_limit_error(self, job: QueryJobId); |
ba9703b0 | 135 | } |