Skip to content

Commit

Permalink
Auto merge of #86150 - cjgillot:notable, r=michaelwoerister
Browse files Browse the repository at this point in the history
Do not require the DefPathTable to construct the on-disk cache.

r? `@michaelwoerister`
  • Loading branch information
bors committed Jun 9, 2021
2 parents 38bc9b9 + aeb050d commit 47d3875
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 39 deletions.
17 changes: 8 additions & 9 deletions compiler/rustc_hir/src/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,6 @@ impl DefPathTable {
.iter_enumerated()
.map(move |(index, key)| (index, key, &self.def_path_hashes[index]))
}

pub fn all_def_path_hashes_and_def_ids(
&self,
krate: CrateNum,
) -> impl Iterator<Item = (DefPathHash, DefId)> + '_ {
self.def_path_hashes
.iter_enumerated()
.map(move |(index, hash)| (*hash, DefId { krate, index }))
}
}

/// The definition table containing node definitions.
Expand Down Expand Up @@ -440,6 +431,14 @@ impl Definitions {
pub fn iter_local_def_id(&self) -> impl Iterator<Item = LocalDefId> + '_ {
self.def_id_to_hir_id.iter_enumerated().map(|(k, _)| k)
}

#[inline(always)]
pub fn local_def_path_hash_to_def_id(&self, hash: DefPathHash) -> Option<LocalDefId> {
self.table
.def_path_hash_to_index
.get(&hash)
.map(|&local_def_index| LocalDefId { local_def_index })
}
}

#[derive(Copy, Clone, PartialEq, Debug)]
Expand Down
8 changes: 2 additions & 6 deletions compiler/rustc_incremental/src/persist/load.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Code to save/load the dep-graph from files.
use rustc_data_structures::fx::FxHashMap;
use rustc_hir::definitions::DefPathTable;
use rustc_middle::dep_graph::{SerializedDepGraph, WorkProduct, WorkProductId};
use rustc_middle::ty::query::OnDiskCache;
use rustc_serialize::opaque::Decoder;
Expand Down Expand Up @@ -196,10 +195,7 @@ pub fn load_dep_graph(sess: &Session) -> DepGraphFuture {
/// If we are not in incremental compilation mode, returns `None`.
/// Otherwise, tries to load the query result cache from disk,
/// creating an empty cache if it could not be loaded.
pub fn load_query_result_cache<'a>(
sess: &'a Session,
def_path_table: &DefPathTable,
) -> Option<OnDiskCache<'a>> {
pub fn load_query_result_cache<'a>(sess: &'a Session) -> Option<OnDiskCache<'a>> {
if sess.opts.incremental.is_none() {
return None;
}
Expand All @@ -212,7 +208,7 @@ pub fn load_query_result_cache<'a>(
sess.is_nightly_build(),
) {
LoadResult::Ok { data: (bytes, start_pos) } => {
Some(OnDiskCache::new(sess, bytes, start_pos, def_path_table))
Some(OnDiskCache::new(sess, bytes, start_pos))
}
_ => Some(OnDiskCache::new_empty(sess.source_map())),
}
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -765,9 +765,7 @@ pub fn create_global_ctxt<'tcx>(
) -> QueryContext<'tcx> {
let sess = &compiler.session();

let def_path_table = resolver_outputs.definitions.def_path_table();
let query_result_on_disk_cache =
rustc_incremental::load_query_result_cache(sess, def_path_table);
let query_result_on_disk_cache = rustc_incremental::load_query_result_cache(sess);

let codegen_backend = compiler.codegen_backend();
let mut local_providers = *DEFAULT_QUERY_PROVIDERS;
Expand Down
24 changes: 3 additions & 21 deletions compiler/rustc_middle/src/ty/query/on_disk_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use rustc_data_structures::thin_vec::ThinVec;
use rustc_data_structures::unhash::UnhashMap;
use rustc_errors::Diagnostic;
use rustc_hir::def_id::{CrateNum, DefId, DefIndex, LocalDefId, LOCAL_CRATE};
use rustc_hir::definitions::{DefPathHash, DefPathTable};
use rustc_hir::definitions::DefPathHash;
use rustc_index::vec::{Idx, IndexVec};
use rustc_query_system::dep_graph::DepContext;
use rustc_query_system::query::QueryContext;
Expand All @@ -27,7 +27,6 @@ use rustc_span::source_map::{SourceMap, StableSourceFileId};
use rustc_span::CachingSourceMapView;
use rustc_span::{BytePos, ExpnData, SourceFile, Span, DUMMY_SP};
use std::collections::hash_map::Entry;
use std::iter::FromIterator;
use std::mem;

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

// Maps `DefPathHashes` to their corresponding `LocalDefId`s for all
// local items in the current compilation session. This is only populated
// when we are in incremental mode and have loaded a pre-existing cache
// from disk, since this map is only used when deserializing a `DefPathHash`
// from the incremental cache.
local_def_path_hash_to_def_id: UnhashMap<DefPathHash, LocalDefId>,
// 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
Expand Down Expand Up @@ -168,12 +161,7 @@ crate struct RawDefId {

impl<'sess> OnDiskCache<'sess> {
/// Creates a new `OnDiskCache` instance from the serialized data in `data`.
pub fn new(
sess: &'sess Session,
data: Vec<u8>,
start_pos: usize,
def_path_table: &DefPathTable,
) -> Self {
pub fn new(sess: &'sess Session, data: Vec<u8>, start_pos: usize) -> Self {
debug_assert!(sess.opts.incremental.is_some());

// Wrap in a scope so we can borrow `data`.
Expand Down Expand Up @@ -210,11 +198,6 @@ impl<'sess> OnDiskCache<'sess> {
hygiene_context: Default::default(),
foreign_def_path_hashes: footer.foreign_def_path_hashes,
latest_foreign_def_path_hashes: Default::default(),
local_def_path_hash_to_def_id: UnhashMap::from_iter(
def_path_table
.all_def_path_hashes_and_def_ids(LOCAL_CRATE)
.map(|(hash, def_id)| (hash, def_id.as_local().unwrap())),
),
def_path_hash_to_def_id_cache: Default::default(),
}
}
Expand All @@ -236,7 +219,6 @@ impl<'sess> OnDiskCache<'sess> {
hygiene_context: Default::default(),
foreign_def_path_hashes: Default::default(),
latest_foreign_def_path_hashes: Default::default(),
local_def_path_hash_to_def_id: Default::default(),
def_path_hash_to_def_id_cache: Default::default(),
}
}
Expand Down Expand Up @@ -616,7 +598,7 @@ impl<'sess> OnDiskCache<'sess> {
debug!("def_path_hash_to_def_id({:?})", hash);
// Check if the `DefPathHash` corresponds to a definition in the current
// crate
if let Some(def_id) = self.local_def_path_hash_to_def_id.get(&hash).cloned() {
if let Some(def_id) = tcx.definitions.local_def_path_hash_to_def_id(hash) {
let def_id = def_id.to_def_id();
e.insert(Some(def_id));
return Some(def_id);
Expand Down

0 comments on commit 47d3875

Please sign in to comment.