Skip to content

Commit c624738

Browse files
committed
Remove metadata_loader query
It is only used by CrateLoader. We can store the metadata loader in CStore instead which CrateLoader has access to.
1 parent 980143b commit c624738

File tree

4 files changed

+15
-16
lines changed

4 files changed

+15
-16
lines changed

compiler/rustc_interface/src/queries.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,10 @@ impl<'tcx> Queries<'tcx> {
193193
self.compiler.register_lints.as_deref(),
194194
&pre_configured_attrs,
195195
));
196-
let cstore = RwLock::new(Box::new(CStore::new(stable_crate_id)) as _);
196+
let cstore = RwLock::new(Box::new(CStore::new(
197+
self.codegen_backend().metadata_loader(),
198+
stable_crate_id,
199+
)) as _);
197200
let definitions = RwLock::new(Definitions::new(stable_crate_id));
198201
let source_span = AppendOnlyIndexVec::new();
199202
let _id = source_span.push(krate.spans.inner_span);
@@ -221,9 +224,6 @@ impl<'tcx> Queries<'tcx> {
221224
tcx.arena.alloc(rustc_expand::config::features(sess, &pre_configured_attrs)),
222225
);
223226
feed.crate_for_resolver(tcx.arena.alloc(Steal::new((krate, pre_configured_attrs))));
224-
feed.metadata_loader(
225-
tcx.arena.alloc(Steal::new(self.codegen_backend().metadata_loader())),
226-
);
227227
});
228228
Ok(qcx)
229229
})

compiler/rustc_metadata/src/creader.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ use rustc_hir::definitions::Definitions;
1515
use rustc_index::IndexVec;
1616
use rustc_middle::ty::TyCtxt;
1717
use rustc_session::config::{self, CrateType, ExternLocation};
18-
use rustc_session::cstore::ExternCrateSource;
19-
use rustc_session::cstore::{CrateDepKind, CrateSource, ExternCrate};
18+
use rustc_session::cstore::{
19+
CrateDepKind, CrateSource, ExternCrate, ExternCrateSource, MetadataLoaderDyn,
20+
};
2021
use rustc_session::lint;
2122
use rustc_session::output::validate_crate_name;
2223
use rustc_session::search_paths::PathKind;
@@ -33,6 +34,8 @@ use std::time::Duration;
3334
use std::{cmp, env, iter};
3435

3536
pub struct CStore {
37+
metadata_loader: Box<MetadataLoaderDyn>,
38+
3639
metas: IndexVec<CrateNum, Option<Box<CrateMetadata>>>,
3740
injected_panic_runtime: Option<CrateNum>,
3841
/// This crate needs an allocator and either provides it itself, or finds it in a dependency.
@@ -261,10 +264,14 @@ impl CStore {
261264
}
262265
}
263266

264-
pub fn new(local_stable_crate_id: StableCrateId) -> CStore {
267+
pub fn new(
268+
metadata_loader: Box<MetadataLoaderDyn>,
269+
local_stable_crate_id: StableCrateId,
270+
) -> CStore {
265271
let mut stable_crate_ids = StableCrateIdMap::default();
266272
stable_crate_ids.insert(local_stable_crate_id, LOCAL_CRATE);
267273
CStore {
274+
metadata_loader,
268275
// We add an empty entry for LOCAL_CRATE (which maps to zero) in
269276
// order to make array indices in `metas` match with the
270277
// corresponding `CrateNum`. This first entry will always remain
@@ -538,10 +545,9 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
538545
(LoadResult::Previous(cnum), None)
539546
} else {
540547
info!("falling back to a load");
541-
let metadata_loader = self.tcx.metadata_loader(()).borrow();
542548
let mut locator = CrateLocator::new(
543549
self.sess,
544-
&**metadata_loader,
550+
&*self.cstore.metadata_loader,
545551
name,
546552
// The all loop is because `--crate-type=rlib --crate-type=rlib` is
547553
// legal and produces both inside this type.

compiler/rustc_middle/src/arena.rs

-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ macro_rules! arena_types {
4040
rustc_data_structures::sync::Lrc<rustc_ast::Crate>,
4141
)>,
4242
[] output_filenames: std::sync::Arc<rustc_session::config::OutputFilenames>,
43-
[] metadata_loader: rustc_data_structures::steal::Steal<Box<rustc_session::cstore::MetadataLoaderDyn>>,
4443
[] crate_for_resolver: rustc_data_structures::steal::Steal<(rustc_ast::Crate, rustc_ast::AttrVec)>,
4544
[] resolutions: rustc_middle::ty::ResolverGlobalCtxt,
4645
[decode] unsafety_check_result: rustc_middle::mir::UnsafetyCheckResult,

compiler/rustc_middle/src/query/mod.rs

-6
Original file line numberDiff line numberDiff line change
@@ -2096,12 +2096,6 @@ rustc_queries! {
20962096
desc { "looking up enabled feature gates" }
20972097
}
20982098

2099-
query metadata_loader((): ()) -> &'tcx Steal<Box<rustc_session::cstore::MetadataLoaderDyn>> {
2100-
feedable
2101-
no_hash
2102-
desc { "raw operations for metadata file access" }
2103-
}
2104-
21052099
query crate_for_resolver((): ()) -> &'tcx Steal<(rustc_ast::Crate, rustc_ast::AttrVec)> {
21062100
feedable
21072101
no_hash

0 commit comments

Comments
 (0)