2021-01-17 19:16:17 +00:00
|
|
|
//! Nodes in the dependency graph.
|
2020-07-15 05:34:25 +00:00
|
|
|
//!
|
2021-01-17 19:16:17 +00:00
|
|
|
//! A node in the [dependency graph] is represented by a [`DepNode`].
|
|
|
|
//! A `DepNode` consists of a [`DepKind`] (which
|
|
|
|
//! specifies the kind of thing it represents, like a piece of HIR, MIR, etc.)
|
|
|
|
//! and a [`Fingerprint`], a 128-bit hash value, the exact meaning of which
|
2017-06-09 15:58:49 +00:00
|
|
|
//! depends on the node's `DepKind`. Together, the kind and the fingerprint
|
|
|
|
//! fully identify a dependency node, even across multiple compilation sessions.
|
|
|
|
//! In other words, the value of the fingerprint does not depend on anything
|
|
|
|
//! that is specific to a given compilation session, like an unpredictable
|
2021-01-17 19:16:17 +00:00
|
|
|
//! interning key (e.g., `NodeId`, `DefId`, `Symbol`) or the numeric value of a
|
2017-06-09 15:58:49 +00:00
|
|
|
//! pointer. The concept behind this could be compared to how git commit hashes
|
2021-01-17 19:16:17 +00:00
|
|
|
//! uniquely identify a given commit. The fingerprinting approach has
|
|
|
|
//! a few advantages:
|
2017-06-09 15:58:49 +00:00
|
|
|
//!
|
|
|
|
//! * A `DepNode` can simply be serialized to disk and loaded in another session
|
2020-07-15 05:34:25 +00:00
|
|
|
//! without the need to do any "rebasing" (like we have to do for Spans and
|
|
|
|
//! NodeIds) or "retracing" (like we had to do for `DefId` in earlier
|
|
|
|
//! implementations of the dependency graph).
|
2017-06-09 15:58:49 +00:00
|
|
|
//! * A `Fingerprint` is just a bunch of bits, which allows `DepNode` to
|
|
|
|
//! implement `Copy`, `Sync`, `Send`, `Freeze`, etc.
|
|
|
|
//! * Since we just have a bit pattern, `DepNode` can be mapped from disk into
|
2018-11-27 02:59:49 +00:00
|
|
|
//! memory without any post-processing (e.g., "abomination-style" pointer
|
2017-06-09 15:58:49 +00:00
|
|
|
//! reconstruction).
|
|
|
|
//! * Because a `DepNode` is self-contained, we can instantiate `DepNodes` that
|
|
|
|
//! refer to things that do not exist anymore. In previous implementations
|
|
|
|
//! `DepNode` contained a `DefId`. A `DepNode` referring to something that
|
|
|
|
//! had been removed between the previous and the current compilation session
|
|
|
|
//! could not be instantiated because the current compilation session
|
|
|
|
//! contained no `DefId` for thing that had been removed.
|
|
|
|
//!
|
|
|
|
//! `DepNode` definition happens in the `define_dep_nodes!()` macro. This macro
|
2021-01-08 23:00:25 +00:00
|
|
|
//! defines the `DepKind` enum. Each `DepKind` has its own parameters that are
|
|
|
|
//! needed at runtime in order to construct a valid `DepNode` fingerprint.
|
2021-04-12 11:58:12 +00:00
|
|
|
//! However, only `CompileCodegenUnit` and `CompileMonoItem` are constructed
|
|
|
|
//! explicitly (with `make_compile_codegen_unit` cq `make_compile_mono_item`).
|
2017-06-09 15:58:49 +00:00
|
|
|
//!
|
|
|
|
//! Because the macro sees what parameters a given `DepKind` requires, it can
|
|
|
|
//! "infer" some properties for each kind of `DepNode`:
|
|
|
|
//!
|
|
|
|
//! * Whether a `DepNode` of a given kind has any parameters at all. Some
|
2020-02-08 03:26:12 +00:00
|
|
|
//! `DepNode`s could represent global concepts with only one value.
|
2017-06-09 15:58:49 +00:00
|
|
|
//! * Whether it is possible, in principle, to reconstruct a query key from a
|
|
|
|
//! given `DepNode`. Many `DepKind`s only require a single `DefId` parameter,
|
|
|
|
//! in which case it is possible to map the node's fingerprint back to the
|
|
|
|
//! `DefId` it was computed from. In other cases, too much information gets
|
|
|
|
//! lost during fingerprint computation.
|
|
|
|
//!
|
2021-04-12 11:58:12 +00:00
|
|
|
//! `make_compile_codegen_unit` and `make_compile_mono_items`, together with
|
|
|
|
//! `DepNode::new()`, ensures that only valid `DepNode` instances can be
|
|
|
|
//! constructed. For example, the API does not allow for constructing
|
|
|
|
//! parameterless `DepNode`s with anything other than a zeroed out fingerprint.
|
|
|
|
//! More generally speaking, it relieves the user of the `DepNode` API of
|
|
|
|
//! having to know how to compute the expected fingerprint for a given set of
|
|
|
|
//! node parameters.
|
2021-01-17 19:16:17 +00:00
|
|
|
//!
|
|
|
|
//! [dependency graph]: https://rustc-dev-guide.rust-lang.org/query.html
|
2017-06-09 15:58:49 +00:00
|
|
|
|
2021-04-12 11:58:12 +00:00
|
|
|
use crate::mir::mono::MonoItem;
|
2021-01-08 23:00:25 +00:00
|
|
|
use crate::ty::TyCtxt;
|
2020-01-05 01:37:57 +00:00
|
|
|
|
2020-11-18 23:10:43 +00:00
|
|
|
use rustc_data_structures::fingerprint::Fingerprint;
|
2022-04-15 17:27:53 +00:00
|
|
|
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId};
|
2020-03-24 08:09:42 +00:00
|
|
|
use rustc_hir::definitions::DefPathHash;
|
2020-01-05 01:37:57 +00:00
|
|
|
use rustc_hir::HirId;
|
2021-10-02 16:06:42 +00:00
|
|
|
use rustc_query_system::dep_graph::FingerprintStyle;
|
2019-12-31 17:15:40 +00:00
|
|
|
use rustc_span::symbol::Symbol;
|
2017-06-06 13:09:21 +00:00
|
|
|
use std::hash::Hash;
|
2016-03-28 21:37:34 +00:00
|
|
|
|
2020-03-18 09:32:58 +00:00
|
|
|
pub use rustc_query_system::dep_graph::{DepContext, DepNodeParams};
|
|
|
|
|
2020-10-27 17:36:11 +00:00
|
|
|
/// This struct stores metadata about each DepKind.
|
|
|
|
///
|
|
|
|
/// Information is retrieved by indexing the `DEP_KINDS` array using the integer value
|
|
|
|
/// of the `DepKind`. Overall, this allows to implement `DepContext` using this manual
|
|
|
|
/// jump table instead of large matches.
|
2020-11-20 18:35:17 +00:00
|
|
|
pub struct DepKindStruct {
|
|
|
|
/// Anonymous queries cannot be replayed from one compiler invocation to the next.
|
|
|
|
/// When their result is needed, it is recomputed. They are useful for fine-grained
|
|
|
|
/// dependency tracking, and caching within one compiler invocation.
|
2021-10-16 18:10:23 +00:00
|
|
|
pub is_anon: bool,
|
2020-10-27 17:43:49 +00:00
|
|
|
|
|
|
|
/// Eval-always queries do not track their dependencies, and are always recomputed, even if
|
|
|
|
/// their inputs have not changed since the last compiler invocation. The result is still
|
|
|
|
/// cached within one compiler invocation.
|
2021-10-16 18:10:23 +00:00
|
|
|
pub is_eval_always: bool,
|
2020-10-27 18:49:10 +00:00
|
|
|
|
|
|
|
/// Whether the query key can be recovered from the hashed fingerprint.
|
|
|
|
/// See [DepNodeParams] trait for the behaviour of each key type.
|
2021-10-16 19:12:34 +00:00
|
|
|
pub fingerprint_style: FingerprintStyle,
|
2021-10-16 18:10:23 +00:00
|
|
|
|
|
|
|
/// The red/green evaluation system will try to mark a specific DepNode in the
|
|
|
|
/// dependency graph as green by recursively trying to mark the dependencies of
|
|
|
|
/// that `DepNode` as green. While doing so, it will sometimes encounter a `DepNode`
|
|
|
|
/// where we don't know if it is red or green and we therefore actually have
|
|
|
|
/// to recompute its value in order to find out. Since the only piece of
|
|
|
|
/// information that we have at that point is the `DepNode` we are trying to
|
|
|
|
/// re-evaluate, we need some way to re-run a query from just that. This is what
|
|
|
|
/// `force_from_dep_node()` implements.
|
|
|
|
///
|
|
|
|
/// In the general case, a `DepNode` consists of a `DepKind` and an opaque
|
|
|
|
/// GUID/fingerprint that will uniquely identify the node. This GUID/fingerprint
|
|
|
|
/// is usually constructed by computing a stable hash of the query-key that the
|
|
|
|
/// `DepNode` corresponds to. Consequently, it is not in general possible to go
|
|
|
|
/// back from hash to query-key (since hash functions are not reversible). For
|
|
|
|
/// this reason `force_from_dep_node()` is expected to fail from time to time
|
|
|
|
/// because we just cannot find out, from the `DepNode` alone, what the
|
|
|
|
/// corresponding query-key is and therefore cannot re-run the query.
|
|
|
|
///
|
|
|
|
/// The system deals with this case letting `try_mark_green` fail which forces
|
|
|
|
/// the root query to be re-evaluated.
|
|
|
|
///
|
|
|
|
/// Now, if `force_from_dep_node()` would always fail, it would be pretty useless.
|
|
|
|
/// Fortunately, we can use some contextual information that will allow us to
|
|
|
|
/// reconstruct query-keys for certain kinds of `DepNode`s. In particular, we
|
|
|
|
/// enforce by construction that the GUID/fingerprint of certain `DepNode`s is a
|
|
|
|
/// valid `DefPathHash`. Since we also always build a huge table that maps every
|
|
|
|
/// `DefPathHash` in the current codebase to the corresponding `DefId`, we have
|
|
|
|
/// everything we need to re-run the query.
|
|
|
|
///
|
|
|
|
/// Take the `mir_promoted` query as an example. Like many other queries, it
|
|
|
|
/// just has a single parameter: the `DefId` of the item it will compute the
|
|
|
|
/// validated MIR for. Now, when we call `force_from_dep_node()` on a `DepNode`
|
|
|
|
/// with kind `MirValidated`, we know that the GUID/fingerprint of the `DepNode`
|
|
|
|
/// is actually a `DefPathHash`, and can therefore just look up the corresponding
|
|
|
|
/// `DefId` in `tcx.def_path_hash_to_def_id`.
|
2021-10-16 19:12:34 +00:00
|
|
|
pub force_from_dep_node: Option<fn(tcx: TyCtxt<'_>, dep_node: DepNode) -> bool>,
|
2021-10-16 18:10:23 +00:00
|
|
|
|
|
|
|
/// Invoke a query to put the on-disk cached value in memory.
|
2021-10-16 19:12:34 +00:00
|
|
|
pub try_load_from_on_disk_cache: Option<fn(TyCtxt<'_>, DepNode)>,
|
2020-10-27 17:36:11 +00:00
|
|
|
}
|
|
|
|
|
2020-10-27 18:49:10 +00:00
|
|
|
impl DepKind {
|
|
|
|
#[inline(always)]
|
2021-10-16 18:10:23 +00:00
|
|
|
pub fn fingerprint_style(self, tcx: TyCtxt<'_>) -> FingerprintStyle {
|
2020-10-27 18:49:10 +00:00
|
|
|
// Only fetch the DepKindStruct once.
|
2021-10-16 18:10:23 +00:00
|
|
|
let data = tcx.query_kind(self);
|
2020-10-27 18:49:10 +00:00
|
|
|
if data.is_anon {
|
2021-10-02 16:06:42 +00:00
|
|
|
return FingerprintStyle::Opaque;
|
2020-10-27 18:49:10 +00:00
|
|
|
}
|
2021-10-16 19:12:34 +00:00
|
|
|
data.fingerprint_style
|
2020-10-27 18:49:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-02 15:36:30 +00:00
|
|
|
macro_rules! define_dep_nodes {
|
2017-06-30 21:53:35 +00:00
|
|
|
(<$tcx:tt>
|
|
|
|
$(
|
2020-02-14 17:29:20 +00:00
|
|
|
[$($attrs:tt)*]
|
2019-02-24 12:59:44 +00:00
|
|
|
$variant:ident $(( $tuple_arg_ty:ty $(,)? ))*
|
2017-06-16 05:25:41 +00:00
|
|
|
,)*
|
2017-06-02 15:36:30 +00:00
|
|
|
) => (
|
2021-01-19 18:07:06 +00:00
|
|
|
#[macro_export]
|
|
|
|
macro_rules! make_dep_kind_array {
|
2021-10-16 19:12:34 +00:00
|
|
|
($mod:ident) => {[ $($mod::$variant()),* ]};
|
2021-01-19 18:07:06 +00:00
|
|
|
}
|
|
|
|
|
2021-10-16 18:10:23 +00:00
|
|
|
/// This enum serves as an index into arrays built by `make_dep_kind_array`.
|
2020-10-27 17:36:11 +00:00
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Encodable, Decodable)]
|
2019-11-13 12:01:43 +00:00
|
|
|
#[allow(non_camel_case_types)]
|
2017-06-02 15:36:30 +00:00
|
|
|
pub enum DepKind {
|
|
|
|
$($variant),*
|
|
|
|
}
|
|
|
|
|
2020-10-24 15:37:26 +00:00
|
|
|
fn dep_kind_from_label_string(label: &str) -> Result<DepKind, ()> {
|
|
|
|
match label {
|
|
|
|
$(stringify!($variant) => Ok(DepKind::$variant),)*
|
|
|
|
_ => Err(()),
|
2017-10-02 07:08:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Contains variant => str representations for constructing
|
|
|
|
/// DepNode groups for tests.
|
|
|
|
#[allow(dead_code, non_upper_case_globals)]
|
|
|
|
pub mod label_strs {
|
|
|
|
$(
|
2018-12-04 11:46:10 +00:00
|
|
|
pub const $variant: &str = stringify!($variant);
|
2017-10-02 07:08:13 +00:00
|
|
|
)*
|
2016-05-26 10:11:16 +00:00
|
|
|
}
|
2017-06-02 15:36:30 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-12-03 00:14:35 +00:00
|
|
|
rustc_dep_node_append!([define_dep_nodes!][ <'tcx>
|
2018-02-14 15:11:02 +00:00
|
|
|
// We use this for most things when incr. comp. is turned off.
|
|
|
|
[] Null,
|
|
|
|
|
2017-07-10 21:10:30 +00:00
|
|
|
[anon] TraitSelect,
|
2017-06-02 15:36:30 +00:00
|
|
|
|
2021-01-08 23:00:25 +00:00
|
|
|
// WARNING: if `Symbol` is changed, make sure you update `make_compile_codegen_unit` below.
|
2019-10-21 06:14:03 +00:00
|
|
|
[] CompileCodegenUnit(Symbol),
|
2021-04-12 11:58:12 +00:00
|
|
|
|
|
|
|
// WARNING: if `MonoItem` is changed, make sure you update `make_compile_mono_item` below.
|
|
|
|
// Only used by rustc_codegen_cranelift
|
|
|
|
[] CompileMonoItem(MonoItem),
|
2018-12-03 00:14:35 +00:00
|
|
|
]);
|
|
|
|
|
2021-01-08 23:00:25 +00:00
|
|
|
// WARNING: `construct` is generic and does not know that `CompileCodegenUnit` takes `Symbol`s as keys.
|
|
|
|
// Be very careful changing this type signature!
|
|
|
|
crate fn make_compile_codegen_unit(tcx: TyCtxt<'_>, name: Symbol) -> DepNode {
|
|
|
|
DepNode::construct(tcx, DepKind::CompileCodegenUnit, &name)
|
|
|
|
}
|
|
|
|
|
2021-04-12 11:58:12 +00:00
|
|
|
// WARNING: `construct` is generic and does not know that `CompileMonoItem` takes `MonoItem`s as keys.
|
|
|
|
// Be very careful changing this type signature!
|
2021-12-16 00:32:30 +00:00
|
|
|
crate fn make_compile_mono_item<'tcx>(tcx: TyCtxt<'tcx>, mono_item: &MonoItem<'tcx>) -> DepNode {
|
2021-04-12 11:58:12 +00:00
|
|
|
DepNode::construct(tcx, DepKind::CompileMonoItem, mono_item)
|
|
|
|
}
|
|
|
|
|
2020-10-24 15:37:26 +00:00
|
|
|
pub type DepNode = rustc_query_system::dep_graph::DepNode<DepKind>;
|
|
|
|
|
|
|
|
// We keep a lot of `DepNode`s in memory during compilation. It's not
|
|
|
|
// required that their size stay the same, but we don't want to change
|
|
|
|
// it inadvertently. This assert just ensures we're aware of any change.
|
|
|
|
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
|
2021-06-04 17:54:28 +00:00
|
|
|
static_assert_size!(DepNode, 18);
|
2020-10-24 15:37:26 +00:00
|
|
|
|
|
|
|
#[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
|
|
|
|
static_assert_size!(DepNode, 24);
|
|
|
|
|
|
|
|
pub trait DepNodeExt: Sized {
|
|
|
|
/// Construct a DepNode from the given DepKind and DefPathHash. This
|
|
|
|
/// method will assert that the given DepKind actually requires a
|
|
|
|
/// single DefId/DefPathHash parameter.
|
2021-10-16 18:10:23 +00:00
|
|
|
fn from_def_path_hash(tcx: TyCtxt<'_>, def_path_hash: DefPathHash, kind: DepKind) -> Self;
|
2020-10-24 15:37:26 +00:00
|
|
|
|
|
|
|
/// Extracts the DefId corresponding to this DepNode. This will work
|
|
|
|
/// if two conditions are met:
|
|
|
|
///
|
|
|
|
/// 1. The Fingerprint of the DepNode actually is a DefPathHash, and
|
|
|
|
/// 2. the item that the DefPath refers to exists in the current tcx.
|
|
|
|
///
|
|
|
|
/// Condition (1) is determined by the DepKind variant of the
|
|
|
|
/// DepNode. Condition (2) might not be fulfilled if a DepNode
|
|
|
|
/// refers to something from the previous compilation session that
|
|
|
|
/// has been removed.
|
|
|
|
fn extract_def_id(&self, tcx: TyCtxt<'_>) -> Option<DefId>;
|
|
|
|
|
|
|
|
/// Used in testing
|
2021-10-16 18:10:23 +00:00
|
|
|
fn from_label_string(
|
|
|
|
tcx: TyCtxt<'_>,
|
|
|
|
label: &str,
|
|
|
|
def_path_hash: DefPathHash,
|
|
|
|
) -> Result<Self, ()>;
|
2020-10-24 15:37:26 +00:00
|
|
|
|
|
|
|
/// Used in testing
|
|
|
|
fn has_label_string(label: &str) -> bool;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl DepNodeExt for DepNode {
|
|
|
|
/// Construct a DepNode from the given DepKind and DefPathHash. This
|
|
|
|
/// method will assert that the given DepKind actually requires a
|
|
|
|
/// single DefId/DefPathHash parameter.
|
2021-10-16 18:10:23 +00:00
|
|
|
fn from_def_path_hash(tcx: TyCtxt<'_>, def_path_hash: DefPathHash, kind: DepKind) -> DepNode {
|
|
|
|
debug_assert!(kind.fingerprint_style(tcx) == FingerprintStyle::DefPathHash);
|
2020-10-24 15:37:26 +00:00
|
|
|
DepNode { kind, hash: def_path_hash.0.into() }
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Extracts the DefId corresponding to this DepNode. This will work
|
|
|
|
/// if two conditions are met:
|
|
|
|
///
|
|
|
|
/// 1. The Fingerprint of the DepNode actually is a DefPathHash, and
|
|
|
|
/// 2. the item that the DefPath refers to exists in the current tcx.
|
|
|
|
///
|
|
|
|
/// Condition (1) is determined by the DepKind variant of the
|
|
|
|
/// DepNode. Condition (2) might not be fulfilled if a DepNode
|
|
|
|
/// refers to something from the previous compilation session that
|
|
|
|
/// has been removed.
|
2021-12-16 00:32:30 +00:00
|
|
|
fn extract_def_id<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Option<DefId> {
|
2021-10-16 18:10:23 +00:00
|
|
|
if self.kind.fingerprint_style(tcx) == FingerprintStyle::DefPathHash {
|
2022-01-19 22:36:44 +00:00
|
|
|
Some(tcx.def_path_hash_to_def_id(DefPathHash(self.hash.into()), &mut || {
|
|
|
|
panic!("Failed to extract DefId: {:?} {}", self.kind, self.hash)
|
|
|
|
}))
|
2020-10-24 15:37:26 +00:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Used in testing
|
2021-10-16 18:10:23 +00:00
|
|
|
fn from_label_string(
|
|
|
|
tcx: TyCtxt<'_>,
|
|
|
|
label: &str,
|
|
|
|
def_path_hash: DefPathHash,
|
|
|
|
) -> Result<DepNode, ()> {
|
2020-10-24 15:37:26 +00:00
|
|
|
let kind = dep_kind_from_label_string(label)?;
|
|
|
|
|
2021-10-16 18:10:23 +00:00
|
|
|
match kind.fingerprint_style(tcx) {
|
2021-10-02 16:06:42 +00:00
|
|
|
FingerprintStyle::Opaque => Err(()),
|
2021-10-16 18:10:23 +00:00
|
|
|
FingerprintStyle::Unit => Ok(DepNode::new_no_params(tcx, kind)),
|
|
|
|
FingerprintStyle::DefPathHash => {
|
|
|
|
Ok(DepNode::from_def_path_hash(tcx, def_path_hash, kind))
|
|
|
|
}
|
2020-10-24 15:37:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Used in testing
|
|
|
|
fn has_label_string(label: &str) -> bool {
|
|
|
|
dep_kind_from_label_string(label).is_ok()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-27 18:54:28 +00:00
|
|
|
impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for () {
|
|
|
|
#[inline(always)]
|
2021-10-02 16:06:42 +00:00
|
|
|
fn fingerprint_style() -> FingerprintStyle {
|
|
|
|
FingerprintStyle::Unit
|
2020-10-27 18:54:28 +00:00
|
|
|
}
|
|
|
|
|
2021-10-17 09:49:30 +00:00
|
|
|
#[inline(always)]
|
2020-10-27 18:54:28 +00:00
|
|
|
fn to_fingerprint(&self, _: TyCtxt<'tcx>) -> Fingerprint {
|
|
|
|
Fingerprint::ZERO
|
|
|
|
}
|
|
|
|
|
2021-10-17 09:49:30 +00:00
|
|
|
#[inline(always)]
|
2020-10-27 18:54:28 +00:00
|
|
|
fn recover(_: TyCtxt<'tcx>, _: &DepNode) -> Option<Self> {
|
|
|
|
Some(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-18 09:32:58 +00:00
|
|
|
impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for DefId {
|
2020-10-27 18:54:28 +00:00
|
|
|
#[inline(always)]
|
2021-10-02 16:06:42 +00:00
|
|
|
fn fingerprint_style() -> FingerprintStyle {
|
|
|
|
FingerprintStyle::DefPathHash
|
2020-06-01 17:58:18 +00:00
|
|
|
}
|
2017-06-02 15:36:30 +00:00
|
|
|
|
2021-10-17 09:49:30 +00:00
|
|
|
#[inline(always)]
|
2020-03-18 09:32:58 +00:00
|
|
|
fn to_fingerprint(&self, tcx: TyCtxt<'tcx>) -> Fingerprint {
|
2021-07-20 12:03:20 +00:00
|
|
|
tcx.def_path_hash(*self).0
|
2016-03-28 21:37:34 +00:00
|
|
|
}
|
2017-06-12 15:00:55 +00:00
|
|
|
|
2021-10-17 09:49:30 +00:00
|
|
|
#[inline(always)]
|
2019-06-13 21:48:52 +00:00
|
|
|
fn to_debug_str(&self, tcx: TyCtxt<'tcx>) -> String {
|
2018-12-19 10:31:35 +00:00
|
|
|
tcx.def_path_str(*self)
|
2017-06-12 15:00:55 +00:00
|
|
|
}
|
2020-02-26 01:20:33 +00:00
|
|
|
|
2021-10-17 09:49:30 +00:00
|
|
|
#[inline(always)]
|
2020-02-26 01:20:33 +00:00
|
|
|
fn recover(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> Option<Self> {
|
2020-03-21 08:28:37 +00:00
|
|
|
dep_node.extract_def_id(tcx)
|
2020-02-26 01:20:33 +00:00
|
|
|
}
|
2017-06-12 15:00:55 +00:00
|
|
|
}
|
|
|
|
|
2020-03-18 09:32:58 +00:00
|
|
|
impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for LocalDefId {
|
2020-10-27 18:54:28 +00:00
|
|
|
#[inline(always)]
|
2021-10-02 16:06:42 +00:00
|
|
|
fn fingerprint_style() -> FingerprintStyle {
|
|
|
|
FingerprintStyle::DefPathHash
|
2020-06-01 17:58:18 +00:00
|
|
|
}
|
2017-09-12 15:07:09 +00:00
|
|
|
|
2021-10-17 09:49:30 +00:00
|
|
|
#[inline(always)]
|
2020-03-18 09:32:58 +00:00
|
|
|
fn to_fingerprint(&self, tcx: TyCtxt<'tcx>) -> Fingerprint {
|
2019-10-31 13:32:07 +00:00
|
|
|
self.to_def_id().to_fingerprint(tcx)
|
2017-09-12 15:07:09 +00:00
|
|
|
}
|
|
|
|
|
2021-10-17 09:49:30 +00:00
|
|
|
#[inline(always)]
|
2019-06-13 21:48:52 +00:00
|
|
|
fn to_debug_str(&self, tcx: TyCtxt<'tcx>) -> String {
|
2019-10-31 13:32:07 +00:00
|
|
|
self.to_def_id().to_debug_str(tcx)
|
2017-09-12 15:07:09 +00:00
|
|
|
}
|
2020-02-26 01:20:33 +00:00
|
|
|
|
2021-10-17 09:49:30 +00:00
|
|
|
#[inline(always)]
|
2020-02-26 01:20:33 +00:00
|
|
|
fn recover(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> Option<Self> {
|
2020-03-21 08:28:37 +00:00
|
|
|
dep_node.extract_def_id(tcx).map(|id| id.expect_local())
|
2020-02-26 01:20:33 +00:00
|
|
|
}
|
2017-09-12 15:07:09 +00:00
|
|
|
}
|
|
|
|
|
2020-03-18 09:32:58 +00:00
|
|
|
impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for CrateNum {
|
2020-10-27 18:54:28 +00:00
|
|
|
#[inline(always)]
|
2021-10-02 16:06:42 +00:00
|
|
|
fn fingerprint_style() -> FingerprintStyle {
|
|
|
|
FingerprintStyle::DefPathHash
|
2020-06-01 17:58:18 +00:00
|
|
|
}
|
2017-09-22 11:03:15 +00:00
|
|
|
|
2021-10-17 09:49:30 +00:00
|
|
|
#[inline(always)]
|
2020-03-18 09:32:58 +00:00
|
|
|
fn to_fingerprint(&self, tcx: TyCtxt<'tcx>) -> Fingerprint {
|
2022-04-15 17:27:53 +00:00
|
|
|
let def_id = self.as_def_id();
|
2020-07-29 16:26:15 +00:00
|
|
|
def_id.to_fingerprint(tcx)
|
2017-09-22 11:03:15 +00:00
|
|
|
}
|
|
|
|
|
2021-10-17 09:49:30 +00:00
|
|
|
#[inline(always)]
|
2019-06-13 21:48:52 +00:00
|
|
|
fn to_debug_str(&self, tcx: TyCtxt<'tcx>) -> String {
|
2019-10-21 21:31:37 +00:00
|
|
|
tcx.crate_name(*self).to_string()
|
2017-09-22 11:03:15 +00:00
|
|
|
}
|
2020-02-26 01:20:33 +00:00
|
|
|
|
2021-10-17 09:49:30 +00:00
|
|
|
#[inline(always)]
|
2020-02-26 01:20:33 +00:00
|
|
|
fn recover(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> Option<Self> {
|
2020-03-21 08:28:37 +00:00
|
|
|
dep_node.extract_def_id(tcx).map(|id| id.krate)
|
2020-02-26 01:20:33 +00:00
|
|
|
}
|
2017-09-22 11:03:15 +00:00
|
|
|
}
|
|
|
|
|
2020-03-18 09:32:58 +00:00
|
|
|
impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for (DefId, DefId) {
|
2020-10-27 18:54:28 +00:00
|
|
|
#[inline(always)]
|
2021-10-02 16:06:42 +00:00
|
|
|
fn fingerprint_style() -> FingerprintStyle {
|
|
|
|
FingerprintStyle::Opaque
|
2020-06-01 17:58:18 +00:00
|
|
|
}
|
2017-06-12 15:00:55 +00:00
|
|
|
|
2017-06-13 15:11:53 +00:00
|
|
|
// We actually would not need to specialize the implementation of this
|
|
|
|
// method but it's faster to combine the hashes than to instantiate a full
|
|
|
|
// hashing context and stable-hashing state.
|
2021-10-17 09:49:30 +00:00
|
|
|
#[inline(always)]
|
2020-03-18 09:32:58 +00:00
|
|
|
fn to_fingerprint(&self, tcx: TyCtxt<'tcx>) -> Fingerprint {
|
2017-06-12 15:00:55 +00:00
|
|
|
let (def_id_0, def_id_1) = *self;
|
|
|
|
|
|
|
|
let def_path_hash_0 = tcx.def_path_hash(def_id_0);
|
|
|
|
let def_path_hash_1 = tcx.def_path_hash(def_id_1);
|
|
|
|
|
|
|
|
def_path_hash_0.0.combine(def_path_hash_1.0)
|
|
|
|
}
|
|
|
|
|
2021-10-17 09:49:30 +00:00
|
|
|
#[inline(always)]
|
2019-06-13 21:48:52 +00:00
|
|
|
fn to_debug_str(&self, tcx: TyCtxt<'tcx>) -> String {
|
2017-06-12 15:00:55 +00:00
|
|
|
let (def_id_0, def_id_1) = *self;
|
|
|
|
|
2017-10-04 12:57:14 +00:00
|
|
|
format!("({}, {})", tcx.def_path_debug_str(def_id_0), tcx.def_path_debug_str(def_id_1))
|
2017-06-12 15:00:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-18 09:32:58 +00:00
|
|
|
impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for HirId {
|
2020-10-27 18:54:28 +00:00
|
|
|
#[inline(always)]
|
2021-10-02 16:06:42 +00:00
|
|
|
fn fingerprint_style() -> FingerprintStyle {
|
|
|
|
FingerprintStyle::Opaque
|
2020-06-01 17:58:18 +00:00
|
|
|
}
|
2017-09-05 12:19:07 +00:00
|
|
|
|
|
|
|
// We actually would not need to specialize the implementation of this
|
|
|
|
// method but it's faster to combine the hashes than to instantiate a full
|
|
|
|
// hashing context and stable-hashing state.
|
2021-10-17 09:49:30 +00:00
|
|
|
#[inline(always)]
|
2020-03-18 09:32:58 +00:00
|
|
|
fn to_fingerprint(&self, tcx: TyCtxt<'tcx>) -> Fingerprint {
|
2018-02-23 20:30:27 +00:00
|
|
|
let HirId { owner, local_id } = *self;
|
2017-09-05 12:19:07 +00:00
|
|
|
|
2020-03-18 18:27:59 +00:00
|
|
|
let def_path_hash = tcx.def_path_hash(owner.to_def_id());
|
2018-11-07 10:01:18 +00:00
|
|
|
let local_id = Fingerprint::from_smaller_hash(local_id.as_u32().into());
|
2017-09-05 12:19:07 +00:00
|
|
|
|
|
|
|
def_path_hash.0.combine(local_id)
|
|
|
|
}
|
|
|
|
}
|