Skip to content

Commit

Permalink
Rename read_query_job -> current_query_job and simplify it.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgillot committed Mar 26, 2020
1 parent fce0d37 commit d224e21
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/librustc/ty/query/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ impl QueryContext for TyCtxt<'tcx> {
&self.dep_graph
}

fn read_query_job<R>(&self, op: impl FnOnce(Option<QueryJobId<Self::DepKind>>) -> R) -> R {
tls::with_related_context(*self, move |icx| op(icx.query))
fn current_query_job(&self) -> Option<QueryJobId<Self::DepKind>> {
tls::with_related_context(*self, |icx| icx.query)
}

fn try_collect_active_jobs(
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_query_system/query/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub trait QueryContext: DepContext {
fn dep_graph(&self) -> &DepGraph<Self::DepKind>;

/// Get the query information from the TLS context.
fn read_query_job<R>(&self, op: impl FnOnce(Option<QueryJobId<Self::DepKind>>) -> R) -> R;
fn current_query_job(&self) -> Option<QueryJobId<Self::DepKind>>;

fn try_collect_active_jobs(
&self,
Expand Down
31 changes: 13 additions & 18 deletions src/librustc_query_system/query/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ impl<CTX: QueryContext> QueryLatch<CTX> {
let query_map = tcx.try_collect_active_jobs().unwrap();

// Get the current executing query (waiter) and find the waitee amongst its parents
let mut current_job = tcx.read_query_job(|query| query);
let mut current_job = tcx.current_query_job();
let mut cycle = Vec::new();

while let Some(job) = current_job {
Expand Down Expand Up @@ -222,23 +222,18 @@ impl<CTX: QueryContext> QueryLatch<CTX> {
impl<CTX: QueryContext> QueryLatch<CTX> {
/// Awaits for the query job to complete.
pub(super) fn wait_on(&self, tcx: CTX, span: Span) -> Result<(), CycleError<CTX::Query>> {
tcx.read_query_job(move |query| {
let waiter = Lrc::new(QueryWaiter {
query,
span,
cycle: Lock::new(None),
condvar: Condvar::new(),
});
self.wait_on_inner(&waiter);
// FIXME: Get rid of this lock. We have ownership of the QueryWaiter
// although another thread may still have a Lrc reference so we cannot
// use Lrc::get_mut
let mut cycle = waiter.cycle.lock();
match cycle.take() {
None => Ok(()),
Some(cycle) => Err(cycle),
}
})
let query = tcx.current_query_job();
let waiter =
Lrc::new(QueryWaiter { query, span, cycle: Lock::new(None), condvar: Condvar::new() });
self.wait_on_inner(&waiter);
// FIXME: Get rid of this lock. We have ownership of the QueryWaiter
// although another thread may still have a Lrc reference so we cannot
// use Lrc::get_mut
let mut cycle = waiter.cycle.lock();
match cycle.take() {
None => Ok(()),
Some(cycle) => Err(cycle),
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/librustc_query_system/query/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ where

let global_id = QueryJobId::new(id, lookup.shard, Q::DEP_KIND);

let job = tcx.read_query_job(|query| QueryJob::new(id, span, query));
let job = tcx.current_query_job();
let job = QueryJob::new(id, span, job);

entry.insert(QueryResult::Started(job));

Expand Down

0 comments on commit d224e21

Please sign in to comment.