-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Edit rustc_middle::dep_graph module documentation #80325
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Drive-by: DepConstructor should really just be a |
||
//! `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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure the API is that restricted any more. There is an escape hatch |
||
//! 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; | ||
|
+23 −19 | src/vec-alloc.md | |
+5 −4 | src/vec-dealloc.md | |
+3 −3 | src/vec-drain.md | |
+5 −5 | src/vec-final.md | |
+6 −6 | src/vec-insert-remove.md | |
+10 −9 | src/vec-into-iter.md | |
+12 −3 | src/vec-layout.md | |
+2 −2 | src/vec-push-pop.md | |
+20 −23 | src/vec-raw.md | |
+17 −21 | src/vec-zsts.md |
+1 −1 | .github/workflows/main.yml | |
+1 −1 | src/SUMMARY.md | |
+0 −3 | src/abi.md | |
+0 −17 | src/behavior-not-considered-unsafe.md | |
+0 −2 | src/const_eval.md | |
+15 −32 | src/expressions/array-expr.md | |
+24 −17 | src/items/associated-items.md | |
+1 −4 | src/items/constant-items.md | |
+2 −2 | src/items/enumerations.md | |
+27 −12 | src/items/external-blocks.md | |
+10 −51 | src/items/functions.md | |
+22 −217 | src/items/generics.md | |
+31 −94 | src/items/implementations.md | |
+1 −5 | src/items/static-items.md | |
+3 −3 | src/items/structs.md | |
+53 −26 | src/items/traits.md | |
+5 −9 | src/items/type-aliases.md | |
+2 −2 | src/items/unions.md | |
+1 −1 | src/linkage.md | |
+14 −19 | src/paths.md | |
+3 −3 | src/tokens.md | |
+1 −1 | src/types/enum.md | |
+2 −5 | src/types/function-pointer.md | |
+1 −1 | src/types/struct.md | |
+0 −1 | src/types/tuple.md |
+1 −1 | .travis.yml | |
+0 −16 | src/flow_control/match/guard.md | |
+10 −2 | src/std_misc/threads/testcase_mapreduce.md |
+90 −113 | Cargo.lock | |
+4 −4 | Cargo.toml | |
+4 −3 | rls-data/Cargo.toml | |
+0 −3 | rls-data/src/config.rs | |
+76 −3 | rls-data/src/lib.rs | |
+9,320 −0 | rls-data/src/serde_expanded.rs | |
+0 −2 | rls-ipc/src/rpc.rs | |
+0 −1 | rls-rustc/src/lib.rs | |
+3 −2 | rls-span/Cargo.toml | |
+0 −3 | rls-span/src/compiler.rs | |
+7 −2 | rls-span/src/lib.rs | |
+2,689 −0 | rls-span/src/serde_expanded.rs | |
+0 −1 | rls/src/actions/requests.rs | |
+0 −1 | rls/src/build/ipc.rs | |
+0 −2 | rls/src/build/plan.rs | |
+0 −1 | rls/src/build/rustc.rs | |
+0 −3 | rls/src/project_model.rs |
+0 −23 | .github/workflows/ci.yml | |
+9 −0 | .travis.yml | |
+13 −25 | src/combiner.rs | |
+0 −154 | src/compression.rs | |
+2 −7 | src/generator.rs | |
+0 −1 | src/lib.rs | |
+1 −9 | src/main.rs | |
+0 −15 | src/main.yml | |
+57 −19 | src/tarballer.rs | |
+2 −2 | src/util.rs | |
+0 −173 | test.sh |
+0 −5 | .github/workflows/upload-assets.yml | |
+1 −12 | .github/workflows/windows.yml | |
+1 −29 | CHANGELOG.md | |
+41 −41 | Cargo.lock | |
+10 −10 | Cargo.toml | |
+2 −2 | Configurations.md | |
+0 −1 | rust-toolchain | |
+1 −3 | src/attr.rs | |
+11 −13 | src/closures.rs | |
+5 −16 | src/config/options.rs | |
+1 −1 | src/formatting.rs | |
+1 −1 | src/imports.rs | |
+1 −1 | src/items.rs | |
+1 −1 | src/macros.rs | |
+1 −8 | src/spanned.rs | |
+3 −17 | src/types.rs | |
+13 −44 | src/visitor.rs | |
+0 −20 | tests/source/issue-4577.rs | |
+0 −19 | tests/source/issue_4584.rs | |
+0 −43 | tests/source/statements.rs | |
+0 −6 | tests/source/type.rs | |
+0 −3 | tests/target/imports_2021_edition.rs | |
+0 −15 | tests/target/issue-4577.rs | |
+0 −32 | tests/target/issue_4584.rs | |
+1 −1 | tests/target/macro_rules.rs | |
+0 −42 | tests/target/statements.rs | |
+0 −4 | tests/target/type.rs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The define_dep_nodes macro is defined in dep_node.rs.
It defines the
DepKind
enum, andDepConstructor
.DepNode
is defined in rustc_query_system::dep_graph::dep_node.