]> git.lizzy.rs Git - rust.git/commitdiff
Let load_query_result_cache take a &DefPathTable
authorbjorn3 <bjorn3@users.noreply.github.com>
Tue, 30 Mar 2021 16:17:14 +0000 (18:17 +0200)
committerbjorn3 <bjorn3@users.noreply.github.com>
Sun, 2 May 2021 16:00:20 +0000 (18:00 +0200)
This allows removing a confusing mem::replace in create_global_ctxt

compiler/rustc_incremental/src/persist/load.rs
compiler/rustc_interface/src/passes.rs
compiler/rustc_middle/src/ty/context.rs
compiler/rustc_middle/src/ty/query/on_disk_cache.rs

index 2b5649bb0594f57de4d749f630278bb4026c8288..74e6e844bd35efba0cbae5a9ac52c841a44c6dd6 100644 (file)
@@ -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())),
     }
index 94be7a03a932b854e099f165037032b3fc4a4800..94864256be2b520496ea97a640fc92e135ed8f6e 100644 (file)
@@ -13,7 +13,6 @@
 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::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(),
index 94c1758b25c21ab4d5b6d068742e41b4fc71b5f9..9e90dadfff950c3714df0b090262819bac0b27e8 100644 (file)
@@ -1122,7 +1122,6 @@ pub fn create_global_ctxt(
         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 @@ pub fn create_global_ctxt(
             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(),
index 416199b384000e72d9498df7f2a054205c1aa4c0..e78faa7079aa1ce5cf9fabd39807673f34b13d4d 100644 (file)
@@ -10,8 +10,7 @@
 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 @@ fn to_usize(self) -> usize {
     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 @@ pub fn new(
             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(),
         }
     }