Skip to content

Commit 99ac405

Browse files
committed
Move MetadataLoader{,Dyn} to rustc_metadata.
They're not used in `rustc_session`, and `rustc_metadata` is a more obvious location. `MetadataLoader` was originally put into `rustc_session` in #41565 to avoid a dependency on LLVM, but things have changed a lot since then and that's no longer relevant, e.g. `rustc_codegen_llvm` depends on `rustc_metadata`.
1 parent 3521abd commit 99ac405

File tree

6 files changed

+21
-28
lines changed

6 files changed

+21
-28
lines changed

compiler/rustc_codegen_ssa/src/back/metadata.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ use object::{
1212

1313
use rustc_data_structures::memmap::Mmap;
1414
use rustc_data_structures::owned_slice::{try_slice_owned, OwnedSlice};
15+
use rustc_metadata::creader::MetadataLoader;
1516
use rustc_metadata::fs::METADATA_FILENAME;
1617
use rustc_metadata::EncodedMetadata;
17-
use rustc_session::cstore::MetadataLoader;
1818
use rustc_session::Session;
1919
use rustc_span::sym;
2020
use rustc_target::abi::Endian;

compiler/rustc_codegen_ssa/src/traits/backend.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ use rustc_ast::expand::allocator::AllocatorKind;
99
use rustc_data_structures::fx::FxIndexMap;
1010
use rustc_data_structures::sync::{DynSend, DynSync};
1111
use rustc_errors::ErrorGuaranteed;
12+
use rustc_metadata::creader::MetadataLoaderDyn;
1213
use rustc_metadata::EncodedMetadata;
1314
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
1415
use rustc_middle::ty::layout::{FnAbiOf, HasTyCtxt, LayoutOf, TyAndLayout};
1516
use rustc_middle::ty::{Ty, TyCtxt};
1617
use rustc_middle::util::Providers;
1718
use rustc_session::{
1819
config::{self, OutputFilenames, PrintRequest},
19-
cstore::MetadataLoaderDyn,
2020
Session,
2121
};
2222
use rustc_span::symbol::Symbol;

compiler/rustc_driver_impl/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ use rustc_feature::find_gated_cfg;
3333
use rustc_interface::util::{self, collect_crate_types, get_codegen_backend};
3434
use rustc_interface::{interface, Queries};
3535
use rustc_lint::unerased_lint_store;
36+
use rustc_metadata::creader::MetadataLoader;
3637
use rustc_metadata::locator;
3738
use rustc_session::config::{nightly_options, CG_OPTIONS, Z_OPTIONS};
3839
use rustc_session::config::{ErrorOutputType, Input, OutFileName, OutputType, TrimmedDefPaths};
39-
use rustc_session::cstore::MetadataLoader;
4040
use rustc_session::getopts::{self, Matches};
4141
use rustc_session::lint::{Lint, LintId};
4242
use rustc_session::{config, EarlyErrorHandler, Session};

compiler/rustc_metadata/src/creader.rs

+15-5
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,24 @@ use crate::rmeta::{CrateDep, CrateMetadata, CrateNumMap, CrateRoot, MetadataBlob
77
use rustc_ast::expand::allocator::{alloc_error_handler_name, global_fn_name, AllocatorKind};
88
use rustc_ast::{self as ast, *};
99
use rustc_data_structures::fx::FxHashSet;
10+
use rustc_data_structures::owned_slice::OwnedSlice;
1011
use rustc_data_structures::svh::Svh;
11-
use rustc_data_structures::sync::{FreezeReadGuard, FreezeWriteGuard};
12+
use rustc_data_structures::sync::{self, FreezeReadGuard, FreezeWriteGuard};
1213
use rustc_expand::base::SyntaxExtension;
1314
use rustc_fs_util::try_canonicalize;
1415
use rustc_hir::def_id::{CrateNum, LocalDefId, StableCrateId, StableCrateIdMap, LOCAL_CRATE};
1516
use rustc_hir::definitions::Definitions;
1617
use rustc_index::IndexVec;
1718
use rustc_middle::ty::TyCtxt;
1819
use rustc_session::config::{self, CrateType, ExternLocation};
19-
use rustc_session::cstore::{
20-
CrateDepKind, CrateSource, ExternCrate, ExternCrateSource, MetadataLoaderDyn,
21-
};
20+
use rustc_session::cstore::{CrateDepKind, CrateSource, ExternCrate, ExternCrateSource};
2221
use rustc_session::lint;
2322
use rustc_session::output::validate_crate_name;
2423
use rustc_session::search_paths::PathKind;
2524
use rustc_span::edition::Edition;
2625
use rustc_span::symbol::{sym, Symbol};
2726
use rustc_span::{Span, DUMMY_SP};
28-
use rustc_target::spec::{PanicStrategy, TargetTriple};
27+
use rustc_target::spec::{PanicStrategy, Target, TargetTriple};
2928

3029
use proc_macro::bridge::client::ProcMacro;
3130
use std::error::Error;
@@ -34,6 +33,17 @@ use std::path::Path;
3433
use std::time::Duration;
3534
use std::{cmp, iter};
3635

36+
/// The backend's way to give the crate store access to the metadata in a library.
37+
/// Note that it returns the raw metadata bytes stored in the library file, whether
38+
/// it is compressed, uncompressed, some weird mix, etc.
39+
/// rmeta files are backend independent and not handled here.
40+
pub trait MetadataLoader {
41+
fn get_rlib_metadata(&self, target: &Target, filename: &Path) -> Result<OwnedSlice, String>;
42+
fn get_dylib_metadata(&self, target: &Target, filename: &Path) -> Result<OwnedSlice, String>;
43+
}
44+
45+
pub type MetadataLoaderDyn = dyn MetadataLoader + Send + Sync + sync::DynSend + sync::DynSync;
46+
3747
pub struct CStore {
3848
metadata_loader: Box<MetadataLoaderDyn>,
3949

compiler/rustc_metadata/src/locator.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@
212212
//! no means all of the necessary details. Take a look at the rest of
213213
//! metadata::locator or metadata::creader for all the juicy details!
214214
215-
use crate::creader::Library;
215+
use crate::creader::{Library, MetadataLoader};
216216
use crate::errors;
217217
use crate::rmeta::{rustc_version, MetadataBlob, METADATA_HEADER};
218218

@@ -223,7 +223,7 @@ use rustc_data_structures::svh::Svh;
223223
use rustc_errors::{DiagnosticArgValue, IntoDiagnosticArg};
224224
use rustc_fs_util::try_canonicalize;
225225
use rustc_session::config;
226-
use rustc_session::cstore::{CrateSource, MetadataLoader};
226+
use rustc_session::cstore::CrateSource;
227227
use rustc_session::filesearch::FileSearch;
228228
use rustc_session::search_paths::PathKind;
229229
use rustc_session::utils::CanonicalizedPath;

compiler/rustc_session/src/cstore.rs

+1-18
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,16 @@ use crate::search_paths::PathKind;
66
use crate::utils::NativeLibKind;
77
use crate::Session;
88
use rustc_ast as ast;
9-
use rustc_data_structures::owned_slice::OwnedSlice;
109
use rustc_data_structures::sync::{self, AppendOnlyIndexVec, FreezeLock};
1110
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, StableCrateId, LOCAL_CRATE};
1211
use rustc_hir::definitions::{DefKey, DefPath, DefPathHash, Definitions};
1312
use rustc_span::hygiene::{ExpnHash, ExpnId};
1413
use rustc_span::symbol::Symbol;
1514
use rustc_span::Span;
1615
use rustc_target::spec::abi::Abi;
17-
use rustc_target::spec::Target;
1816

1917
use std::any::Any;
20-
use std::path::{Path, PathBuf};
18+
use std::path::PathBuf;
2119

2220
// lonely orphan structs and enums looking for a better home
2321

@@ -197,21 +195,6 @@ pub enum ExternCrateSource {
197195
Path,
198196
}
199197

200-
/// The backend's way to give the crate store access to the metadata in a library.
201-
/// Note that it returns the raw metadata bytes stored in the library file, whether
202-
/// it is compressed, uncompressed, some weird mix, etc.
203-
/// rmeta files are backend independent and not handled here.
204-
///
205-
/// At the time of this writing, there is only one backend and one way to store
206-
/// metadata in library -- this trait just serves to decouple rustc_metadata from
207-
/// the archive reader, which depends on LLVM.
208-
pub trait MetadataLoader: std::fmt::Debug {
209-
fn get_rlib_metadata(&self, target: &Target, filename: &Path) -> Result<OwnedSlice, String>;
210-
fn get_dylib_metadata(&self, target: &Target, filename: &Path) -> Result<OwnedSlice, String>;
211-
}
212-
213-
pub type MetadataLoaderDyn = dyn MetadataLoader + Send + Sync + sync::DynSend + sync::DynSync;
214-
215198
/// A store of Rust crates, through which their metadata can be accessed.
216199
///
217200
/// Note that this trait should probably not be expanding today. All new

0 commit comments

Comments
 (0)