diff options
| author | John Kåre Alsaker <john.kare.alsaker@gmail.com> | 2024-03-07 06:47:08 +0100 |
|---|---|---|
| committer | John Kåre Alsaker <john.kare.alsaker@gmail.com> | 2025-03-14 16:01:58 +0100 |
| commit | 3ca5220114c1e690d876aa46c3aa0f6ec594b9c5 (patch) | |
| tree | 42a42ac8a3a3b378c2a6da3faa244e68893e16b4 /compiler/rustc_query_system/src/query | |
| parent | f7b43542838f0a4a6cfdb17fbeadf45002042a77 (diff) | |
| download | rust-3ca5220114c1e690d876aa46c3aa0f6ec594b9c5.tar.gz rust-3ca5220114c1e690d876aa46c3aa0f6ec594b9c5.zip | |
Represent diagnostic side effects as dep nodes
Diffstat (limited to 'compiler/rustc_query_system/src/query')
| -rw-r--r-- | compiler/rustc_query_system/src/query/mod.rs | 45 | ||||
| -rw-r--r-- | compiler/rustc_query_system/src/query/plumbing.rs | 60 |
2 files changed, 31 insertions, 74 deletions
diff --git a/compiler/rustc_query_system/src/query/mod.rs b/compiler/rustc_query_system/src/query/mod.rs index 7490a3f3503..ad246b3e8b1 100644 --- a/compiler/rustc_query_system/src/query/mod.rs +++ b/compiler/rustc_query_system/src/query/mod.rs @@ -11,14 +11,12 @@ mod caches; pub use self::caches::{DefIdCache, DefaultCache, QueryCache, SingleCache, VecCache}; mod config; -use rustc_data_structures::sync::Lock; use rustc_errors::DiagInner; use rustc_hashes::Hash64; use rustc_hir::def::DefKind; use rustc_macros::{Decodable, Encodable}; use rustc_span::Span; use rustc_span::def_id::DefId; -use thin_vec::ThinVec; pub use self::config::{HashResult, QueryConfig}; use crate::dep_graph::{DepKind, DepNodeIndex, HasDepContext, SerializedDepNodeIndex}; @@ -70,27 +68,12 @@ impl QueryStackFrame { /// This allows us to 'replay' changes to global state /// that would otherwise only occur if we actually /// executed the query method. -#[derive(Debug, Clone, Default, Encodable, Decodable)] +#[derive(Debug, Encodable, Decodable)] pub struct QuerySideEffects { /// Stores any diagnostics emitted during query execution. /// These diagnostics will be re-emitted if we mark /// the query as green. - pub(super) diagnostics: ThinVec<DiagInner>, -} - -impl QuerySideEffects { - /// Returns true if there might be side effects. - #[inline] - pub fn maybe_any(&self) -> bool { - let QuerySideEffects { diagnostics } = self; - // Use `has_capacity` so that the destructor for `self.diagnostics` can be skipped - // if `maybe_any` is known to be false. - diagnostics.has_capacity() - } - pub fn append(&mut self, other: QuerySideEffects) { - let QuerySideEffects { diagnostics } = self; - diagnostics.extend(other.diagnostics); - } + pub(super) diagnostic: DiagInner, } pub trait QueryContext: HasDepContext { @@ -102,28 +85,18 @@ pub trait QueryContext: HasDepContext { fn collect_active_jobs(self) -> QueryMap; /// Load side effects associated to the node in the previous session. - fn load_side_effects(self, prev_dep_node_index: SerializedDepNodeIndex) -> QuerySideEffects; + fn load_side_effects( + self, + prev_dep_node_index: SerializedDepNodeIndex, + ) -> Option<QuerySideEffects>; /// Register diagnostics for the given node, for use in next session. fn store_side_effects(self, dep_node_index: DepNodeIndex, side_effects: QuerySideEffects); - /// Register diagnostics for the given node, for use in next session. - fn store_side_effects_for_anon_node( - self, - dep_node_index: DepNodeIndex, - side_effects: QuerySideEffects, - ); - /// Executes a job by changing the `ImplicitCtxt` to point to the - /// new query job while it executes. It returns the diagnostics - /// captured during execution and the actual result. - fn start_query<R>( - self, - token: QueryJobId, - depth_limit: bool, - diagnostics: Option<&Lock<ThinVec<DiagInner>>>, - compute: impl FnOnce() -> R, - ) -> R; + /// new query job while it executes. + fn start_query<R>(self, token: QueryJobId, depth_limit: bool, compute: impl FnOnce() -> R) + -> R; fn depth_limit_error(self, job: QueryJobId); } diff --git a/compiler/rustc_query_system/src/query/plumbing.rs b/compiler/rustc_query_system/src/query/plumbing.rs index 18aae8c00b2..7578cb5e2ae 100644 --- a/compiler/rustc_query_system/src/query/plumbing.rs +++ b/compiler/rustc_query_system/src/query/plumbing.rs @@ -12,11 +12,9 @@ use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::sharded::Sharded; use rustc_data_structures::stack::ensure_sufficient_stack; -use rustc_data_structures::sync::Lock; use rustc_data_structures::{outline, sync}; use rustc_errors::{Diag, FatalError, StashKey}; use rustc_span::{DUMMY_SP, Span}; -use thin_vec::ThinVec; use tracing::instrument; use super::QueryConfig; @@ -25,9 +23,7 @@ use crate::dep_graph::{DepContext, DepGraphData, DepNode, DepNodeIndex, DepNodeP use crate::ich::StableHashingContext; use crate::query::caches::QueryCache; use crate::query::job::{QueryInfo, QueryJob, QueryJobId, QueryJobInfo, QueryLatch, report_cycle}; -use crate::query::{ - QueryContext, QueryMap, QuerySideEffects, QueryStackFrame, SerializedDepNodeIndex, -}; +use crate::query::{QueryContext, QueryMap, QueryStackFrame, SerializedDepNodeIndex}; pub struct QueryState<K> { active: Sharded<FxHashMap<K, QueryResult>>, @@ -470,7 +466,7 @@ where } let prof_timer = qcx.dep_context().profiler().query_provider(); - let result = qcx.start_query(job_id, query.depth_limit(), None, || query.compute(qcx, key)); + let result = qcx.start_query(job_id, query.depth_limit(), || query.compute(qcx, key)); let dep_node_index = qcx.dep_context().dep_graph().next_virtual_depnode_index(); prof_timer.finish_with_query_invocation_id(dep_node_index.into()); @@ -507,7 +503,7 @@ where // The diagnostics for this query will be promoted to the current session during // `try_mark_green()`, so we can ignore them here. - if let Some(ret) = qcx.start_query(job_id, false, None, || { + if let Some(ret) = qcx.start_query(job_id, false, || { try_load_from_disk_and_cache_in_memory(query, dep_graph_data, qcx, &key, dep_node) }) { return ret; @@ -515,43 +511,31 @@ where } let prof_timer = qcx.dep_context().profiler().query_provider(); - let diagnostics = Lock::new(ThinVec::new()); - let (result, dep_node_index) = - qcx.start_query(job_id, query.depth_limit(), Some(&diagnostics), || { - if query.anon() { - return dep_graph_data.with_anon_task_inner( - *qcx.dep_context(), - query.dep_kind(), - || query.compute(qcx, key), - ); - } + let (result, dep_node_index) = qcx.start_query(job_id, query.depth_limit(), || { + if query.anon() { + return dep_graph_data.with_anon_task_inner( + *qcx.dep_context(), + query.dep_kind(), + || query.compute(qcx, key), + ); + } - // `to_dep_node` is expensive for some `DepKind`s. - let dep_node = - dep_node_opt.unwrap_or_else(|| query.construct_dep_node(*qcx.dep_context(), &key)); + // `to_dep_node` is expensive for some `DepKind`s. + let dep_node = + dep_node_opt.unwrap_or_else(|| query.construct_dep_node(*qcx.dep_context(), &key)); - dep_graph_data.with_task( - dep_node, - (qcx, query), - key, - |(qcx, query), key| query.compute(qcx, key), - query.hash_result(), - ) - }); + dep_graph_data.with_task( + dep_node, + (qcx, query), + key, + |(qcx, query), key| query.compute(qcx, key), + query.hash_result(), + ) + }); prof_timer.finish_with_query_invocation_id(dep_node_index.into()); - let side_effects = QuerySideEffects { diagnostics: diagnostics.into_inner() }; - - if std::intrinsics::unlikely(side_effects.maybe_any()) { - if query.anon() { - qcx.store_side_effects_for_anon_node(dep_node_index, side_effects); - } else { - qcx.store_side_effects(dep_node_index, side_effects); - } - } - (result, dep_node_index) } |
