Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove QueryResult #57031

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
37 changes: 14 additions & 23 deletions src/librustc/ty/query/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@ use dep_graph::{DepNodeIndex, DepNode, DepKind, DepNodeColor};
use errors::DiagnosticBuilder;
use errors::Level;
use errors::Diagnostic;
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 @@ -35,8 +34,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 @@ -127,12 +130,7 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
return TryGetJob::JobCompleted(result);
}
let job = match lock.active.entry((*key).clone()) {
Entry::Occupied(entry) => {
match *entry.get() {
QueryResult::Started(ref job) => job.clone(),
QueryResult::Poisoned => FatalError.raise(),
}
}
Entry::Occupied(entry) => entry.get().clone(),
Entry::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 @@ -146,7 +144,7 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
job: job.clone(),
key: (*key).clone(),
};
entry.insert(QueryResult::Started(job));
entry.insert(job);
TryGetJob::NotYetStarted(owner)
})
}
Expand Down Expand Up @@ -228,10 +226,11 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {

impl<'a, 'tcx, Q: QueryDescription<'tcx>> Drop for JobOwner<'a, 'tcx, Q> {
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 Expand Up @@ -706,8 +705,6 @@ macro_rules! define_queries_inner {
[$($modifiers:tt)*] fn $name:ident: $node:ident($K:ty) -> $V:ty,)*) => {

use std::mem;
#[cfg(parallel_queries)]
use ty::query::job::QueryResult;
use rustc_data_structures::sync::Lock;
use {
rustc_data_structures::stable_hasher::HashStable,
Expand Down Expand Up @@ -744,13 +741,7 @@ macro_rules! define_queries_inner {
// deadlock handler, and this shouldn't be locked
$(
jobs.extend(
self.$name.try_lock().unwrap().active.values().filter_map(|v|
if let QueryResult::Started(ref job) = *v {
Some(job.clone())
} else {
None
}
)
self.$name.try_lock().unwrap().active.values().cloned()
);
)*

Expand Down