Lazy DefPath decoding for incremental compilation

This commit is contained in:
Aaron Hill 2020-07-29 12:26:15 -04:00
parent db79d2f637
commit e935d3832c
No known key found for this signature in database
GPG key ID: B4087E510E98B164
11 changed files with 275 additions and 43 deletions

View file

@ -252,8 +252,8 @@ macro_rules! define_dep_nodes {
/// has been removed.
fn extract_def_id(&self, tcx: TyCtxt<'tcx>) -> Option<DefId> {
if self.kind.can_reconstruct_query_key() {
let def_path_hash = DefPathHash(self.hash.into());
tcx.def_path_hash_to_def_id.as_ref()?.get(&def_path_hash).cloned()
let def_path_hash = DefPathHash(self.hash);
tcx.queries.on_disk_cache.as_ref()?.def_path_hash_to_def_id(tcx, def_path_hash)
} else {
None
}
@ -320,7 +320,15 @@ impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for DefId {
}
fn to_fingerprint(&self, tcx: TyCtxt<'tcx>) -> Fingerprint {
tcx.def_path_hash(*self).0
let hash = tcx.def_path_hash(*self);
// If this is a foreign `DefId`, store its current value
// in the incremental cache. When we decode the cache,
// we will use the old DefIndex as an initial guess for
// a lookup into the crate metadata.
if !self.is_local() {
tcx.queries.on_disk_cache.store_foreign_def_id_hash(*self, hash);
}
hash.0
}
fn to_debug_str(&self, tcx: TyCtxt<'tcx>) -> String {
@ -359,7 +367,7 @@ impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for CrateNum {
fn to_fingerprint(&self, tcx: TyCtxt<'tcx>) -> Fingerprint {
let def_id = DefId { krate: *self, index: CRATE_DEF_INDEX };
tcx.def_path_hash(def_id).0
def_id.to_fingerprint(tcx)
}
fn to_debug_str(&self, tcx: TyCtxt<'tcx>) -> String {

View file

@ -5,7 +5,7 @@ use rustc_data_structures::profiling::SelfProfilerRef;
use rustc_data_structures::sync::Lock;
use rustc_data_structures::thin_vec::ThinVec;
use rustc_errors::Diagnostic;
use rustc_hir::def_id::LocalDefId;
use rustc_hir::def_id::{DefPathHash, LocalDefId};
mod dep_node;
@ -91,6 +91,10 @@ impl<'tcx> DepContext for TyCtxt<'tcx> {
type DepKind = DepKind;
type StableHashingContext = StableHashingContext<'tcx>;
fn register_reused_dep_path_hash(&self, hash: DefPathHash) {
self.queries.on_disk_cache.register_reused_dep_path_hash(hash)
}
fn create_stable_hashing_context(&self) -> Self::StableHashingContext {
TyCtxt::create_stable_hashing_context(*self)
}