Rollup merge of #136671 - nnethercote:middle-limits, r=Nadrieril
Overhaul `rustc_middle::limits` In particular, to make `pattern_complexity` work more like other limits, which then enables some other simplifications. r? ``@Nadrieril``
This commit is contained in:
commit
0c051c8196
28 changed files with 100 additions and 97 deletions
|
@ -81,10 +81,6 @@ middle_failed_writing_file =
|
|||
middle_layout_references_error =
|
||||
the type has an unknown layout
|
||||
|
||||
middle_limit_invalid =
|
||||
`limit` must be a non-negative integer
|
||||
.label = {$error_str}
|
||||
|
||||
middle_opaque_hidden_type_mismatch =
|
||||
concrete type differs from previous defining opaque type use
|
||||
.label = expected `{$self_ty}`, got `{$other_ty}`
|
||||
|
|
|
@ -67,16 +67,6 @@ pub enum TypeMismatchReason {
|
|||
},
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(middle_limit_invalid)]
|
||||
pub(crate) struct LimitInvalid<'a> {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
#[label]
|
||||
pub value_span: Span,
|
||||
pub error_str: &'a str,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(middle_recursion_limit_reached)]
|
||||
#[help]
|
||||
|
|
|
@ -1,88 +0,0 @@
|
|||
//! Registering limits:
|
||||
//! * recursion_limit,
|
||||
//! * move_size_limit, and
|
||||
//! * type_length_limit
|
||||
//!
|
||||
//! There are various parts of the compiler that must impose arbitrary limits
|
||||
//! on how deeply they recurse to prevent stack overflow. Users can override
|
||||
//! this via an attribute on the crate like `#![recursion_limit="22"]`. This pass
|
||||
//! just peeks and looks for that attribute.
|
||||
|
||||
use std::num::IntErrorKind;
|
||||
|
||||
use rustc_ast::attr::AttributeExt;
|
||||
use rustc_session::{Limit, Limits, Session};
|
||||
use rustc_span::{Symbol, sym};
|
||||
|
||||
use crate::error::LimitInvalid;
|
||||
use crate::query::Providers;
|
||||
|
||||
pub fn provide(providers: &mut Providers) {
|
||||
providers.limits = |tcx, ()| Limits {
|
||||
recursion_limit: get_recursion_limit(tcx.hir().krate_attrs(), tcx.sess),
|
||||
move_size_limit: get_limit(
|
||||
tcx.hir().krate_attrs(),
|
||||
tcx.sess,
|
||||
sym::move_size_limit,
|
||||
tcx.sess.opts.unstable_opts.move_size_limit.unwrap_or(0),
|
||||
),
|
||||
type_length_limit: get_limit(
|
||||
tcx.hir().krate_attrs(),
|
||||
tcx.sess,
|
||||
sym::type_length_limit,
|
||||
2usize.pow(24),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_recursion_limit(krate_attrs: &[impl AttributeExt], sess: &Session) -> Limit {
|
||||
get_limit(krate_attrs, sess, sym::recursion_limit, 128)
|
||||
}
|
||||
|
||||
fn get_limit(
|
||||
krate_attrs: &[impl AttributeExt],
|
||||
sess: &Session,
|
||||
name: Symbol,
|
||||
default: usize,
|
||||
) -> Limit {
|
||||
match get_limit_size(krate_attrs, sess, name) {
|
||||
Some(size) => Limit::new(size),
|
||||
None => Limit::new(default),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_limit_size(
|
||||
krate_attrs: &[impl AttributeExt],
|
||||
sess: &Session,
|
||||
name: Symbol,
|
||||
) -> Option<usize> {
|
||||
for attr in krate_attrs {
|
||||
if !attr.has_name(name) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if let Some(sym) = attr.value_str() {
|
||||
match sym.as_str().parse() {
|
||||
Ok(n) => return Some(n),
|
||||
Err(e) => {
|
||||
let error_str = match e.kind() {
|
||||
IntErrorKind::PosOverflow => "`limit` is too large",
|
||||
IntErrorKind::Empty => "`limit` must be a non-negative integer",
|
||||
IntErrorKind::InvalidDigit => "not a valid integer",
|
||||
IntErrorKind::NegOverflow => {
|
||||
bug!("`limit` should never negatively overflow")
|
||||
}
|
||||
IntErrorKind::Zero => bug!("zero is a valid `limit`"),
|
||||
kind => bug!("unimplemented IntErrorKind variant: {:?}", kind),
|
||||
};
|
||||
sess.dcx().emit_err(LimitInvalid {
|
||||
span: attr.span(),
|
||||
value_span: attr.value_span().unwrap(),
|
||||
error_str,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
|
@ -30,12 +30,7 @@ pub mod lib_features {
|
|||
}
|
||||
}
|
||||
}
|
||||
pub mod limits;
|
||||
pub mod privacy;
|
||||
pub mod region;
|
||||
pub mod resolve_bound_vars;
|
||||
pub mod stability;
|
||||
|
||||
pub fn provide(providers: &mut crate::query::Providers) {
|
||||
limits::provide(providers);
|
||||
}
|
||||
|
|
|
@ -2168,6 +2168,10 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
self.limits(()).move_size_limit
|
||||
}
|
||||
|
||||
pub fn pattern_complexity_limit(self) -> Limit {
|
||||
self.limits(()).pattern_complexity_limit
|
||||
}
|
||||
|
||||
/// All traits in the crate graph, including those not visible to the user.
|
||||
pub fn all_traits(self) -> impl Iterator<Item = DefId> + 'tcx {
|
||||
iter::once(LOCAL_CRATE)
|
||||
|
|
|
@ -2168,7 +2168,6 @@ pub fn provide(providers: &mut Providers) {
|
|||
util::provide(providers);
|
||||
print::provide(providers);
|
||||
super::util::bug::provide(providers);
|
||||
super::middle::provide(providers);
|
||||
*providers = Providers {
|
||||
trait_impls_of: trait_def::trait_impls_of_provider,
|
||||
incoherent_impls: trait_def::incoherent_impls_provider,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue