Skip to content

Commit 1876e12

Browse files
committed
Avoid duplicated query modifier comments.
By removing the ones in `compiler/rustc_middle/src/queries.rs`, and making `compiler/rustc_middle/src/query/modifiers.rs` the single source of truth.
1 parent f0a1104 commit 1876e12

2 files changed

Lines changed: 29 additions & 36 deletions

File tree

compiler/rustc_middle/src/queries.rs

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,11 @@
2323
//! ## Query Modifiers
2424
//!
2525
//! Query modifiers are special flags that alter the behavior of a query. They are parsed and processed by the `rustc_macros`
26-
//! The main modifiers are:
2726
//!
28-
//! - `desc { ... }`: Sets the human-readable description for diagnostics and profiling. Required
29-
//! for every query. The block should contain a `format!`-style string literal followed by
30-
//! optional arguments. The query key identifier is available for use within the block, as is
31-
//! `tcx`.
32-
//! - `arena_cache`: Use an arena for in-memory caching of the query result.
33-
//! - `cache_on_disk_if { ... }`: Cache the query result to disk if the provided block evaluates to
34-
//! true. The query key identifier is available for use within the block, as is `tcx`.
35-
//! - `cycle_fatal`: If a dependency cycle is detected, abort compilation with a fatal error.
36-
//! - `cycle_delayed_bug`: If a dependency cycle is detected, emit a delayed bug instead of aborting immediately.
37-
//! - `cycle_stash`: If a dependency cycle is detected, stash the error for later handling.
38-
//! - `no_hash`: Do not hash the query result for incremental compilation; just mark as dirty if recomputed.
39-
//! - `anon`: Make the query anonymous in the dependency graph (no dep node is created).
40-
//! - `eval_always`: Always evaluate the query, ignoring its dependencies and cached results.
41-
//! - `depth_limit`: Impose a recursion depth limit on the query to prevent stack overflows.
42-
//! - `separate_provide_extern`: Use separate provider functions for local and external crates.
43-
//! - `feedable`: Allow the query result to be set from another query ("fed" externally).
44-
//! - `return_result_from_ensure_ok`: When called via `tcx.ensure_ok()`, return `Result<(), ErrorGuaranteed>` instead of `()`.
45-
//! If the query needs to be executed and returns an error, the error is returned to the caller.
46-
//! Only valid for queries returning `Result<_, ErrorGuaranteed>`.
27+
//! For the list of modifiers, see
28+
//! [`rustc_middle/src/query/modifiers.rs`](https://github.com/rust-lang/rust/blob/HEAD/compiler/rustc_middle/src/query/modifiers.rs).
4729
//!
48-
//! For the up-to-date list, see the `QueryModifiers` struct in
49-
//! [`rustc_macros/src/query.rs`](https://github.com/rust-lang/rust/blob/HEAD/compiler/rustc_macros/src/query.rs)
50-
//! and for more details in incremental compilation, see the
30+
//! For more details on incremental compilation, see the
5131
//! [Query modifiers in incremental compilation](https://rustc-dev-guide.rust-lang.org/queries/incremental-compilation-in-detail.html#query-modifiers) section of the rustc-dev-guide.
5232
//!
5333
//! ## Query Expansion and Code Generation

compiler/rustc_middle/src/query/modifiers.rs

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,53 +4,66 @@
44
//! modifier names in the query list, and to allow find-all-references to list
55
//! all queries that use a particular modifier.
66
#![allow(unused, non_camel_case_types)]
7-
// FIXME: Update and clarify documentation for these modifiers.
87

98
// tidy-alphabetical-start
109
//
1110
/// # `anon` query modifier
1211
///
13-
/// Generate a dep node based on the dependencies of the query
12+
/// Generate a dep node based not on the query key, but on the query's dependencies.
1413
pub(crate) struct anon;
1514

1615
/// # `arena_cache` query modifier
1716
///
18-
/// Use this type for the in-memory cache.
17+
/// Query return values must impl `Copy` and be small, but some queries must return values that
18+
/// doesn't meet those criteria. Queries marked with this modifier have their values allocated in
19+
/// an arena and the query returns a reference to the value. There are two cases.
20+
/// - If the provider function returns `T` then the query will return `&'tcx T`.
21+
/// - If the provider function returns `Option<T>` then the query will return `Option<&'tcx T>`.
22+
///
23+
/// The query plumbing takes care of the arenas and the type manipulations.
1924
pub(crate) struct arena_cache;
2025

21-
/// # `cache_on_disk_if` query modifier
26+
/// # `cache_on_disk_if { ... }` query modifier
27+
///
28+
/// Cache the query result to disk if the provided block evaluates to true. The query key
29+
/// identifier is available for use within the block, as is `tcx`.
2230
///
23-
/// Cache the query to disk if the `Block` returns true.
31+
/// The decision to use this modifier comes down to whether it helps performance. Not all query
32+
/// results need to be saved to disk. In particular, caching values from upstream crates is
33+
/// pointless because they are already available in the upstream crate’s metadata.
2434
pub(crate) struct cache_on_disk_if;
2535

2636
/// # `cycle_delayed_bug` query modifier
2737
///
2838
/// A cycle error results in a delay_bug call
39+
/// If a dependency cycle is detected, emit a delayed bug instead of a normal error.
2940
pub(crate) struct cycle_delayed_bug;
3041

3142
/// # `cycle_fatal` query modifier
3243
///
33-
/// A cycle error for this query aborting the compilation with a fatal error.
44+
/// If a dependency cycle for this query is detected, abort compilation with a fatal error.
3445
pub(crate) struct cycle_fatal;
3546

3647
/// # `cycle_stash` query modifier
3748
///
38-
/// A cycle error results in a stashed cycle error that can be unstashed and canceled later
49+
/// If a dependency cycle is detected, stash the error for later handling.
3950
pub(crate) struct cycle_stash;
4051

4152
/// # `depth_limit` query modifier
4253
///
43-
/// Whether the query has a call depth limit
54+
/// Impose a recursion call depth limit on the query to prevent stack overflow.
4455
pub(crate) struct depth_limit;
4556

46-
/// # `desc` query modifier
57+
/// # `desc { ... }` query modifier
4758
///
48-
/// The description of the query. This modifier is required on every query.
59+
/// The human-readable description of the query, for diagnostics and profiling. Required for every
60+
/// query. The block should contain a `format!`-style string literal followed by optional
61+
/// arguments. The query key identifier is available for use within the block, as is `tcx`.
4962
pub(crate) struct desc;
5063

5164
/// # `eval_always` query modifier
5265
///
53-
/// Always evaluate the query, ignoring its dependencies
66+
/// Always evaluate the query, ignoring its dependencies and cached results.
5467
pub(crate) struct eval_always;
5568

5669
/// # `feedable` query modifier
@@ -60,7 +73,7 @@ pub(crate) struct feedable;
6073

6174
/// # `no_hash` query modifier
6275
///
63-
/// Don't hash the result, instead just mark a query red if it runs
76+
/// Do not hash the query result for incremental compilation; just mark it as dirty if recomputed.
6477
pub(crate) struct no_hash;
6578

6679
/// # `return_result_from_ensure_ok` query modifier
@@ -79,7 +92,7 @@ pub(crate) struct return_result_from_ensure_ok;
7992

8093
/// # `separate_provide_extern` query modifier
8194
///
82-
/// Use a separate query provider for local and extern crates
95+
/// Use separate query provider functions for local and extern crates.
8396
pub(crate) struct separate_provide_extern;
8497

8598
// tidy-alphabetical-end

0 commit comments

Comments
 (0)