about summary refs log tree commit diff
path: root/compiler/rustc_query_system/src/query/plumbing.rs
diff options
context:
space:
mode:
authorCamille GILLOT <gillot.camille@gmail.com>2020-11-28 22:48:05 +0100
committerCamille GILLOT <gillot.camille@gmail.com>2021-02-20 22:53:47 +0100
commit3897395787866281e98e3f0e41cf26dab5d94d7b (patch)
tree2a114967ca3e1965e2b2bdb9afc61456af463817 /compiler/rustc_query_system/src/query/plumbing.rs
parent0144d6a3b7e2f2bba4c7cc9adc04c2b6e4e01b93 (diff)
downloadrust-3897395787866281e98e3f0e41cf26dab5d94d7b.tar.gz
rust-3897395787866281e98e3f0e41cf26dab5d94d7b.zip
Move Query to rustc_query_system.
Rename it to QueryStackFrame and document a bit.
Diffstat (limited to 'compiler/rustc_query_system/src/query/plumbing.rs')
-rw-r--r--compiler/rustc_query_system/src/query/plumbing.rs69
1 files changed, 32 insertions, 37 deletions
diff --git a/compiler/rustc_query_system/src/query/plumbing.rs b/compiler/rustc_query_system/src/query/plumbing.rs
index dbe7c4c2320..28ee1a17994 100644
--- a/compiler/rustc_query_system/src/query/plumbing.rs
+++ b/compiler/rustc_query_system/src/query/plumbing.rs
@@ -7,7 +7,7 @@ use crate::dep_graph::{DepNodeIndex, SerializedDepNodeIndex};
 use crate::query::caches::QueryCache;
 use crate::query::config::{QueryDescription, QueryVtable, QueryVtableExt};
 use crate::query::job::{QueryInfo, QueryJob, QueryJobId, QueryJobInfo, QueryShardJobId};
-use crate::query::{QueryContext, QueryMap};
+use crate::query::{QueryContext, QueryMap, QueryStackFrame};
 
 #[cfg(not(parallel_compiler))]
 use rustc_data_structures::cold_path;
@@ -81,37 +81,36 @@ impl<C: QueryCache> QueryCacheStore<C> {
     }
 }
 
