Skip to content

Commit

Permalink
Monomorphise encode_query_results.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgillot committed Mar 7, 2020
1 parent f03e9ce commit cae3639
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/librustc/ty/query/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub(crate) struct QueryVtable<'tcx, K, V> {
pub anon: bool,
pub dep_kind: DepKind,
pub eval_always: bool,
pub name: &'static str,

// Don't use this method to compute query results, instead use the methods on TyCtxt
pub compute: fn(TyCtxt<'tcx>, K) -> V,
Expand Down Expand Up @@ -103,6 +104,7 @@ pub(crate) trait QueryDescription<'tcx>: QueryAccessors<'tcx> {
anon: Self::ANON,
dep_kind: Self::DEP_KIND,
eval_always: Self::EVAL_ALWAYS,
name: Self::NAME,
compute: Self::compute,
hash_result: Self::hash_result,
cache_on_disk: Self::cache_on_disk,
Expand Down
22 changes: 13 additions & 9 deletions src/librustc/ty/query/on_disk_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::mir::{self, interpret};
use crate::session::{CrateDisambiguator, Session};
use crate::ty::codec::{self as ty_codec, TyDecoder, TyEncoder};
use crate::ty::context::TyCtxt;
use crate::ty::query::config::{QueryAccessors, QueryDescription, QueryVtable};
use crate::ty::{self, Ty};
use rustc_ast::ast::Ident;
use rustc_data_structures::fx::FxHashMap;
Expand Down Expand Up @@ -205,8 +206,10 @@ impl<'sess> OnDiskCache<'sess> {
macro_rules! encode_queries {
($($query:ident,)*) => {
$(
encode_query_results::<ty::query::queries::$query<'_>, _>(
encode_query_results(
tcx,
ty::query::queries::$query::query_state(tcx),
&ty::query::queries::$query::reify(),
enc,
qri
)?;
Expand Down Expand Up @@ -1022,26 +1025,27 @@ impl<'a> SpecializedDecoder<IntEncodedWithFixedSize> for opaque::Decoder<'a> {
}
}

fn encode_query_results<'a, 'tcx, Q, E>(
fn encode_query_results<'a, 'tcx, C, E>(
tcx: TyCtxt<'tcx>,
state: &'a super::plumbing::QueryState<'tcx, C>,
query: &QueryVtable<'tcx, C::Key, C::Value>,
encoder: &mut CacheEncoder<'a, 'tcx, E>,
query_result_index: &mut EncodedQueryResultIndex,
) -> Result<(), E::Error>
where
Q: super::config::QueryDescription<'tcx, Value: Encodable>,
C: super::caches::QueryCache,
E: 'a + TyEncoder,
C::Key: Clone,
C::Value: Encodable,
{
let _timer = tcx
.sess
.prof
.extra_verbose_generic_activity("encode_query_results_for", ::std::any::type_name::<Q>());
let _timer =
tcx.sess.prof.extra_verbose_generic_activity("encode_query_results_for", query.name);

let state = Q::query_state(tcx);
assert!(state.all_inactive());

state.iter_results(|results| {
for (key, value, dep_node) in results {
if Q::cache_on_disk(tcx, key.clone(), Some(&value)) {
if query.cache_on_disk(tcx, key.clone(), Some(&value)) {
let dep_node = SerializedDepNodeIndex::new(dep_node.index());

// Record position of the cache entry.
Expand Down

0 comments on commit cae3639

Please sign in to comment.