Remove RawDefId tracking infrastructure from incr. comp. framework.
This infrastructure is obsolete now with the new encoding scheme for the DefPathHash->DefIndex maps in crate metadata.
This commit is contained in:
parent
960893c50a
commit
5445715c20
7 changed files with 6 additions and 134 deletions
|
@ -385,17 +385,7 @@ impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for DefId {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn to_fingerprint(&self, tcx: TyCtxt<'tcx>) -> Fingerprint {
|
fn to_fingerprint(&self, tcx: TyCtxt<'tcx>) -> Fingerprint {
|
||||||
let hash = tcx.def_path_hash(*self);
|
tcx.def_path_hash(*self).0
|
||||||
// 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() {
|
|
||||||
if let Some(cache) = &tcx.on_disk_cache {
|
|
||||||
cache.store_foreign_def_id_hash(*self, hash);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
hash.0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn to_debug_str(&self, tcx: TyCtxt<'tcx>) -> String {
|
fn to_debug_str(&self, tcx: TyCtxt<'tcx>) -> String {
|
||||||
|
|
|
@ -92,12 +92,7 @@ impl<'tcx> DepContext for TyCtxt<'tcx> {
|
||||||
type DepKind = DepKind;
|
type DepKind = DepKind;
|
||||||
type StableHashingContext = StableHashingContext<'tcx>;
|
type StableHashingContext = StableHashingContext<'tcx>;
|
||||||
|
|
||||||
fn register_reused_dep_node(&self, dep_node: &DepNode) {
|
#[inline]
|
||||||
if let Some(cache) = self.on_disk_cache.as_ref() {
|
|
||||||
cache.register_reused_dep_node(*self, dep_node)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn create_stable_hashing_context(&self) -> Self::StableHashingContext {
|
fn create_stable_hashing_context(&self) -> Self::StableHashingContext {
|
||||||
TyCtxt::create_stable_hashing_context(*self)
|
TyCtxt::create_stable_hashing_context(*self)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
//! Type context book-keeping.
|
//! Type context book-keeping.
|
||||||
|
|
||||||
use crate::arena::Arena;
|
use crate::arena::Arena;
|
||||||
use crate::dep_graph::{DepGraph, DepNode};
|
use crate::dep_graph::DepGraph;
|
||||||
use crate::hir::place::Place as HirPlace;
|
use crate::hir::place::Place as HirPlace;
|
||||||
use crate::ich::{NodeIdHashingMode, StableHashingContext};
|
use crate::ich::{NodeIdHashingMode, StableHashingContext};
|
||||||
use crate::infer::canonical::{Canonical, CanonicalVarInfo, CanonicalVarInfos};
|
use crate::infer::canonical::{Canonical, CanonicalVarInfo, CanonicalVarInfos};
|
||||||
|
@ -89,18 +89,6 @@ pub trait OnDiskCache<'tcx>: rustc_data_structures::sync::Sync {
|
||||||
def_path_hash: DefPathHash,
|
def_path_hash: DefPathHash,
|
||||||
) -> Option<DefId>;
|
) -> Option<DefId>;
|
||||||
|
|
||||||
/// If the given `dep_node`'s hash still exists in the current compilation,
|
|
||||||
/// and its current `DefId` is foreign, calls `store_foreign_def_id` with it.
|
|
||||||
///
|
|
||||||
/// Normally, `store_foreign_def_id_hash` can be called directly by
|
|
||||||
/// the dependency graph when we construct a `DepNode`. However,
|
|
||||||
/// when we re-use a deserialized `DepNode` from the previous compilation
|
|
||||||
/// session, we only have the `DefPathHash` available. This method is used
|
|
||||||
/// to that any `DepNode` that we re-use has a `DefPathHash` -> `RawId` written
|
|
||||||
/// out for usage in the next compilation session.
|
|
||||||
fn register_reused_dep_node(&self, tcx: TyCtxt<'tcx>, dep_node: &DepNode);
|
|
||||||
fn store_foreign_def_id_hash(&self, def_id: DefId, hash: DefPathHash);
|
|
||||||
|
|
||||||
fn drop_serialized_data(&self, tcx: TyCtxt<'tcx>);
|
fn drop_serialized_data(&self, tcx: TyCtxt<'tcx>);
|
||||||
|
|
||||||
fn serialize(&self, tcx: TyCtxt<'tcx>, encoder: &mut FileEncoder) -> FileEncodeResult;
|
fn serialize(&self, tcx: TyCtxt<'tcx>, encoder: &mut FileEncoder) -> FileEncodeResult;
|
||||||
|
|
|
@ -6,7 +6,7 @@ use rustc_data_structures::unhash::UnhashMap;
|
||||||
use rustc_hir::def_id::{CrateNum, DefId, DefIndex, LocalDefId, StableCrateId, LOCAL_CRATE};
|
use rustc_hir::def_id::{CrateNum, DefId, DefIndex, LocalDefId, StableCrateId, LOCAL_CRATE};
|
||||||
use rustc_hir::definitions::DefPathHash;
|
use rustc_hir::definitions::DefPathHash;
|
||||||
use rustc_index::vec::{Idx, IndexVec};
|
use rustc_index::vec::{Idx, IndexVec};
|
||||||
use rustc_middle::dep_graph::{DepNode, DepNodeIndex, SerializedDepNodeIndex};
|
use rustc_middle::dep_graph::{DepNodeIndex, SerializedDepNodeIndex};
|
||||||
use rustc_middle::mir::interpret::{AllocDecodingSession, AllocDecodingState};
|
use rustc_middle::mir::interpret::{AllocDecodingSession, AllocDecodingState};
|
||||||
use rustc_middle::mir::{self, interpret};
|
use rustc_middle::mir::{self, interpret};
|
||||||
use rustc_middle::thir;
|
use rustc_middle::thir;
|
||||||
|
@ -86,27 +86,9 @@ pub struct OnDiskCache<'sess> {
|
||||||
expn_data: UnhashMap<ExpnHash, AbsoluteBytePos>,
|
expn_data: UnhashMap<ExpnHash, AbsoluteBytePos>,
|
||||||
// Additional information used when decoding hygiene data.
|
// Additional information used when decoding hygiene data.
|
||||||
hygiene_context: HygieneDecodeContext,
|
hygiene_context: HygieneDecodeContext,
|
||||||
// Maps `DefPathHash`es to their `RawDefId`s from the *previous*
|
// FIXME(mw): Update this comment:
|
||||||
// compilation session. This is used as an initial 'guess' when
|
|
||||||
// we try to map a `DefPathHash` to its `DefId` in the current compilation
|
|
||||||
// session.
|
|
||||||
foreign_def_path_hashes: UnhashMap<DefPathHash, RawDefId>,
|
|
||||||
// Likewise for ExpnId.
|
// Likewise for ExpnId.
|
||||||
foreign_expn_data: UnhashMap<ExpnHash, u32>,
|
foreign_expn_data: UnhashMap<ExpnHash, u32>,
|
||||||
|
|
||||||
// The *next* compilation sessison's `foreign_def_path_hashes` - at
|
|
||||||
// the end of our current compilation session, this will get written
|
|
||||||
// out to the `foreign_def_path_hashes` field of the `Footer`, which
|
|
||||||
// will become `foreign_def_path_hashes` of the next compilation session.
|
|
||||||
// This stores any `DefPathHash` that we may need to map to a `DefId`
|
|
||||||
// during the next compilation session.
|
|
||||||
latest_foreign_def_path_hashes: Lock<UnhashMap<DefPathHash, RawDefId>>,
|
|
||||||
|
|
||||||
// Caches all lookups of `DefPathHashes`, both for local and foreign
|
|
||||||
// definitions. A definition from the previous compilation session
|
|
||||||
// may no longer exist in the current compilation session, so
|
|
||||||
// we use `Option<DefId>` so that we can cache a lookup failure.
|
|
||||||
def_path_hash_to_def_id_cache: Lock<UnhashMap<DefPathHash, Option<DefId>>>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// This type is used only for serialization and deserialization.
|
// This type is used only for serialization and deserialization.
|
||||||
|
@ -121,7 +103,6 @@ struct Footer {
|
||||||
syntax_contexts: FxHashMap<u32, AbsoluteBytePos>,
|
syntax_contexts: FxHashMap<u32, AbsoluteBytePos>,
|
||||||
// See `OnDiskCache.expn_data`
|
// See `OnDiskCache.expn_data`
|
||||||
expn_data: UnhashMap<ExpnHash, AbsoluteBytePos>,
|
expn_data: UnhashMap<ExpnHash, AbsoluteBytePos>,
|
||||||
foreign_def_path_hashes: UnhashMap<DefPathHash, RawDefId>,
|
|
||||||
foreign_expn_data: UnhashMap<ExpnHash, u32>,
|
foreign_expn_data: UnhashMap<ExpnHash, u32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,19 +125,6 @@ impl AbsoluteBytePos {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Represents a potentially invalid `DefId`. This is used during incremental
|
|
||||||
/// compilation to represent a `DefId` from the *previous* compilation session,
|
|
||||||
/// which may no longer be valid. This is used to help map a `DefPathHash`
|
|
||||||
/// to a `DefId` in the current compilation session.
|
|
||||||
#[derive(Encodable, Decodable, Copy, Clone, Debug)]
|
|
||||||
crate struct RawDefId {
|
|
||||||
// We deliberately do not use `CrateNum` and `DefIndex`
|
|
||||||
// here, since a crate/index from the previous compilation
|
|
||||||
// session may no longer exist.
|
|
||||||
pub krate: u32,
|
|
||||||
pub index: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// An `EncodedSourceFileId` is the same as a `StableSourceFileId` except that
|
/// An `EncodedSourceFileId` is the same as a `StableSourceFileId` except that
|
||||||
/// the source crate is represented as a [StableCrateId] instead of as a
|
/// the source crate is represented as a [StableCrateId] instead of as a
|
||||||
/// `CrateNum`. This way `EncodedSourceFileId` can be encoded and decoded
|
/// `CrateNum`. This way `EncodedSourceFileId` can be encoded and decoded
|
||||||
|
@ -220,9 +188,6 @@ impl<'sess> rustc_middle::ty::OnDiskCache<'sess> for OnDiskCache<'sess> {
|
||||||
expn_data: footer.expn_data,
|
expn_data: footer.expn_data,
|
||||||
foreign_expn_data: footer.foreign_expn_data,
|
foreign_expn_data: footer.foreign_expn_data,
|
||||||
hygiene_context: Default::default(),
|
hygiene_context: Default::default(),
|
||||||
foreign_def_path_hashes: footer.foreign_def_path_hashes,
|
|
||||||
latest_foreign_def_path_hashes: Default::default(),
|
|
||||||
def_path_hash_to_def_id_cache: Default::default(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -241,9 +206,6 @@ impl<'sess> rustc_middle::ty::OnDiskCache<'sess> for OnDiskCache<'sess> {
|
||||||
expn_data: UnhashMap::default(),
|
expn_data: UnhashMap::default(),
|
||||||
foreign_expn_data: UnhashMap::default(),
|
foreign_expn_data: UnhashMap::default(),
|
||||||
hygiene_context: Default::default(),
|
hygiene_context: Default::default(),
|
||||||
foreign_def_path_hashes: Default::default(),
|
|
||||||
latest_foreign_def_path_hashes: Default::default(),
|
|
||||||
def_path_hash_to_def_id_cache: Default::default(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -253,13 +215,6 @@ impl<'sess> rustc_middle::ty::OnDiskCache<'sess> for OnDiskCache<'sess> {
|
||||||
/// In order to serialize the new on-disk cache, the former on-disk cache file needs to be
|
/// In order to serialize the new on-disk cache, the former on-disk cache file needs to be
|
||||||
/// deleted, hence we won't be able to refer to its memmapped data.
|
/// deleted, hence we won't be able to refer to its memmapped data.
|
||||||
fn drop_serialized_data(&self, tcx: TyCtxt<'tcx>) {
|
fn drop_serialized_data(&self, tcx: TyCtxt<'tcx>) {
|
||||||
// Register any dep nodes that we reused from the previous session,
|
|
||||||
// but didn't `DepNode::construct` in this session. This ensures
|
|
||||||
// that their `DefPathHash` to `RawDefId` mappings are registered
|
|
||||||
// in 'latest_foreign_def_path_hashes' if necessary, since that
|
|
||||||
// normally happens in `DepNode::construct`.
|
|
||||||
tcx.dep_graph.register_reused_dep_nodes(tcx);
|
|
||||||
|
|
||||||
// Load everything into memory so we can write it out to the on-disk
|
// Load everything into memory so we can write it out to the on-disk
|
||||||
// cache. The vast majority of cacheable query results should already
|
// cache. The vast majority of cacheable query results should already
|
||||||
// be in memory, so this should be a cheap operation.
|
// be in memory, so this should be a cheap operation.
|
||||||
|
@ -293,7 +248,6 @@ impl<'sess> rustc_middle::ty::OnDiskCache<'sess> for OnDiskCache<'sess> {
|
||||||
(file_to_file_index, file_index_to_stable_id)
|
(file_to_file_index, file_index_to_stable_id)
|
||||||
};
|
};
|
||||||
|
|
||||||
let latest_foreign_def_path_hashes = self.latest_foreign_def_path_hashes.lock().clone();
|
|
||||||
let hygiene_encode_context = HygieneEncodeContext::default();
|
let hygiene_encode_context = HygieneEncodeContext::default();
|
||||||
|
|
||||||
let mut encoder = CacheEncoder {
|
let mut encoder = CacheEncoder {
|
||||||
|
@ -305,7 +259,6 @@ impl<'sess> rustc_middle::ty::OnDiskCache<'sess> for OnDiskCache<'sess> {
|
||||||
source_map: CachingSourceMapView::new(tcx.sess.source_map()),
|
source_map: CachingSourceMapView::new(tcx.sess.source_map()),
|
||||||
file_to_file_index,
|
file_to_file_index,
|
||||||
hygiene_context: &hygiene_encode_context,
|
hygiene_context: &hygiene_encode_context,
|
||||||
latest_foreign_def_path_hashes,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Encode query results.
|
// Encode query results.
|
||||||
|
@ -382,9 +335,6 @@ impl<'sess> rustc_middle::ty::OnDiskCache<'sess> for OnDiskCache<'sess> {
|
||||||
},
|
},
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let foreign_def_path_hashes =
|
|
||||||
std::mem::take(&mut encoder.latest_foreign_def_path_hashes);
|
|
||||||
|
|
||||||
// `Encode the file footer.
|
// `Encode the file footer.
|
||||||
let footer_pos = encoder.position() as u64;
|
let footer_pos = encoder.position() as u64;
|
||||||
encoder.encode_tagged(
|
encoder.encode_tagged(
|
||||||
|
@ -397,7 +347,6 @@ impl<'sess> rustc_middle::ty::OnDiskCache<'sess> for OnDiskCache<'sess> {
|
||||||
syntax_contexts,
|
syntax_contexts,
|
||||||
expn_data,
|
expn_data,
|
||||||
foreign_expn_data,
|
foreign_expn_data,
|
||||||
foreign_def_path_hashes,
|
|
||||||
},
|
},
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
@ -460,17 +409,6 @@ impl<'sess> OnDiskCache<'sess> {
|
||||||
debug_assert!(prev.is_none());
|
debug_assert!(prev.is_none());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_raw_def_id(&self, hash: &DefPathHash) -> Option<RawDefId> {
|
|
||||||
self.foreign_def_path_hashes.get(hash).copied()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn try_remap_cnum(&self, tcx: TyCtxt<'_>, stable_crate_id: StableCrateId) -> Option<CrateNum> {
|
|
||||||
let cnum_map = self.cnum_map.get_or_init(|| Self::compute_cnum_map(tcx));
|
|
||||||
debug!("try_remap_cnum({:?}): cnum_map={:?}", stable_crate_id, cnum_map);
|
|
||||||
|
|
||||||
cnum_map.get(&stable_crate_id).copied()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the cached query result if there is something in the cache for
|
/// Returns the cached query result if there is something in the cache for
|
||||||
/// the given `SerializedDepNodeIndex`; otherwise returns `None`.
|
/// the given `SerializedDepNodeIndex`; otherwise returns `None`.
|
||||||
pub fn try_load_query_result<'tcx, T>(
|
pub fn try_load_query_result<'tcx, T>(
|
||||||
|
@ -911,7 +849,6 @@ pub struct CacheEncoder<'a, 'tcx, E: OpaqueEncoder> {
|
||||||
source_map: CachingSourceMapView<'tcx>,
|
source_map: CachingSourceMapView<'tcx>,
|
||||||
file_to_file_index: FxHashMap<*const SourceFile, SourceFileIndex>,
|
file_to_file_index: FxHashMap<*const SourceFile, SourceFileIndex>,
|
||||||
hygiene_context: &'a HygieneEncodeContext,
|
hygiene_context: &'a HygieneEncodeContext,
|
||||||
latest_foreign_def_path_hashes: UnhashMap<DefPathHash, RawDefId>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'tcx, E> CacheEncoder<'a, 'tcx, E>
|
impl<'a, 'tcx, E> CacheEncoder<'a, 'tcx, E>
|
||||||
|
@ -1044,17 +981,7 @@ where
|
||||||
E: 'a + OpaqueEncoder,
|
E: 'a + OpaqueEncoder,
|
||||||
{
|
{
|
||||||
fn encode(&self, s: &mut CacheEncoder<'a, 'tcx, E>) -> Result<(), E::Error> {
|
fn encode(&self, s: &mut CacheEncoder<'a, 'tcx, E>) -> Result<(), E::Error> {
|
||||||
let def_path_hash = s.tcx.def_path_hash(*self);
|
s.tcx.def_path_hash(*self).encode(s)
|
||||||
// Store additional information when we encode a foreign `DefId`,
|
|
||||||
// so that we can map its `DefPathHash` back to a `DefId` in the next
|
|
||||||
// compilation session.
|
|
||||||
if !self.is_local() {
|
|
||||||
s.latest_foreign_def_path_hashes.insert(
|
|
||||||
def_path_hash,
|
|
||||||
RawDefId { krate: self.krate.as_u32(), index: self.index.as_u32() },
|
|
||||||
);
|
|
||||||
}
|
|
||||||
def_path_hash.encode(s)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,18 +53,6 @@ use std::hash::Hash;
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Encodable, Decodable)]
|
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Encodable, Decodable)]
|
||||||
pub struct DepNode<K> {
|
pub struct DepNode<K> {
|
||||||
pub kind: K,
|
pub kind: K,
|
||||||
// Important - whenever a `DepNode` is constructed, we need to make
|
|
||||||
// sure to register a `DefPathHash -> DefId` mapping if needed.
|
|
||||||
// This is currently done in two places:
|
|
||||||
//
|
|
||||||
// * When a `DepNode::construct` is called, `arg.to_fingerprint()`
|
|
||||||
// is responsible for calling `OnDiskCache::store_foreign_def_id_hash`
|
|
||||||
// if needed
|
|
||||||
// * When we serialize the on-disk cache, `OnDiskCache::serialize` is
|
|
||||||
// responsible for calling `DepGraph::register_reused_dep_nodes`.
|
|
||||||
//
|
|
||||||
// FIXME: Enforce this by preventing manual construction of `DefNode`
|
|
||||||
// (e.g. add a `_priv: ()` field)
|
|
||||||
pub hash: PackedFingerprint,
|
pub hash: PackedFingerprint,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -760,20 +760,6 @@ impl<K: DepKind> DepGraph<K> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register reused dep nodes (i.e. nodes we've marked red or green) with the context.
|
|
||||||
pub fn register_reused_dep_nodes<Ctxt: DepContext<DepKind = K>>(&self, tcx: Ctxt) {
|
|
||||||
let data = self.data.as_ref().unwrap();
|
|
||||||
for prev_index in data.colors.values.indices() {
|
|
||||||
match data.colors.get(prev_index) {
|
|
||||||
Some(DepNodeColor::Red) | Some(DepNodeColor::Green(_)) => {
|
|
||||||
let dep_node = data.previous.index_to_node(prev_index);
|
|
||||||
tcx.register_reused_dep_node(&dep_node);
|
|
||||||
}
|
|
||||||
None => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn print_incremental_info(&self) {
|
pub fn print_incremental_info(&self) {
|
||||||
if let Some(data) = &self.data {
|
if let Some(data) = &self.data {
|
||||||
data.current.encoder.borrow().print_incremental_info(
|
data.current.encoder.borrow().print_incremental_info(
|
||||||
|
|
|
@ -27,8 +27,6 @@ pub trait DepContext: Copy {
|
||||||
/// Access the DepGraph.
|
/// Access the DepGraph.
|
||||||
fn dep_graph(&self) -> &DepGraph<Self::DepKind>;
|
fn dep_graph(&self) -> &DepGraph<Self::DepKind>;
|
||||||
|
|
||||||
fn register_reused_dep_node(&self, dep_node: &DepNode<Self::DepKind>);
|
|
||||||
|
|
||||||
/// Access the profiler.
|
/// Access the profiler.
|
||||||
fn profiler(&self) -> &SelfProfilerRef;
|
fn profiler(&self) -> &SelfProfilerRef;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue