Skip to content

Commit 6c3305e

Browse files
committed
Remove QueryResult
1 parent bb78d13 commit 6c3305e

File tree

2 files changed

+13
-23
lines changed

2 files changed

+13
-23
lines changed

src/librustc/ty/query/job.rs

-9
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

+13-14
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@
1515
use dep_graph::{DepNodeIndex, DepNode, DepKind, DepNodeColor, OpenTask};
1616
use errors::DiagnosticBuilder;
1717
use errors::Level;
18-
use errors::FatalError;
1918
use ty::tls;
2019
use ty::{TyCtxt};
2120
use ty::query::Query;
2221
use ty::query::config::{QueryConfig, QueryDescription};
23-
use ty::query::job::{QueryJob, QueryResult, QueryInfo};
22+
use ty::query::job::{QueryJob, QueryInfo};
2423
use ty::item_path;
2524

2625
use util::common::{profq_msg, ProfileQueriesMsg, QueryMsg};
@@ -36,8 +35,12 @@ use syntax_pos::Span;
3635
use syntax::source_map::DUMMY_SP;
3736

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

4346
pub(super) struct QueryValue<T> {
@@ -209,12 +212,7 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
209212
return TryGetJob::JobCompleted(result);
210213
}
211214
let job = match lock.active.raw_entry_mut().from_key_hashed_nocheck(key_hash, key) {
212-
RawEntryMut::Occupied(entry) => {
213-
match *entry.get() {
214-
QueryResult::Started(ref job) => job.clone(),
215-
QueryResult::Poisoned => FatalError.raise(),
216-
}
217-
}
215+
RawEntryMut::Occupied(entry) => entry.get().clone(),
218216
RawEntryMut::Vacant(entry) => {
219217
// No job entry for this query. Return a new one to be started later
220218
return tls::with_related_context(tcx, |icx| {
@@ -236,7 +234,7 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
236234
entry.insert_hashed_nocheck(
237235
key_hash,
238236
key.clone(),
239-
QueryResult::Started(job));
237+
job);
240238
TryGetJob::NotYetStarted(owner)
241239
})
242240
}
@@ -313,10 +311,11 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> Drop for JobOwner<'a, 'tcx, Q> {
313311
#[inline(never)]
314312
#[cold]
315313
fn drop(&mut self) {
316-
// Poison the query so jobs waiting on it panic
317-
self.cache.borrow_mut().active.insert(self.key.clone(), QueryResult::Poisoned);
318-
// Also signal the completion of the job, so waiters
319-
// will continue execution
314+
// This job failed to execute due to a panic.
315+
// Remove it from the list of active queries
316+
self.cache.borrow_mut().active.remove(&self.key);
317+
// Signal that the job not longer executes, so the waiters will continue execution.
318+
// The waiters will try to execute the query which may result in them panicking too.
320319
self.job.signal_complete();
321320
}
322321
}

0 commit comments

Comments
 (0)