X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=compiler%2Frustc_query_system%2Fsrc%2Fquery%2Fplumbing.rs;h=53844dab9db59490992e073f0b62bf742df3f223;hb=58233e90b8e4f2712b0155f437cbad8d1bc6c58e;hp=848fa67e3df25f4e1643b9ca06a004747ae092a7;hpb=4d5a2f3d81ed3d36bef505258149bcee1be1394b;p=rust.git diff --git a/compiler/rustc_query_system/src/query/plumbing.rs b/compiler/rustc_query_system/src/query/plumbing.rs index 848fa67e3df..53844dab9db 100644 --- a/compiler/rustc_query_system/src/query/plumbing.rs +++ b/compiler/rustc_query_system/src/query/plumbing.rs @@ -2,7 +2,7 @@ //! generate the actual methods on tcx which find and execute the provider, //! manage the caches, and so forth. -use crate::dep_graph::{DepContext, DepNode, DepNodeIndex, DepNodeParams}; +use crate::dep_graph::{DepContext, DepKind, DepNode, DepNodeIndex, DepNodeParams}; use crate::ich::StableHashingContext; use crate::query::caches::QueryCache; use crate::query::config::QueryVTable; @@ -31,26 +31,27 @@ use super::QueryConfig; -pub struct QueryState { +pub struct QueryState { #[cfg(parallel_compiler)] - active: Sharded>, + active: Sharded>>, #[cfg(not(parallel_compiler))] - active: Lock>, + active: Lock>>, } /// Indicates the state of a query for a given key in a query map. -enum QueryResult { +enum QueryResult { /// An already executing query. The query job can be used to await for its completion. - Started(QueryJob), + Started(QueryJob), /// The query panicked. Queries trying to wait on this will raise a fatal error which will /// silently panic. Poisoned, } -impl QueryState +impl QueryState where K: Eq + Hash + Clone + Debug, + D: DepKind, { pub fn all_inactive(&self) -> bool { #[cfg(parallel_compiler)] @@ -67,8 +68,8 @@ pub fn all_inactive(&self) -> bool { pub fn try_collect_active_jobs( &self, qcx: Qcx, - make_query: fn(Qcx, K) -> QueryStackFrame, - jobs: &mut QueryMap, + make_query: fn(Qcx, K) -> QueryStackFrame, + jobs: &mut QueryMap, ) -> Option<()> { #[cfg(parallel_compiler)] { @@ -102,34 +103,34 @@ pub fn try_collect_active_jobs( } } -impl Default for QueryState { - fn default() -> QueryState { +impl Default for QueryState { + fn default() -> QueryState { QueryState { active: Default::default() } } } /// A type representing the responsibility to execute the job in the `job` field. /// This will poison the relevant query if dropped. -struct JobOwner<'tcx, K> +struct JobOwner<'tcx, K, D: DepKind> where K: Eq + Hash + Clone, { - state: &'tcx QueryState, + state: &'tcx QueryState, key: K, id: QueryJobId, } #[cold] #[inline(never)] -fn mk_cycle( +fn mk_cycle( qcx: Qcx, - cycle_error: CycleError, + cycle_error: CycleError, handler: HandleCycleError, cache: &dyn crate::query::QueryStorage, ) -> R where - Qcx: QueryContext, - V: std::fmt::Debug + Value, + Qcx: QueryContext + crate::query::HasDepContext, + V: std::fmt::Debug + Value, R: Clone, { let error = report_cycle(qcx.dep_context().sess(), &cycle_error); @@ -139,13 +140,13 @@ fn mk_cycle( fn handle_cycle_error( tcx: Tcx, - cycle_error: &CycleError, + cycle_error: &CycleError, mut error: DiagnosticBuilder<'_, ErrorGuaranteed>, handler: HandleCycleError, ) -> V where Tcx: DepContext, - V: Value, + V: Value, { use HandleCycleError::*; match handler { @@ -165,7 +166,7 @@ fn handle_cycle_error( } } -impl<'tcx, K> JobOwner<'tcx, K> +impl<'tcx, K, D: DepKind> JobOwner<'tcx, K, D> where K: Eq + Hash + Clone, { @@ -180,12 +181,12 @@ impl<'tcx, K> JobOwner<'tcx, K> #[inline(always)] fn try_start<'b, Qcx>( qcx: &'b Qcx, - state: &'b QueryState, + state: &'b QueryState, span: Span, key: K, - ) -> TryGetJob<'b, K> + ) -> TryGetJob<'b, K, D> where - Qcx: QueryContext, + Qcx: QueryContext + crate::query::HasDepContext, { #[cfg(parallel_compiler)] let mut state_lock = state.active.get_shard_by_value(&key).lock(); @@ -280,9 +281,10 @@ fn complete(self, cache: &C, result: C::Value, dep_node_index: DepNodeIndex) } } -impl<'tcx, K> Drop for JobOwner<'tcx, K> +impl<'tcx, K, D> Drop for JobOwner<'tcx, K, D> where K: Eq + Hash + Clone, + D: DepKind, { #[inline(never)] #[cold] @@ -308,19 +310,20 @@ fn drop(&mut self) { } #[derive(Clone)] -pub(crate) struct CycleError { +pub(crate) struct CycleError { /// The query and related span that uses the cycle. - pub usage: Option<(Span, QueryStackFrame)>, - pub cycle: Vec, + pub usage: Option<(Span, QueryStackFrame)>, + pub cycle: Vec>, } /// The result of `try_start`. -enum TryGetJob<'tcx, K> +enum TryGetJob<'tcx, K, D> where K: Eq + Hash + Clone, + D: DepKind, { /// The query is not yet started. Contains a guard to the cache eventually used to start it. - NotYetStarted(JobOwner<'tcx, K>), + NotYetStarted(JobOwner<'tcx, K, D>), /// The query was already completed. /// Returns the result of the query and its dep-node index @@ -329,7 +332,7 @@ enum TryGetJob<'tcx, K> JobCompleted(TimingGuard<'tcx>), /// Trying to execute the query resulted in a cycle. - Cycle(CycleError), + Cycle(CycleError), } /// Checks if the query is already computed and in the cache. @@ -337,9 +340,9 @@ enum TryGetJob<'tcx, K> /// which will be used if the query is not in the cache and we need /// to compute it. #[inline] -pub fn try_get_cached<'a, Tcx, C, R, OnHit>( +pub fn try_get_cached( tcx: Tcx, - cache: &'a C, + cache: &C, key: &C::Key, // `on_hit` can be called while holding a lock to the query cache on_hit: OnHit, @@ -360,7 +363,7 @@ pub fn try_get_cached<'a, Tcx, C, R, OnHit>( fn try_execute_query( qcx: Qcx, - state: &QueryState, + state: &QueryState, cache: &C, span: Span, key: C::Key, @@ -370,11 +373,11 @@ fn try_execute_query( where C: QueryCache, C::Key: Clone + DepNodeParams, - C::Value: Value, + C::Value: Value, C::Stored: Debug + std::borrow::Borrow, Qcx: QueryContext, { - match JobOwner::<'_, C::Key>::try_start(&qcx, state, span, key.clone()) { + match JobOwner::<'_, C::Key, Qcx::DepKind>::try_start(&qcx, state, span, key.clone()) { TryGetJob::NotYetStarted(job) => { let (result, dep_node_index) = execute_job(qcx, key.clone(), dep_node, query, job.id); if query.feedable { @@ -739,11 +742,12 @@ pub enum QueryMode { Ensure, } -pub fn get_query(qcx: Qcx, span: Span, key: Q::Key, mode: QueryMode) -> Option +pub fn get_query(qcx: Qcx, span: Span, key: Q::Key, mode: QueryMode) -> Option where + D: DepKind, Q: QueryConfig, Q::Key: DepNodeParams, - Q::Value: Value, + Q::Value: Value, Qcx: QueryContext, { let query = Q::make_vtable(qcx, &key); @@ -772,11 +776,12 @@ pub fn get_query(qcx: Qcx, span: Span, key: Q::Key, mode: QueryMode) -> Some(result) } -pub fn force_query(qcx: Qcx, key: Q::Key, dep_node: DepNode) +pub fn force_query(qcx: Qcx, key: Q::Key, dep_node: DepNode) where + D: DepKind, Q: QueryConfig, Q::Key: DepNodeParams, - Q::Value: Value, + Q::Value: Value, Qcx: QueryContext, { // We may be concurrently trying both execute and force a query.