about summary refs log tree commit diff
path: root/compiler/rustc_interface
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-03-30 06:22:29 +0000
committerbors <bors@rust-lang.org>2021-03-30 06:22:29 +0000
commita0e229abadfe47df74625309fba44c0f3b8a0649 (patch)
tree405ba01d86c506ac646652a609df4159426bcd13 /compiler/rustc_interface
parent32d3276561e88bfdf92cc483cff842a24fdd4b37 (diff)
parentcd7a011f37c51d6cb367e87c37b4d7bc464da09d (diff)
downloadrust-a0e229abadfe47df74625309fba44c0f3b8a0649.tar.gz
rust-a0e229abadfe47df74625309fba44c0f3b8a0649.zip
Auto merge of #83649 - bjorn3:dedup_providers, r=petrochenkov
Don't duplicate the extern providers once for each crate

This should give a small perf improvement for small crates by avoiding a memcpy of a pretty big struct for each loaded crate. In addition would be useful for replacing the sequential `CrateNum` everywhere with the hash based `StableCrateId` introduced in #81635, which would allow avoiding remapping of `CrateNum`'s when loading crate metadata. While this PR is not strictly needed for that, it is necessary to prevent a performance loss due to it.

I think this duplication was done in https://github.com/rust-lang/rust/pull/40008 (which introduced the query system) to make it possible to compile multiple crates in a single session in the future. I think this is unlikely to be implemented any time soon. In addition this PR can easily be reverted if necessary to implement this.
Diffstat (limited to 'compiler/rustc_interface')
-rw-r--r--compiler/rustc_interface/src/passes.rs9
1 files changed, 1 insertions, 8 deletions
diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs
index 94be7a03a93..87d00287828 100644
--- a/compiler/rustc_interface/src/passes.rs
+++ b/compiler/rustc_interface/src/passes.rs
@@ -15,7 +15,6 @@ 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 rustc_middle::arena::Arena;
 use rustc_middle::dep_graph::DepGraph;
@@ -788,13 +787,7 @@ pub fn create_global_ctxt<'tcx>(
         callback(sess, &mut local_providers, &mut extern_providers);
     }
 
-    let queries = {
-        let crates = resolver_outputs.cstore.crates_untracked();
-        let max_cnum = crates.iter().map(|c| c.as_usize()).max().unwrap_or(0);
-        let mut providers = IndexVec::from_elem_n(extern_providers, max_cnum + 1);
-        providers[LOCAL_CRATE] = local_providers;
-        queries.get_or_init(|| TcxQueries::new(providers, extern_providers))
-    };
+    let queries = queries.get_or_init(|| TcxQueries::new(local_providers, extern_providers));
 
     let gcx = sess.time("setup_global_ctxt", || {
         global_ctxt.get_or_init(|| {