|
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 |
5 | 5 | //! depends on the node's `DepKind`. Together, the kind and the fingerprint |
6 | 6 | //! fully identify a dependency node, even across multiple compilation sessions. |
7 | 7 | //! In other words, the value of the fingerprint does not depend on anything |
8 | 8 | //! 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 |
10 | 10 | //! 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: |
12 | 13 | //! |
13 | 14 | //! * 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). |
17 | 18 | //! * A `Fingerprint` is just a bunch of bits, which allows `DepNode` to |
18 | 19 | //! implement `Copy`, `Sync`, `Send`, `Freeze`, etc. |
19 | 20 | //! * Since we just have a bit pattern, `DepNode` can be mapped from disk into |
|
26 | 27 | //! could not be instantiated because the current compilation session |
27 | 28 | //! contained no `DefId` for thing that had been removed. |
28 | 29 | //! |
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`). |
33 | 36 | //! |
34 | 37 | //! Because the macro sees what parameters a given `DepKind` requires, it can |
35 | 38 | //! "infer" some properties for each kind of `DepNode`: |
|
41 | 44 | //! in which case it is possible to map the node's fingerprint back to the |
42 | 45 | //! `DefId` it was computed from. In other cases, too much information gets |
43 | 46 | //! 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 |
44 | 57 |
|
45 | 58 | use std::fmt; |
46 | 59 | use std::hash::Hash; |
|
0 commit comments