Query the fingerprint style during key reconstruction
Keys can be reconstructed from fingerprints that are not DefPathHash, but then we cannot extract a DefId from them.
This commit is contained in:
parent
0eabf25b90
commit
6f78eed1c7
6 changed files with 74 additions and 48 deletions
|
@ -42,7 +42,7 @@
|
|||
//! `DefId` it was computed from. In other cases, too much information gets
|
||||
//! lost during fingerprint computation.
|
||||
|
||||
use super::{DepContext, DepKind};
|
||||
use super::{DepContext, DepKind, FingerprintStyle};
|
||||
use crate::ich::StableHashingContext;
|
||||
|
||||
use rustc_data_structures::fingerprint::{Fingerprint, PackedFingerprint};
|
||||
|
@ -75,7 +75,7 @@ impl<K: DepKind> DepNode<K> {
|
|||
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
if !kind.can_reconstruct_query_key()
|
||||
if !kind.fingerprint_style().reconstructible()
|
||||
&& (tcx.sess().opts.debugging_opts.incremental_info
|
||||
|| tcx.sess().opts.debugging_opts.query_dep_graph)
|
||||
{
|
||||
|
@ -94,7 +94,7 @@ impl<K: DepKind> fmt::Debug for DepNode<K> {
|
|||
}
|
||||
|
||||
pub trait DepNodeParams<Ctxt: DepContext>: fmt::Debug + Sized {
|
||||
fn can_reconstruct_query_key() -> bool;
|
||||
fn fingerprint_style() -> FingerprintStyle;
|
||||
|
||||
/// This method turns the parameters of a DepNodeConstructor into an opaque
|
||||
/// Fingerprint to be used in DepNode.
|
||||
|
@ -111,7 +111,7 @@ pub trait DepNodeParams<Ctxt: DepContext>: fmt::Debug + Sized {
|
|||
/// This method tries to recover the query key from the given `DepNode`,
|
||||
/// something which is needed when forcing `DepNode`s during red-green
|
||||
/// evaluation. The query system will only call this method if
|
||||
/// `can_reconstruct_query_key()` is `true`.
|
||||
/// `fingerprint_style()` is not `FingerprintStyle::Opaque`.
|
||||
/// It is always valid to return `None` here, in which case incremental
|
||||
/// compilation will treat the query as having changed instead of forcing it.
|
||||
fn recover(tcx: Ctxt, dep_node: &DepNode<Ctxt::DepKind>) -> Option<Self>;
|
||||
|
@ -122,8 +122,8 @@ where
|
|||
T: for<'a> HashStable<StableHashingContext<'a>> + fmt::Debug,
|
||||
{
|
||||
#[inline]
|
||||
default fn can_reconstruct_query_key() -> bool {
|
||||
false
|
||||
default fn fingerprint_style() -> FingerprintStyle {
|
||||
FingerprintStyle::Opaque
|
||||
}
|
||||
|
||||
default fn to_fingerprint(&self, tcx: Ctxt) -> Fingerprint {
|
||||
|
|
|
@ -50,6 +50,27 @@ impl<T: DepContext> HasDepContext for T {
|
|||
}
|
||||
}
|
||||
|
||||
/// Describes the contents of the fingerprint generated by a given query.
|
||||
#[derive(PartialEq, Eq, Copy, Clone)]
|
||||
pub enum FingerprintStyle {
|
||||
/// The fingerprint is actually a DefPathHash.
|
||||
DefPathHash,
|
||||
/// Query key was `()` or equivalent, so fingerprint is just zero.
|
||||
Unit,
|
||||
/// Some opaque hash.
|
||||
Opaque,
|
||||
}
|
||||
|
||||
impl FingerprintStyle {
|
||||
#[inline]
|
||||
pub fn reconstructible(self) -> bool {
|
||||
match self {
|
||||
FingerprintStyle::DefPathHash | FingerprintStyle::Unit => true,
|
||||
FingerprintStyle::Opaque => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Describe the different families of dependency nodes.
|
||||
pub trait DepKind: Copy + fmt::Debug + Eq + Hash + Send + Encodable<FileEncoder> + 'static {
|
||||
const NULL: Self;
|
||||
|
@ -73,5 +94,5 @@ pub trait DepKind: Copy + fmt::Debug + Eq + Hash + Send + Encodable<FileEncoder>
|
|||
where
|
||||
OP: for<'a> FnOnce(Option<&'a Lock<TaskDeps<Self>>>);
|
||||
|
||||
fn can_reconstruct_query_key(&self) -> bool;
|
||||
fn fingerprint_style(&self) -> FingerprintStyle;
|
||||
}
|
||||
|
|
|
@ -540,7 +540,7 @@ where
|
|||
// We always expect to find a cached result for things that
|
||||
// can be forced from `DepNode`.
|
||||
debug_assert!(
|
||||
!dep_node.kind.can_reconstruct_query_key() || result.is_some(),
|
||||
!dep_node.kind.fingerprint_style().reconstructible() || result.is_some(),
|
||||
"missing on-disk cache entry for {:?}",
|
||||
dep_node
|
||||
);
|
||||
|
@ -778,7 +778,7 @@ where
|
|||
return false;
|
||||
}
|
||||
|
||||
if !<Q::Key as DepNodeParams<CTX::DepContext>>::can_reconstruct_query_key() {
|
||||
if !<Q::Key as DepNodeParams<CTX::DepContext>>::fingerprint_style().reconstructible() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue