Skip to content

Commit

Permalink
Remove QueryResult
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoxc committed Dec 7, 2018
1 parent bb78d13 commit 6c3305e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 23 deletions.
9 changes: 0 additions & 9 deletions src/librustc/ty/query/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,6 @@ use {
rustc_data_structures::stable_hasher::{StableHasherResult, StableHasher, HashStable},
};

/// Indicates the state of a query for a given key in a query map
pub(super) enum QueryResult<'tcx> {
/// An already executing query. The query job can be used to await for its completion
Started(Lrc<QueryJob<'tcx>>),

/// The query panicked. Queries trying to wait on this will raise a fatal error / silently panic
Poisoned,
}

/// A span and a query key
#[derive(Clone, Debug)]
pub struct QueryInfo<'tcx> {
Expand Down
27 changes: 13 additions & 14 deletions src/librustc/ty/query/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@
use dep_graph::{DepNodeIndex, DepNode, DepKind, DepNodeColor, OpenTask};
use errors::DiagnosticBuilder;
use errors::Level;
use errors::FatalError;
use ty::tls;
use ty::{TyCtxt};
use ty::query::Query;
use ty::query::config::{QueryConfig, QueryDescription};
use ty::query::job::{QueryJob, QueryResult, QueryInfo};
use ty::query::job::{QueryJob, QueryInfo};
use ty::item_path;

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

pub struct QueryCache<'tcx, D: QueryConfig<'tcx> + ?Sized> {
/// Completed queries have their result stored here
pub(super) results: FxHashMap<D::Key, QueryValue<D::Value>>,
pub(super) active: FxHashMap<D::Key, QueryResult<'tcx>>,

/// Queries under execution will have an entry in this map.
/// The query job inside can be used to await for completion of queries.
pub(super) active: FxHashMap<D::Key, Lrc<QueryJob<'tcx>>>,
}

pub(super) struct QueryValue<T> {
Expand Down Expand Up @@ -209,12 +212,7 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
return TryGetJob::JobCompleted(result);
}
let job = match lock.active.raw_entry_mut().from_key_hashed_nocheck(key_hash, key) {
RawEntryMut::Occupied(entry) => {
match *entry.get() {
QueryResult::Started(ref job) => job.clone(),
QueryResult::Poisoned => FatalError.raise(),
}
}
RawEntryMut::Occupied(entry) => entry.get().clone(),
RawEntryMut::Vacant(entry) => {
// No job entry for this query. Return a new one to be started later
return tls::with_related_context(tcx, |icx| {
Expand All @@ -236,7 +234,7 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
entry.insert_hashed_nocheck(
key_hash,
key.clone(),
QueryResult::Started(job));
job);
TryGetJob::NotYetStarted(owner)
})
}
Expand Down Expand Up @@ -313,10 +311,11 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> Drop for JobOwner<'a, 'tcx, Q> {
#[inline(never)]
#[cold]
fn drop(&mut self) {
// Poison the query so jobs waiting on it panic
self.cache.borrow_mut().active.insert(self.key.clone(), QueryResult::Poisoned);
// Also signal the completion of the job, so waiters
// will continue execution
// This job failed to execute due to a panic.
// Remove it from the list of active queries
self.cache.borrow_mut().active.remove(&self.key);
// Signal that the job not longer executes, so the waiters will continue execution.
// The waiters will try to execute the query which may result in them panicking too.
self.job.signal_complete();
}
}
Expand Down

0 comments on commit 6c3305e

Please sign in to comment.