1
Fork 0

Auto merge of #83610 - bjorn3:driver_cleanup, r=cjgillot

rustc_driver cleanup

Best reviewed one commit at a time.
This commit is contained in:
bors 2021-05-12 08:38:03 +00:00
commit ac923d94f8
16 changed files with 168 additions and 224 deletions

View file

@ -973,7 +973,7 @@ pub struct GlobalCtxt<'tcx> {
export_map: ExportMap<LocalDefId>,
pub(crate) untracked_crate: &'tcx hir::Crate<'tcx>,
pub(crate) definitions: &'tcx Definitions,
pub(crate) definitions: Definitions,
/// This provides access to the incremental compilation on-disk cache for query results.
/// Do not access this directly. It is only meant to be used by
@ -1130,7 +1130,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>,
@ -1172,7 +1171,7 @@ impl<'tcx> TyCtxt<'tcx> {
glob_map: resolutions.glob_map,
extern_prelude: resolutions.extern_prelude,
untracked_crate: krate,
definitions,
definitions: resolutions.definitions,
on_disk_cache,
queries,
query_caches: query::QueryCaches::default(),
@ -1329,14 +1328,14 @@ impl<'tcx> TyCtxt<'tcx> {
pub fn create_stable_hashing_context(self) -> StableHashingContext<'tcx> {
let krate = self.gcx.untracked_crate;
StableHashingContext::new(self.sess, krate, self.definitions, &*self.cstore)
StableHashingContext::new(self.sess, krate, &self.definitions, &*self.cstore)
}
#[inline(always)]
pub fn create_no_span_stable_hashing_context(self) -> StableHashingContext<'tcx> {
let krate = self.gcx.untracked_crate;
StableHashingContext::ignore_spans(self.sess, krate, self.definitions, &*self.cstore)
StableHashingContext::ignore_spans(self.sess, krate, &self.definitions, &*self.cstore)
}
pub fn serialize_query_result_cache(self, encoder: &mut FileEncoder) -> FileEncodeResult {

View file

@ -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(),
}
}