-struct QueryStateShard<D, Q, K> {
-    active: FxHashMap<K, QueryResult<D, Q>>,
+struct QueryStateShard<D, K> {
+    active: FxHashMap<K, QueryResult<D>>,
 
     /// Used to generate unique ids for active jobs.
     jobs: u32,
 }
 
-impl<D, Q, K> Default for QueryStateShard<D, Q, K> {
-    fn default() -> QueryStateShard<D, Q, K> {
+impl<D, K> Default for QueryStateShard<D, K> {
+    fn default() -> QueryStateShard<D, K> {
         QueryStateShard { active: Default::default(), jobs: 0 }
     }
 }
 
-pub struct QueryState<D, Q, K> {
-    shards: Sharded<QueryStateShard<D, Q, K>>,
+pub struct QueryState<D, K> {
+    shards: Sharded<QueryStateShard<D, K>>,
 }
 
 /// Indicates the state of a query for a given key in a query map.
-enum QueryResult<D, Q> {
+enum QueryResult<D> {
     /// An already executing query. The query job can be used to await for its completion.
-    Started(QueryJob<D, Q>),
+    Started(QueryJob<D>),
 
     /// The query panicked. Queries trying to wait on this will raise a fatal error which will
     /// silently panic.
     Poisoned,
 }
 
-impl<D, Q, K> QueryState<D, Q, K>
+impl<D, K> QueryState<D, K>
 where
     D: Copy + Clone + Eq + Hash,
-    Q: Clone,
     K: Eq + Hash + Clone + Debug,
 {
     pub fn all_inactive(&self) -> bool {
@@ -123,8 +122,8 @@ where
         &self,
         tcx: CTX,
         kind: D,
-        make_query: fn(CTX, K) -> Q,
-        jobs: &mut QueryMap<D, Q>,
+        make_query: fn(CTX, K) -> QueryStackFrame,
+        jobs: &mut QueryMap<D>,
     ) -> Option<()> {
         // We use try_lock_shards here since we are called from the
         // deadlock handler, and this shouldn't be locked.
@@ -146,30 +145,28 @@ where
     }
 }
 
-impl<D, Q, K> Default for QueryState<D, Q, K> {
-    fn default() -> QueryState<D, Q, K> {
+impl<D, K> Default for QueryState<D, K> {
+    fn default() -> QueryState<D, K> {
         QueryState { shards: 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, D, Q, C>
+struct JobOwner<'tcx, D, C>
 where
     D: Copy + Clone + Eq + Hash,
-    Q: Clone,
     C: QueryCache,
 {
-    state: &'tcx QueryState<D, Q, C::Key>,
+    state: &'tcx QueryState<D, C::Key>,
     cache: &'tcx QueryCacheStore<C>,
     key: C::Key,
     id: QueryJobId<D>,
 }
 
-impl<'tcx, D, Q, C> JobOwner<'tcx, D, Q, C>
+impl<'tcx, D, C> JobOwner<'tcx, D, C>
 where
     D: Copy + Clone + Eq + Hash,
-    Q: Clone,
     C: QueryCache,
 {
     /// Either gets a `JobOwner` corresponding the query, allowing us to
@@ -183,13 +180,13 @@ where
     #[inline(always)]
     fn try_start<'b, CTX>(
         tcx: CTX,
-        state: &'b QueryState<CTX::DepKind, CTX::Query, C::Key>,
+        state: &'b QueryState<CTX::DepKind, C::Key>,
         cache: &'b QueryCacheStore<C>,
         span: Span,
         key: &C::Key,
         lookup: QueryLookup,
         query: &QueryVtable<CTX, C::Key, C::Value>,
-    ) -> TryGetJob<'b, CTX::DepKind, CTX::Query, C>
+    ) -> TryGetJob<'b, CTX::DepKind, C>
     where
         CTX: QueryContext,
     {
@@ -243,7 +240,7 @@ where
         // so we just return the error.
         #[cfg(not(parallel_compiler))]
         return TryGetJob::Cycle(cold_path(|| {
-            let error: CycleError<CTX::Query> = latch.find_cycle_in_stack(
+            let error: CycleError = latch.find_cycle_in_stack(
                 tcx.try_collect_active_jobs().unwrap(),
                 &tcx.current_query_job(),
                 span,
@@ -328,10 +325,9 @@ where
     (result, diagnostics.into_inner())
 }
 
-impl<'tcx, D, Q, C> Drop for JobOwner<'tcx, D, Q, C>
+impl<'tcx, D, C> Drop for JobOwner<'tcx, D, C>
 where
     D: Copy + Clone + Eq + Hash,
-    Q: Clone,
     C: QueryCache,
 {
     #[inline(never)]
@@ -356,21 +352,20 @@ where
 }
 
 #[derive(Clone)]
-pub struct CycleError<Q> {
+pub struct CycleError {
     /// The query and related span that uses the cycle.
-    pub usage: Option<(Span, Q)>,
-    pub cycle: Vec<QueryInfo<Q>>,
+    pub usage: Option<(Span, QueryStackFrame)>,
+    pub cycle: Vec<QueryInfo>,
 }
 
 /// The result of `try_start`.
-enum TryGetJob<'tcx, D, Q, C>
+enum TryGetJob<'tcx, D, C>
 where
     D: Copy + Clone + Eq + Hash,
-    Q: Clone,
     C: QueryCache,
 {
     /// The query is not yet started. Contains a guard to the cache eventually used to start it.
-    NotYetStarted(JobOwner<'tcx, D, Q, C>),
+    NotYetStarted(JobOwner<'tcx, D, C>),
 
     /// The query was already completed.
     /// Returns the result of the query and its dep-node index
@@ -414,7 +409,7 @@ where
 
 fn try_execute_query<CTX, C>(
     tcx: CTX,
-    state: &QueryState<CTX::DepKind, CTX::Query, C::Key>,
+    state: &QueryState<CTX::DepKind, C::Key>,
     cache: &QueryCacheStore<C>,
     span: Span,
     key: C::Key,
@@ -426,7 +421,7 @@ where
     C::Key: crate::dep_graph::DepNodeParams<CTX::DepContext>,
     CTX: QueryContext,
 {
-    let job = match JobOwner::<'_, CTX::DepKind, CTX::Query, C>::try_start(
+    let job = match JobOwner::<'_, CTX::DepKind, C>::try_start(
         tcx, state, cache, span, &key, lookup, query,
     ) {
         TryGetJob::NotYetStarted(job) => job,
@@ -590,7 +585,7 @@ fn incremental_verify_ich<CTX, K, V: Debug>(
 fn force_query_with_job<C, CTX>(
     tcx: CTX,
     key: C::Key,
-    job: JobOwner<'_, CTX::DepKind, CTX::Query, C>,
+    job: JobOwner<'_, CTX::DepKind, C>,
     dep_node: DepNode<CTX::DepKind>,
     query: &QueryVtable<CTX, C::Key, C::Value>,
 ) -> (C::Stored, DepNodeIndex)
@@ -650,7 +645,7 @@ where
 #[inline(never)]
 fn get_query_impl<CTX, C>(
     tcx: CTX,
-    state: &QueryState<CTX::DepKind, CTX::Query, C::Key>,
+    state: &QueryState<CTX::DepKind, C::Key>,
     cache: &QueryCacheStore<C>,
     span: Span,
     key: C::Key,
@@ -708,7 +703,7 @@ where
 #[inline(never)]
 fn force_query_impl<CTX, C>(
     tcx: CTX,
-    state: &QueryState<CTX::DepKind, CTX::Query, C::Key>,
+    state: &QueryState<CTX::DepKind, C::Key>,
     cache: &QueryCacheStore<C>,
     key: C::Key,
     span: Span,
@@ -736,7 +731,7 @@ fn force_query_impl<CTX, C>(
         Err(lookup) => lookup,
     };
 
-    let job = match JobOwner::<'_, CTX::DepKind, CTX::Query, C>::try_start(
+    let job = match JobOwner::<'_, CTX::DepKind, C>::try_start(
         tcx, state, cache, span, &key, lookup, query,
     ) {
         TryGetJob::NotYetStarted(job) => job,