//! Code to save/load the dep-graph from files.
use rustc_data_structures::fx::FxHashMap;
-use rustc_hir::definitions::Definitions;
+use rustc_hir::definitions::DefPathTable;
use rustc_middle::dep_graph::{PreviousDepGraph, SerializedDepGraph, WorkProduct, WorkProductId};
use rustc_middle::ty::query::OnDiskCache;
use rustc_serialize::opaque::Decoder;
/// creating an empty cache if it could not be loaded.
pub fn load_query_result_cache<'a>(
sess: &'a Session,
- definitions: &Definitions,
+ def_path_table: &DefPathTable,
) -> Option<OnDiskCache<'a>> {
if sess.opts.incremental.is_none() {
return None;
sess.is_nightly_build(),
) {
LoadResult::Ok { data: (bytes, start_pos) } => {
- Some(OnDiskCache::new(sess, bytes, start_pos, definitions))
+ Some(OnDiskCache::new(sess, bytes, start_pos, def_path_table))
}
_ => Some(OnDiskCache::new_empty(sess.source_map())),
}
use rustc_errors::{ErrorReported, PResult};
use rustc_expand::base::ExtCtxt;
use rustc_hir::def_id::{CrateNum, LOCAL_CRATE};
-use rustc_hir::definitions::Definitions;
use rustc_hir::Crate;
use rustc_index::vec::IndexVec;
use rustc_lint::LintStore;
use std::lazy::SyncLazy;
use std::path::PathBuf;
use std::rc::Rc;
-use std::{env, fs, iter, mem};
+use std::{env, fs, iter};
pub fn parse<'a>(sess: &'a Session, input: &Input) -> PResult<'a, ast::Crate> {
let krate = sess.time("parse_crate", || match input {
lint_store: Lrc<LintStore>,
krate: &'tcx Crate<'tcx>,
dep_graph: DepGraph,
- mut resolver_outputs: ResolverOutputs,
+ resolver_outputs: ResolverOutputs,
outputs: OutputFilenames,
crate_name: &str,
queries: &'tcx OnceCell<TcxQueries<'tcx>>,
arena: &'tcx WorkerLocal<Arena<'tcx>>,
) -> QueryContext<'tcx> {
let sess = &compiler.session();
- let defs: &'tcx Definitions = arena.alloc(mem::replace(
- &mut resolver_outputs.definitions,
- Definitions::new(crate_name, sess.local_crate_disambiguator()),
- ));
- let query_result_on_disk_cache = rustc_incremental::load_query_result_cache(sess, defs);
+ 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 codegen_backend = compiler.codegen_backend();
let mut local_providers = *DEFAULT_QUERY_PROVIDERS;
arena,
resolver_outputs,
krate,
- defs,
dep_graph,
query_result_on_disk_cache,
queries.as_dyn(),
arena: &'tcx WorkerLocal<Arena<'tcx>>,
resolutions: ty::ResolverOutputs,
krate: &'tcx hir::Crate<'tcx>,
- definitions: &'tcx Definitions,
dep_graph: DepGraph,
on_disk_cache: Option<query::OnDiskCache<'tcx>>,
queries: &'tcx dyn query::QueryEngine<'tcx>,
glob_map: resolutions.glob_map,
extern_prelude: resolutions.extern_prelude,
untracked_crate: krate,
- definitions,
+ definitions: arena.alloc(resolutions.definitions),
on_disk_cache,
queries,
query_caches: query::QueryCaches::default(),
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;
-use rustc_hir::definitions::Definitions;
+use rustc_hir::definitions::{DefPathHash, DefPathTable};
use rustc_index::vec::{Idx, IndexVec};
use rustc_query_system::dep_graph::DepContext;
use rustc_query_system::query::QueryContext;
pub index: u32,
}
-fn make_local_def_path_hash_map(definitions: &Definitions) -> UnhashMap<DefPathHash, LocalDefId> {
- UnhashMap::from_iter(
- definitions
- .def_path_table()
- .all_def_path_hashes_and_def_ids(LOCAL_CRATE)
- .map(|(hash, def_id)| (hash, def_id.as_local().unwrap())),
- )
-}
-
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,
- definitions: &Definitions,
+ def_path_table: &DefPathTable,
) -> Self {
debug_assert!(sess.opts.incremental.is_some());
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: make_local_def_path_hash_map(definitions),
+ 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(),
}
}