Skip to content

Commit

Permalink
Don't duplicate the extern providers once for each crate
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorn3 committed Mar 29, 2021
1 parent 3aedcf0 commit cd7a011
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 23 deletions.
9 changes: 1 addition & 8 deletions compiler/rustc_interface/src/passes.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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(|| {
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_query_impl/src/lib.rs
Expand Up @@ -19,8 +19,7 @@ extern crate tracing;
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};
Expand Down
25 changes: 12 additions & 13 deletions compiler/rustc_query_impl/src/plumbing.rs
Expand Up @@ -390,13 +390,12 @@ macro_rules! define_queries {

#[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)
}

Expand Down Expand Up @@ -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,
Expand All @@ -518,12 +517,12 @@ macro_rules! define_queries_struct {

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()),*
}
}
Expand Down

0 comments on commit cd7a011

Please sign in to comment.