Skip to content

Commit 47d3875

Browse files
committedJun 9, 2021
Auto merge of #86150 - cjgillot:notable, r=michaelwoerister
Do not require the DefPathTable to construct the on-disk cache. r? `@michaelwoerister`
2 parents 38bc9b9 + aeb050d commit 47d3875

File tree

4 files changed

+14
-39
lines changed

4 files changed

+14
-39
lines changed
 

‎compiler/rustc_hir/src/definitions.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,6 @@ impl DefPathTable {
9494
.iter_enumerated()
9595
.map(move |(index, key)| (index, key, &self.def_path_hashes[index]))
9696
}
97-
98-
pub fn all_def_path_hashes_and_def_ids(
99-
&self,
100-
krate: CrateNum,
101-
) -> impl Iterator<Item = (DefPathHash, DefId)> + '_ {
102-
self.def_path_hashes
103-
.iter_enumerated()
104-
.map(move |(index, hash)| (*hash, DefId { krate, index }))
105-
}
10697
}
10798

10899
/// The definition table containing node definitions.
@@ -440,6 +431,14 @@ impl Definitions {
440431
pub fn iter_local_def_id(&self) -> impl Iterator<Item = LocalDefId> + '_ {
441432
self.def_id_to_hir_id.iter_enumerated().map(|(k, _)| k)
442433
}
434+
435+
#[inline(always)]
436+
pub fn local_def_path_hash_to_def_id(&self, hash: DefPathHash) -> Option<LocalDefId> {
437+
self.table
438+
.def_path_hash_to_index
439+
.get(&hash)
440+
.map(|&local_def_index| LocalDefId { local_def_index })
441+
}
443442
}
444443

445444
#[derive(Copy, Clone, PartialEq, Debug)]

‎compiler/rustc_incremental/src/persist/load.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! Code to save/load the dep-graph from files.
22
33
use rustc_data_structures::fx::FxHashMap;
4-
use rustc_hir::definitions::DefPathTable;
54
use rustc_middle::dep_graph::{SerializedDepGraph, WorkProduct, WorkProductId};
65
use rustc_middle::ty::query::OnDiskCache;
76
use rustc_serialize::opaque::Decoder;
@@ -196,10 +195,7 @@ pub fn load_dep_graph(sess: &Session) -> DepGraphFuture {
196195
/// If we are not in incremental compilation mode, returns `None`.
197196
/// Otherwise, tries to load the query result cache from disk,
198197
/// creating an empty cache if it could not be loaded.
199-
pub fn load_query_result_cache<'a>(
200-
sess: &'a Session,
201-
def_path_table: &DefPathTable,
202-
) -> Option<OnDiskCache<'a>> {
198+
pub fn load_query_result_cache<'a>(sess: &'a Session) -> Option<OnDiskCache<'a>> {
203199
if sess.opts.incremental.is_none() {
204200
return None;
205201
}
@@ -212,7 +208,7 @@ pub fn load_query_result_cache<'a>(
212208
sess.is_nightly_build(),
213209
) {
214210
LoadResult::Ok { data: (bytes, start_pos) } => {
215-
Some(OnDiskCache::new(sess, bytes, start_pos, def_path_table))
211+
Some(OnDiskCache::new(sess, bytes, start_pos))
216212
}
217213
_ => Some(OnDiskCache::new_empty(sess.source_map())),
218214
}

‎compiler/rustc_interface/src/passes.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -765,9 +765,7 @@ pub fn create_global_ctxt<'tcx>(
765765
) -> QueryContext<'tcx> {
766766
let sess = &compiler.session();
767767

768-
let def_path_table = resolver_outputs.definitions.def_path_table();
769-
let query_result_on_disk_cache =
770-
rustc_incremental::load_query_result_cache(sess, def_path_table);
768+
let query_result_on_disk_cache = rustc_incremental::load_query_result_cache(sess);
771769

772770
let codegen_backend = compiler.codegen_backend();
773771
let mut local_providers = *DEFAULT_QUERY_PROVIDERS;

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

