Skip to content

Commit 5445715

Browse files
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.
1 parent 960893c commit 5445715

File tree

7 files changed

+6
-134
lines changed

7 files changed

+6
-134
lines changed

Diff for: compiler/rustc_middle/src/dep_graph/dep_node.rs

+1-11
Original file line numberDiff line numberDiff line change
@@ -385,17 +385,7 @@ impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for DefId {
385385
}
386386

387387
fn to_fingerprint(&self, tcx: TyCtxt<'tcx>) -> Fingerprint {
388-
let hash = tcx.def_path_hash(*self);
389-
// If this is a foreign `DefId`, store its current value
390-
// in the incremental cache. When we decode the cache,
391-
// we will use the old DefIndex as an initial guess for
392-
// a lookup into the crate metadata.
393-
if !self.is_local() {
394-
if let Some(cache) = &tcx.on_disk_cache {
395-
cache.store_foreign_def_id_hash(*self, hash);
396-
}
397-
}
398-
hash.0
388+
tcx.def_path_hash(*self).0
399389
}
400390

401391
fn to_debug_str(&self, tcx: TyCtxt<'tcx>) -> String {

Diff for: compiler/rustc_middle/src/dep_graph/mod.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,7 @@ impl<'tcx> DepContext for TyCtxt<'tcx> {
9292
type DepKind = DepKind;
9393
type StableHashingContext = StableHashingContext<'tcx>;
9494

95-
fn register_reused_dep_node(&self, dep_node: &DepNode) {
96-
if let Some(cache) = self.on_disk_cache.as_ref() {
97-
cache.register_reused_dep_node(*self, dep_node)
98-
}
99-
}
100-
95+
#[inline]
10196
fn create_stable_hashing_context(&self) -> Self::StableHashingContext {
10297
TyCtxt::create_stable_hashing_context(*self)
10398
}

Diff for: compiler/rustc_middle/src/ty/context.rs

+1-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Type context book-keeping.
22
33
use crate::arena::Arena;
4-
use crate::dep_graph::{DepGraph, DepNode};
4+
use crate::dep_graph::DepGraph;
55
use crate::hir::place::Place as HirPlace;
66
use crate::ich::{NodeIdHashingMode, StableHashingContext};
77
use crate::infer::canonical::{Canonical, CanonicalVarInfo, CanonicalVarInfos};
@@ -89,18 +89,6 @@ pub trait OnDiskCache<'tcx>: rustc_data_structures::sync::Sync {
8989
def_path_hash: DefPathHash,
9090
) -> Option<DefId>;
9191

92-
/// If the given `dep_node`'s hash still exists in the current compilation,
93-
/// and its current `DefId` is foreign, calls `store_foreign_def_id` with it.
94-
///
95-
/// Normally, `store_foreign_def_id_hash` can be called directly by
96-
/// the dependency graph when we construct a `DepNode`. However,
97-
/// when we re-use a deserialized `DepNode` from the previous compilation
98-
/// session, we only have the `DefPathHash` available. This method is used
99-
/// to that any `DepNode` that we re-use has a `DefPathHash` -> `RawId` written
100-
/// out for usage in the next compilation session.
101-
fn register_reused_dep_node(&self, tcx: TyCtxt<'tcx>, dep_node: &DepNode);
102-
fn store_foreign_def_id_hash(&self, def_id: DefId, hash: DefPathHash);
103-
10492
fn drop_serialized_data(&self, tcx: TyCtxt<'tcx>);
10593

10694
fn serialize(&self, tcx: TyCtxt<'tcx>, encoder: &mut FileEncoder) -> FileEncodeResult;

Diff for: compiler/rustc_query_impl/src/on_disk_cache.rs

+3-76
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_data_structures::unhash::UnhashMap;
66
use rustc_hir::def_id::{CrateNum, DefId, DefIndex, LocalDefId, StableCrateId, LOCAL_CRATE};
77
use rustc_hir::definitions::DefPathHash;
88
use rustc_index::vec::{Idx, IndexVec};
9-
use rustc_middle::dep_graph::{DepNode, DepNodeIndex, SerializedDepNodeIndex};
9+
use rustc_middle::dep_graph::{DepNodeIndex, SerializedDepNodeIndex};
1010
use rustc_middle::mir::interpret::{AllocDecodingSession, AllocDecodingState};
1111
use rustc_middle::mir::{self, interpret};
1212
use rustc_middle::thir;
@@ -86,27 +86,9 @@ pub struct OnDiskCache<'sess> {
8686
expn_data: UnhashMap<ExpnHash, AbsoluteBytePos>,
8787
// Additional information used when decoding hygiene data.
8888
hygiene_context: HygieneDecodeContext,
89-
// Maps `DefPathHash`es to their `RawDefId`s from the *previous*
90-
// compilation session. This is used as an initial 'guess' when
91-
// we try to map a `DefPathHash` to its `DefId` in the current compilation
92-
// session.
93-
foreign_def_path_hashes: UnhashMap<DefPathHash, RawDefId>,
89+
// FIXME(mw): Update this comment:
9490
// Likewise for ExpnId.
9591
foreign_expn_data: UnhashMap<ExpnHash, u32>,
96-
97-
// The *next* compilation sessison's `foreign_def_path_hashes` - at
98-
// the end of our current compilation session, this will get written
99-
// out to the `foreign_def_path_hashes` field of the `Footer`, which
100-
// will become `foreign_def_path_hashes` of the next compilation session.
101-
// This stores any `DefPathHash` that we may need to map to a `DefId`
102-
// during the next compilation session.
103-
latest_foreign_def_path_hashes: Lock<UnhashMap<DefPathHash, RawDefId>>,
104-
105-
// Caches all lookups of `DefPathHashes`, both for local and foreign
106-
// definitions. A definition from the previous compilation session
107-
// may no longer exist in the current compilation session, so
108-
// we use `Option<DefId>` so that we can cache a lookup failure.
109-
def_path_hash_to_def_id_cache: Lock<UnhashMap<DefPathHash, Option<DefId>>>,
11092
}
11193

11294
// This type is used only for serialization and deserialization.
@@ -121,7 +103,6 @@ struct Footer {
121103
syntax_contexts: FxHashMap<u32, AbsoluteBytePos>,
122104
// See `OnDiskCache.expn_data`
123105
expn_data: UnhashMap<ExpnHash, AbsoluteBytePos>,
124-
foreign_def_path_hashes: UnhashMap<DefPathHash, RawDefId>,
125106
foreign_expn_data: UnhashMap<ExpnHash, u32>,
126107
}
127108

@@ -144,19 +125,6 @@ impl AbsoluteBytePos {
144125
}
145126
}
146127

147-
/// Represents a potentially invalid `DefId`. This is used during incremental
148-
/// compilation to represent a `DefId` from the *previous* compilation session,
149-
/// which may no longer be valid. This is used to help map a `DefPathHash`
150-
/// to a `DefId` in the current compilation session.
151-
#[derive(Encodable, Decodable, Copy, Clone, Debug)]
152-
crate struct RawDefId {
153-
// We deliberately do not use `CrateNum` and `DefIndex`
154-
// here, since a crate/index from the previous compilation
155-
// session may no longer exist.
156-
pub krate: u32,
157-
pub index: u32,
158-
}
159-
160128
/// An `EncodedSourceFileId` is the same as a `StableSourceFileId` except that
161129
/// the source crate is represented as a [StableCrateId] instead of as a
162130
/// `CrateNum`. This way `EncodedSourceFileId` can be encoded and decoded
@@ -220,9 +188,6 @@ impl<'sess> rustc_middle::ty::OnDiskCache<'sess> for OnDiskCache<'sess> {
220188
expn_data: footer.expn_data,
221189
foreign_expn_data: footer.foreign_expn_data,
222190
hygiene_context: Default::default(),
223-
foreign_def_path_hashes: footer.foreign_def_path_hashes,
224-
latest_foreign_def_path_hashes: Default::default(),
225-
def_path_hash_to_def_id_cache: Default::default(),
226191
}
227192
}
228193

