Reduce amount of function pointers.
This commit is contained in:
parent
f60a670256
commit
fd318a2f9b
@ -386,14 +386,15 @@ fn query_cache<'a>(tcx: QueryCtxt<$tcx>) -> &'a QueryCacheStore<Self::Cache>
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn compute(tcx: QueryCtxt<'tcx>, key: Self::Key) -> Self::Value {
|
||||
fn compute_fn(tcx: QueryCtxt<'tcx>, key: &Self::Key) ->
|
||||
fn(TyCtxt<'tcx>, Self::Key) -> Self::Value
|
||||
{
|
||||
let is_local = key.query_crate() == LOCAL_CRATE;
|
||||
let provider = if is_local {
|
||||
if is_local {
|
||||
tcx.queries.local_providers.$name
|
||||
} else {
|
||||
tcx.queries.extern_providers.$name
|
||||
};
|
||||
provider(*tcx, key)
|
||||
}
|
||||
}
|
||||
|
||||
fn hash_result(
|
||||
|
@ -23,9 +23,6 @@ pub(crate) struct QueryVtable<CTX: QueryContext, K, V> {
|
||||
pub dep_kind: CTX::DepKind,
|
||||
pub eval_always: bool,
|
||||
|
||||
// Don't use this method to compute query results, instead use the methods on TyCtxt
|
||||
pub compute: fn(CTX, K) -> V,
|
||||
|
||||
pub hash_result: fn(&mut CTX::StableHashingContext, &V) -> Option<Fingerprint>,
|
||||
pub handle_cycle_error: fn(CTX, DiagnosticBuilder<'_>) -> V,
|
||||
pub cache_on_disk: fn(CTX, &K, Option<&V>) -> bool,
|
||||
@ -40,10 +37,6 @@ pub(crate) fn to_dep_node(&self, tcx: CTX::DepContext, key: &K) -> DepNode<CTX::
|
||||
DepNode::construct(tcx, self.dep_kind, key)
|
||||
}
|
||||
|
||||
pub(crate) fn compute(&self, tcx: CTX, key: K) -> V {
|
||||
(self.compute)(tcx, key)
|
||||
}
|
||||
|
||||
pub(crate) fn hash_result(
|
||||
&self,
|
||||
hcx: &mut CTX::StableHashingContext,
|
||||
@ -79,7 +72,7 @@ fn query_cache<'a>(tcx: CTX) -> &'a QueryCacheStore<Self::Cache>
|
||||
CTX: 'a;
|
||||
|
||||
// Don't use this method to compute query results, instead use the methods on TyCtxt
|
||||
fn compute(tcx: CTX, key: Self::Key) -> Self::Value;
|
||||
fn compute_fn(tcx: CTX, key: &Self::Key) -> fn(CTX::DepContext, Self::Key) -> Self::Value;
|
||||
|
||||
fn hash_result(
|
||||
hcx: &mut CTX::StableHashingContext,
|
||||
@ -115,7 +108,6 @@ impl<CTX, Q> QueryVtableExt<CTX, Q::Key, Q::Value> for Q
|
||||
anon: Q::ANON,
|
||||
dep_kind: Q::DEP_KIND,
|
||||
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,
|
||||
|
@ -428,6 +428,7 @@ fn try_execute_query<CTX, C>(
|
||||
key: C::Key,
|
||||
lookup: QueryLookup,
|
||||
query: &QueryVtable<CTX, C::Key, C::Value>,
|
||||
compute: fn(CTX::DepContext, C::Key) -> C::Value,
|
||||
) -> C::Stored
|
||||
where
|
||||
C: QueryCache,
|
||||
@ -457,7 +458,7 @@ fn try_execute_query<CTX, C>(
|
||||
// Fast path for when incr. comp. is off.
|
||||
if !dep_graph.is_fully_enabled() {
|
||||
let prof_timer = tcx.dep_context().profiler().query_provider();
|
||||
let result = tcx.start_query(job.id, None, || query.compute(tcx, key));
|
||||
let result = tcx.start_query(job.id, None, || compute(*tcx.dep_context(), key));
|
||||
let dep_node_index = dep_graph.next_virtual_depnode_index();
|
||||
prof_timer.finish_with_query_invocation_id(dep_node_index.into());
|
||||
return job.complete(result, dep_node_index);
|
||||
@ -468,8 +469,9 @@ fn try_execute_query<CTX, C>(
|
||||
|
||||
let ((result, dep_node_index), diagnostics) = with_diagnostics(|diagnostics| {
|
||||
tcx.start_query(job.id, diagnostics, || {
|
||||
dep_graph
|
||||
.with_anon_task(*tcx.dep_context(), query.dep_kind, || query.compute(tcx, key))
|
||||
dep_graph.with_anon_task(*tcx.dep_context(), query.dep_kind, || {
|
||||
compute(*tcx.dep_context(), key)
|
||||
})
|
||||
})
|
||||
});
|
||||
|
||||
@ -501,6 +503,7 @@ fn try_execute_query<CTX, C>(
|
||||
dep_node_index,
|
||||
&dep_node,
|
||||
query,
|
||||
compute,
|
||||
),
|
||||
dep_node_index,
|
||||
)
|
||||
@ -511,7 +514,7 @@ fn try_execute_query<CTX, C>(
|
||||
}
|
||||
}
|
||||
|
||||
let (result, dep_node_index) = force_query_with_job(tcx, key, job, dep_node, query);
|
||||
let (result, dep_node_index) = force_query_with_job(tcx, key, job, dep_node, query, compute);
|
||||
dep_graph.read_index(dep_node_index);
|
||||
result
|
||||
}
|
||||
@ -523,6 +526,7 @@ fn load_from_disk_and_cache_in_memory<CTX, K, V: Debug>(
|
||||
dep_node_index: DepNodeIndex,
|
||||
dep_node: &DepNode<CTX::DepKind>,
|
||||
query: &QueryVtable<CTX, K, V>,
|
||||
compute: fn(CTX::DepContext, K) -> V,
|
||||
) -> V
|
||||
where
|
||||
CTX: QueryContext,
|
||||
@ -565,7 +569,7 @@ fn load_from_disk_and_cache_in_memory<CTX, K, V: Debug>(
|
||||
let prof_timer = tcx.dep_context().profiler().query_provider();
|
||||
|
||||
// The dep-graph for this computation is already in-place.
|
||||
let result = tcx.dep_context().dep_graph().with_ignore(|| query.compute(tcx, key));
|
||||
let result = tcx.dep_context().dep_graph().with_ignore(|| compute(*tcx.dep_context(), key));
|
||||
|
||||
prof_timer.finish_with_query_invocation_id(dep_node_index.into());
|
||||
|
||||
@ -627,6 +631,7 @@ fn force_query_with_job<C, CTX>(
|
||||
job: JobOwner<'_, CTX::DepKind, C>,
|
||||
dep_node: DepNode<CTX::DepKind>,
|
||||
query: &QueryVtable<CTX, C::Key, C::Value>,
|
||||
compute: fn(CTX::DepContext, C::Key) -> C::Value,
|
||||
) -> (C::Stored, DepNodeIndex)
|
||||
where
|
||||
C: QueryCache,
|
||||
@ -653,17 +658,17 @@ fn force_query_with_job<C, CTX>(
|
||||
if query.eval_always {
|
||||
tcx.dep_context().dep_graph().with_eval_always_task(
|
||||
dep_node,
|
||||
tcx,
|
||||
*tcx.dep_context(),
|
||||
key,
|
||||
query.compute,
|
||||
compute,
|
||||
query.hash_result,
|
||||
)
|
||||
} else {
|
||||
tcx.dep_context().dep_graph().with_task(
|
||||
dep_node,
|
||||
tcx,
|
||||
*tcx.dep_context(),
|
||||
key,
|
||||
query.compute,
|
||||
compute,
|
||||
query.hash_result,
|
||||
)
|
||||
}
|
||||
@ -690,13 +695,14 @@ fn get_query_impl<CTX, C>(
|
||||
key: C::Key,
|
||||
lookup: QueryLookup,
|
||||
query: &QueryVtable<CTX, C::Key, C::Value>,
|
||||
compute: fn(CTX::DepContext, C::Key) -> C::Value,
|
||||
) -> C::Stored
|
||||
where
|
||||
CTX: QueryContext,
|
||||
C: QueryCache,
|
||||
C::Key: DepNodeParams<CTX::DepContext>,
|
||||
{
|
||||
try_execute_query(tcx, state, cache, span, key, lookup, query)
|
||||
try_execute_query(tcx, state, cache, span, key, lookup, query, compute)
|
||||
}
|
||||
|
||||
/// Ensure that either this query has all green inputs or been executed.
|
||||
@ -744,8 +750,10 @@ 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,
|
||||
@ -754,18 +762,6 @@ fn force_query_impl<CTX, C>(
|
||||
{
|
||||
debug_assert!(!query.anon);
|
||||
|
||||
if !<C::Key as DepNodeParams<CTX::DepContext>>::can_reconstruct_query_key() {
|
||||
return false;
|
||||
}
|
||||
|
||||
let key = if let Some(key) =
|
||||
<C::Key as DepNodeParams<CTX::DepContext>>::recover(*tcx.dep_context(), &dep_node)
|
||||
{
|
||||
key
|
||||
} else {
|
||||
return false;
|
||||
};
|
||||
|
||||
// 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| {
|
||||
@ -798,7 +794,7 @@ fn force_query_impl<CTX, C>(
|
||||
TryGetJob::JobCompleted(_) => return true,
|
||||
};
|
||||
|
||||
force_query_with_job(tcx, key, job, dep_node, query);
|
||||
force_query_with_job(tcx, key, job, dep_node, query, compute);
|
||||
|
||||
true
|
||||
}
|
||||
@ -828,8 +824,17 @@ pub fn get_query<Q, CTX>(
|
||||
}
|
||||
|
||||
debug!("ty::query::get_query<{}>(key={:?}, span={:?})", Q::NAME, key, span);
|
||||
let value =
|
||||
get_query_impl(tcx, Q::query_state(tcx), Q::query_cache(tcx), span, key, lookup, query);
|
||||
let compute = Q::compute_fn(tcx, &key);
|
||||
let value = get_query_impl(
|
||||
tcx,
|
||||
Q::query_state(tcx),
|
||||
Q::query_cache(tcx),
|
||||
span,
|
||||
key,
|
||||
lookup,
|
||||
query,
|
||||
compute,
|
||||
);
|
||||
Some(value)
|
||||
}
|
||||
|
||||
@ -843,5 +848,26 @@ pub fn force_query<Q, CTX>(tcx: CTX, dep_node: &DepNode<CTX::DepKind>) -> bool
|
||||
return false;
|
||||
}
|
||||
|
||||
force_query_impl(tcx, Q::query_state(tcx), Q::query_cache(tcx), *dep_node, &Q::VTABLE)
|
||||
if !<Q::Key as DepNodeParams<CTX::DepContext>>::can_reconstruct_query_key() {
|
||||
return false;
|
||||
}
|
||||
|
||||
let key = if let Some(key) =
|
||||
<Q::Key as DepNodeParams<CTX::DepContext>>::recover(*tcx.dep_context(), &dep_node)
|
||||
{
|
||||
key
|
||||
} else {
|
||||
return false;
|
||||
};
|
||||
|
||||
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,
|
||||
)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user