From d224e214e051a92c5313a2d4ec0c94d41c4ba01d Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Wed, 25 Mar 2020 07:52:12 +0100 Subject: [PATCH] Rename read_query_job -> current_query_job and simplify it. --- src/librustc/ty/query/plumbing.rs | 4 +-- src/librustc_query_system/query/config.rs | 2 +- src/librustc_query_system/query/job.rs | 31 +++++++++------------ src/librustc_query_system/query/plumbing.rs | 3 +- 4 files changed, 18 insertions(+), 22 deletions(-) diff --git a/src/librustc/ty/query/plumbing.rs b/src/librustc/ty/query/plumbing.rs index 8e34aba8a9e..8cdc1ae27ee 100644 --- a/src/librustc/ty/query/plumbing.rs +++ b/src/librustc/ty/query/plumbing.rs @@ -32,8 +32,8 @@ fn dep_graph(&self) -> &DepGraph { &self.dep_graph } - fn read_query_job(&self, op: impl FnOnce(Option>) -> R) -> R { - tls::with_related_context(*self, move |icx| op(icx.query)) + fn current_query_job(&self) -> Option> { + tls::with_related_context(*self, |icx| icx.query) } fn try_collect_active_jobs( diff --git a/src/librustc_query_system/query/config.rs b/src/librustc_query_system/query/config.rs index 10338f65471..106688d2b54 100644 --- a/src/librustc_query_system/query/config.rs +++ b/src/librustc_query_system/query/config.rs @@ -43,7 +43,7 @@ pub trait QueryContext: DepContext { fn dep_graph(&self) -> &DepGraph; /// Get the query information from the TLS context. - fn read_query_job(&self, op: impl FnOnce(Option>) -> R) -> R; + fn current_query_job(&self) -> Option>; fn try_collect_active_jobs( &self, diff --git a/src/librustc_query_system/query/job.rs b/src/librustc_query_system/query/job.rs index 92ab97f210a..a7488b6fdff 100644 --- a/src/librustc_query_system/query/job.rs +++ b/src/librustc_query_system/query/job.rs @@ -150,7 +150,7 @@ pub(super) fn find_cycle_in_stack(&self, tcx: CTX, span: Span) -> CycleError Self { impl QueryLatch { /// Awaits for the query job to complete. pub(super) fn wait_on(&self, tcx: CTX, span: Span) -> Result<(), CycleError> { - 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), + } } } diff --git a/src/librustc_query_system/query/plumbing.rs b/src/librustc_query_system/query/plumbing.rs index e1b86e55ce8..b3187ba9189 100644 --- a/src/librustc_query_system/query/plumbing.rs +++ b/src/librustc_query_system/query/plumbing.rs @@ -211,7 +211,8 @@ fn try_start<'a, 'b, Q>( 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)); -- 2.44.0