diff --git a/compiler/rustc_middle/src/dep_graph/dep_node.rs b/compiler/rustc_middle/src/dep_graph/dep_node.rs index 62f2874af0493..9762170890cc0 100644 --- a/compiler/rustc_middle/src/dep_graph/dep_node.rs +++ b/compiler/rustc_middle/src/dep_graph/dep_node.rs @@ -54,6 +54,7 @@ use crate::ty::TyCtxt; + use rustc_data_structures::fingerprint::Fingerprint; use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, CRATE_DEF_INDEX}; use rustc_hir::definitions::DefPathHash; diff --git a/compiler/rustc_middle/src/dep_graph/mod.rs b/compiler/rustc_middle/src/dep_graph/mod.rs index b88ffa2bb7347..74c8be08b60da 100644 --- a/compiler/rustc_middle/src/dep_graph/mod.rs +++ b/compiler/rustc_middle/src/dep_graph/mod.rs @@ -1,3 +1,68 @@ +//! Nodes in the dependency graph. +//! +//! A node in the dependency graph is represented by a [`DepNode`].[^1] +//! 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 +//! 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 +//! interning key (e.g., `NodeId`, `DefId`, `Symbol`) or the numeric value of a +//! pointer. The concept behind this could be compared to how git commit hashes +//! uniquely identify a given commit. +//! +//! The fingerprinting approach and has some benefits: +//! +//! * A `DepNode` can simply be serialized to disk and loaded in another session +//! 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). +//! * 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 +//! memory without any post-processing (e.g., "abomination-style" pointer +//! 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` creation and "inference" +//! +// Where is the `define_dep_nodes!()` macro? +// How much of this section is outdated? +//! `DepNode` definition happens in the `define_dep_nodes!()` macro. This macro +//! defines the `DepKind` enum and a corresponding [`DepConstructor`] enum. The +//! `DepConstructor` enum links a `DepKind` to the parameters that are needed at +//! runtime in order to construct a valid `DepNode` fingerprint. +//! +//! 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 +//! `DepNode`s could represent global concepts with only one value. +//! * 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. +//! +//! The `DepConstructor` enum, 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. +//! +//! [^1]: For an overview of the dependency graph and its role in +//! the query system and incremental compilation, see +//! [the rustc-dev-guide](https://rustc-dev-guide.rust-lang.org/query.html). +//! +//! [`Fingerprint`]: rustc_data_structures::fingerprint::Fingerprint + use crate::ich::StableHashingContext; use crate::ty::{self, TyCtxt}; use rustc_data_structures::profiling::SelfProfilerRef; diff --git a/src/doc/book b/src/doc/book index ac57a0ddd23d1..5bb44f8b5b0aa 160000 --- a/src/doc/book +++ b/src/doc/book @@ -1 +1 @@ -Subproject commit ac57a0ddd23d173b26731ccf939f3ba729753275 +Subproject commit 5bb44f8b5b0aa105c8b22602e9b18800484afa21 diff --git a/src/doc/embedded-book b/src/doc/embedded-book index ceec19e873be8..ba34b8a968f95 160000 --- a/src/doc/embedded-book +++ b/src/doc/embedded-book @@ -1 +1 @@ -Subproject commit ceec19e873be87c6ee5666b030c6bb612f889a96 +Subproject commit ba34b8a968f9531d38c4dc4411d5568b7c076bfe diff --git a/src/doc/nomicon b/src/doc/nomicon index a8584998eacde..a5a48441d411f 160000 --- a/src/doc/nomicon +++ b/src/doc/nomicon @@ -1 +1 @@ -Subproject commit a8584998eacdea7106a1dfafcbf6c1c06fcdf925 +Subproject commit a5a48441d411f61556b57d762b03d6874afe575d diff --git a/src/doc/reference b/src/doc/reference index 50af691f83893..b278478b76617 160000 --- a/src/doc/reference +++ b/src/doc/reference @@ -1 +1 @@ -Subproject commit 50af691f838937c300b47812d0507c6d88c14f97 +Subproject commit b278478b766178491a8b6f67afa4bcd6b64d977a diff --git a/src/doc/rust-by-example b/src/doc/rust-by-example index 03e23af01f0b4..1cce0737d6a7d 160000 --- a/src/doc/rust-by-example +++ b/src/doc/rust-by-example @@ -1 +1 @@ -Subproject commit 03e23af01f0b4f83a3a513da280e1ca92587f2ec +Subproject commit 1cce0737d6a7d3ceafb139b4a206861fb1dcb2ab diff --git a/src/llvm-project b/src/llvm-project index f9a8d70b6e036..8d78ad13896b9 160000 --- a/src/llvm-project +++ b/src/llvm-project @@ -1 +1 @@ -Subproject commit f9a8d70b6e0365ac2172ca6b7f1de0341297458d +Subproject commit 8d78ad13896b955f630714f386a95ed91b237e3d diff --git a/src/tools/cargo b/src/tools/cargo index a73e5b7d567c3..a3c2627fbc2f5 160000 --- a/src/tools/cargo +++ b/src/tools/cargo @@ -1 +1 @@ -Subproject commit a73e5b7d567c3036b296fc6b33ed52c5edcd882e +Subproject commit a3c2627fbc2f5391c65ba45ab53b81bf71fa323c diff --git a/src/tools/miri b/src/tools/miri index 1cf1a2e40a686..2065b52dfef3c 160000 --- a/src/tools/miri +++ b/src/tools/miri @@ -1 +1 @@ -Subproject commit 1cf1a2e40a6867948db84f806085a875fbefce3c +Subproject commit 2065b52dfef3cd5a5216e65c21a056a69574bddc diff --git a/src/tools/rls b/src/tools/rls index 88a58d1f484af..2cf84baa5e3c5 160000 --- a/src/tools/rls +++ b/src/tools/rls @@ -1 +1 @@ -Subproject commit 88a58d1f484af31d87b75e1d17655b59910f41fe +Subproject commit 2cf84baa5e3c55ac02f42919e67440acb5417125 diff --git a/src/tools/rust-installer b/src/tools/rust-installer index 5254dbfd25d52..d66f476b4d5e7 160000 --- a/src/tools/rust-installer +++ b/src/tools/rust-installer @@ -1 +1 @@ -Subproject commit 5254dbfd25d5284728ab624dca1969d61427a0db +Subproject commit d66f476b4d5e7fdf1ec215c9ac16c923dc292324 diff --git a/src/tools/rustfmt b/src/tools/rustfmt index 4f9c794ce1e3c..70ce18255f429 160000 --- a/src/tools/rustfmt +++ b/src/tools/rustfmt @@ -1 +1 @@ -Subproject commit 4f9c794ce1e3c77698f522c3eb1ab935f23df303 +Subproject commit 70ce18255f429caf0d75ecfed8c1464535ee779b