From 218caa410aa38c29984be31a5229b9fa717560ee Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:19:13 +0200 Subject: Merging upstream version 1.68.2+dfsg1. Signed-off-by: Daniel Baumann --- compiler/rustc_metadata/src/creader.rs | 81 ++++++++++++++++------------------ 1 file changed, 39 insertions(+), 42 deletions(-) (limited to 'compiler/rustc_metadata/src/creader.rs') diff --git a/compiler/rustc_metadata/src/creader.rs b/compiler/rustc_metadata/src/creader.rs index efeaac8fe..653f2b39d 100644 --- a/compiler/rustc_metadata/src/creader.rs +++ b/compiler/rustc_metadata/src/creader.rs @@ -1,10 +1,9 @@ //! Validates all used crates and extern libraries and loads their metadata use crate::errors::{ - AllocFuncRequired, ConflictingAllocErrorHandler, ConflictingGlobalAlloc, CrateNotPanicRuntime, - GlobalAllocRequired, MissingAllocErrorHandler, NoMultipleAllocErrorHandler, - NoMultipleGlobalAlloc, NoPanicStrategy, NoTransitiveNeedsDep, NotProfilerRuntime, - ProfilerBuiltinsNeedsCore, + ConflictingAllocErrorHandler, ConflictingGlobalAlloc, CrateNotPanicRuntime, + GlobalAllocRequired, NoMultipleAllocErrorHandler, NoMultipleGlobalAlloc, NoPanicStrategy, + NoTransitiveNeedsDep, NotProfilerRuntime, ProfilerBuiltinsNeedsCore, }; use crate::locator::{CrateError, CrateLocator, CratePaths}; use crate::rmeta::{CrateDep, CrateMetadata, CrateNumMap, CrateRoot, MetadataBlob}; @@ -13,7 +12,7 @@ use rustc_ast::expand::allocator::AllocatorKind; use rustc_ast::{self as ast, *}; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::svh::Svh; -use rustc_data_structures::sync::Lrc; +use rustc_data_structures::sync::{Lrc, ReadGuard}; use rustc_expand::base::SyntaxExtension; use rustc_hir::def_id::{CrateNum, LocalDefId, StableCrateId, LOCAL_CRATE}; use rustc_hir::definitions::Definitions; @@ -68,11 +67,12 @@ impl std::fmt::Debug for CStore { pub struct CrateLoader<'a> { // Immutable configuration. sess: &'a Session, - metadata_loader: Box, + metadata_loader: &'a MetadataLoaderDyn, + definitions: ReadGuard<'a, Definitions>, local_crate_name: Symbol, // Mutable output. - cstore: CStore, - used_extern_options: FxHashSet, + cstore: &'a mut CStore, + used_extern_options: &'a mut FxHashSet, } pub enum LoadedMacro { @@ -112,7 +112,7 @@ impl<'a> std::fmt::Debug for CrateDump<'a> { writeln!(fmt, "resolved crates:")?; for (cnum, data) in self.0.iter_crate_data() { writeln!(fmt, " name: {}", data.name())?; - writeln!(fmt, " cnum: {}", cnum)?; + writeln!(fmt, " cnum: {cnum}")?; writeln!(fmt, " hash: {}", data.hash())?; writeln!(fmt, " reqd: {:?}", data.dep_kind())?; let CrateSource { dylib, rlib, rmeta } = data.source(); @@ -150,7 +150,7 @@ impl CStore { pub(crate) fn get_crate_data(&self, cnum: CrateNum) -> CrateMetadataRef<'_> { let cdata = self.metas[cnum] .as_ref() - .unwrap_or_else(|| panic!("Failed to get crate data for {:?}", cnum)); + .unwrap_or_else(|| panic!("Failed to get crate data for {cnum:?}")); CrateMetadataRef { cdata, cstore: self } } @@ -239,47 +239,49 @@ impl CStore { ); } } + + pub fn new(sess: &Session) -> CStore { + let mut stable_crate_ids = FxHashMap::default(); + stable_crate_ids.insert(sess.local_stable_crate_id(), LOCAL_CRATE); + CStore { + // We add an empty entry for LOCAL_CRATE (which maps to zero) in + // order to make array indices in `metas` match with the + // corresponding `CrateNum`. This first entry will always remain + // `None`. + metas: IndexVec::from_elem_n(None, 1), + injected_panic_runtime: None, + allocator_kind: None, + alloc_error_handler_kind: None, + has_global_allocator: false, + has_alloc_error_handler: false, + stable_crate_ids, + unused_externs: Vec::new(), + } + } } impl<'a> CrateLoader<'a> { pub fn new( sess: &'a Session, - metadata_loader: Box, + metadata_loader: &'a MetadataLoaderDyn, local_crate_name: Symbol, + cstore: &'a mut CStore, + definitions: ReadGuard<'a, Definitions>, + used_extern_options: &'a mut FxHashSet, ) -> Self { - let mut stable_crate_ids = FxHashMap::default(); - stable_crate_ids.insert(sess.local_stable_crate_id(), LOCAL_CRATE); - CrateLoader { sess, metadata_loader, local_crate_name, - cstore: CStore { - // We add an empty entry for LOCAL_CRATE (which maps to zero) in - // order to make array indices in `metas` match with the - // corresponding `CrateNum`. This first entry will always remain - // `None`. - metas: IndexVec::from_elem_n(None, 1), - injected_panic_runtime: None, - allocator_kind: None, - alloc_error_handler_kind: None, - has_global_allocator: false, - has_alloc_error_handler: false, - stable_crate_ids, - unused_externs: Vec::new(), - }, - used_extern_options: Default::default(), + cstore, + used_extern_options, + definitions, } } - pub fn cstore(&self) -> &CStore { &self.cstore } - pub fn into_cstore(self) -> CStore { - self.cstore - } - fn existing_match(&self, name: Symbol, hash: Option, kind: PathKind) -> Option { for (cnum, data) in self.cstore.iter_crate_data() { if data.name() != name { @@ -518,8 +520,8 @@ impl<'a> CrateLoader<'a> { })) } - fn resolve_crate<'b>( - &'b mut self, + fn resolve_crate( + &mut self, name: Symbol, span: Span, dep_kind: CrateDepKind, @@ -892,10 +894,6 @@ impl<'a> CrateLoader<'a> { } else { // The alloc crate provides a default allocation error handler if // one isn't specified. - if !self.sess.features_untracked().default_alloc_error_handler { - self.sess.emit_err(AllocFuncRequired); - self.sess.emit_note(MissingAllocErrorHandler); - } self.cstore.alloc_error_handler_kind = Some(AllocatorKind::Default); } } @@ -989,7 +987,6 @@ impl<'a> CrateLoader<'a> { pub fn process_extern_crate( &mut self, item: &ast::Item, - definitions: &Definitions, def_id: LocalDefId, ) -> Option { match item.kind { @@ -1013,7 +1010,7 @@ impl<'a> CrateLoader<'a> { let cnum = self.resolve_crate(name, item.span, dep_kind)?; - let path_len = definitions.def_path(def_id).data.len(); + let path_len = self.definitions.def_path(def_id).data.len(); self.update_extern_crate( cnum, ExternCrate { -- cgit v1.2.3