Rename DefPathHashMap in rustc_metadata so its name does not clash with DefPathHashMap in rustc_hir.

This commit is contained in:
Michael Woerister 2021-08-18 18:29:11 +02:00
parent 021c0520e3
commit 5f73085f92
4 changed files with 19 additions and 21 deletions

View File

@ -55,7 +55,7 @@ mod cstore_impl;
crate struct MetadataBlob(Lrc<MetadataRef>);
// 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<Vec<ImportedSourceFile>>,
/// 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<UnhashMap<ExpnHash, ExpnIndex>>,
/// Used for decoding interpret::AllocIds in a cached & thread-safe manner.

View File

@ -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<HashMapConfig, OwningRef<MetadataBlob, [u8]>>),
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<EncodeContext<'a, 'tcx>> for DefPathHashMap<'tcx> {
impl<'a, 'tcx> Encodable<EncodeContext<'a, 'tcx>> 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<DecodeContext<'a, 'tcx>> for DefPathHashMap<'static> {
fn decode(d: &mut DecodeContext<'a, 'tcx>) -> Result<DefPathHashMap<'static>, String> {
impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for DefPathHashMapRef<'static> {
fn decode(d: &mut DecodeContext<'a, 'tcx>) -> Result<DefPathHashMapRef<'static>, 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<DecodeContext<'a, 'tcx>> 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))
}
}

View File

@ -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<DefPathHashMap<'tcx>> {
self.lazy(DefPathHashMap::BorrowedFromTcx(
fn encode_def_path_hash_map(&mut self) -> Lazy<DefPathHashMapRef<'tcx>> {
self.lazy(DefPathHashMapRef::BorrowedFromTcx(
self.tcx.resolutions(()).definitions.def_path_hash_to_def_index_map(),
))
}

View File

@ -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<DefPathHashMap<'tcx>>,
def_path_hash_map: Lazy<DefPathHashMapRef<'tcx>>,
source_map: Lazy<[rustc_span::SourceFile]>,