diff options
| author | Michael Woerister <michaelwoerister@posteo> | 2021-07-20 14:03:20 +0200 |
|---|---|---|
| committer | Michael Woerister <michaelwoerister@posteo> | 2021-09-14 13:56:33 +0200 |
| commit | 5445715c20dbedbe9b14d185937ab1ebcd81118e (patch) | |
| tree | bb1c84f088944b5ce70600f7e4a8de66cabe38c5 /compiler | |
| parent | 960893c50a61e6eec6635d8f18b586e3ce0865d9 (diff) | |
| download | rust-5445715c20dbedbe9b14d185937ab1ebcd81118e.tar.gz rust-5445715c20dbedbe9b14d185937ab1ebcd81118e.zip | |
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.
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_middle/src/dep_graph/dep_node.rs | 12 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/dep_graph/mod.rs | 7 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/context.rs | 14 | ||||
| -rw-r--r-- | compiler/rustc_query_impl/src/on_disk_cache.rs | 79 | ||||
| -rw-r--r-- | compiler/rustc_query_system/src/dep_graph/dep_node.rs | 12 | ||||
| -rw-r--r-- | compiler/rustc_query_system/src/dep_graph/graph.rs | 14 | ||||
| -rw-r--r-- | compiler/rustc_query_system/src/dep_graph/mod.rs | 2 |
7 files changed, 6 insertions, 134 deletions
diff --git a/compiler/rustc_middle/src/dep_graph/dep_node.rs b/compiler/rustc_middle/src/dep_graph/dep_node.rs index 8476929eaec..3f28cd51af7 100644 --- a/compiler/rustc_middle/src/dep_graph/dep_node.rs +++ b/compiler/rustc_middle/src/dep_graph/dep_node.rs @@ -385,17 +385,7 @@ impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for DefId { } fn to_fingerprint(&self, tcx: TyCtxt<'tcx>) -> Fingerprint { - 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() { - if let Some(cache) = &tcx.on_disk_cache { - cache.store_foreign_def_id_hash(*self, hash); - } - } - hash.0 + tcx.def_path_hash(*self).0 } fn to_debug_str(&self, tcx: TyCtxt<'tcx>) -> String { diff --git a/compiler/rustc_middle/src/dep_graph/mod.rs b/compiler/rustc_middle/src/dep_graph/mod.rs index aa61219ad78..35dc1631db3 100644 --- a/compiler/rustc_middle/src/dep_graph/mod.rs +++ b/compiler/rustc_middle/src/dep_graph/mod.rs @@ -92,12 +92,7 @@ impl<'tcx> DepContext for TyCtxt<'tcx> { type DepKind = DepKind; type StableHashingContext = StableHashingContext<'tcx>; - fn register_reused_dep_node(&self, dep_node: &DepNode) { - if let Some(cache) = self.on_disk_cache.as_ref() { - cache.register_reused_dep_node(*self, dep_node) - } - } - + #[inline] fn create_stable_hashing_context(&self) -> Self::StableHashingContext { TyCtxt::create_stable_hashing_context(*self) } diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 224a01c4ab6..a13fe75fd4d 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -1,7 +1,7 @@ //! Type context book-keeping. use crate::arena::Arena; -use crate::dep_graph::{DepGraph, DepNode}; +use crate::dep_graph::DepGraph; use crate::hir::place::Place as HirPlace; use crate::ich::{NodeIdHashingMode, StableHashingContext}; use crate::infer::canonical::{Canonical, CanonicalVarInfo, CanonicalVarInfos}; @@ -89,18 +89,6 @@ pub trait OnDiskCache<'tcx>: rustc_data_structures::sync::Sync { def_path_hash: DefPathHash, ) -> 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 serialize(&self, tcx: TyCtxt<'tcx>, encoder: &mut FileEncoder) -> FileEncodeResult; diff --git a/compiler/rustc_query_impl/src/on_disk_cache.rs b/compiler/rustc_query_impl/src/on_disk_cache.rs index ddba6e5ae7a..82cc81ec4c3 100644 --- a/compiler/rustc_query_impl/src/on_disk_cache.rs +++ b/compiler/rustc_query_impl/src/on_disk_cache.rs @@ -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::definitions::DefPathHash; 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::{self, interpret}; use rustc_middle::thir; @@ -86,27 +86,9 @@ pub struct OnDiskCache<'sess> { expn_data: UnhashMap<ExpnHash, AbsoluteBytePos>, // Additional information used when decoding hygiene data. hygiene_context: HygieneDecodeContext, - // Maps `DefPathHash`es to their `RawDefId`s from the *previous* - // 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>, + // FIXME(mw): Update this comment: // Likewise for ExpnId. 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. @@ -121,7 +103,6 @@ struct Footer { syntax_contexts: FxHashMap<u32, AbsoluteBytePos>, // See `OnDiskCache.expn_data` expn_data: UnhashMap<ExpnHash, AbsoluteBytePos>, - foreign_def_path_hashes: UnhashMap<DefPathHash, RawDefId>, 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 /// the source crate is represented as a [StableCrateId] instead of as a /// `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, foreign_expn_data: footer.foreign_expn_data, 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(), foreign_expn_data: UnhashMap::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 /// deleted, hence we won't be able to refer to its memmapped data. 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 // cache. The vast majority of cacheable query results should already // 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) }; - let latest_foreign_def_path_hashes = self.latest_foreign_def_path_hashes.lock().clone(); let hygiene_encode_context = HygieneEncodeContext::default(); 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()), file_to_file_index, hygiene_context: &hygiene_encode_context, - latest_foreign_def_path_hashes, }; // 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. let footer_pos = encoder.position() as u64; encoder.encode_tagged( @@ -397,7 +347,6 @@ impl<'sess> rustc_middle::ty::OnDiskCache<'sess> for OnDiskCache<'sess> { syntax_contexts, expn_data, foreign_expn_data, - foreign_def_path_hashes, }, )?; @@ -460,17 +409,6 @@ impl<'sess> OnDiskCache<'sess> { 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 /// the given `SerializedDepNodeIndex`; otherwise returns `None`. pub fn try_load_query_result<'tcx, T>( @@ -911,7 +849,6 @@ pub struct CacheEncoder<'a, 'tcx, E: OpaqueEncoder> { source_map: CachingSourceMapView<'tcx>, file_to_file_index: FxHashMap<*const SourceFile, SourceFileIndex>, hygiene_context: &'a HygieneEncodeContext, - latest_foreign_def_path_hashes: UnhashMap<DefPathHash, RawDefId>, } impl<'a, 'tcx, E> CacheEncoder<'a, 'tcx, E> @@ -1044,17 +981,7 @@ where E: 'a + OpaqueEncoder, { fn encode(&self, s: &mut CacheEncoder<'a, 'tcx, E>) -> Result<(), E::Error> { - let def_path_hash = s.tcx.def_path_hash(*self); - // 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) + s.tcx.def_path_hash(*self).encode(s) } } diff --git a/compiler/rustc_query_system/src/dep_graph/dep_node.rs b/compiler/rustc_query_system/src/dep_graph/dep_node.rs index 59ef6052a60..46dc0c720ce 100644 --- a/compiler/rustc_query_system/src/dep_graph/dep_node.rs +++ b/compiler/rustc_query_system/src/dep_graph/dep_node.rs @@ -53,18 +53,6 @@ use std::hash::Hash; #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Encodable, Decodable)] pub struct DepNode<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, } diff --git a/compiler/rustc_query_system/src/dep_graph/graph.rs b/compiler/rustc_query_system/src/dep_graph/graph.rs index e589d16992f..23a43771842 100644 --- a/compiler/rustc_query_system/src/dep_graph/graph.rs +++ b/compiler/rustc_query_system/src/dep_graph/graph.rs @@ -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) { if let Some(data) = &self.data { data.current.encoder.borrow().print_incremental_info( diff --git a/compiler/rustc_query_system/src/dep_graph/mod.rs b/compiler/rustc_query_system/src/dep_graph/mod.rs index 15e2633c4f1..b5be1192ce7 100644 --- a/compiler/rustc_query_system/src/dep_graph/mod.rs +++ b/compiler/rustc_query_system/src/dep_graph/mod.rs @@ -27,8 +27,6 @@ pub trait DepContext: Copy { /// Access the DepGraph. fn dep_graph(&self) -> &DepGraph<Self::DepKind>; - fn register_reused_dep_node(&self, dep_node: &DepNode<Self::DepKind>); - /// Access the profiler. fn profiler(&self) -> &SelfProfilerRef; |
