1
Fork 0

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`.
This commit is contained in:
Nicholas Nethercote 2023-11-28 15:48:31 +11:00
parent 3521abde39
commit 99ac405b96
6 changed files with 21 additions and 28 deletions

View file

@ -12,9 +12,9 @@ use object::{
use rustc_data_structures::memmap::Mmap; use rustc_data_structures::memmap::Mmap;
use rustc_data_structures::owned_slice::{try_slice_owned, OwnedSlice}; use rustc_data_structures::owned_slice::{try_slice_owned, OwnedSlice};
use rustc_metadata::creader::MetadataLoader;
use rustc_metadata::fs::METADATA_FILENAME; use rustc_metadata::fs::METADATA_FILENAME;
use rustc_metadata::EncodedMetadata; use rustc_metadata::EncodedMetadata;
use rustc_session::cstore::MetadataLoader;
use rustc_session::Session; use rustc_session::Session;
use rustc_span::sym; use rustc_span::sym;
use rustc_target::abi::Endian; use rustc_target::abi::Endian;

View file

@ -9,6 +9,7 @@ use rustc_ast::expand::allocator::AllocatorKind;
use rustc_data_structures::fx::FxIndexMap; use rustc_data_structures::fx::FxIndexMap;
use rustc_data_structures::sync::{DynSend, DynSync}; use rustc_data_structures::sync::{DynSend, DynSync};
use rustc_errors::ErrorGuaranteed; use rustc_errors::ErrorGuaranteed;
use rustc_metadata::creader::MetadataLoaderDyn;
use rustc_metadata::EncodedMetadata; use rustc_metadata::EncodedMetadata;
use rustc_middle::dep_graph::{WorkProduct, WorkProductId}; use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
use rustc_middle::ty::layout::{FnAbiOf, HasTyCtxt, LayoutOf, TyAndLayout}; use rustc_middle::ty::layout::{FnAbiOf, HasTyCtxt, LayoutOf, TyAndLayout};
@ -16,7 +17,6 @@ use rustc_middle::ty::{Ty, TyCtxt};
use rustc_middle::util::Providers; use rustc_middle::util::Providers;
use rustc_session::{ use rustc_session::{
config::{self, OutputFilenames, PrintRequest}, config::{self, OutputFilenames, PrintRequest},
cstore::MetadataLoaderDyn,
Session, Session,
}; };
use rustc_span::symbol::Symbol; use rustc_span::symbol::Symbol;

View file

@ -33,10 +33,10 @@ use rustc_feature::find_gated_cfg;
use rustc_interface::util::{self, collect_crate_types, get_codegen_backend}; use rustc_interface::util::{self, collect_crate_types, get_codegen_backend};
use rustc_interface::{interface, Queries}; use rustc_interface::{interface, Queries};
use rustc_lint::unerased_lint_store; use rustc_lint::unerased_lint_store;
use rustc_metadata::creader::MetadataLoader;
use rustc_metadata::locator; use rustc_metadata::locator;
use rustc_session::config::{nightly_options, CG_OPTIONS, Z_OPTIONS}; use rustc_session::config::{nightly_options, CG_OPTIONS, Z_OPTIONS};
use rustc_session::config::{ErrorOutputType, Input, OutFileName, OutputType, TrimmedDefPaths}; use rustc_session::config::{ErrorOutputType, Input, OutFileName, OutputType, TrimmedDefPaths};
use rustc_session::cstore::MetadataLoader;
use rustc_session::getopts::{self, Matches}; use rustc_session::getopts::{self, Matches};
use rustc_session::lint::{Lint, LintId}; use rustc_session::lint::{Lint, LintId};
use rustc_session::{config, EarlyErrorHandler, Session}; use rustc_session::{config, EarlyErrorHandler, Session};

View file

@ -7,8 +7,9 @@ use crate::rmeta::{CrateDep, CrateMetadata, CrateNumMap, CrateRoot, MetadataBlob
use rustc_ast::expand::allocator::{alloc_error_handler_name, global_fn_name, AllocatorKind}; use rustc_ast::expand::allocator::{alloc_error_handler_name, global_fn_name, AllocatorKind};
use rustc_ast::{self as ast, *}; use rustc_ast::{self as ast, *};
use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::owned_slice::OwnedSlice;
use rustc_data_structures::svh::Svh; use rustc_data_structures::svh::Svh;
use rustc_data_structures::sync::{FreezeReadGuard, FreezeWriteGuard}; use rustc_data_structures::sync::{self, FreezeReadGuard, FreezeWriteGuard};
use rustc_expand::base::SyntaxExtension; use rustc_expand::base::SyntaxExtension;
use rustc_fs_util::try_canonicalize; use rustc_fs_util::try_canonicalize;
use rustc_hir::def_id::{CrateNum, LocalDefId, StableCrateId, StableCrateIdMap, LOCAL_CRATE}; use rustc_hir::def_id::{CrateNum, LocalDefId, StableCrateId, StableCrateIdMap, LOCAL_CRATE};
@ -16,16 +17,14 @@ use rustc_hir::definitions::Definitions;
use rustc_index::IndexVec; use rustc_index::IndexVec;
use rustc_middle::ty::TyCtxt; use rustc_middle::ty::TyCtxt;
use rustc_session::config::{self, CrateType, ExternLocation}; use rustc_session::config::{self, CrateType, ExternLocation};
use rustc_session::cstore::{ use rustc_session::cstore::{CrateDepKind, CrateSource, ExternCrate, ExternCrateSource};
CrateDepKind, CrateSource, ExternCrate, ExternCrateSource, MetadataLoaderDyn,
};
use rustc_session::lint; use rustc_session::lint;
use rustc_session::output::validate_crate_name; use rustc_session::output::validate_crate_name;
use rustc_session::search_paths::PathKind; use rustc_session::search_paths::PathKind;
use rustc_span::edition::Edition; use rustc_span::edition::Edition;
use rustc_span::symbol::{sym, Symbol}; use rustc_span::symbol::{sym, Symbol};
use rustc_span::{Span, DUMMY_SP}; use rustc_span::{Span, DUMMY_SP};
use rustc_target::spec::{PanicStrategy, TargetTriple}; use rustc_target::spec::{PanicStrategy, Target, TargetTriple};
use proc_macro::bridge::client::ProcMacro; use proc_macro::bridge::client::ProcMacro;
use std::error::Error; use std::error::Error;
@ -34,6 +33,17 @@ use std::path::Path;
use std::time::Duration; use std::time::Duration;
use std::{cmp, iter}; use std::{cmp, iter};
/// The backend's way to give the crate store access to the metadata in a library.
/// Note that it returns the raw metadata bytes stored in the library file, whether
/// it is compressed, uncompressed, some weird mix, etc.
/// rmeta files are backend independent and not handled here.
pub trait MetadataLoader {
fn get_rlib_metadata(&self, target: &Target, filename: &Path) -> Result<OwnedSlice, String>;
fn get_dylib_metadata(&self, target: &Target, filename: &Path) -> Result<OwnedSlice, String>;
}
pub type MetadataLoaderDyn = dyn MetadataLoader + Send + Sync + sync::DynSend + sync::DynSync;
pub struct CStore { pub struct CStore {
metadata_loader: Box<MetadataLoaderDyn>, metadata_loader: Box<MetadataLoaderDyn>,

View file

@ -212,7 +212,7 @@
//! no means all of the necessary details. Take a look at the rest of //! no means all of the necessary details. Take a look at the rest of
//! metadata::locator or metadata::creader for all the juicy details! //! metadata::locator or metadata::creader for all the juicy details!
use crate::creader::Library; use crate::creader::{Library, MetadataLoader};
use crate::errors; use crate::errors;
use crate::rmeta::{rustc_version, MetadataBlob, METADATA_HEADER}; use crate::rmeta::{rustc_version, MetadataBlob, METADATA_HEADER};
@ -223,7 +223,7 @@ use rustc_data_structures::svh::Svh;
use rustc_errors::{DiagnosticArgValue, IntoDiagnosticArg}; use rustc_errors::{DiagnosticArgValue, IntoDiagnosticArg};
use rustc_fs_util::try_canonicalize; use rustc_fs_util::try_canonicalize;
use rustc_session::config; use rustc_session::config;
use rustc_session::cstore::{CrateSource, MetadataLoader}; use rustc_session::cstore::CrateSource;
use rustc_session::filesearch::FileSearch; use rustc_session::filesearch::FileSearch;
use rustc_session::search_paths::PathKind; use rustc_session::search_paths::PathKind;
use rustc_session::utils::CanonicalizedPath; use rustc_session::utils::CanonicalizedPath;

View file

@ -6,7 +6,6 @@ use crate::search_paths::PathKind;
use crate::utils::NativeLibKind; use crate::utils::NativeLibKind;
use crate::Session; use crate::Session;
use rustc_ast as ast; use rustc_ast as ast;
use rustc_data_structures::owned_slice::OwnedSlice;
use rustc_data_structures::sync::{self, AppendOnlyIndexVec, FreezeLock}; use rustc_data_structures::sync::{self, AppendOnlyIndexVec, FreezeLock};
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, StableCrateId, LOCAL_CRATE}; use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, StableCrateId, LOCAL_CRATE};
use rustc_hir::definitions::{DefKey, DefPath, DefPathHash, Definitions}; use rustc_hir::definitions::{DefKey, DefPath, DefPathHash, Definitions};
@ -14,10 +13,9 @@ use rustc_span::hygiene::{ExpnHash, ExpnId};
use rustc_span::symbol::Symbol; use rustc_span::symbol::Symbol;
use rustc_span::Span; use rustc_span::Span;
use rustc_target::spec::abi::Abi; use rustc_target::spec::abi::Abi;
use rustc_target::spec::Target;
use std::any::Any; use std::any::Any;
use std::path::{Path, PathBuf}; use std::path::PathBuf;
// lonely orphan structs and enums looking for a better home // lonely orphan structs and enums looking for a better home
@ -197,21 +195,6 @@ pub enum ExternCrateSource {
Path, Path,
} }
/// The backend's way to give the crate store access to the metadata in a library.
/// Note that it returns the raw metadata bytes stored in the library file, whether
/// it is compressed, uncompressed, some weird mix, etc.
/// rmeta files are backend independent and not handled here.
///
/// At the time of this writing, there is only one backend and one way to store
/// metadata in library -- this trait just serves to decouple rustc_metadata from
/// the archive reader, which depends on LLVM.
pub trait MetadataLoader: std::fmt::Debug {
fn get_rlib_metadata(&self, target: &Target, filename: &Path) -> Result<OwnedSlice, String>;
fn get_dylib_metadata(&self, target: &Target, filename: &Path) -> Result<OwnedSlice, String>;
}
pub type MetadataLoaderDyn = dyn MetadataLoader + Send + Sync + sync::DynSend + sync::DynSync;
/// A store of Rust crates, through which their metadata can be accessed. /// A store of Rust crates, through which their metadata can be accessed.
/// ///
/// Note that this trait should probably not be expanding today. All new /// Note that this trait should probably not be expanding today. All new