Skip to content

Commit

Permalink
Rename DefPathHashMap in rustc_metadata so its name does not clash wi…
Browse files Browse the repository at this point in the history
…th DefPathHashMap in rustc_hir.
michaelwoerister committed Sep 14, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 021c052 commit 5f73085
Showing 4 changed files with 19 additions and 21 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_metadata/src/rmeta/decoder.rs
Original file line number Diff line number Diff line change
@@ -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.
26 changes: 12 additions & 14 deletions compiler/rustc_metadata/src/rmeta/def_path_hash_map.rs
Original file line number Diff line number Diff line change
@@ -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))
}
}
6 changes: 3 additions & 3 deletions compiler/rustc_metadata/src/rmeta/encoder.rs
Original file line number Diff line number Diff line change
@@ -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(),
))
}
4 changes: 2 additions & 2 deletions compiler/rustc_metadata/src/rmeta/mod.rs
Original file line number Diff line number Diff line change
@@ -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]>,

0 comments on commit 5f73085

Please sign in to comment.