Skip to content
Merged
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
10 changes: 5 additions & 5 deletions compiler/rustc_driver_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,16 +353,16 @@ pub fn run_compiler(at_args: &[String], callbacks: &mut (dyn Callbacks + Send))
})
}

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

Expand Down
15 changes: 11 additions & 4 deletions compiler/rustc_interface/src/limits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
use rustc_hir::limit::Limit;
use rustc_hir::{Attribute, find_attr};
use rustc_middle::query::Providers;
use rustc_session::Limits;
use rustc_session::{Limits, Session};

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

// This one is separate because it must be read prior to macro expansion.
pub(crate) fn get_recursion_limit(attrs: &[Attribute]) -> Limit {
find_attr!(attrs, RecursionLimit { limit, .. } => *limit).unwrap_or(Limit::new(128))
pub(crate) fn get_recursion_limit(attrs: &[Attribute], sess: &Session) -> Limit {
let limit_from_crate =
find_attr!(attrs, RecursionLimit { limit, .. } => limit.0).unwrap_or(128);
Limit::new(
sess.opts
.unstable_opts
.min_recursion_limit
.map_or(limit_from_crate, |min| min.max(limit_from_crate)),
)
}
2 changes: 1 addition & 1 deletion compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1429,5 +1429,5 @@ fn get_recursion_limit(krate_attrs: &[ast::Attribute], sess: &Session) -> Limit
// So, no lints here to avoid duplicates.
ShouldEmit::EarlyFatal { also_emit_lints: false },
);
crate::limits::get_recursion_limit(attr.as_slice())
crate::limits::get_recursion_limit(attr.as_slice(), sess)
}
1 change: 1 addition & 0 deletions compiler/rustc_interface/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,7 @@ fn test_unstable_options_tracking_hash() {
tracked!(maximal_hir_to_mir_coverage, true);
tracked!(merge_functions, Some(MergeFunctions::Disabled));
tracked!(min_function_alignment, Some(Align::EIGHT));
tracked!(min_recursion_limit, Some(256));
tracked!(mir_emit_retag, true);
tracked!(mir_enable_passes, vec![("DestProp".to_string(), false)]);
tracked!(mir_opt_level, Some(4));
Expand Down
12 changes: 6 additions & 6 deletions compiler/rustc_middle/src/dep_graph/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ impl DepGraph {

pub fn with_anon_task<'tcx, OP, R>(
&self,
cx: TyCtxt<'tcx>,
tcx: TyCtxt<'tcx>,
dep_kind: DepKind,
op: OP,
) -> (R, DepNodeIndex)
Expand All @@ -301,7 +301,7 @@ impl DepGraph {
{
match self.data() {
Some(data) => {
let (result, index) = data.with_anon_task_inner(cx, dep_kind, op);
let (result, index) = data.with_anon_task_inner(tcx, dep_kind, op);
self.read_index(index);
(result, index)
}
Expand Down Expand Up @@ -379,14 +379,14 @@ impl DepGraphData {
/// how to make that work with `anon` in `execute_job_incr`, though.
pub fn with_anon_task_inner<'tcx, OP, R>(
&self,
cx: TyCtxt<'tcx>,
tcx: TyCtxt<'tcx>,
dep_kind: DepKind,
op: OP,
) -> (R, DepNodeIndex)
where
OP: FnOnce() -> R,
{
debug_assert!(!cx.is_eval_always(dep_kind));
debug_assert!(!tcx.is_eval_always(dep_kind));

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

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

Expand Down Expand Up @@ -1103,7 +1103,7 @@ impl DepGraph {
}
}

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

Expand Down
20 changes: 2 additions & 18 deletions compiler/rustc_middle/src/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,10 @@
//! ## Query Modifiers
//!
//! Query modifiers are special flags that alter the behavior of a query. They are parsed and processed by the `rustc_macros`
//! The main modifiers are:
//!
//! - `desc { ... }`: Sets the human-readable description for diagnostics and profiling. Required
//! for every query. The block should contain a `format!`-style string literal followed by
//! optional arguments. The query key identifier is available for use within the block, as is
//! `tcx`.
//! - `arena_cache`: Use an arena for in-memory caching of the query result.
//! - `cache_on_disk_if { ... }`: Cache the query result to disk if the provided block evaluates to
//! true. The query key identifier is available for use within the block, as is `tcx`.
//! - `cycle_delay_bug`: If a dependency cycle is detected, emit a delayed bug instead of aborting immediately.
//! - `no_hash`: Do not hash the query result for incremental compilation; just mark as dirty if recomputed.
//! - `anon`: Make the query anonymous in the dependency graph (no dep node is created).
//! - `eval_always`: Always evaluate the query, ignoring its dependencies and cached results.
//! - `depth_limit`: Impose a recursion depth limit on the query to prevent stack overflows.
//! - `separate_provide_extern`: Use separate provider functions for local and external crates.
//! - `feedable`: Allow the query result to be set from another query ("fed" externally).
//! For the list of modifiers, see [`rustc_middle::query::modifiers`].
//!
//! For the up-to-date list, see the `QueryModifiers` struct in
//! [`rustc_macros/src/query.rs`](https://github.com/rust-lang/rust/blob/HEAD/compiler/rustc_macros/src/query.rs)
//! and for more details in incremental compilation, see the
//! For more details on incremental compilation, see the
//! [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.
//!
//! ## Query Expansion and Code Generation
Expand Down
11 changes: 2 additions & 9 deletions compiler/rustc_middle/src/query/erase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use rustc_span::{ErrorGuaranteed, Spanned};
use crate::mir::interpret::EvalToValTreeResult;
use crate::mir::mono::{MonoItem, NormalizationErrorInMono};
use crate::traits::solve;
use crate::ty::adjustment::CoerceUnsizedInfo;
use crate::ty::{self, Ty, TyCtxt};
use crate::{mir, traits};

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

impl Erasable for Result<CoerceUnsizedInfo, rustc_errors::ErrorGuaranteed> {
type Storage = [u8; size_of::<Result<CoerceUnsizedInfo, rustc_errors::ErrorGuaranteed>>()];
}

impl Erasable
for Result<Option<ty::EarlyBinder<'_, ty::Const<'_>>>, rustc_errors::ErrorGuaranteed>
{
Expand Down Expand Up @@ -194,10 +189,6 @@ impl Erasable for Result<mir::ConstAlloc<'_>, mir::interpret::ErrorHandled> {
[u8; size_of::<Result<mir::ConstAlloc<'static>, mir::interpret::ErrorHandled>>()];
}

impl Erasable for Result<mir::ConstValue, mir::interpret::ErrorHandled> {
type Storage = [u8; size_of::<Result<mir::ConstValue, mir::interpret::ErrorHandled>>()];
}

impl Erasable for Option<(mir::ConstValue, Ty<'_>)> {
type Storage = [u8; size_of::<Option<(mir::ConstValue, Ty<'_>)>>()];
}
Expand Down Expand Up @@ -337,6 +328,8 @@ impl_erasable_for_simple_types! {
Result<(), rustc_errors::ErrorGuaranteed>,
Result<(), rustc_middle::traits::query::NoSolution>,
Result<rustc_middle::traits::EvaluationResult, rustc_middle::traits::OverflowError>,
Result<rustc_middle::ty::adjustment::CoerceUnsizedInfo, rustc_errors::ErrorGuaranteed>,
Result<mir::ConstValue, mir::interpret::ErrorHandled>,
rustc_abi::ReprOptions,
rustc_ast::expand::allocator::AllocatorKind,
rustc_hir::DefaultBodyStability,
Expand Down
41 changes: 29 additions & 12 deletions compiler/rustc_middle/src/query/modifiers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,59 @@
//! modifier names in the query list, and to allow find-all-references to list
//! all queries that use a particular modifier.
#![allow(unused, non_camel_case_types)]
// FIXME: Update and clarify documentation for these modifiers.

// tidy-alphabetical-start
//
/// # `anon` query modifier
///
/// Generate a dep node based on the dependencies of the query
/// Generate a dep node based not on the query key, but on the query's dependencies.
pub(crate) struct anon;

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

/// # `cache_on_disk_if` query modifier
/// # `cache_on_disk_if { ... }` query modifier
///
/// Cache the query to disk if the `Block` returns true.
/// Cache the query result to disk if the provided block evaluates to true. The query key
/// identifier is available for use within the block, as is `tcx`.
pub(crate) struct cache_on_disk_if;

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

/// # `depth_limit` query modifier
///
/// Whether the query has a call depth limit
/// Impose a recursion call depth limit on the query to prevent stack overflow.
pub(crate) struct depth_limit;

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

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

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

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

/// # `separate_provide_extern` query modifier
///
/// Use a separate query provider for local and extern crates
/// Use separate query provider functions for local and extern crates.
pub(crate) struct separate_provide_extern;

// tidy-alphabetical-end
1 change: 0 additions & 1 deletion compiler/rustc_middle/src/query/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,6 @@ macro_rules! define_callbacks {
non_queries { $($_:tt)* }
) => {
$(
#[allow(unused_lifetimes)]
pub mod $name {
use super::*;
use $crate::query::erase::{self, Erased};
Expand Down
Loading
Loading