mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-01 23:12:02 +00:00
Do not require the DefPathTable to construct the on-disk cache.
This commit is contained in:
parent
e4a6032706
commit
aeb050da9f
@ -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.
|
||||
@ -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)]
|
||||
|
@ -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;
|
||||
@ -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;
|
||||
}
|
||||
@ -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())),
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
@ -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;
|
||||
@ -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
|
||||
@ -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`.
|
||||
@ -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(),
|
||||
}
|
||||
}
|
||||
@ -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(),
|
||||
}
|
||||
}
|
||||
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user