Skip to content

Commit 1fa9200

Browse files
committed
Remove dep_node comment duplication.
`rustc_middle` and `rustc_query_system` both have a file called `dep_node.rs` with a big comment at the top, and the comments are very similar. The one in `rustc_query_system` looks like the original, and the one in `rustc_middle` is a copy with some improvements. This commit removes the comment from `rustc_middle` and updates the one in `rustc_query_system` to include the improvements. I did it this way because `rustc_query_system` is the crate that defines `DepNode`, and so seems like the right place for the comment.
1 parent 0825202 commit 1fa9200

File tree

2 files changed

+26
-71
lines changed

2 files changed

+26
-71
lines changed

compiler/rustc_middle/src/dep_graph/dep_node.rs

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,3 @@
1-
//! Nodes in the dependency graph.
2-
//!
3-
//! A node in the [dependency graph] is represented by a [`DepNode`].
4-
//! A `DepNode` consists of a [`DepKind`] (which
5-
//! specifies the kind of thing it represents, like a piece of HIR, MIR, etc.)
6-
//! and a [`Fingerprint`], a 128-bit hash value, the exact meaning of which
7-
//! depends on the node's `DepKind`. Together, the kind and the fingerprint
8-
//! fully identify a dependency node, even across multiple compilation sessions.
9-
//! In other words, the value of the fingerprint does not depend on anything
10-
//! that is specific to a given compilation session, like an unpredictable
11-
//! interning key (e.g., `NodeId`, `DefId`, `Symbol`) or the numeric value of a
12-
//! pointer. The concept behind this could be compared to how git commit hashes
13-
//! uniquely identify a given commit. The fingerprinting approach has
14-
//! a few advantages:
15-
//!
16-
//! * A `DepNode` can simply be serialized to disk and loaded in another session
17-
//! without the need to do any "rebasing" (like we have to do for Spans and
18-
//! NodeIds) or "retracing" (like we had to do for `DefId` in earlier
19-
//! implementations of the dependency graph).
20-
//! * A `Fingerprint` is just a bunch of bits, which allows `DepNode` to
21-
//! implement `Copy`, `Sync`, `Send`, `Freeze`, etc.
22-
//! * Since we just have a bit pattern, `DepNode` can be mapped from disk into
23-
//! memory without any post-processing (e.g., "abomination-style" pointer
24-
//! reconstruction).
25-
//! * Because a `DepNode` is self-contained, we can instantiate `DepNodes` that
26-
//! refer to things that do not exist anymore. In previous implementations
27-
//! `DepNode` contained a `DefId`. A `DepNode` referring to something that
28-
//! had been removed between the previous and the current compilation session
29-
//! could not be instantiated because the current compilation session
30-
//! contained no `DefId` for thing that had been removed.
31-
//!
32-
//! `DepNode` definition happens in the `define_dep_nodes!()` macro. This macro
33-
//! defines the `DepKind` enum. Each `DepKind` has its own parameters that are
34-
//! needed at runtime in order to construct a valid `DepNode` fingerprint.
35-
//! However, only `CompileCodegenUnit` and `CompileMonoItem` are constructed
36-
//! explicitly (with `make_compile_codegen_unit` cq `make_compile_mono_item`).
37-
//!
38-
//! Because the macro sees what parameters a given `DepKind` requires, it can
39-
//! "infer" some properties for each kind of `DepNode`:
40-
//!
41-
//! * Whether a `DepNode` of a given kind has any parameters at all. Some
42-
//! `DepNode`s could represent global concepts with only one value.
43-
//! * Whether it is possible, in principle, to reconstruct a query key from a
44-
//! given `DepNode`. Many `DepKind`s only require a single `DefId` parameter,
45-
//! in which case it is possible to map the node's fingerprint back to the
46-
//! `DefId` it was computed from. In other cases, too much information gets
47-
//! lost during fingerprint computation.
48-
//!
49-
//! `make_compile_codegen_unit` and `make_compile_mono_items`, together with
50-
//! `DepNode::new()`, ensures that only valid `DepNode` instances can be
51-
//! constructed. For example, the API does not allow for constructing
52-
//! parameterless `DepNode`s with anything other than a zeroed out fingerprint.
53-
//! More generally speaking, it relieves the user of the `DepNode` API of
54-
//! having to know how to compute the expected fingerprint for a given set of
55-
//! node parameters.
56-
//!
57-
//! [dependency graph]: https://rustc-dev-guide.rust-lang.org/query.html
58-
591
use rustc_data_structures::fingerprint::Fingerprint;
602
use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE, LocalDefId, LocalModDefId, ModDefId};
613
use rustc_hir::definitions::DefPathHash;

