Remove MetadataRef type alias

This commit is contained in:
Maybe Waffle 2023-04-10 15:30:11 +00:00
parent 086c08d86a
commit e39d61cbf3
5 changed files with 12 additions and 18 deletions

View File

@ -14,8 +14,7 @@
use object::elf::NT_GNU_PROPERTY_TYPE_0; use object::elf::NT_GNU_PROPERTY_TYPE_0;
use rustc_data_structures::memmap::Mmap; use rustc_data_structures::memmap::Mmap;
use rustc_data_structures::owned_slice::try_slice_owned; use rustc_data_structures::owned_slice::{try_slice_owned, OwnedSlice};
use rustc_data_structures::sync::MetadataRef;
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::cstore::MetadataLoader;
@ -39,7 +38,7 @@
fn load_metadata_with( fn load_metadata_with(
path: &Path, path: &Path,
f: impl for<'a> FnOnce(&'a [u8]) -> Result<&'a [u8], String>, f: impl for<'a> FnOnce(&'a [u8]) -> Result<&'a [u8], String>,
) -> Result<MetadataRef, String> { ) -> Result<OwnedSlice, String> {
let file = let file =
File::open(path).map_err(|e| format!("failed to open file '{}': {}", path.display(), e))?; File::open(path).map_err(|e| format!("failed to open file '{}': {}", path.display(), e))?;
@ -49,7 +48,7 @@ fn load_metadata_with(
} }
impl MetadataLoader for DefaultMetadataLoader { impl MetadataLoader for DefaultMetadataLoader {
fn get_rlib_metadata(&self, _target: &Target, path: &Path) -> Result<MetadataRef, String> { fn get_rlib_metadata(&self, _target: &Target, path: &Path) -> Result<OwnedSlice, String> {
load_metadata_with(path, |data| { load_metadata_with(path, |data| {
let archive = object::read::archive::ArchiveFile::parse(&*data) let archive = object::read::archive::ArchiveFile::parse(&*data)
.map_err(|e| format!("failed to parse rlib '{}': {}", path.display(), e))?; .map_err(|e| format!("failed to parse rlib '{}': {}", path.display(), e))?;
@ -69,7 +68,7 @@ fn get_rlib_metadata(&self, _target: &Target, path: &Path) -> Result<MetadataRef
}) })
} }
fn get_dylib_metadata(&self, _target: &Target, path: &Path) -> Result<MetadataRef, String> { fn get_dylib_metadata(&self, _target: &Target, path: &Path) -> Result<OwnedSlice, String> {
load_metadata_with(path, |data| search_for_section(path, data, ".rustc")) load_metadata_with(path, |data| search_for_section(path, data, ".rustc"))
} }
} }

View File

@ -1,3 +1,5 @@
use std::any::Any;
use super::write::WriteBackendMethods; use super::write::WriteBackendMethods;
use super::CodegenObject; use super::CodegenObject;
use crate::back::write::TargetMachineFactoryFn; use crate::back::write::TargetMachineFactoryFn;
@ -5,6 +7,7 @@
use rustc_ast::expand::allocator::AllocatorKind; use rustc_ast::expand::allocator::AllocatorKind;
use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::sync::{DynSend, DynSync};
use rustc_errors::ErrorGuaranteed; use rustc_errors::ErrorGuaranteed;
use rustc_metadata::EncodedMetadata; use rustc_metadata::EncodedMetadata;
use rustc_middle::dep_graph::{WorkProduct, WorkProductId}; use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
@ -20,11 +23,6 @@
use rustc_target::abi::call::FnAbi; use rustc_target::abi::call::FnAbi;
use rustc_target::spec::Target; use rustc_target::spec::Target;
pub use rustc_data_structures::sync::MetadataRef;
use rustc_data_structures::sync::{DynSend, DynSync};
use std::any::Any;
pub trait BackendTypes { pub trait BackendTypes {
type Value: CodegenObject; type Value: CodegenObject;
type Function: CodegenObject; type Function: CodegenObject;

View File

@ -40,7 +40,6 @@
//! [^2] `MTLockRef` is a typedef. //! [^2] `MTLockRef` is a typedef.
pub use crate::marker::*; pub use crate::marker::*;
use crate::owned_slice::OwnedSlice;
use std::collections::HashMap; use std::collections::HashMap;
use std::hash::{BuildHasher, Hash}; use std::hash::{BuildHasher, Hash};
use std::ops::{Deref, DerefMut}; use std::ops::{Deref, DerefMut};
@ -93,8 +92,6 @@ pub fn set_dyn_thread_safe_mode(mode: bool) {
pub use mode::{is_dyn_thread_safe, set_dyn_thread_safe_mode}; pub use mode::{is_dyn_thread_safe, set_dyn_thread_safe_mode};
pub type MetadataRef = OwnedSlice;
cfg_if! { cfg_if! {
if #[cfg(not(parallel_compiler))] { if #[cfg(not(parallel_compiler))] {
pub unsafe auto trait Send {} pub unsafe auto trait Send {}

View File

@ -220,7 +220,6 @@
use rustc_data_structures::memmap::Mmap; use rustc_data_structures::memmap::Mmap;
use rustc_data_structures::owned_slice::slice_owned; use rustc_data_structures::owned_slice::slice_owned;
use rustc_data_structures::svh::Svh; use rustc_data_structures::svh::Svh;
use rustc_data_structures::sync::MetadataRef;
use rustc_errors::{DiagnosticArgValue, FatalError, IntoDiagnosticArg}; use rustc_errors::{DiagnosticArgValue, FatalError, IntoDiagnosticArg};
use rustc_fs_util::try_canonicalize; use rustc_fs_util::try_canonicalize;
use rustc_session::config::{self, CrateType}; use rustc_session::config::{self, CrateType};
@ -782,7 +781,7 @@ fn get_metadata_section<'p>(
if !filename.exists() { if !filename.exists() {
return Err(MetadataError::NotPresent(filename)); return Err(MetadataError::NotPresent(filename));
} }
let raw_bytes: MetadataRef = match flavor { let raw_bytes = match flavor {
CrateFlavor::Rlib => { CrateFlavor::Rlib => {
loader.get_rlib_metadata(target, filename).map_err(MetadataError::LoadFailure)? loader.get_rlib_metadata(target, filename).map_err(MetadataError::LoadFailure)?
} }

View File

@ -6,7 +6,8 @@
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::sync::{self, AppendOnlyIndexVec, MetadataRef, RwLock}; use rustc_data_structures::owned_slice::OwnedSlice;
use rustc_data_structures::sync::{self, AppendOnlyIndexVec, RwLock};
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};
use rustc_span::hygiene::{ExpnHash, ExpnId}; use rustc_span::hygiene::{ExpnHash, ExpnId};
@ -203,8 +204,8 @@ pub enum ExternCrateSource {
/// metadata in library -- this trait just serves to decouple rustc_metadata from /// metadata in library -- this trait just serves to decouple rustc_metadata from
/// the archive reader, which depends on LLVM. /// the archive reader, which depends on LLVM.
pub trait MetadataLoader: std::fmt::Debug { pub trait MetadataLoader: std::fmt::Debug {
fn get_rlib_metadata(&self, target: &Target, filename: &Path) -> Result<MetadataRef, String>; fn get_rlib_metadata(&self, target: &Target, filename: &Path) -> Result<OwnedSlice, String>;
fn get_dylib_metadata(&self, target: &Target, filename: &Path) -> Result<MetadataRef, 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 type MetadataLoaderDyn = dyn MetadataLoader + Send + Sync + sync::DynSend + sync::DynSync;