@@ -241,9 +206,6 @@ impl<'sess> rustc_middle::ty::OnDiskCache<'sess> for OnDiskCache<'sess> {
241206
expn_data: UnhashMap::default(),
242207
foreign_expn_data: UnhashMap::default(),
243208
hygiene_context: Default::default(),
244-
foreign_def_path_hashes: Default::default(),
245-
latest_foreign_def_path_hashes: Default::default(),
246-
def_path_hash_to_def_id_cache: Default::default(),
247209
}
248210
}
249211

@@ -253,13 +215,6 @@ impl<'sess> rustc_middle::ty::OnDiskCache<'sess> for OnDiskCache<'sess> {
253215
/// In order to serialize the new on-disk cache, the former on-disk cache file needs to be
254216
/// deleted, hence we won't be able to refer to its memmapped data.
255217
fn drop_serialized_data(&self, tcx: TyCtxt<'tcx>) {
256-
// Register any dep nodes that we reused from the previous session,
257-
// but didn't `DepNode::construct` in this session. This ensures
258-
// that their `DefPathHash` to `RawDefId` mappings are registered
259-
// in 'latest_foreign_def_path_hashes' if necessary, since that
260-
// normally happens in `DepNode::construct`.
261-
tcx.dep_graph.register_reused_dep_nodes(tcx);
262-
263218
// Load everything into memory so we can write it out to the on-disk
264219
// cache. The vast majority of cacheable query results should already
265220
// be in memory, so this should be a cheap operation.
@@ -293,7 +248,6 @@ impl<'sess> rustc_middle::ty::OnDiskCache<'sess> for OnDiskCache<'sess> {
293248
(file_to_file_index, file_index_to_stable_id)
294249
};
295250

