Skip to content

Commit 1c7376e

Browse files
committed
Monomorphise try_start.
1 parent d56085c commit 1c7376e

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
lines changed

src/librustc_query_system/query/config.rs

+6
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ pub(crate) struct QueryVtable<CTX: QueryContext, K, V> {
3333
pub compute: fn(CTX, K) -> V,
3434

3535
pub hash_result: fn(&mut CTX::StableHashingContext, &V) -> Option<Fingerprint>,
36+
pub handle_cycle_error: fn(CTX, CycleError<CTX::Query>) -> V,
3637
pub cache_on_disk: fn(CTX, &K, Option<&V>) -> bool,
3738
pub try_load_from_disk: fn(CTX, SerializedDepNodeIndex) -> Option<V>,
3839
}
@@ -50,6 +51,10 @@ impl<CTX: QueryContext, K, V> QueryVtable<CTX, K, V> {
5051
(self.hash_result)(hcx, value)
5152
}
5253

54+
pub(crate) fn handle_cycle_error(&self, tcx: CTX, error: CycleError<CTX::Query>) -> V {
55+
(self.handle_cycle_error)(tcx, error)
56+
}
57+
5358
pub(crate) fn cache_on_disk(&self, tcx: CTX, key: &K, value: Option<&V>) -> bool {
5459
(self.cache_on_disk)(tcx, key, value)
5560
}
@@ -110,6 +115,7 @@ where
110115
eval_always: Q::EVAL_ALWAYS,
111116
compute: Q::compute,
112117
hash_result: Q::hash_result,
118+
handle_cycle_error: Q::handle_cycle_error,
113119
cache_on_disk: Q::cache_on_disk,
114120
try_load_from_disk: Q::try_load_from_disk,
115121
};

src/librustc_query_system/query/plumbing.rs

+20-18
Original file line numberDiff line numberDiff line change
@@ -168,14 +168,15 @@ where
168168
/// This function is inlined because that results in a noticeable speed-up
169169
/// for some compile-time benchmarks.
170170
#[inline(always)]
171-
fn try_start<'a, 'b, Q>(
171+
fn try_start<'a, 'b>(
172172
tcx: CTX,
173+
state: &'b QueryState<CTX, C>,
173174
span: Span,
174175
key: &C::Key,
175176
mut lookup: QueryLookup<'a, CTX, C::Key, C::Sharded>,
177+
query: &QueryVtable<CTX, C::Key, C::Value>,
176178
) -> TryGetJob<'b, CTX, C>
177179
where
178-
Q: QueryDescription<CTX, Key = C::Key, Stored = C::Stored, Value = C::Value, Cache = C>,
179180
CTX: QueryContext,
180181
{
181182
let lock = &mut *lookup.lock;
@@ -194,7 +195,7 @@ where
194195
};
195196

196197
// Create the id of the job we're waiting for
197-
let id = QueryJobId::new(job.id, lookup.shard, Q::DEP_KIND);
198+
let id = QueryJobId::new(job.id, lookup.shard, query.dep_kind);
198199

199200
(job.latch(id), _query_blocked_prof_timer)
200201
}
@@ -209,15 +210,14 @@ where
209210
lock.jobs = id;
210211
let id = QueryShardJobId(NonZeroU32::new(id).unwrap());
211212

212-
let global_id = QueryJobId::new(id, lookup.shard, Q::DEP_KIND);
213+
let global_id = QueryJobId::new(id, lookup.shard, query.dep_kind);
213214

214215
let job = tcx.current_query_job();
215216
let job = QueryJob::new(id, span, job);
216217

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

219-
let owner =
220-
JobOwner { state: Q::query_state(tcx), id: global_id, key: (*key).clone() };
220+
let owner = JobOwner { state, id: global_id, key: (*key).clone() };
221221
return TryGetJob::NotYetStarted(owner);
222222
}
223223
};
@@ -227,8 +227,8 @@ where
227227
// so we just return the error.
228228
#[cfg(not(parallel_compiler))]
229229
return TryGetJob::Cycle(cold_path(|| {
230-
let value = Q::handle_cycle_error(tcx, latch.find_cycle_in_stack(tcx, span));
231-
Q::query_state(tcx).cache.store_nocache(value)
230+
let value = query.handle_cycle_error(tcx, latch.find_cycle_in_stack(tcx, span));
231+
state.cache.store_nocache(value)
232232
}));
233233

234234
// With parallel queries we might just have to wait on some other
@@ -238,14 +238,14 @@ where
238238
let result = latch.wait_on(tcx, span);
239239

240240
if let Err(cycle) = result {
241-
let value = Q::handle_cycle_error(tcx, cycle);
242-
let value = Q::query_state(tcx).cache.store_nocache(value);
241+
let value = query.handle_cycle_error(tcx, cycle);
242+
let value = state.cache.store_nocache(value);
243243
return TryGetJob::Cycle(value);
244244
}
245245

246246
let cached = try_get_cached(
247247
tcx,
248-
Q::query_state(tcx),
248+
state,
249249
(*key).clone(),
250250
|value, index| (value.clone(), index),
251251
|_, _| panic!("value must be in cache after waiting"),
@@ -392,7 +392,7 @@ where
392392
Q: QueryDescription<CTX>,
393393
CTX: QueryContext,
394394
{
395-
let job = match JobOwner::try_start::<Q>(tcx, span, &key, lookup) {
395+
let job = match JobOwner::try_start(tcx, Q::query_state(tcx), span, &key, lookup, &Q::VTABLE) {
396396
TryGetJob::NotYetStarted(job) => job,
397397
TryGetJob::Cycle(result) => return result,
398398
#[cfg(parallel_compiler)]
@@ -697,12 +697,14 @@ where
697697
// Cache hit, do nothing
698698
},
699699
|key, lookup| {
700-
let job = match JobOwner::try_start::<Q>(tcx, span, &key, lookup) {
701-
TryGetJob::NotYetStarted(job) => job,
702-
TryGetJob::Cycle(_) => return,
703-
#[cfg(parallel_compiler)]
704-
TryGetJob::JobCompleted(_) => return,
705-
};
700+
let job =
701+
match JobOwner::try_start(tcx, Q::query_state(tcx), span, &key, lookup, &Q::VTABLE)
702+
{
703+
TryGetJob::NotYetStarted(job) => job,
704+
TryGetJob::Cycle(_) => return,
705+
#[cfg(parallel_compiler)]
706+
TryGetJob::JobCompleted(_) => return,
707+
};
706708
force_query_with_job(tcx, key, job, dep_node, &Q::VTABLE);
707709
},
708710
);

0 commit comments

Comments
 (0)