incr.comp.: Refactor query cache serialization to be more re-usable.
This commit is contained in:
parent
2c1aeddf27
commit
279b6df1f2
@ -1313,7 +1313,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||||||
-> Result<(), E::Error>
|
-> Result<(), E::Error>
|
||||||
where E: ty::codec::TyEncoder
|
where E: ty::codec::TyEncoder
|
||||||
{
|
{
|
||||||
self.on_disk_query_result_cache.serialize(self, self.cstore, encoder)
|
self.on_disk_query_result_cache.serialize(self.global_tcx(), self.cstore, encoder)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,6 @@ use syntax_pos::{BytePos, Span, NO_EXPANSION, DUMMY_SP};
|
|||||||
use ty;
|
use ty;
|
||||||
use ty::codec::{self as ty_codec, TyDecoder, TyEncoder};
|
use ty::codec::{self as ty_codec, TyDecoder, TyEncoder};
|
||||||
use ty::context::TyCtxt;
|
use ty::context::TyCtxt;
|
||||||
use ty::maps::config::QueryDescription;
|
|
||||||
use ty::subst::Substs;
|
use ty::subst::Substs;
|
||||||
|
|
||||||
// Some magic values used for verifying that encoding and decoding. These are
|
// Some magic values used for verifying that encoding and decoding. These are
|
||||||
@ -162,8 +161,8 @@ impl<'sess> OnDiskCache<'sess> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn serialize<'a, 'gcx, 'lcx, E>(&self,
|
pub fn serialize<'a, 'tcx, E>(&self,
|
||||||
tcx: TyCtxt<'a, 'gcx, 'lcx>,
|
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||||
cstore: &CrateStore,
|
cstore: &CrateStore,
|
||||||
encoder: &mut E)
|
encoder: &mut E)
|
||||||
-> Result<(), E::Error>
|
-> Result<(), E::Error>
|
||||||
@ -232,19 +231,13 @@ impl<'sess> OnDiskCache<'sess> {
|
|||||||
// Encode query results
|
// Encode query results
|
||||||
let mut query_result_index = EncodedQueryResultIndex::new();
|
let mut query_result_index = EncodedQueryResultIndex::new();
|
||||||
|
|
||||||
|
{
|
||||||
|
use ty::maps::queries::*;
|
||||||
|
let enc = &mut encoder;
|
||||||
|
let qri = &mut query_result_index;
|
||||||
|
|
||||||
// Encode TypeckTables
|
// Encode TypeckTables
|
||||||
for (def_id, entry) in tcx.maps.typeck_tables_of.borrow().map.iter() {
|
encode_query_results::<typeck_tables_of, _>(tcx, enc, qri)?;
|
||||||
if ty::maps::queries::typeck_tables_of::cache_on_disk(*def_id) {
|
|
||||||
let dep_node = SerializedDepNodeIndex::new(entry.index.index());
|
|
||||||
|
|
||||||
// Record position of the cache entry
|
|
||||||
query_result_index.push((dep_node, encoder.position()));
|
|
||||||
|
|
||||||
// Encode the type check tables with the SerializedDepNodeIndex
|
|
||||||
// as tag.
|
|
||||||
let typeck_tables: &ty::TypeckTables<'gcx> = &entry.value;
|
|
||||||
encoder.encode_tagged(dep_node, typeck_tables)?;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Encode query result index
|
// Encode query result index
|
||||||
@ -842,3 +835,27 @@ for CacheDecoder<'a, 'tcx, 'x> {
|
|||||||
Ok(IntEncodedWithFixedSize(value))
|
Ok(IntEncodedWithFixedSize(value))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn encode_query_results<'x, 'a, 'tcx, Q, E>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||||
|
encoder: &mut CacheEncoder<'x, 'tcx, E>,
|
||||||
|
query_result_index: &mut EncodedQueryResultIndex)
|
||||||
|
-> Result<(), E::Error>
|
||||||
|
where Q: super::plumbing::GetCacheInternal<'tcx>,
|
||||||
|
E: 'x + TyEncoder,
|
||||||
|
Q::Value: Encodable,
|
||||||
|
{
|
||||||
|
for (key, entry) in Q::get_cache_internal(tcx).map.iter() {
|
||||||
|
if Q::cache_on_disk(key.clone()) {
|
||||||
|
let dep_node = SerializedDepNodeIndex::new(entry.index.index());
|
||||||
|
|
||||||
|
// Record position of the cache entry
|
||||||
|
query_result_index.push((dep_node, encoder.position()));
|
||||||
|
|
||||||
|
// Encode the type check tables with the SerializedDepNodeIndex
|
||||||
|
// as tag.
|
||||||
|
encoder.encode_tagged(dep_node, &entry.value)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
@ -20,7 +20,7 @@ use ty::maps::config::QueryDescription;
|
|||||||
use ty::item_path;
|
use ty::item_path;
|
||||||
|
|
||||||
use rustc_data_structures::fx::{FxHashMap};
|
use rustc_data_structures::fx::{FxHashMap};
|
||||||
use std::cell::RefMut;
|
use std::cell::{Ref, RefMut};
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use syntax_pos::Span;
|
use syntax_pos::Span;
|
||||||
@ -55,6 +55,11 @@ impl<'tcx, M: QueryDescription<'tcx>> QueryMap<'tcx, M> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(super) trait GetCacheInternal<'tcx>: QueryDescription<'tcx> + Sized {
|
||||||
|
fn get_cache_internal<'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>)
|
||||||
|
-> Ref<'a, QueryMap<'tcx, Self>>;
|
||||||
|
}
|
||||||
|
|
||||||
pub(super) struct CycleError<'a, 'tcx: 'a> {
|
pub(super) struct CycleError<'a, 'tcx: 'a> {
|
||||||
span: Span,
|
span: Span,
|
||||||
cycle: RefMut<'a, [(Span, Query<'tcx>)]>,
|
cycle: RefMut<'a, [(Span, Query<'tcx>)]>,
|
||||||
@ -242,6 +247,13 @@ macro_rules! define_maps {
|
|||||||
type Value = $V;
|
type Value = $V;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<$tcx> GetCacheInternal<$tcx> for queries::$name<$tcx> {
|
||||||
|
fn get_cache_internal<'a>(tcx: TyCtxt<'a, $tcx, $tcx>)
|
||||||
|
-> ::std::cell::Ref<'a, QueryMap<$tcx, Self>> {
|
||||||
|
tcx.maps.$name.borrow()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'a, $tcx, 'lcx> queries::$name<$tcx> {
|
impl<'a, $tcx, 'lcx> queries::$name<$tcx> {
|
||||||
|
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
|
Loading…
Reference in New Issue
Block a user