Skip to content
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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler/rustc_middle/src/dep_graph/dep_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
65 changes: 65 additions & 0 deletions compiler/rustc_middle/src/dep_graph/mod.rs
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?
Copy link
Contributor

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, and DepConstructor.
DepNode is defined in rustc_query_system::dep_graph::dep_node.

// 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drive-by: DepConstructor should really just be a mod, since all it does is provide a namespace for functions constructing DepNodes.

//! `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
Copy link
Contributor

Choose a reason for hiding this comment

The 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 DepNode::new_no_params which is used in non-incremental runs.

//! 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;
Expand Down
2 changes: 1 addition & 1 deletion src/doc/book
Submodule book updated 36 files
+2 −2 .github/workflows/main.yml
+1 −1 listings/ch06-enums-and-pattern-matching/no-listing-12-if-let/src/main.rs
+1 −1 listings/ch11-writing-automated-tests/listing-11-10/output.txt
+3 −3 listings/ch12-an-io-project/listing-12-03/poem.txt
+3 −3 listings/ch12-an-io-project/listing-12-04/output.txt
+3 −3 listings/ch12-an-io-project/listing-12-04/poem.txt
+3 −3 listings/ch12-an-io-project/listing-12-05/poem.txt
+3 −3 listings/ch12-an-io-project/listing-12-06/poem.txt
+3 −3 listings/ch12-an-io-project/listing-12-07/poem.txt
+3 −3 listings/ch12-an-io-project/listing-12-08/poem.txt
+3 −3 listings/ch12-an-io-project/listing-12-09/poem.txt
+3 −3 listings/ch12-an-io-project/listing-12-10/poem.txt
+3 −3 listings/ch12-an-io-project/listing-12-11/poem.txt
+3 −3 listings/ch12-an-io-project/listing-12-12/output.txt
+3 −3 listings/ch12-an-io-project/listing-12-12/poem.txt
+3 −3 listings/ch12-an-io-project/listing-12-13/poem.txt
+3 −3 listings/ch12-an-io-project/listing-12-14/poem.txt
+3 −3 listings/ch12-an-io-project/listing-12-15/poem.txt
+3 −3 listings/ch12-an-io-project/listing-12-16/poem.txt
+3 −3 listings/ch12-an-io-project/listing-12-17/poem.txt
+3 −3 listings/ch12-an-io-project/listing-12-18/poem.txt
+3 −3 listings/ch12-an-io-project/listing-12-19/poem.txt
+3 −3 listings/ch12-an-io-project/listing-12-20/poem.txt
+3 −3 listings/ch12-an-io-project/listing-12-21/poem.txt
+3 −3 listings/ch12-an-io-project/listing-12-22/poem.txt
+3 −3 listings/ch12-an-io-project/listing-12-23/poem.txt
+3 −3 listings/ch12-an-io-project/listing-12-24/poem.txt
+3 −3 listings/ch12-an-io-project/no-listing-01-handling-errors-in-main/poem.txt
+3 −3 listings/ch12-an-io-project/no-listing-02-using-search-in-run/poem.txt
+3 −3 listings/ch12-an-io-project/output-only-02-missing-lifetimes/poem.txt
+1 −1 listings/ch12-an-io-project/output-only-03-multiple-matches/output.txt
+3 −3 listings/ch12-an-io-project/output-only-03-multiple-matches/poem.txt
+3 −3 listings/ch12-an-io-project/output-only-04-no-matches/poem.txt
+2 −3 src/ch04-01-what-is-ownership.md
+3 −3 src/ch13-01-closures.md
+3 −1 src/ch16-03-shared-state.md
2 changes: 1 addition & 1 deletion src/doc/embedded-book
Submodule embedded-book updated 1 files
+0 −3 book.toml
2 changes: 1 addition & 1 deletion src/llvm-project
Submodule llvm-project updated 190 files
2 changes: 1 addition & 1 deletion src/tools/cargo
Submodule cargo updated 143 files
2 changes: 1 addition & 1 deletion src/tools/miri
Submodule miri updated 60 files
+2 −22 .github/workflows/ci.yml
+55 −60 Cargo.lock
+2 −2 README.md
+32 −40 cargo-miri/Cargo.lock
+1 −1 rust-version
+27 −107 src/data_race.rs
+1 −16 src/machine.rs
+5 −0 src/shims/intrinsics.rs
+14 −14 test-cargo-miri/Cargo.lock
+10 −15 test-cargo-miri/run-test.py
+0 −0 test-cargo-miri/stderr.ref1
+0 −0 test-cargo-miri/stderr.ref2
+0 −0 test-cargo-miri/stderr.ref3
+0 −0 test-cargo-miri/stdout.ref1
+0 −0 test-cargo-miri/stdout.ref2
+0 −0 test-cargo-miri/stdout.ref3
+0 −0 test-cargo-miri/test.stderr.ref1
+0 −0 test-cargo-miri/test.stderr.ref2
+0 −0 test-cargo-miri/test.stdout.ref1
+0 −0 test-cargo-miri/test.stdout.ref2
+0 −0 test-cargo-miri/test.stdout.ref3
+0 −0 test-cargo-miri/test.stdout.ref4
+0 −0 test-cargo-miri/test.stdout.ref5
+0 −18 tests/compile-fail/box-cell-alias.rs
+0 −48 tests/compile-fail/data_race/alloc_read_race.rs
+0 −50 tests/compile-fail/data_race/alloc_write_race.rs
+1 −1 tests/compile-fail/data_race/atomic_read_na_write_race1.rs
+1 −1 tests/compile-fail/data_race/atomic_read_na_write_race2.rs
+1 −1 tests/compile-fail/data_race/atomic_write_na_read_race1.rs
+1 −1 tests/compile-fail/data_race/atomic_write_na_read_race2.rs
+1 −1 tests/compile-fail/data_race/atomic_write_na_write_race1.rs
+1 −1 tests/compile-fail/data_race/atomic_write_na_write_race2.rs
+3 −3 tests/compile-fail/data_race/dangling_thread_async_race.rs
+3 −3 tests/compile-fail/data_race/dangling_thread_race.rs
+0 −32 tests/compile-fail/data_race/dealloc_read_race1.rs
+0 −34 tests/compile-fail/data_race/dealloc_read_race2.rs
+0 −52 tests/compile-fail/data_race/dealloc_read_race_stack.rs
+0 −52 tests/compile-fail/data_race/dealloc_read_race_stack_drop.rs
+0 −31 tests/compile-fail/data_race/dealloc_write_race1.rs
+0 −33 tests/compile-fail/data_race/dealloc_write_race2.rs
+0 −52 tests/compile-fail/data_race/dealloc_write_race_stack.rs
+0 −53 tests/compile-fail/data_race/dealloc_write_race_stack_drop.rs
+1 −1 tests/compile-fail/data_race/enable_after_join_to_main.rs
+1 −1 tests/compile-fail/data_race/read_write_race.rs
+0 −57 tests/compile-fail/data_race/read_write_race_stack.rs
+1 −1 tests/compile-fail/data_race/relax_acquire_race.rs
+3 −3 tests/compile-fail/data_race/release_seq_race.rs
+1 −1 tests/compile-fail/data_race/release_seq_race_same_thread.rs
+1 −1 tests/compile-fail/data_race/rmw_race.rs
+1 −1 tests/compile-fail/data_race/write_write_race.rs
+0 −57 tests/compile-fail/data_race/write_write_race_stack.rs
+0 −19 tests/run-pass/concurrency/concurrent_caller_location.rs
+0 −2 tests/run-pass/concurrency/concurrent_caller_location.stderr
+0 −16 tests/run-pass/concurrency/issue1643.rs
+0 −2 tests/run-pass/concurrency/issue1643.stderr
+0 −1 tests/run-pass/concurrency/sync_singlethread.rs
+1 −1 tests/run-pass/dyn-lcsit.rs
+2 −6 tests/run-pass/intrinsics.rs
+0 −4 tests/run-pass/leak-in-static.rs
+1 −7 tests/run-pass/rc.rs