Don't duplicate the extern providers once for each crate

This commit is contained in:
bjorn3 2021-03-29 18:03:07 +02:00
parent 3aedcf06b7
commit cd7a011f37
3 changed files with 14 additions and 23 deletions

View File

@ -15,7 +15,6 @@
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(|| {

View File

@ -19,8 +19,7 @@
use rustc_data_structures::fingerprint::Fingerprint;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_errors::{DiagnosticBuilder, Handler};
use rustc_hir::def_id::CrateNum;
use rustc_index::vec::IndexVec;
use rustc_hir::def_id::LOCAL_CRATE;
use rustc_middle::dep_graph;
use rustc_middle::ich::StableHashingContext;
use rustc_middle::ty::query::{query_keys, query_storage, query_stored, query_values};

View File

@ -390,13 +390,12 @@ fn query_cache<'a>(tcx: QueryCtxt<$tcx>) -> &'a QueryCacheStore<Self::Cache>
#[inline]
fn compute(tcx: QueryCtxt<'tcx>, key: Self::Key) -> Self::Value {
let provider = tcx.queries.providers.get(key.query_crate())
// HACK(eddyb) it's possible crates may be loaded after
// the query engine is created, and because crate loading
// is not yet integrated with the query engine, such crates
// would be missing appropriate entries in `providers`.
.unwrap_or(&tcx.queries.fallback_extern_providers)
.$name;
let is_local = key.query_crate() == LOCAL_CRATE;
let provider = if is_local {
tcx.queries.local_providers.$name
} else {
tcx.queries.extern_providers.$name
};
provider(*tcx, key)
}
@ -507,8 +506,8 @@ macro_rules! define_queries_struct {
(tcx: $tcx:tt,
input: ($(([$($modifiers:tt)*] [$($attr:tt)*] [$name:ident]))*)) => {
pub struct Queries<$tcx> {
providers: IndexVec<CrateNum, Providers>,
fallback_extern_providers: Box<Providers>,
local_providers: Box<Providers>,
extern_providers: Box<Providers>,
$($(#[$attr])* $name: QueryState<
crate::dep_graph::DepKind,
@ -518,12 +517,12 @@ pub struct Queries<$tcx> {
impl<$tcx> Queries<$tcx> {
pub fn new(
providers: IndexVec<CrateNum, Providers>,
fallback_extern_providers: Providers,
local_providers: Providers,
extern_providers: Providers,
) -> Self {
Queries {
providers,
fallback_extern_providers: Box::new(fallback_extern_providers),
local_providers: Box::new(local_providers),
extern_providers: Box::new(extern_providers),
$($name: Default::default()),*
}
}