Let load_query_result_cache take a &DefPathTable
This allows removing a confusing mem::replace in create_global_ctxt
This commit is contained in:
parent
18d1b3f3eb
commit
0447f91e10
4 changed files with 16 additions and 27 deletions
|
@ -1,7 +1,7 @@
|
|||
//! 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;
|
||||
|
@ -198,7 +198,7 @@ pub fn load_dep_graph(sess: &Session) -> DepGraphFuture {
|
|||
/// 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;
|
||||
|
@ -212,7 +212,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, definitions))
|
||||
Some(OnDiskCache::new(sess, bytes, start_pos, def_path_table))
|
||||
}
|
||||
_ => Some(OnDiskCache::new_empty(sess.source_map())),
|
||||
}
|
||||
|
|
|
@ -13,7 +13,6 @@ use rustc_data_structures::{box_region_allow_access, declare_box_region_type, pa
|
|||
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;
|
||||
|
@ -51,7 +50,7 @@ use std::io::{self, BufWriter, Write};
|
|||
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 {
|
||||
|
@ -761,7 +760,7 @@ pub fn create_global_ctxt<'tcx>(
|
|||
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>>,
|
||||
|
@ -769,12 +768,10 @@ pub fn create_global_ctxt<'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;
|
||||
|
@ -804,7 +801,6 @@ pub fn create_global_ctxt<'tcx>(
|
|||
arena,
|
||||
resolver_outputs,
|
||||
krate,
|
||||
defs,
|
||||
dep_graph,
|
||||
query_result_on_disk_cache,
|
||||
queries.as_dyn(),
|
||||
|
|
|
@ -1122,7 +1122,6 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
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>,
|
||||
|
@ -1164,7 +1163,7 @@ impl<'tcx> TyCtxt<'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(),
|
||||
|
|
|
@ -10,8 +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;
|
||||
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;
|
||||
|
@ -167,22 +166,13 @@ crate struct RawDefId {
|
|||
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());
|
||||
|
||||
|
@ -220,7 +210,11 @@ 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: 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(),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue