Skip to content

Commit 0155f5a

Browse files
committed
Monomorphise force_query_with_job.
1 parent c429704 commit 0155f5a

File tree

2 files changed

+36
-13
lines changed

2 files changed

+36
-13
lines changed

src/librustc/ty/query/config.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ pub trait QueryConfig<'tcx> {
2626
type Value: Clone;
2727
}
2828

29+
pub(crate) struct QueryVtable<'tcx, K, V> {
30+
pub eval_always: bool,
31+
32+
// Don't use this method to compute query results, instead use the methods on TyCtxt
33+
pub compute: fn(TyCtxt<'tcx>, K) -> V,
34+
35+
pub hash_result: fn(&mut StableHashingContext<'_>, &V) -> Option<Fingerprint>,
36+
}
37+
2938
pub(crate) trait QueryAccessors<'tcx>: QueryConfig<'tcx> {
3039
const ANON: bool;
3140
const EVAL_ALWAYS: bool;
@@ -45,6 +54,14 @@ pub(crate) trait QueryAccessors<'tcx>: QueryConfig<'tcx> {
4554
-> Option<Fingerprint>;
4655

4756
fn handle_cycle_error(tcx: TyCtxt<'tcx>, error: CycleError<'tcx>) -> Self::Value;
57+
58+
fn reify() -> QueryVtable<'tcx, Self::Key, Self::Value> {
59+
QueryVtable {
60+
eval_always: Self::EVAL_ALWAYS,
61+
compute: Self::compute,
62+
hash_result: Self::hash_result,
63+
}
64+
}
4865
}
4966

5067
pub(crate) trait QueryDescription<'tcx>: QueryAccessors<'tcx> {

src/librustc/ty/query/plumbing.rs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
use crate::dep_graph::{DepKind, DepNode, DepNodeIndex, SerializedDepNodeIndex};
66
use crate::ty::query::caches::QueryCache;
7-
use crate::ty::query::config::QueryDescription;
7+
use crate::ty::query::config::{QueryDescription, QueryVtable};
88
use crate::ty::query::job::{QueryInfo, QueryJob, QueryJobId, QueryJobInfo, QueryShardJobId};
99
use crate::ty::query::Query;
1010
use crate::ty::tls;
@@ -160,7 +160,7 @@ where
160160
id: QueryJobId,
161161
}
162162

163-
impl<'tcx, C: QueryCache> JobOwner<'tcx, C>
163+
impl<'tcx, C> JobOwner<'tcx, C>
164164
where
165165
C: QueryCache,
166166
C::Key: Eq + Hash + Clone + Debug,
@@ -545,7 +545,7 @@ impl<'tcx> TyCtxt<'tcx> {
545545
// expensive for some `DepKind`s.
546546
if !self.dep_graph.is_fully_enabled() {
547547
let null_dep_node = DepNode::new_no_params(crate::dep_graph::DepKind::Null);
548-
return self.force_query_with_job::<Q>(key, job, null_dep_node).0;
548+
return self.force_query_with_job(key, job, null_dep_node, &Q::reify()).0;
549549
}
550550

551551
if Q::ANON {
@@ -598,7 +598,7 @@ impl<'tcx> TyCtxt<'tcx> {
598598
}
599599
}
600600

601-
let (result, dep_node_index) = self.force_query_with_job::<Q>(key, job, dep_node);
601+
let (result, dep_node_index) = self.force_query_with_job(key, job, dep_node, &Q::reify());
602602
self.dep_graph.read_index(dep_node_index);
603603
result
604604
}
@@ -689,12 +689,18 @@ impl<'tcx> TyCtxt<'tcx> {
689689
}
690690

691691
#[inline(always)]
692-
fn force_query_with_job<Q: QueryDescription<'tcx>>(
692+
fn force_query_with_job<C>(
693693
self,
694-
key: Q::Key,
695-
job: JobOwner<'tcx, Q::Cache>,
694+
key: C::Key,
695+
job: JobOwner<'tcx, C>,
696696
dep_node: DepNode,
697-
) -> (Q::Value, DepNodeIndex) {
697+
query: &QueryVtable<'tcx, C::Key, C::Value>,
698+
) -> (C::Value, DepNodeIndex)
699+
where
700+
C: QueryCache,
701+
C::Key: Eq + Hash + Clone + Debug,
702+
C::Value: Clone,
703+
{
698704
// If the following assertion triggers, it can have two reasons:
699705
// 1. Something is wrong with DepNode creation, either here or
700706
// in `DepGraph::try_mark_green()`.
@@ -713,16 +719,16 @@ impl<'tcx> TyCtxt<'tcx> {
713719

714720
let ((result, dep_node_index), diagnostics) = with_diagnostics(|diagnostics| {
715721
self.start_query(job.id, diagnostics, |tcx| {
716-
if Q::EVAL_ALWAYS {
722+
if query.eval_always {
717723
tcx.dep_graph.with_eval_always_task(
718724
dep_node,
719725
tcx,
720726
key,
721-
Q::compute,
722-
Q::hash_result,
727+
query.compute,
728+
query.hash_result,
723729
)
724730
} else {
725-
tcx.dep_graph.with_task(dep_node, tcx, key, Q::compute, Q::hash_result)
731+
tcx.dep_graph.with_task(dep_node, tcx, key, query.compute, query.hash_result)
726732
}
727733
})
728734
});
@@ -797,7 +803,7 @@ impl<'tcx> TyCtxt<'tcx> {
797803
#[cfg(parallel_compiler)]
798804
TryGetJob::JobCompleted(_) => return,
799805
};
800-
self.force_query_with_job::<Q>(key, job, dep_node);
806+
self.force_query_with_job(key, job, dep_node, &Q::reify());
801807
},
802808
);
803809
}

0 commit comments

Comments
 (0)