Rename read_query_job -> current_query_job and simplify it.

This commit is contained in:
Camille GILLOT 2020-03-25 07:52:12 +01:00
parent fce0d37619
commit d224e214e0
4 changed files with 18 additions and 22 deletions

View File

@ -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(

View File

@ -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,

View File

@ -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 {
@ -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),
}
}
}

View File

@ -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));