Skip to content

Commit 7ad5c60

Browse files
committed
Auto merge of #153805 - Zalathar:rollup-rfXICNX, r=Zalathar
Rollup of 5 pull requests Successful merges: - #152258 (fixed VecDeque::splice() not filling the buffer correctly when resizing the buffer on start = end range) - #153691 (Miscellaneous tweaks) - #153766 (`try_execute_query` tweaks) - #153188 (implementation of `-Z min-recursion-limit`) - #153428 (Avoid duplicated query modifier comments.)
2 parents 4efe3dc + 8669e0c commit 7ad5c60

20 files changed

Lines changed: 286 additions & 133 deletions

File tree

compiler/rustc_driver_impl/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -353,16 +353,16 @@ pub fn run_compiler(at_args: &[String], callbacks: &mut (dyn Callbacks + Send))
353353
})
354354
}
355355

356-
fn dump_feature_usage_metrics(tcxt: TyCtxt<'_>, metrics_dir: &Path) {
357-
let hash = tcxt.crate_hash(LOCAL_CRATE);
358-
let crate_name = tcxt.crate_name(LOCAL_CRATE);
356+
fn dump_feature_usage_metrics(tcx: TyCtxt<'_>, metrics_dir: &Path) {
357+
let hash = tcx.crate_hash(LOCAL_CRATE);
358+
let crate_name = tcx.crate_name(LOCAL_CRATE);
359359
let metrics_file_name = format!("unstable_feature_usage_metrics-{crate_name}-{hash}.json");
360360
let metrics_path = metrics_dir.join(metrics_file_name);
361-
if let Err(error) = tcxt.features().dump_feature_usage_metrics(metrics_path) {
361+
if let Err(error) = tcx.features().dump_feature_usage_metrics(metrics_path) {
362362
// FIXME(yaahc): once metrics can be enabled by default we will want "failure to emit
363363
// default metrics" to only produce a warning when metrics are enabled by default and emit
364364
// an error only when the user manually enables metrics
365-
tcxt.dcx().emit_err(UnstableFeatureUsage { error });
365+
tcx.dcx().emit_err(UnstableFeatureUsage { error });
366366
}
367367
}
368368

compiler/rustc_interface/src/limits.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
use rustc_hir::limit::Limit;
1212
use rustc_hir::{Attribute, find_attr};
1313
use rustc_middle::query::Providers;
14-
use rustc_session::Limits;
14+
use rustc_session::{Limits, Session};
1515

1616
pub(crate) fn provide(providers: &mut Providers) {
1717
providers.limits = |tcx, ()| {
1818
let attrs = tcx.hir_krate_attrs();
1919
Limits {
20-
recursion_limit: get_recursion_limit(tcx.hir_krate_attrs()),
20+
recursion_limit: get_recursion_limit(tcx.hir_krate_attrs(), tcx.sess),
2121
move_size_limit: find_attr!(attrs, MoveSizeLimit { limit, .. } => *limit)
2222
.unwrap_or(Limit::new(tcx.sess.opts.unstable_opts.move_size_limit.unwrap_or(0))),
2323
type_length_limit: find_attr!(attrs, TypeLengthLimit { limit, .. } => *limit)
@@ -30,6 +30,13 @@ pub(crate) fn provide(providers: &mut Providers) {
3030
}
3131

3232
// This one is separate because it must be read prior to macro expansion.
33-
pub(crate) fn get_recursion_limit(attrs: &[Attribute]) -> Limit {
34-
find_attr!(attrs, RecursionLimit { limit, .. } => *limit).unwrap_or(Limit::new(128))
33+
pub(crate) fn get_recursion_limit(attrs: &[Attribute], sess: &Session) -> Limit {
34+
let limit_from_crate =
35+
find_attr!(attrs, RecursionLimit { limit, .. } => limit.0).unwrap_or(128);
36+
Limit::new(
37+
sess.opts
38+
.unstable_opts
39+
.min_recursion_limit
40+
.map_or(limit_from_crate, |min| min.max(limit_from_crate)),
41+
)
3542
}

compiler/rustc_interface/src/passes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1429,5 +1429,5 @@ fn get_recursion_limit(krate_attrs: &[ast::Attribute], sess: &Session) -> Limit
14291429
// So, no lints here to avoid duplicates.
14301430
ShouldEmit::EarlyFatal { also_emit_lints: false },
14311431
);
1432-
crate::limits::get_recursion_limit(attr.as_slice())
1432+
crate::limits::get_recursion_limit(attr.as_slice(), sess)
14331433
}

compiler/rustc_interface/src/tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,7 @@ fn test_unstable_options_tracking_hash() {
822822
tracked!(maximal_hir_to_mir_coverage, true);
823823
tracked!(merge_functions, Some(MergeFunctions::Disabled));
824824
tracked!(min_function_alignment, Some(Align::EIGHT));
825+
tracked!(min_recursion_limit, Some(256));
825826
tracked!(mir_emit_retag, true);
826827
tracked!(mir_enable_passes, vec![("DestProp".to_string(), false)]);
827828
tracked!(mir_opt_level, Some(4));

compiler/rustc_middle/src/dep_graph/graph.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ impl DepGraph {
292292

293293
pub fn with_anon_task<'tcx, OP, R>(
294294
&self,
295-
cx: TyCtxt<'tcx>,
295+
tcx: TyCtxt<'tcx>,
296296
dep_kind: DepKind,
297297
op: OP,
298298
) -> (R, DepNodeIndex)
@@ -301,7 +301,7 @@ impl DepGraph {
301301
{
302302
match self.data() {
303303
Some(data) => {
304-
let (result, index) = data.with_anon_task_inner(cx, dep_kind, op);
304+
let (result, index) = data.with_anon_task_inner(tcx, dep_kind, op);
305305
self.read_index(index);
306306
(result, index)
307307
}
@@ -379,14 +379,14 @@ impl DepGraphData {
379379
/// how to make that work with `anon` in `execute_job_incr`, though.
380380
pub fn with_anon_task_inner<'tcx, OP, R>(
381381
&self,
382-
cx: TyCtxt<'tcx>,
382+
tcx: TyCtxt<'tcx>,
383383
dep_kind: DepKind,
384384
op: OP,
385385
) -> (R, DepNodeIndex)
386386
where
387387
OP: FnOnce() -> R,
388388
{
389-
debug_assert!(!cx.is_eval_always(dep_kind));
389+
debug_assert!(!tcx.is_eval_always(dep_kind));
390390

391391
// Large numbers of reads are common enough here that pre-sizing `read_set`
392392
// to 128 actually helps perf on some benchmarks.
@@ -865,7 +865,7 @@ impl DepGraph {
865865
dep_node_debug.borrow_mut().insert(dep_node, debug_str);
866866
}
867867

868-
pub fn dep_node_debug_str(&self, dep_node: DepNode) -> Option<String> {
868+
pub(crate) fn dep_node_debug_str(&self, dep_node: DepNode) -> Option<String> {
869869
self.data.as_ref()?.dep_node_debug.borrow().get(&dep_node).cloned()
870870
}
871871

@@ -1103,7 +1103,7 @@ impl DepGraph {
11031103
}
11041104
}
11051105

1106-
pub fn finish_encoding(&self) -> FileEncodeResult {
1106+
pub(crate) fn finish_encoding(&self) -> FileEncodeResult {
11071107
if let Some(data) = &self.data { data.current.encoder.finish(&data.current) } else { Ok(0) }
11081108
}
11091109

compiler/rustc_middle/src/queries.rs

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,10 @@
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_delay_bug`: If a dependency cycle is detected, emit a delayed bug instead of aborting immediately.
36-
//! - `no_hash`: Do not hash the query result for incremental compilation; just mark as dirty if recomputed.
37-
//! - `anon`: Make the query anonymous in the dependency graph (no dep node is created).
38-
//! - `eval_always`: Always evaluate the query, ignoring its dependencies and cached results.
39-
//! - `depth_limit`: Impose a recursion depth limit on the query to prevent stack overflows.
40-
//! - `separate_provide_extern`: Use separate provider functions for local and external crates.
41-
//! - `feedable`: Allow the query result to be set from another query ("fed" externally).
27+
//! For the list of modifiers, see [`rustc_middle::query::modifiers`].
4228
//!
43-
//! For the up-to-date list, see the `QueryModifiers` struct in
44-
//! [`rustc_macros/src/query.rs`](https://github.com/rust-lang/rust/blob/HEAD/compiler/rustc_macros/src/query.rs)
45-
//! and for more details in incremental compilation, see the
29+
//! For more details on incremental compilation, see the
4630
//! [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.
4731
//!
4832
//! ## Query Expansion and Code Generation

compiler/rustc_middle/src/query/erase.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use rustc_span::{ErrorGuaranteed, Spanned};
1515
use crate::mir::interpret::EvalToValTreeResult;
1616
use crate::mir::mono::{MonoItem, NormalizationErrorInMono};
1717
use crate::traits::solve;
18-
use crate::ty::adjustment::CoerceUnsizedInfo;
1918
use crate::ty::{self, Ty, TyCtxt};
2019
use crate::{mir, traits};
2120

@@ -160,10 +159,6 @@ impl Erasable for Result<Option<ty::Instance<'_>>, rustc_errors::ErrorGuaranteed
160159
[u8; size_of::<Result<Option<ty::Instance<'static>>, rustc_errors::ErrorGuaranteed>>()];
161160
}
162161

163-
impl Erasable for Result<CoerceUnsizedInfo, rustc_errors::ErrorGuaranteed> {
164-
type Storage = [u8; size_of::<Result<CoerceUnsizedInfo, rustc_errors::ErrorGuaranteed>>()];
165-
}
166-
167162
impl Erasable
168163
for Result<Option<ty::EarlyBinder<'_, ty::Const<'_>>>, rustc_errors::ErrorGuaranteed>
169164
{
@@ -194,10 +189,6 @@ impl Erasable for Result<mir::ConstAlloc<'_>, mir::interpret::ErrorHandled> {
194189
[u8; size_of::<Result<mir::ConstAlloc<'static>, mir::interpret::ErrorHandled>>()];
195190
}
196191

197-
impl Erasable for Result<mir::ConstValue, mir::interpret::ErrorHandled> {
198-
type Storage = [u8; size_of::<Result<mir::ConstValue, mir::interpret::ErrorHandled>>()];
199-
}
200-
201192
impl Erasable for Option<(mir::ConstValue, Ty<'_>)> {
202193
type Storage = [u8; size_of::<Option<(mir::ConstValue, Ty<'_>)>>()];
203194
}
@@ -337,6 +328,8 @@ impl_erasable_for_simple_types! {
337328
Result<(), rustc_errors::ErrorGuaranteed>,
338329
Result<(), rustc_middle::traits::query::NoSolution>,
339330
Result<rustc_middle::traits::EvaluationResult, rustc_middle::traits::OverflowError>,
331+
Result<rustc_middle::ty::adjustment::CoerceUnsizedInfo, rustc_errors::ErrorGuaranteed>,
332+
Result<mir::ConstValue, mir::interpret::ErrorHandled>,
340333
rustc_abi::ReprOptions,
341334
rustc_ast::expand::allocator::AllocatorKind,
342335
rustc_hir::DefaultBodyStability,

compiler/rustc_middle/src/query/modifiers.rs

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,59 @@
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
2227
///
23-
/// Cache the query to disk if the `Block` returns true.
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`.
2430
pub(crate) struct cache_on_disk_if;
2531

2632
/// # `cycle_delay_bug` query modifier
2733
///
28-
/// A cycle error results in a delay_bug call
34+
/// If a dependency cycle is detected, emit a delayed bug instead of a normal error.
2935
pub(crate) struct cycle_delay_bug;
3036

3137
/// # `depth_limit` query modifier
3238
///
33-
/// Whether the query has a call depth limit
39+
/// Impose a recursion call depth limit on the query to prevent stack overflow.
3440
pub(crate) struct depth_limit;
3541

36-
/// # `desc` query modifier
42+
/// # `desc { ... }` query modifier
3743
///
38-
/// The description of the query. This modifier is required on every query.
44+
/// The human-readable description of the query, for diagnostics and profiling. Required for every
45+
/// query. The block should contain a `format!`-style string literal followed by optional
46+
/// arguments. The query key identifier is available for use within the block, as is `tcx`.
3947
pub(crate) struct desc;
4048

4149
/// # `eval_always` query modifier
4250
///
43-
/// Always evaluate the query, ignoring its dependencies
51+
/// Queries with this modifier do not track their dependencies, and are treated as always having a
52+
/// red (dirty) dependency instead. This is necessary for queries that interact with state that
53+
/// isn't tracked by the query system.
54+
///
55+
/// It can also improve performance for queries that are so likely to be dirtied by any change that
56+
/// it's not worth tracking their actual dependencies at all.
57+
///
58+
/// As with all queries, the return value is still cached in memory for the rest of the compiler
59+
/// session.
4460
pub(crate) struct eval_always;
4561

4662
/// # `feedable` query modifier
@@ -50,12 +66,13 @@ pub(crate) struct feedable;
5066

5167
/// # `no_hash` query modifier
5268
///
53-
/// Don't hash the result, instead just mark a query red if it runs
69+
/// Do not hash the query's return value for incremental compilation. If the value needs to be
70+
/// recomputed, always mark its node as red (dirty).
5471
pub(crate) struct no_hash;
5572

5673
/// # `separate_provide_extern` query modifier
5774
///
58-
/// Use a separate query provider for local and extern crates
75+
/// Use separate query provider functions for local and extern crates.
5976
pub(crate) struct separate_provide_extern;
6077

6178
// tidy-alphabetical-end

compiler/rustc_middle/src/query/plumbing.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,6 @@ macro_rules! define_callbacks {
322322
non_queries { $($_:tt)* }
323323
) => {
324324
$(
325-
#[allow(unused_lifetimes)]
326325
pub mod $name {
327326
use super::*;
328327
use $crate::query::erase::{self, Erased};

0 commit comments

Comments
 (0)