Skip to content

Commit afc2149

Browse files
committed
rustc: support extern crates loaded after query engine creation.
1 parent 9f53c87 commit afc2149

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/librustc/ty/context.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1247,7 +1247,11 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
12471247
.collect(),
12481248
hir,
12491249
def_path_hash_to_def_id,
1250-
queries: query::Queries::new(providers, on_disk_query_result_cache),
1250+
queries: query::Queries::new(
1251+
providers,
1252+
extern_providers,
1253+
on_disk_query_result_cache,
1254+
),
12511255
rcache: Lock::new(FxHashMap()),
12521256
selection_cache: traits::SelectionCache::new(),
12531257
evaluation_cache: traits::EvaluationCache::new(),

src/librustc/ty/query/plumbing.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,10 +692,12 @@ macro_rules! define_queries_inner {
692692
impl<$tcx> Queries<$tcx> {
693693
pub fn new(
694694
providers: IndexVec<CrateNum, Providers<$tcx>>,
695+
fallback_extern_providers: Providers<$tcx>,
695696
on_disk_cache: OnDiskCache<'tcx>,
696697
) -> Self {
697698
Queries {
698699
providers,
700+
fallback_extern_providers: Box::new(fallback_extern_providers),
699701
on_disk_cache,
700702
$($name: Lock::new(QueryCache::new())),*
701703
}
@@ -818,7 +820,13 @@ macro_rules! define_queries_inner {
818820
#[inline]
819821
fn compute(tcx: TyCtxt<'_, 'tcx, '_>, key: Self::Key) -> Self::Value {
820822
__query_compute::$name(move || {
821-
let provider = tcx.queries.providers[key.query_crate()].$name;
823+
let provider = tcx.queries.providers.get(key.query_crate())
824+
// HACK(eddyb) it's possible crates may be loaded after
825+
// the query engine is created, and because crate loading
826+
// is not yet integrated with the query engine, such crates
827+
// would be be missing appropriate entries in `providers`.
828+
.unwrap_or(&tcx.queries.fallback_extern_providers)
829+
.$name;
822830
provider(tcx.global_tcx(), key)
823831
})
824832
}
@@ -899,6 +907,7 @@ macro_rules! define_queries_struct {
899907
pub(crate) on_disk_cache: OnDiskCache<'tcx>,
900908

901909
providers: IndexVec<CrateNum, Providers<$tcx>>,
910+
fallback_extern_providers: Box<Providers<$tcx>>,
902911

903912
$($(#[$attr])* $name: Lock<QueryCache<$tcx, queries::$name<$tcx>>>,)*
904913
}

0 commit comments

Comments
 (0)