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