1
Fork 0

Build jump table at runtime.

This commit is contained in:
Camille GILLOT 2021-10-16 21:12:34 +02:00
parent 602d3cbce3
commit bd5c107672
10 changed files with 112 additions and 131 deletions

View file

@ -576,7 +576,7 @@ impl<K: DepKind> DepGraph<K> {
"try_mark_previous_green({:?}) --- trying to force dependency {:?}",
dep_node, dep_dep_node
);
if !tcx.dep_context().try_force_from_dep_node(dep_dep_node) {
if !tcx.dep_context().try_force_from_dep_node(*dep_dep_node) {
// The DepNode could not be forced.
debug!(
"try_mark_previous_green({:?}) - END - dependency {:?} could not be forced",
@ -749,7 +749,7 @@ impl<K: DepKind> DepGraph<K> {
match data.colors.get(prev_index) {
Some(DepNodeColor::Green(_)) => {
let dep_node = data.previous.index_to_node(prev_index);
tcx.try_load_from_on_disk_cache(&dep_node);
tcx.try_load_from_on_disk_cache(dep_node);
}
None | Some(DepNodeColor::Red) => {
// We can skip red nodes because a node can only be marked

View file

@ -39,10 +39,10 @@ pub trait DepContext: Copy {
fn fingerprint_style(&self, kind: Self::DepKind) -> FingerprintStyle;
/// Try to force a dep node to execute and see if it's green.
fn try_force_from_dep_node(&self, dep_node: &DepNode<Self::DepKind>) -> bool;
fn try_force_from_dep_node(&self, dep_node: DepNode<Self::DepKind>) -> bool;
/// Load data from the on-disk cache.
fn try_load_from_on_disk_cache(&self, dep_node: &DepNode<Self::DepKind>);
fn try_load_from_on_disk_cache(&self, dep_node: DepNode<Self::DepKind>);
}
pub trait HasDepContext: Copy {

View file

@ -665,41 +665,6 @@ where
}
}
#[inline(never)]
fn force_query_impl<CTX, C>(
tcx: CTX,
state: &QueryState<CTX::DepKind, C::Key>,
cache: &QueryCacheStore<C>,
key: C::Key,
dep_node: DepNode<CTX::DepKind>,
query: &QueryVtable<CTX, C::Key, C::Value>,
compute: fn(CTX::DepContext, C::Key) -> C::Value,
) -> bool
where
C: QueryCache,
C::Key: DepNodeParams<CTX::DepContext>,
CTX: QueryContext,
{
debug_assert!(!query.anon);
// We may be concurrently trying both execute and force a query.
// Ensure that only one of them runs the query.
let cached = cache.cache.lookup(cache, &key, |_, index| {
if unlikely!(tcx.dep_context().profiler().enabled()) {
tcx.dep_context().profiler().query_cache_hit(index.into());
}
});
let lookup = match cached {
Ok(()) => return true,
Err(lookup) => lookup,
};
let _ =
try_execute_query(tcx, state, cache, DUMMY_SP, key, lookup, Some(dep_node), query, compute);
true
}
pub enum QueryMode {
Get,
Ensure,
@ -747,34 +712,30 @@ where
Some(result)
}
pub fn force_query<Q, CTX>(tcx: CTX, dep_node: &DepNode<CTX::DepKind>) -> bool
pub fn force_query<Q, CTX>(tcx: CTX, key: Q::Key, dep_node: DepNode<CTX::DepKind>)
where
Q: QueryDescription<CTX>,
Q::Key: DepNodeParams<CTX::DepContext>,
CTX: QueryContext,
{
if Q::ANON {
return false;
}
let query = &Q::VTABLE;
debug_assert!(!Q::ANON);
if !<Q::Key as DepNodeParams<CTX::DepContext>>::fingerprint_style().reconstructible() {
return false;
}
// We may be concurrently trying both execute and force a query.
// Ensure that only one of them runs the query.
let cache = Q::query_cache(tcx);
let cached = cache.cache.lookup(cache, &key, |_, index| {
if unlikely!(tcx.dep_context().profiler().enabled()) {
tcx.dep_context().profiler().query_cache_hit(index.into());
}
});
let Some(key) =
<Q::Key as DepNodeParams<CTX::DepContext>>::recover(*tcx.dep_context(), &dep_node)
else {
return false;
let lookup = match cached {
Ok(()) => return,
Err(lookup) => lookup,
};
let compute = Q::compute_fn(tcx, &key);
force_query_impl(
tcx,
Q::query_state(tcx),
Q::query_cache(tcx),
key,
*dep_node,
&Q::VTABLE,
compute,
)
let state = Q::query_state(tcx);
try_execute_query(tcx, state, cache, DUMMY_SP, key, lookup, Some(dep_node), query, compute);
}