+3-21
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_data_structures::thin_vec::ThinVec;
1010
use rustc_data_structures::unhash::UnhashMap;
1111
use rustc_errors::Diagnostic;
1212
use rustc_hir::def_id::{CrateNum, DefId, DefIndex, LocalDefId, LOCAL_CRATE};
13-
use rustc_hir::definitions::{DefPathHash, DefPathTable};
13+
use rustc_hir::definitions::DefPathHash;
1414
use rustc_index::vec::{Idx, IndexVec};
1515
use rustc_query_system::dep_graph::DepContext;
1616
use rustc_query_system::query::QueryContext;
@@ -27,7 +27,6 @@ use rustc_span::source_map::{SourceMap, StableSourceFileId};
2727
use rustc_span::CachingSourceMapView;
2828
use rustc_span::{BytePos, ExpnData, SourceFile, Span, DUMMY_SP};
2929
use std::collections::hash_map::Entry;
30-
use std::iter::FromIterator;
3130
use std::mem;
3231

3332
const TAG_FILE_FOOTER: u128 = 0xC0FFEE_C0FFEE_C0FFEE_C0FFEE_C0FFEE;
@@ -103,12 +102,6 @@ pub struct OnDiskCache<'sess> {
103102
// during the next compilation session.
104103
latest_foreign_def_path_hashes: Lock<UnhashMap<DefPathHash, RawDefId>>,
105104

106-
// Maps `DefPathHashes` to their corresponding `LocalDefId`s for all
107-
// local items in the current compilation session. This is only populated
108-
// when we are in incremental mode and have loaded a pre-existing cache
109-
// from disk, since this map is only used when deserializing a `DefPathHash`
110-
// from the incremental cache.
111-
local_def_path_hash_to_def_id: UnhashMap<DefPathHash, LocalDefId>,
112105
// Caches all lookups of `DefPathHashes`, both for local and foreign
113106
// definitions. A definition from the previous compilation session
114107
// may no longer exist in the current compilation session, so
@@ -168,12 +161,7 @@ crate struct RawDefId {
168161

169162
impl<'sess> OnDiskCache<'sess> {
170163
/// Creates a new `OnDiskCache` instance from the serialized data in `data`.
171-
pub fn new(
172-
sess: &'sess Session,
173-
data: Vec<u8>,
174-
start_pos: usize,
175-
def_path_table: &DefPathTable,
176-
) -> Self {
164+
pub fn new(sess: &'sess Session, data: Vec<u8>, start_pos: usize) -> Self {
177165
debug_assert!(sess.opts.incremental.is_some());
178166

179167
// Wrap in a scope so we can borrow `data`.
@@ -210,11 +198,6 @@ impl<'sess> OnDiskCache<'sess> {
210198
hygiene_context: Default::default(),
211199
foreign_def_path_hashes: footer.foreign_def_path_hashes,
212200
latest_foreign_def_path_hashes: Default::default(),
213-
local_def_path_hash_to_def_id: UnhashMap::from_iter(
214-
def_path_table
215-
.all_def_path_hashes_and_def_ids(LOCAL_CRATE)
216-
.map(|(hash, def_id)| (hash, def_id.as_local().unwrap())),
217-
),
218201
def_path_hash_to_def_id_cache: Default::default(),
219202
}
220203
}
@@ -236,7 +219,6 @@ impl<'sess> OnDiskCache<'sess> {
236219
hygiene_context: Default::default(),
237220
foreign_def_path_hashes: Default::default(),
238221
latest_foreign_def_path_hashes: Default::default(),
239-
local_def_path_hash_to_def_id: Default::default(),
240222
def_path_hash_to_def_id_cache: Default::default(),
241223
}
242224
}
@@ -616,7 +598,7 @@ impl<'sess> OnDiskCache<'sess> {
616598
debug!("def_path_hash_to_def_id({:?})", hash);
617599
// Check if the `DefPathHash` corresponds to a definition in the current
618600
// crate
619-
if let Some(def_id) = self.local_def_path_hash_to_def_id.get(&hash).cloned() {
601+
if let Some(def_id) = tcx.definitions.local_def_path_hash_to_def_id(hash) {
620602
let def_id = def_id.to_def_id();
621603
e.insert(Some(def_id));
622604
return Some(def_id);

0 commit comments

Comments
 (0)