Allow query system to recover a HirId.
This commit is contained in:
parent
744e397d88
commit
6019cbbfd3
@ -62,7 +62,7 @@ use crate::ty::TyCtxt;
|
||||
use rustc_data_structures::fingerprint::Fingerprint;
|
||||
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId};
|
||||
use rustc_hir::definitions::DefPathHash;
|
||||
use rustc_hir::{HirId, OwnerId};
|
||||
use rustc_hir::{HirId, ItemLocalId, OwnerId};
|
||||
use rustc_query_system::dep_graph::FingerprintStyle;
|
||||
use rustc_span::symbol::Symbol;
|
||||
use std::hash::Hash;
|
||||
@ -194,7 +194,7 @@ impl DepNodeExt for DepNode {
|
||||
let kind = dep_kind_from_label_string(label)?;
|
||||
|
||||
match tcx.fingerprint_style(kind) {
|
||||
FingerprintStyle::Opaque => Err(()),
|
||||
FingerprintStyle::Opaque | FingerprintStyle::HirId => Err(()),
|
||||
FingerprintStyle::Unit => Ok(DepNode::new_no_params(tcx, kind)),
|
||||
FingerprintStyle::DefPathHash => {
|
||||
Ok(DepNode::from_def_path_hash(tcx, def_path_hash, kind))
|
||||
@ -344,7 +344,7 @@ impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for (DefId, DefId) {
|
||||
impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for HirId {
|
||||
#[inline(always)]
|
||||
fn fingerprint_style() -> FingerprintStyle {
|
||||
FingerprintStyle::Opaque
|
||||
FingerprintStyle::HirId
|
||||
}
|
||||
|
||||
// We actually would not need to specialize the implementation of this
|
||||
@ -353,10 +353,36 @@ impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for HirId {
|
||||
#[inline(always)]
|
||||
fn to_fingerprint(&self, tcx: TyCtxt<'tcx>) -> Fingerprint {
|
||||
let HirId { owner, local_id } = *self;
|
||||
|
||||
let def_path_hash = tcx.def_path_hash(owner.to_def_id());
|
||||
let local_id = Fingerprint::from_smaller_hash(local_id.as_u32().into());
|
||||
Fingerprint::new(
|
||||
// `owner` is local, so is completely defined by the local hash
|
||||
def_path_hash.local_hash(),
|
||||
local_id.as_u32().into(),
|
||||
)
|
||||
}
|
||||
|
||||
def_path_hash.0.combine(local_id)
|
||||
#[inline(always)]
|
||||
fn to_debug_str(&self, tcx: TyCtxt<'tcx>) -> String {
|
||||
let HirId { owner, local_id } = *self;
|
||||
format!("{}.{}", tcx.def_path_str(owner.to_def_id()), local_id.as_u32())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn recover(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> Option<Self> {
|
||||
if tcx.fingerprint_style(dep_node.kind) == FingerprintStyle::HirId {
|
||||
let (local_hash, local_id) = Fingerprint::from(dep_node.hash).as_value();
|
||||
let def_path_hash = DefPathHash::new(tcx.sess.local_stable_crate_id(), local_hash);
|
||||
let def_id = tcx
|
||||
.def_path_hash_to_def_id(def_path_hash, &mut || {
|
||||
panic!("Failed to extract HirId: {:?} {}", dep_node.kind, dep_node.hash)
|
||||
})
|
||||
.expect_local();
|
||||
let local_id = local_id
|
||||
.try_into()
|
||||
.unwrap_or_else(|_| panic!("local id should be u32, found {:?}", local_id));
|
||||
Some(HirId { owner: OwnerId { def_id }, local_id: ItemLocalId::from_u32(local_id) })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -94,6 +94,8 @@ impl<T: DepContext> HasDepContext for T {
|
||||
pub enum FingerprintStyle {
|
||||
/// The fingerprint is actually a DefPathHash.
|
||||
DefPathHash,
|
||||
/// The fingerprint is actually a HirId.
|
||||
HirId,
|
||||
/// Query key was `()` or equivalent, so fingerprint is just zero.
|
||||
Unit,
|
||||
/// Some opaque hash.
|
||||
@ -104,7 +106,9 @@ impl FingerprintStyle {
|
||||
#[inline]
|
||||
pub fn reconstructible(self) -> bool {
|
||||
match self {
|
||||
FingerprintStyle::DefPathHash | FingerprintStyle::Unit => true,
|
||||
FingerprintStyle::DefPathHash | FingerprintStyle::Unit | FingerprintStyle::HirId => {
|
||||
true
|
||||
}
|
||||
FingerprintStyle::Opaque => false,
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user