Monomorphise try_execute_query.

This commit is contained in:
Camille GILLOT 2020-03-28 13:12:20 +01:00
parent 1c7376e797
commit 8f3e96d658
2 changed files with 38 additions and 43 deletions

View File

@ -28,6 +28,7 @@ pub(crate) struct QueryVtable<CTX: QueryContext, K, V> {
pub anon: bool, pub anon: bool,
pub dep_kind: CTX::DepKind, pub dep_kind: CTX::DepKind,
pub eval_always: bool, pub eval_always: bool,
pub to_dep_node: fn(CTX, &K) -> DepNode<CTX::DepKind>,
// Don't use this method to compute query results, instead use the methods on TyCtxt // Don't use this method to compute query results, instead use the methods on TyCtxt
pub compute: fn(CTX, K) -> V, pub compute: fn(CTX, K) -> V,
@ -39,6 +40,10 @@ pub(crate) struct QueryVtable<CTX: QueryContext, K, V> {
} }
impl<CTX: QueryContext, K, V> QueryVtable<CTX, K, V> { impl<CTX: QueryContext, K, V> QueryVtable<CTX, K, V> {
pub(crate) fn to_dep_node(&self, tcx: CTX, key: &K) -> DepNode<CTX::DepKind> {
(self.to_dep_node)(tcx, key)
}
pub(crate) fn compute(&self, tcx: CTX, key: K) -> V { pub(crate) fn compute(&self, tcx: CTX, key: K) -> V {
(self.compute)(tcx, key) (self.compute)(tcx, key)
} }
@ -112,6 +117,7 @@ where
const VTABLE: QueryVtable<CTX, Q::Key, Q::Value> = QueryVtable { const VTABLE: QueryVtable<CTX, Q::Key, Q::Value> = QueryVtable {
anon: Q::ANON, anon: Q::ANON,
dep_kind: Q::DEP_KIND, dep_kind: Q::DEP_KIND,
to_dep_node: Q::to_dep_node,
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,

View File

@ -382,17 +382,21 @@ where
} }
#[inline(always)] #[inline(always)]
fn try_execute_query<Q, CTX>( fn try_execute_query<CTX, C>(
tcx: CTX, tcx: CTX,
state: &QueryState<CTX, C>,
span: Span, span: Span,
key: Q::Key, key: C::Key,
lookup: QueryLookup<'_, CTX, Q::Key, <Q::Cache as QueryCache>::Sharded>, lookup: QueryLookup<'_, CTX, C::Key, C::Sharded>,
) -> Q::Stored query: &QueryVtable<CTX, C::Key, C::Value>,
) -> C::Stored
where where
Q: QueryDescription<CTX>, C: QueryCache,
C::Key: Eq + Clone + Debug,
C::Stored: Clone,
CTX: QueryContext, CTX: QueryContext,
{ {
let job = match JobOwner::try_start(tcx, Q::query_state(tcx), span, &key, lookup, &Q::VTABLE) { let job = match JobOwner::try_start(tcx, state, span, &key, lookup, query) {
TryGetJob::NotYetStarted(job) => job, TryGetJob::NotYetStarted(job) => job,
TryGetJob::Cycle(result) => return result, TryGetJob::Cycle(result) => return result,
#[cfg(parallel_compiler)] #[cfg(parallel_compiler)]
@ -406,18 +410,32 @@ where
// expensive for some `DepKind`s. // expensive for some `DepKind`s.
if !tcx.dep_graph().is_fully_enabled() { if !tcx.dep_graph().is_fully_enabled() {
let null_dep_node = DepNode::new_no_params(DepKind::NULL); let null_dep_node = DepNode::new_no_params(DepKind::NULL);
return force_query_with_job(tcx, key, job, null_dep_node, &Q::VTABLE).0; return force_query_with_job(tcx, key, job, null_dep_node, query).0;
} }
if Q::ANON { if query.anon {
let (result, dep_node_index) = try_execute_anon_query(tcx, key, job.id, &Q::VTABLE); let prof_timer = tcx.profiler().query_provider();
let ((result, dep_node_index), diagnostics) = with_diagnostics(|diagnostics| {
tcx.start_query(job.id, diagnostics, |tcx| {
tcx.dep_graph().with_anon_task(query.dep_kind, || query.compute(tcx, key))
})
});
prof_timer.finish_with_query_invocation_id(dep_node_index.into());
tcx.dep_graph().read_index(dep_node_index);
if unlikely!(!diagnostics.is_empty()) {
tcx.store_diagnostics_for_anon_node(dep_node_index, diagnostics);
}
return job.complete(tcx, result, dep_node_index); return job.complete(tcx, result, dep_node_index);
} }
let dep_node = Q::to_dep_node(tcx, &key); let dep_node = query.to_dep_node(tcx, &key);
if !Q::EVAL_ALWAYS { if !query.eval_always {
// The diagnostics for this query will be // The diagnostics for this query will be
// promoted to the current session during // promoted to the current session during
// `try_mark_green()`, so we can ignore them here. // `try_mark_green()`, so we can ignore them here.
@ -431,7 +449,7 @@ where
prev_dep_node_index, prev_dep_node_index,
dep_node_index, dep_node_index,
&dep_node, &dep_node,
&Q::VTABLE, query,
), ),
dep_node_index, dep_node_index,
) )
@ -442,40 +460,11 @@ where
} }
} }
let (result, dep_node_index) = force_query_with_job(tcx, key, job, dep_node, &Q::VTABLE); let (result, dep_node_index) = force_query_with_job(tcx, key, job, dep_node, query);
tcx.dep_graph().read_index(dep_node_index); tcx.dep_graph().read_index(dep_node_index);
result result
} }
fn try_execute_anon_query<CTX, K, V>(
tcx: CTX,
key: K,
job_id: QueryJobId<CTX::DepKind>,
query: &QueryVtable<CTX, K, V>,
) -> (V, DepNodeIndex)
where
CTX: QueryContext,
{
debug_assert!(query.anon);
let prof_timer = tcx.profiler().query_provider();
let ((result, dep_node_index), diagnostics) = with_diagnostics(|diagnostics| {
tcx.start_query(job_id, diagnostics, |tcx| {
tcx.dep_graph().with_anon_task(query.dep_kind, || query.compute(tcx, key))
})
});
prof_timer.finish_with_query_invocation_id(dep_node_index.into());
tcx.dep_graph().read_index(dep_node_index);
if unlikely!(!diagnostics.is_empty()) {
tcx.store_diagnostics_for_anon_node(dep_node_index, diagnostics);
}
(result, dep_node_index)
}
fn load_from_disk_and_cache_in_memory<CTX, K, V>( fn load_from_disk_and_cache_in_memory<CTX, K, V>(
tcx: CTX, tcx: CTX,
key: K, key: K,
@ -639,7 +628,7 @@ where
tcx.dep_graph().read_index(index); tcx.dep_graph().read_index(index);
value.clone() value.clone()
}, },
|key, lookup| try_execute_query::<Q, _>(tcx, span, key, lookup), |key, lookup| try_execute_query(tcx, Q::query_state(tcx), span, key, lookup, &Q::VTABLE),
) )
} }