Skip to content

Commit 86e63ba

Browse files
committed
Remove QueryResult
1 parent 6d34ec1 commit 86e63ba

File tree

2 files changed

+14
-32
lines changed

2 files changed

+14
-32
lines changed

src/librustc/ty/query/job.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,6 @@ use {
4040
rustc_data_structures::stable_hasher::{StableHasherResult, StableHasher, HashStable},
4141
};
4242

43-
/// Indicates the state of a query for a given key in a query map
44-
pub(super) enum QueryResult<'tcx> {
45-
/// An already executing query. The query job can be used to await for its completion
46-
Started(Lrc<QueryJob<'tcx>>),
47-
48-
/// The query panicked. Queries trying to wait on this will raise a fatal error / silently panic
49-
Poisoned,
50-
}
51-
5243
/// A span and a query key
5344
#[derive(Clone, Debug)]
5445
pub struct QueryInfo<'tcx> {

src/librustc/ty/query/plumbing.rs

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@ use dep_graph::{DepNodeIndex, DepNode, DepKind, DepNodeColor};
1616
use errors::DiagnosticBuilder;
1717
use errors::Level;
1818
use errors::Diagnostic;
19-
use errors::FatalError;
2019
use ty::tls;
2120
use ty::{TyCtxt};
2221
use ty::query::Query;
2322
use ty::query::config::{QueryConfig, QueryDescription};
24-
use ty::query::job::{QueryJob, QueryResult, QueryInfo};
23+
use ty::query::job::{QueryJob, QueryInfo};
2524
use ty::item_path;
2625

2726
use util::common::{profq_msg, ProfileQueriesMsg, QueryMsg};
@@ -35,8 +34,12 @@ use syntax_pos::Span;
3534
use syntax::source_map::DUMMY_SP;
3635

3736
pub struct QueryCache<'tcx, D: QueryConfig<'tcx> + ?Sized> {
37+
/// Completed queries have their result stored here
3838
pub(super) results: FxHashMap<D::Key, QueryValue<D::Value>>,
39-
pub(super) active: FxHashMap<D::Key, QueryResult<'tcx>>,
39+
40+
/// Queries under execution will have an entry in this map.
41+
/// The query job inside can be used to await for completion of queries.
42+
pub(super) active: FxHashMap<D::Key, Lrc<QueryJob<'tcx>>>,
4043
}
4144

4245
pub(super) struct QueryValue<T> {
@@ -127,12 +130,7 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
127130
return TryGetJob::JobCompleted(result);
128131
}
129132
let job = match lock.active.entry((*key).clone()) {
130-
Entry::Occupied(entry) => {
131-
match *entry.get() {
132-
QueryResult::Started(ref job) => job.clone(),
133-
QueryResult::Poisoned => FatalError.raise(),
134-
}
135-
}
133+
Entry::Occupied(entry) => entry.get().clone(),
136134
Entry::Vacant(entry) => {
137135
// No job entry for this query. Return a new one to be started later
138136
return tls::with_related_context(tcx, |icx| {
@@ -146,7 +144,7 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
146144
job: job.clone(),
147145
key: (*key).clone(),
148146
};
149-
entry.insert(QueryResult::Started(job));
147+
entry.insert(job);
150148
TryGetJob::NotYetStarted(owner)
151149
})
152150
}
@@ -228,10 +226,11 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
228226

229227
impl<'a, 'tcx, Q: QueryDescription<'tcx>> Drop for JobOwner<'a, 'tcx, Q> {
230228
fn drop(&mut self) {
231-
// Poison the query so jobs waiting on it panic
232-
self.cache.borrow_mut().active.insert(self.key.clone(), QueryResult::Poisoned);
233-
// Also signal the completion of the job, so waiters
234-
// will continue execution
229+
// This job failed to execute due to a panic.
230+
// Remove it from the list of active queries
231+
self.cache.borrow_mut().active.remove(&self.key);
232+
// Signal that the job not longer executes, so the waiters will continue execution.
233+
// The waiters will try to execute the query which may result in them panicking too.
235234
self.job.signal_complete();
236235
}
237236
}
@@ -706,8 +705,6 @@ macro_rules! define_queries_inner {
706705
[$($modifiers:tt)*] fn $name:ident: $node:ident($K:ty) -> $V:ty,)*) => {
707706

708707
use std::mem;
709-
#[cfg(parallel_queries)]
710-
use ty::query::job::QueryResult;
711708
use rustc_data_structures::sync::Lock;
712709
use {
713710
rustc_data_structures::stable_hasher::HashStable,
@@ -744,13 +741,7 @@ macro_rules! define_queries_inner {
744741
// deadlock handler, and this shouldn't be locked
745742
$(
746743
jobs.extend(
747-
self.$name.try_lock().unwrap().active.values().filter_map(|v|
748-
if let QueryResult::Started(ref job) = *v {
749-
Some(job.clone())
750-
} else {
751-
None
752-
}
753-
)
744+
self.$name.try_lock().unwrap().active.values().cloned()
754745
);
755746
)*
756747

0 commit comments

Comments
 (0)