296-
let latest_foreign_def_path_hashes = self.latest_foreign_def_path_hashes.lock().clone();
297251
let hygiene_encode_context = HygieneEncodeContext::default();
298252

299253
let mut encoder = CacheEncoder {
@@ -305,7 +259,6 @@ impl<'sess> rustc_middle::ty::OnDiskCache<'sess> for OnDiskCache<'sess> {
305259
source_map: CachingSourceMapView::new(tcx.sess.source_map()),
306260
file_to_file_index,
307261
hygiene_context: &hygiene_encode_context,
308-
latest_foreign_def_path_hashes,
309262
};
310263

311264
// Encode query results.
@@ -382,9 +335,6 @@ impl<'sess> rustc_middle::ty::OnDiskCache<'sess> for OnDiskCache<'sess> {
382335
},
383336
)?;
384337

385-
let foreign_def_path_hashes =
386-
std::mem::take(&mut encoder.latest_foreign_def_path_hashes);
387-
388338
// `Encode the file footer.
389339
let footer_pos = encoder.position() as u64;
390340
encoder.encode_tagged(
@@ -397,7 +347,6 @@ impl<'sess> rustc_middle::ty::OnDiskCache<'sess> for OnDiskCache<'sess> {
397347
syntax_contexts,
398348
expn_data,
399349
foreign_expn_data,
400-
foreign_def_path_hashes,
401350
},
402351
)?;
403352

@@ -460,17 +409,6 @@ impl<'sess> OnDiskCache<'sess> {
460409
debug_assert!(prev.is_none());
461410
}
462411

463-
fn get_raw_def_id(&self, hash: &DefPathHash) -> Option<RawDefId> {
464-
self.foreign_def_path_hashes.get(hash).copied()
465-
}
466-
467-
fn try_remap_cnum(&self, tcx: TyCtxt<'_>, stable_crate_id: StableCrateId) -> Option<CrateNum> {
468-
let cnum_map = self.cnum_map.get_or_init(|| Self::compute_cnum_map(tcx));
469-
debug!("try_remap_cnum({:?}): cnum_map={:?}", stable_crate_id, cnum_map);
470-
471-
cnum_map.get(&stable_crate_id).copied()
472-
}
473-
474412
/// Returns the cached query result if there is something in the cache for
475413
/// the given `SerializedDepNodeIndex`; otherwise returns `None`.
476414
pub fn try_load_query_result<'tcx, T>(
@@ -911,7 +849,6 @@ pub struct CacheEncoder<'a, 'tcx, E: OpaqueEncoder> {
911849
source_map: CachingSourceMapView<'tcx>,
912850
file_to_file_index: FxHashMap<*const SourceFile, SourceFileIndex>,
913851
hygiene_context: &'a HygieneEncodeContext,
914-
latest_foreign_def_path_hashes: UnhashMap<DefPathHash, RawDefId>,
915852
}
916853

