Skip to content

Commit 4ac4ccd

Browse files
committed
Generalise JobOwner::try_start.
1 parent decfd70 commit 4ac4ccd

File tree

1 file changed

+13
-18
lines changed

1 file changed

+13
-18
lines changed

src/librustc/ty/query/plumbing.rs

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,9 @@ where
162162
id: QueryJobId<CTX::DepKind>,
163163
}
164164

165-
impl<'tcx, C> JobOwner<'tcx, TyCtxt<'tcx>, C>
165+
impl<'tcx, CTX: QueryContext, C> JobOwner<'tcx, CTX, C>
166166
where
167-
C: QueryCache<TyCtxt<'tcx>> + 'tcx,
167+
C: QueryCache<CTX>,
168168
C::Key: Eq + Hash + Clone + Debug,
169169
C::Value: Clone,
170170
{
@@ -177,14 +177,16 @@ where
177177
/// This function is inlined because that results in a noticeable speed-up
178178
/// for some compile-time benchmarks.
179179
#[inline(always)]
180-
fn try_start<'a, 'b, Q>(
181-
tcx: TyCtxt<'tcx>,
180+
fn try_start<'a, 'b, Q, K>(
181+
tcx: CTX,
182182
span: Span,
183183
key: &C::Key,
184-
mut lookup: QueryLookup<'a, TyCtxt<'tcx>, C::Key, C::Sharded>,
185-
) -> TryGetJob<'b, TyCtxt<'tcx>, C>
184+
mut lookup: QueryLookup<'a, CTX, C::Key, C::Sharded>,
185+
) -> TryGetJob<'b, CTX, C>
186186
where
187-
Q: QueryDescription<TyCtxt<'tcx>, Key = C::Key, Value = C::Value, Cache = C>,
187+
K: DepKind,
188+
Q: QueryDescription<CTX, Key = C::Key, Value = C::Value, Cache = C>,
189+
CTX: QueryContext<DepKind = K>,
188190
{
189191
let lock = &mut *lookup.lock;
190192

@@ -196,7 +198,7 @@ where
196198
// in another thread has completed. Record how long we wait in the
197199
// self-profiler.
198200
let _query_blocked_prof_timer = if cfg!(parallel_compiler) {
199-
Some(tcx.prof.query_blocked())
201+
Some(tcx.profiler().query_blocked())
200202
} else {
201203
None
202204
};
@@ -219,7 +221,7 @@ where
219221

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

222-
let job = tls::with_related_context(tcx, |icx| QueryJob::new(id, span, icx.query));
224+
let job = tcx.read_query_job(|query| QueryJob::new(id, span, query));
223225

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

@@ -262,14 +264,7 @@ where
262264
return TryGetJob::JobCompleted(cached);
263265
}
264266
}
265-
}
266267

267-
impl<'tcx, CTX: QueryContext, C> JobOwner<'tcx, CTX, C>
268-
where
269-
C: QueryCache<CTX>,
270-
C::Key: Eq + Hash + Clone + Debug,
271-
C::Value: Clone,
272-
{
273268
/// Completes the query by updating the query cache with the `result`,
274269
/// signals the waiter and forgets the JobOwner, so it won't poison the query
275270
#[inline(always)]
@@ -573,7 +568,7 @@ impl<'tcx> TyCtxt<'tcx> {
573568
<Q::Cache as QueryCache<TyCtxt<'tcx>>>::Sharded,
574569
>,
575570
) -> Q::Value {
576-
let job = match JobOwner::try_start::<Q>(self, span, &key, lookup) {
571+
let job = match JobOwner::try_start::<Q, _>(self, span, &key, lookup) {
577572
TryGetJob::NotYetStarted(job) => job,
578573
TryGetJob::Cycle(result) => return result,
579574
#[cfg(parallel_compiler)]
@@ -832,7 +827,7 @@ impl<'tcx> TyCtxt<'tcx> {
832827
// Cache hit, do nothing
833828
},
834829
|key, lookup| {
835-
let job = match JobOwner::try_start::<Q>(self, span, &key, lookup) {
830+
let job = match JobOwner::try_start::<Q, _>(self, span, &key, lookup) {
836831
TryGetJob::NotYetStarted(job) => job,
837832
TryGetJob::Cycle(_) => return,
838833
#[cfg(parallel_compiler)]

0 commit comments

Comments
 (0)