Skip to content

Commit d224e21

Browse files
committed
Rename read_query_job -> current_query_job and simplify it.
1 parent fce0d37 commit d224e21

File tree

4 files changed

+18
-22
lines changed

4 files changed

+18
-22
lines changed

src/librustc/ty/query/plumbing.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ impl QueryContext for TyCtxt<'tcx> {
3232
&self.dep_graph
3333
}
3434

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

3939
fn try_collect_active_jobs(

src/librustc_query_system/query/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub trait QueryContext: DepContext {
4343
fn dep_graph(&self) -> &DepGraph<Self::DepKind>;
4444

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

4848
fn try_collect_active_jobs(
4949
&self,

src/librustc_query_system/query/job.rs

+13-18
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ impl<CTX: QueryContext> QueryLatch<CTX> {
150150
let query_map = tcx.try_collect_active_jobs().unwrap();
151151

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

156156
while let Some(job) = current_job {
@@ -222,23 +222,18 @@ impl<CTX: QueryContext> QueryLatch<CTX> {
222222
impl<CTX: QueryContext> QueryLatch<CTX> {
223223
/// Awaits for the query job to complete.
224224
pub(super) fn wait_on(&self, tcx: CTX, span: Span) -> Result<(), CycleError<CTX::Query>> {
225-
tcx.read_query_job(move |query| {
226-
let waiter = Lrc::new(QueryWaiter {
227-
query,
228-
span,
229-
cycle: Lock::new(None),
230-
condvar: Condvar::new(),
231-
});
232-
self.wait_on_inner(&waiter);
233-
// FIXME: Get rid of this lock. We have ownership of the QueryWaiter
234-
// although another thread may still have a Lrc reference so we cannot
235-
// use Lrc::get_mut
236-
let mut cycle = waiter.cycle.lock();
237-
match cycle.take() {
238-
None => Ok(()),
239-
Some(cycle) => Err(cycle),
240-
}
241-
})
225+
let query = tcx.current_query_job();
226+
let waiter =
227+
Lrc::new(QueryWaiter { query, span, cycle: Lock::new(None), condvar: Condvar::new() });
228+
self.wait_on_inner(&waiter);
229+
// FIXME: Get rid of this lock. We have ownership of the QueryWaiter
230+
// although another thread may still have a Lrc reference so we cannot
231+
// use Lrc::get_mut
232+
let mut cycle = waiter.cycle.lock();
233+
match cycle.take() {
234+
None => Ok(()),
235+
Some(cycle) => Err(cycle),
236+
}
242237
}
243238
}
244239

src/librustc_query_system/query/plumbing.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,8 @@ where
211211

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

214-
let job = tcx.read_query_job(|query| QueryJob::new(id, span, query));
214+
let job = tcx.current_query_job();
215+
let job = QueryJob::new(id, span, job);
215216

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

0 commit comments

Comments
 (0)