917854
impl<'a, 'tcx, E> CacheEncoder<'a, 'tcx, E>
@@ -1044,17 +981,7 @@ where
1044981
E: 'a + OpaqueEncoder,
1045982
{
1046983
fn encode(&self, s: &mut CacheEncoder<'a, 'tcx, E>) -> Result<(), E::Error> {
1047-
let def_path_hash = s.tcx.def_path_hash(*self);
1048-
// Store additional information when we encode a foreign `DefId`,
1049-
// so that we can map its `DefPathHash` back to a `DefId` in the next
1050-
// compilation session.
1051-
if !self.is_local() {
1052-
s.latest_foreign_def_path_hashes.insert(
1053-
def_path_hash,
1054-
RawDefId { krate: self.krate.as_u32(), index: self.index.as_u32() },
1055-
);
1056-
}
1057-
def_path_hash.encode(s)
984+
s.tcx.def_path_hash(*self).encode(s)
1058985
}
1059986
}
1060987

Diff for: compiler/rustc_query_system/src/dep_graph/dep_node.rs

-12
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,6 @@ use std::hash::Hash;
5353
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Encodable, Decodable)]
5454
pub struct DepNode<K> {
5555
pub kind: K,
56-
// Important - whenever a `DepNode` is constructed, we need to make
57-
// sure to register a `DefPathHash -> DefId` mapping if needed.
58-
// This is currently done in two places:
59-
//
60-
// * When a `DepNode::construct` is called, `arg.to_fingerprint()`
61-
// is responsible for calling `OnDiskCache::store_foreign_def_id_hash`
62-
// if needed
63-
// * When we serialize the on-disk cache, `OnDiskCache::serialize` is
64-
// responsible for calling `DepGraph::register_reused_dep_nodes`.
65-
//
66-
// FIXME: Enforce this by preventing manual construction of `DefNode`
67-
// (e.g. add a `_priv: ()` field)
6856
pub hash: PackedFingerprint,
6957
}
7058

Diff for: compiler/rustc_query_system/src/dep_graph/graph.rs

-14
Original file line numberDiff line numberDiff line change
@@ -760,20 +760,6 @@ impl<K: DepKind> DepGraph<K> {
760760
}
761761
}
762762

763-
// Register reused dep nodes (i.e. nodes we've marked red or green) with the context.
764-
pub fn register_reused_dep_nodes<Ctxt: DepContext<DepKind = K>>(&self, tcx: Ctxt) {
765-
let data = self.data.as_ref().unwrap();
766-
for prev_index in data.colors.values.indices() {
767-
match data.colors.get(prev_index) {
768-
Some(DepNodeColor::Red) | Some(DepNodeColor::Green(_)) => {
769-
let dep_node = data.previous.index_to_node(prev_index);
770-
tcx.register_reused_dep_node(&dep_node);
771-
}
772-
None => {}
773-
}
774-
}
775-
}
776-
777763
pub fn print_incremental_info(&self) {
778764
if let Some(data) = &self.data {
779765
data.current.encoder.borrow().print_incremental_info(

Diff for: compiler/rustc_query_system/src/dep_graph/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ pub trait DepContext: Copy {
2727
/// Access the DepGraph.
2828
fn dep_graph(&self) -> &DepGraph<Self::DepKind>;
2929

30-
fn register_reused_dep_node(&self, dep_node: &DepNode<Self::DepKind>);
31-
3230
/// Access the profiler.
3331
fn profiler(&self) -> &SelfProfilerRef;
3432

0 commit comments

Comments
 (0)