Skip to content

Commit 0dc9b26

Browse files
committed
Use UnhashMap whenever we have a key of DefPathHash
1 parent 0876f59 commit 0dc9b26

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

compiler/rustc_metadata/src/rmeta/decoder.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use rustc_data_structures::fingerprint::{Fingerprint, FingerprintDecoder};
1111
use rustc_data_structures::fx::FxHashMap;
1212
use rustc_data_structures::svh::Svh;
1313
use rustc_data_structures::sync::{AtomicCell, Lock, LockGuard, Lrc, OnceCell};
14+
use rustc_data_structures::unhash::UnhashMap;
1415
use rustc_errors::ErrorReported;
1516
use rustc_expand::base::{SyntaxExtension, SyntaxExtensionKind};
1617
use rustc_expand::proc_macro::{AttrProcMacro, BangProcMacro, ProcMacroDerive};
@@ -80,7 +81,7 @@ crate struct CrateMetadata {
8081
/// For every definition in this crate, maps its `DefPathHash` to its
8182
/// `DefIndex`. See `raw_def_id_to_def_id` for more details about how
8283
/// this is used.
83-
def_path_hash_map: OnceCell<FxHashMap<DefPathHash, DefIndex>>,
84+
def_path_hash_map: OnceCell<UnhashMap<DefPathHash, DefIndex>>,
8485
/// Used for decoding interpret::AllocIds in a cached & thread-safe manner.
8586
alloc_decoding_state: AllocDecodingState,
8687
/// The `DepNodeIndex` of the `DepNode` representing this upstream crate.
@@ -1560,7 +1561,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
15601561
// stored in this crate.
15611562
let map = self.cdata.def_path_hash_map.get_or_init(|| {
15621563
let end_id = self.root.tables.def_path_hashes.size() as u32;
1563-
let mut map = FxHashMap::with_capacity_and_hasher(end_id as usize, Default::default());
1564+
let mut map = UnhashMap::with_capacity_and_hasher(end_id as usize, Default::default());
15641565
for i in 0..end_id {
15651566
let def_index = DefIndex::from_u32(i);
15661567
// There may be gaps in the encoded table if we're decoding a proc-macro crate

compiler/rustc_middle/src/ty/query/on_disk_cache.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use rustc_data_structures::fingerprint::{Fingerprint, FingerprintDecoder, Finger
88
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet};
99
use rustc_data_structures::sync::{HashMapExt, Lock, Lrc, OnceCell};
1010
use rustc_data_structures::thin_vec::ThinVec;
11+
use rustc_data_structures::unhash::UnhashMap;
1112
use rustc_errors::Diagnostic;
1213
use rustc_hir::def_id::{CrateNum, DefId, DefIndex, LocalDefId, LOCAL_CRATE};
1314
use rustc_hir::definitions::DefPathHash;
@@ -87,27 +88,27 @@ pub struct OnDiskCache<'sess> {
8788
// compilation session. This is used as an initial 'guess' when
8889
// we try to map a `DefPathHash` to its `DefId` in the current compilation
8990
// session.
90-
foreign_def_path_hashes: FxHashMap<DefPathHash, RawDefId>,
91+
foreign_def_path_hashes: UnhashMap<DefPathHash, RawDefId>,
9192

9293
// The *next* compilation sessison's `foreign_def_path_hashes` - at
9394
// the end of our current compilation session, this will get written
9495
// out to the `foreign_def_path_hashes` field of the `Footer`, which
9596
// will become `foreign_def_path_hashes` of the next compilation session.
9697
// This stores any `DefPathHash` that we may need to map to a `DefId`
9798
// during the next compilation session.
98-
latest_foreign_def_path_hashes: Lock<FxHashMap<DefPathHash, RawDefId>>,
99+
latest_foreign_def_path_hashes: Lock<UnhashMap<DefPathHash, RawDefId>>,
99100

100101
// Maps `DefPathHashes` to their corresponding `LocalDefId`s for all
101102
// local items in the current compilation session. This is only populated
102103
// when we are in incremental mode and have loaded a pre-existing cache
103104
// from disk, since this map is only used when deserializing a `DefPathHash`
104105
// from the incremental cache.
105-
local_def_path_hash_to_def_id: FxHashMap<DefPathHash, LocalDefId>,
106+
local_def_path_hash_to_def_id: UnhashMap<DefPathHash, LocalDefId>,
106107
// Caches all lookups of `DefPathHashes`, both for local and foreign
107108
// definitions. A definition from the previous compilation session
108109
// may no longer exist in the current compilation session, so
109110
// we use `Option<DefId>` so that we can cache a lookup failure.
110-
def_path_hash_to_def_id_cache: Lock<FxHashMap<DefPathHash, Option<DefId>>>,
111+
def_path_hash_to_def_id_cache: Lock<UnhashMap<DefPathHash, Option<DefId>>>,
111112
}
112113

113114
// This type is used only for serialization and deserialization.
@@ -123,7 +124,7 @@ struct Footer {
123124
syntax_contexts: FxHashMap<u32, AbsoluteBytePos>,
124125
// See `OnDiskCache.expn_data`
125126
expn_data: FxHashMap<u32, AbsoluteBytePos>,
126-
foreign_def_path_hashes: FxHashMap<DefPathHash, RawDefId>,
127+
foreign_def_path_hashes: UnhashMap<DefPathHash, RawDefId>,
127128
}
128129

129130
type EncodedQueryResultIndex = Vec<(SerializedDepNodeIndex, AbsoluteBytePos)>;
@@ -160,8 +161,8 @@ crate struct RawDefId {
160161
pub index: u32,
161162
}
162163

163-
fn make_local_def_path_hash_map(definitions: &Definitions) -> FxHashMap<DefPathHash, LocalDefId> {
164-
FxHashMap::from_iter(
164+
fn make_local_def_path_hash_map(definitions: &Definitions) -> UnhashMap<DefPathHash, LocalDefId> {
165+
UnhashMap::from_iter(
165166
definitions
166167
.def_path_table()
167168
.all_def_path_hashes_and_def_ids(LOCAL_CRATE)
@@ -964,7 +965,7 @@ struct CacheEncoder<'a, 'tcx, E: OpaqueEncoder> {
964965
source_map: CachingSourceMapView<'tcx>,
965966
file_to_file_index: FxHashMap<*const SourceFile, SourceFileIndex>,
966967
hygiene_context: &'a HygieneEncodeContext,
967-
latest_foreign_def_path_hashes: FxHashMap<DefPathHash, RawDefId>,
968+
latest_foreign_def_path_hashes: UnhashMap<DefPathHash, RawDefId>,
968969
}
969970

970971
impl<'a, 'tcx, E> CacheEncoder<'a, 'tcx, E>

0 commit comments

Comments
 (0)