Skip to content

Commit 87d0eac

Browse files
committed
Monomorphise load_from_disk_and_cache_in_memory.
1 parent 0155f5a commit 87d0eac

File tree

2 files changed

+52
-19
lines changed

2 files changed

+52
-19
lines changed

src/librustc/ty/query/config.rs

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,34 @@ pub(crate) struct QueryVtable<'tcx, K, V> {
3333
pub compute: fn(TyCtxt<'tcx>, K) -> V,
3434

3535
pub hash_result: fn(&mut StableHashingContext<'_>, &V) -> Option<Fingerprint>,
36+
pub cache_on_disk: fn(TyCtxt<'tcx>, K, Option<&V>) -> bool,
37+
pub try_load_from_disk: fn(TyCtxt<'tcx>, SerializedDepNodeIndex) -> Option<V>,
38+
}
39+
40+
impl<'tcx, K, V> QueryVtable<'tcx, K, V> {
41+
pub(crate) fn compute(&self, tcx: TyCtxt<'tcx>, key: K) -> V {
42+
(self.compute)(tcx, key)
43+
}
44+
45+
pub(crate) fn hash_result(
46+
&self,
47+
hcx: &mut StableHashingContext<'_>,
48+
value: &V,
49+
) -> Option<Fingerprint> {
50+
(self.hash_result)(hcx, value)
51+
}
52+
53+
pub(crate) fn cache_on_disk(&self, tcx: TyCtxt<'tcx>, key: K, value: Option<&V>) -> bool {
54+
(self.cache_on_disk)(tcx, key, value)
55+
}
56+
57+
pub(crate) fn try_load_from_disk(
58+
&self,
59+
tcx: TyCtxt<'tcx>,
60+
index: SerializedDepNodeIndex,
61+
) -> Option<V> {
62+
(self.try_load_from_disk)(tcx, index)
63+
}
3664
}
3765

3866
pub(crate) trait QueryAccessors<'tcx>: QueryConfig<'tcx> {
@@ -54,14 +82,6 @@ pub(crate) trait QueryAccessors<'tcx>: QueryConfig<'tcx> {
5482
-> Option<Fingerprint>;
5583

5684
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-
}
6585
}
6686

6787
pub(crate) trait QueryDescription<'tcx>: QueryAccessors<'tcx> {
@@ -75,6 +95,16 @@ pub(crate) trait QueryDescription<'tcx>: QueryAccessors<'tcx> {
7595
fn try_load_from_disk(_: TyCtxt<'tcx>, _: SerializedDepNodeIndex) -> Option<Self::Value> {
7696
bug!("QueryDescription::load_from_disk() called for an unsupported query.")
7797
}
98+
99+
fn reify() -> QueryVtable<'tcx, Self::Key, Self::Value> {
100+
QueryVtable {
101+
eval_always: Self::EVAL_ALWAYS,
102+
compute: Self::compute,
103+
hash_result: Self::hash_result,
104+
cache_on_disk: Self::cache_on_disk,
105+
try_load_from_disk: Self::try_load_from_disk,
106+
}
107+
}
78108
}
79109

80110
impl<'tcx, M: QueryAccessors<'tcx, Key = DefId>> QueryDescription<'tcx> for M {

src/librustc/ty/query/plumbing.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -582,11 +582,12 @@ impl<'tcx> TyCtxt<'tcx> {
582582
let marked = tcx.dep_graph.try_mark_green_and_read(tcx, &dep_node);
583583
marked.map(|(prev_dep_node_index, dep_node_index)| {
584584
(
585-
tcx.load_from_disk_and_cache_in_memory::<Q>(
585+
tcx.load_from_disk_and_cache_in_memory(
586586
key.clone(),
587587
prev_dep_node_index,
588588
dep_node_index,
589589
&dep_node,
590+
&Q::reify(),
590591
),
591592
dep_node_index,
592593
)
@@ -603,24 +604,25 @@ impl<'tcx> TyCtxt<'tcx> {
603604
result
604605
}
605606

606-
fn load_from_disk_and_cache_in_memory<Q: QueryDescription<'tcx>>(
607+
fn load_from_disk_and_cache_in_memory<K: Clone, V>(
607608
self,
608-
key: Q::Key,
609+
key: K,
609610
prev_dep_node_index: SerializedDepNodeIndex,
610611
dep_node_index: DepNodeIndex,
611612
dep_node: &DepNode,
612-
) -> Q::Value {
613+
query: &QueryVtable<'tcx, K, V>,
614+
) -> V {
613615
// Note this function can be called concurrently from the same query
614616
// We must ensure that this is handled correctly.
615617

616618
debug_assert!(self.dep_graph.is_green(dep_node));
617619

618620
// First we try to load the result from the on-disk cache.
619-
let result = if Q::cache_on_disk(self, key.clone(), None)
621+
let result = if query.cache_on_disk(self, key.clone(), None)
620622
&& self.sess.opts.debugging_opts.incremental_queries
621623
{
622624
let prof_timer = self.prof.incr_cache_loading();
623-
let result = Q::try_load_from_disk(self, prev_dep_node_index);
625+
let result = query.try_load_from_disk(self, prev_dep_node_index);
624626
prof_timer.finish_with_query_invocation_id(dep_node_index.into());
625627

626628
// We always expect to find a cached result for things that
@@ -644,7 +646,7 @@ impl<'tcx> TyCtxt<'tcx> {
644646
let prof_timer = self.prof.query_provider();
645647

646648
// The dep-graph for this computation is already in-place.
647-
let result = self.dep_graph.with_ignore(|| Q::compute(self, key));
649+
let result = self.dep_graph.with_ignore(|| query.compute(self, key));
648650

649651
prof_timer.finish_with_query_invocation_id(dep_node_index.into());
650652

@@ -654,19 +656,20 @@ impl<'tcx> TyCtxt<'tcx> {
654656
// If `-Zincremental-verify-ich` is specified, re-hash results from
655657
// the cache and make sure that they have the expected fingerprint.
656658
if unlikely!(self.sess.opts.debugging_opts.incremental_verify_ich) {
657-
self.incremental_verify_ich::<Q>(&result, dep_node, dep_node_index);
659+
self.incremental_verify_ich(&result, dep_node, dep_node_index, query);
658660
}
659661

660662
result
661663
}
662664

663665
#[inline(never)]
664666
#[cold]
665-
fn incremental_verify_ich<Q: QueryDescription<'tcx>>(
667+
fn incremental_verify_ich<K, V>(
666668
self,
667-
result: &Q::Value,
669+
result: &V,
668670
dep_node: &DepNode,
669671
dep_node_index: DepNodeIndex,
672+
query: &QueryVtable<'tcx, K, V>,
670673
) {
671674
use crate::ich::Fingerprint;
672675

@@ -680,7 +683,7 @@ impl<'tcx> TyCtxt<'tcx> {
680683
debug!("BEGIN verify_ich({:?})", dep_node);
681684
let mut hcx = self.create_stable_hashing_context();
682685

683-
let new_hash = Q::hash_result(&mut hcx, result).unwrap_or(Fingerprint::ZERO);
686+
let new_hash = query.hash_result(&mut hcx, result).unwrap_or(Fingerprint::ZERO);
684687
debug!("END verify_ich({:?})", dep_node);
685688

686689
let old_hash = self.dep_graph.fingerprint_of(dep_node_index);

0 commit comments

Comments
 (0)