compiler/rustc_query_system/src/dep_graph/dep_node.rs

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
//! This module defines the `DepNode` type which the compiler uses to represent
2-
//! nodes in the dependency graph. A `DepNode` consists of a `DepKind` (which
3-
//! specifies the kind of thing it represents, like a piece of HIR, MIR, etc)
4-
//! and a `Fingerprint`, a 128 bit hash value the exact meaning of which
1+
//! This module defines the [`DepNode`] type which the compiler uses to represent
2+
//! nodes in the [dependency graph]. A `DepNode` consists of a [`DepKind`] (which
3+
//! specifies the kind of thing it represents, like a piece of HIR, MIR, etc.)
4+
//! and a [`Fingerprint`], a 128-bit hash value, the exact meaning of which
55
//! depends on the node's `DepKind`. Together, the kind and the fingerprint
66
//! fully identify a dependency node, even across multiple compilation sessions.
77
//! In other words, the value of the fingerprint does not depend on anything
88
//! that is specific to a given compilation session, like an unpredictable
9-
//! interning key (e.g., NodeId, DefId, Symbol) or the numeric value of a
9+
//! interning key (e.g., `NodeId`, `DefId`, `Symbol`) or the numeric value of a
1010
//! pointer. The concept behind this could be compared to how git commit hashes
11-
//! uniquely identify a given commit and has a few advantages:
11+
//! uniquely identify a given commit. The fingerprinting approach has
12+
//! a few advantages:
1213
//!
1314
//! * A `DepNode` can simply be serialized to disk and loaded in another session
14-
//! without the need to do any "rebasing (like we have to do for Spans and
15-
//! NodeIds) or "retracing" like we had to do for `DefId` in earlier
16-
//! implementations of the dependency graph.
15+
//! without the need to do any "rebasing" (like we have to do for Spans and
16+
//! NodeIds) or "retracing" (like we had to do for `DefId` in earlier
17+
//! implementations of the dependency graph).
1718
//! * A `Fingerprint` is just a bunch of bits, which allows `DepNode` to
1819
//! implement `Copy`, `Sync`, `Send`, `Freeze`, etc.
1920
//! * Since we just have a bit pattern, `DepNode` can be mapped from disk into
@@ -26,10 +27,12 @@
2627
//! could not be instantiated because the current compilation session
2728
//! contained no `DefId` for thing that had been removed.
2829
//!
29-
//! `DepNode` definition happens in `rustc_middle` with the `define_dep_nodes!()` macro.
30-
//! This macro defines the `DepKind` enum and a corresponding `DepConstructor` enum. The
31-
//! `DepConstructor` enum links a `DepKind` to the parameters that are needed at runtime in order
32-
//! to construct a valid `DepNode` fingerprint.
30+
//! `DepNode` definition happens in `rustc_middle` with the
31+
//! `define_dep_nodes!()` macro. This macro defines the `DepKind` enum. Each
32+
//! `DepKind` has its own parameters that are needed at runtime in order to
33+
//! construct a valid `DepNode` fingerprint. However, only `CompileCodegenUnit`
34+
//! and `CompileMonoItem` are constructed explicitly (with
35+
//! `make_compile_codegen_unit` and `make_compile_mono_item`).
3336
//!
3437
//! Because the macro sees what parameters a given `DepKind` requires, it can
3538
//! "infer" some properties for each kind of `DepNode`:
@@ -41,6 +44,16 @@
4144
//! in which case it is possible to map the node's fingerprint back to the
4245
//! `DefId` it was computed from. In other cases, too much information gets
4346
//! lost during fingerprint computation.
47+
//!
48+
//! `make_compile_codegen_unit` and `make_compile_mono_items`, together with
49+
//! `DepNode::new()`, ensure that only valid `DepNode` instances can be
50+
//! constructed. For example, the API does not allow for constructing
51+
//! parameterless `DepNode`s with anything other than a zeroed out fingerprint.
52+
//! More generally speaking, it relieves the user of the `DepNode` API of
53+
//! having to know how to compute the expected fingerprint for a given set of
54+
//! node parameters.
55+
//!
56+
//! [dependency graph]: https://rustc-dev-guide.rust-lang.org/query.html
4457
4558
use std::fmt;
4659
use std::hash::Hash;

0 commit comments

Comments
 (0)