mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-11 08:05:12 +00:00
Monomorphise try_start.
This commit is contained in:
parent
d56085cbc9
commit
1c7376e797
@ -33,6 +33,7 @@ pub(crate) struct QueryVtable<CTX: QueryContext, K, V> {
|
||||
pub compute: fn(CTX, K) -> V,
|
||||
|
||||
pub hash_result: fn(&mut CTX::StableHashingContext, &V) -> Option<Fingerprint>,
|
||||
pub handle_cycle_error: fn(CTX, CycleError<CTX::Query>) -> V,
|
||||
pub cache_on_disk: fn(CTX, &K, Option<&V>) -> bool,
|
||||
pub try_load_from_disk: fn(CTX, SerializedDepNodeIndex) -> Option<V>,
|
||||
}
|
||||
@ -50,6 +51,10 @@ impl<CTX: QueryContext, K, V> QueryVtable<CTX, K, V> {
|
||||
(self.hash_result)(hcx, value)
|
||||
}
|
||||
|
||||
pub(crate) fn handle_cycle_error(&self, tcx: CTX, error: CycleError<CTX::Query>) -> V {
|
||||
(self.handle_cycle_error)(tcx, error)
|
||||
}
|
||||
|
||||
pub(crate) fn cache_on_disk(&self, tcx: CTX, key: &K, value: Option<&V>) -> bool {
|
||||
(self.cache_on_disk)(tcx, key, value)
|
||||
}
|
||||
@ -110,6 +115,7 @@ where
|
||||
eval_always: Q::EVAL_ALWAYS,
|
||||
compute: Q::compute,
|
||||
hash_result: Q::hash_result,
|
||||
handle_cycle_error: Q::handle_cycle_error,
|
||||
cache_on_disk: Q::cache_on_disk,
|
||||
try_load_from_disk: Q::try_load_from_disk,
|
||||
};
|
||||
|
@ -168,14 +168,15 @@ where
|
||||
/// This function is inlined because that results in a noticeable speed-up
|
||||
/// for some compile-time benchmarks.
|
||||
#[inline(always)]
|
||||
fn try_start<'a, 'b, Q>(
|
||||
fn try_start<'a, 'b>(
|
||||
tcx: CTX,
|
||||
state: &'b QueryState<CTX, C>,
|
||||
span: Span,
|
||||
key: &C::Key,
|
||||
mut lookup: QueryLookup<'a, CTX, C::Key, C::Sharded>,
|
||||
query: &QueryVtable<CTX, C::Key, C::Value>,
|
||||
) -> TryGetJob<'b, CTX, C>
|
||||
where
|
||||
Q: QueryDescription<CTX, Key = C::Key, Stored = C::Stored, Value = C::Value, Cache = C>,
|
||||
CTX: QueryContext,
|
||||
{
|
||||
let lock = &mut *lookup.lock;
|
||||
@ -194,7 +195,7 @@ where
|
||||
};
|
||||
|
||||
// Create the id of the job we're waiting for
|
||||
let id = QueryJobId::new(job.id, lookup.shard, Q::DEP_KIND);
|
||||
let id = QueryJobId::new(job.id, lookup.shard, query.dep_kind);
|
||||
|
||||
(job.latch(id), _query_blocked_prof_timer)
|
||||
}
|
||||
@ -209,15 +210,14 @@ where
|
||||
lock.jobs = id;
|
||||
let id = QueryShardJobId(NonZeroU32::new(id).unwrap());
|
||||
|
||||
let global_id = QueryJobId::new(id, lookup.shard, Q::DEP_KIND);
|
||||
let global_id = QueryJobId::new(id, lookup.shard, query.dep_kind);
|
||||
|
||||
let job = tcx.current_query_job();
|
||||
let job = QueryJob::new(id, span, job);
|
||||
|
||||
entry.insert(QueryResult::Started(job));
|
||||
|
||||
let owner =
|
||||
JobOwner { state: Q::query_state(tcx), id: global_id, key: (*key).clone() };
|
||||
let owner = JobOwner { state, id: global_id, key: (*key).clone() };
|
||||
return TryGetJob::NotYetStarted(owner);
|
||||
}
|
||||
};
|
||||
@ -227,8 +227,8 @@ where
|
||||
// so we just return the error.
|
||||
#[cfg(not(parallel_compiler))]
|
||||
return TryGetJob::Cycle(cold_path(|| {
|
||||
let value = Q::handle_cycle_error(tcx, latch.find_cycle_in_stack(tcx, span));
|
||||
Q::query_state(tcx).cache.store_nocache(value)
|
||||
let value = query.handle_cycle_error(tcx, latch.find_cycle_in_stack(tcx, span));
|
||||
state.cache.store_nocache(value)
|
||||
}));
|
||||
|
||||
// With parallel queries we might just have to wait on some other
|
||||
@ -238,14 +238,14 @@ where
|
||||
let result = latch.wait_on(tcx, span);
|
||||
|
||||
if let Err(cycle) = result {
|
||||
let value = Q::handle_cycle_error(tcx, cycle);
|
||||
let value = Q::query_state(tcx).cache.store_nocache(value);
|
||||
let value = query.handle_cycle_error(tcx, cycle);
|
||||
let value = state.cache.store_nocache(value);
|
||||
return TryGetJob::Cycle(value);
|
||||
}
|
||||
|
||||
let cached = try_get_cached(
|
||||
tcx,
|
||||
Q::query_state(tcx),
|
||||
state,
|
||||
(*key).clone(),
|
||||
|value, index| (value.clone(), index),
|
||||
|_, _| panic!("value must be in cache after waiting"),
|
||||
@ -392,7 +392,7 @@ where
|
||||
Q: QueryDescription<CTX>,
|
||||
CTX: QueryContext,
|
||||
{
|
||||
let job = match JobOwner::try_start::<Q>(tcx, span, &key, lookup) {
|
||||
let job = match JobOwner::try_start(tcx, Q::query_state(tcx), span, &key, lookup, &Q::VTABLE) {
|
||||
TryGetJob::NotYetStarted(job) => job,
|
||||
TryGetJob::Cycle(result) => return result,
|
||||
#[cfg(parallel_compiler)]
|
||||
@ -697,7 +697,9 @@ where
|
||||
// Cache hit, do nothing
|
||||
},
|
||||
|key, lookup| {
|
||||
let job = match JobOwner::try_start::<Q>(tcx, span, &key, lookup) {
|
||||
let job =
|
||||
match JobOwner::try_start(tcx, Q::query_state(tcx), span, &key, lookup, &Q::VTABLE)
|
||||
{
|
||||
TryGetJob::NotYetStarted(job) => job,
|
||||
TryGetJob::Cycle(_) => return,
|
||||
#[cfg(parallel_compiler)]
|
||||
|
Loading…
Reference in New Issue
Block a user