diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs index 51a8dcc9db4ad..8bb36103cd099 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder.rs @@ -55,7 +55,7 @@ mod cstore_impl; crate struct MetadataBlob(Lrc); // This is needed so we can create an OwningRef into the blob. -// The data behind a `MetadataBlob` has a stable address because it +// The data behind a `MetadataBlob` has a stable address because it is // contained within an Rc/Arc. unsafe impl rustc_data_structures::owning_ref::StableAddress for MetadataBlob {} @@ -96,7 +96,7 @@ crate struct CrateMetadata { /// Source maps for code from the crate. source_map_import_info: OnceCell>, /// For every definition in this crate, maps its `DefPathHash` to its `DefIndex`. - def_path_hash_map: DefPathHashMap<'static>, + def_path_hash_map: DefPathHashMapRef<'static>, /// Likewise for ExpnHash. expn_hash_map: OnceCell>, /// Used for decoding interpret::AllocIds in a cached & thread-safe manner. diff --git a/compiler/rustc_metadata/src/rmeta/def_path_hash_map.rs b/compiler/rustc_metadata/src/rmeta/def_path_hash_map.rs index e2095d553f535..d6435bb649d6d 100644 --- a/compiler/rustc_metadata/src/rmeta/def_path_hash_map.rs +++ b/compiler/rustc_metadata/src/rmeta/def_path_hash_map.rs @@ -2,46 +2,44 @@ use crate::rmeta::DecodeContext; use crate::rmeta::EncodeContext; use crate::rmeta::MetadataBlob; use rustc_data_structures::owning_ref::OwningRef; -use rustc_hir::def_path_hash_map::{ - Config as HashMapConfig, DefPathHashMap as DefPathHashMapInner, -}; +use rustc_hir::def_path_hash_map::{Config as HashMapConfig, DefPathHashMap}; use rustc_serialize::{opaque, Decodable, Decoder, Encodable, Encoder}; use rustc_span::def_id::{DefIndex, DefPathHash}; -crate enum DefPathHashMap<'tcx> { +crate enum DefPathHashMapRef<'tcx> { OwnedFromMetadata(odht::HashTable>), - BorrowedFromTcx(&'tcx DefPathHashMapInner), + BorrowedFromTcx(&'tcx DefPathHashMap), } -impl DefPathHashMap<'tcx> { +impl DefPathHashMapRef<'tcx> { #[inline] pub fn def_path_hash_to_def_index(&self, def_path_hash: &DefPathHash) -> DefIndex { match *self { - DefPathHashMap::OwnedFromMetadata(ref map) => map.get(def_path_hash).unwrap(), - DefPathHashMap::BorrowedFromTcx(_) => { + DefPathHashMapRef::OwnedFromMetadata(ref map) => map.get(def_path_hash).unwrap(), + DefPathHashMapRef::BorrowedFromTcx(_) => { panic!("DefPathHashMap::BorrowedFromTcx variant only exists for serialization") } } } } -impl<'a, 'tcx> Encodable> for DefPathHashMap<'tcx> { +impl<'a, 'tcx> Encodable> for DefPathHashMapRef<'tcx> { fn encode(&self, e: &mut EncodeContext<'a, 'tcx>) -> opaque::EncodeResult { match *self { - DefPathHashMap::BorrowedFromTcx(def_path_hash_map) => { + DefPathHashMapRef::BorrowedFromTcx(def_path_hash_map) => { let bytes = def_path_hash_map.raw_bytes(); e.emit_usize(bytes.len())?; e.emit_raw_bytes(bytes) } - DefPathHashMap::OwnedFromMetadata(_) => { + DefPathHashMapRef::OwnedFromMetadata(_) => { panic!("DefPathHashMap::OwnedFromMetadata variant only exists for deserialization") } } } } -impl<'a, 'tcx> Decodable> for DefPathHashMap<'static> { - fn decode(d: &mut DecodeContext<'a, 'tcx>) -> Result, String> { +impl<'a, 'tcx> Decodable> for DefPathHashMapRef<'static> { + fn decode(d: &mut DecodeContext<'a, 'tcx>) -> Result, String> { // Import TyDecoder so we can access the DecodeContext::position() method use crate::rustc_middle::ty::codec::TyDecoder; @@ -55,6 +53,6 @@ impl<'a, 'tcx> Decodable> for DefPathHashMap<'static> { let _ = d.read_raw_bytes(len); let inner = odht::HashTable::from_raw_bytes(o).map_err(|e| format!("{}", e))?; - Ok(DefPathHashMap::OwnedFromMetadata(inner)) + Ok(DefPathHashMapRef::OwnedFromMetadata(inner)) } } diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 5a901e33df945..a50c4549d3d3f 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -1,4 +1,4 @@ -use crate::rmeta::def_path_hash_map::DefPathHashMap; +use crate::rmeta::def_path_hash_map::DefPathHashMapRef; use crate::rmeta::table::{FixedSizeEncoding, TableBuilder}; use crate::rmeta::*; @@ -473,8 +473,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { } } - fn encode_def_path_hash_map(&mut self) -> Lazy> { - self.lazy(DefPathHashMap::BorrowedFromTcx( + fn encode_def_path_hash_map(&mut self) -> Lazy> { + self.lazy(DefPathHashMapRef::BorrowedFromTcx( self.tcx.resolutions(()).definitions.def_path_hash_to_def_index_map(), )) } diff --git a/compiler/rustc_metadata/src/rmeta/mod.rs b/compiler/rustc_metadata/src/rmeta/mod.rs index d47537b86ab58..eb2bd80f46e64 100644 --- a/compiler/rustc_metadata/src/rmeta/mod.rs +++ b/compiler/rustc_metadata/src/rmeta/mod.rs @@ -1,5 +1,5 @@ use decoder::Metadata; -use def_path_hash_map::DefPathHashMap; +use def_path_hash_map::DefPathHashMapRef; use table::{Table, TableBuilder}; use rustc_ast::{self as ast, MacroDef}; @@ -233,7 +233,7 @@ crate struct CrateRoot<'tcx> { expn_data: ExpnDataTable, expn_hashes: ExpnHashTable, - def_path_hash_map: Lazy>, + def_path_hash_map: Lazy>, source_map: Lazy<[rustc_span::SourceFile]>,