Rollup merge of #83519 - oli-obk:assign_shrink_your_normal_code, r=pnkfelix
Implement a lint that highlights all moves larger than a configured limit Tracking issue: #83518 [MCP 420](https://github.com/rust-lang/compiler-team/issues/420) still ~blazing~ in progress r? ```@pnkfelix``` The main open issue I see with this minimal impl of the feature is that the lint is immediately "stable" (so it can be named on stable), even if it is never executed on stable. I don't think we have the concept of unstable lint names or hiding lint names without an active feature gate, so that would be a bigger change.
This commit is contained in:
commit
e109aa3613
13 changed files with 218 additions and 21 deletions
|
@ -1,4 +1,8 @@
|
|||
//! Registering limits, recursion_limit, type_length_limit and const_eval_limit
|
||||
//! Registering limits:
|
||||
//! * recursion_limit,
|
||||
//! * move_size_limit,
|
||||
//! * type_length_limit, and
|
||||
//! * const_eval_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
|
||||
|
@ -8,13 +12,14 @@
|
|||
use crate::bug;
|
||||
use rustc_ast as ast;
|
||||
use rustc_data_structures::sync::OnceCell;
|
||||
use rustc_session::{Limit, Session};
|
||||
use rustc_session::Session;
|
||||
use rustc_span::symbol::{sym, Symbol};
|
||||
|
||||
use std::num::IntErrorKind;
|
||||
|
||||
pub fn update_limits(sess: &Session, krate: &ast::Crate) {
|
||||
update_limit(sess, krate, &sess.recursion_limit, sym::recursion_limit, 128);
|
||||
update_limit(sess, krate, &sess.move_size_limit, sym::move_size_limit, 0);
|
||||
update_limit(sess, krate, &sess.type_length_limit, sym::type_length_limit, 1048576);
|
||||
update_limit(sess, krate, &sess.const_eval_limit, sym::const_eval_limit, 1_000_000);
|
||||
}
|
||||
|
@ -22,7 +27,7 @@ pub fn update_limits(sess: &Session, krate: &ast::Crate) {
|
|||
fn update_limit(
|
||||
sess: &Session,
|
||||
krate: &ast::Crate,
|
||||
limit: &OnceCell<Limit>,
|
||||
limit: &OnceCell<impl From<usize> + std::fmt::Debug>,
|
||||
name: Symbol,
|
||||
default: usize,
|
||||
) {
|
||||
|
@ -34,7 +39,7 @@ fn update_limit(
|
|||
if let Some(s) = attr.value_str() {
|
||||
match s.as_str().parse() {
|
||||
Ok(n) => {
|
||||
limit.set(Limit::new(n)).unwrap();
|
||||
limit.set(From::from(n)).unwrap();
|
||||
return;
|
||||
}
|
||||
Err(e) => {
|
||||
|
@ -63,5 +68,5 @@ fn update_limit(
|
|||
}
|
||||
}
|
||||
}
|
||||
limit.set(Limit::new(default)).unwrap();
|
||||
limit.set(From::from(default)).unwrap();
|
||||
}
|
||||
|
|
|
@ -12,10 +12,10 @@ use crate::ty::print::{FmtPrinter, Printer};
|
|||
use crate::ty::subst::{Subst, SubstsRef};
|
||||
use crate::ty::{self, List, Ty, TyCtxt};
|
||||
use crate::ty::{AdtDef, InstanceDef, Region, ScalarInt, UserTypeAnnotationIndex};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::{CtorKind, Namespace};
|
||||
use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX};
|
||||
use rustc_hir::{self, GeneratorKind};
|
||||
use rustc_hir::{self as hir, HirId};
|
||||
use rustc_target::abi::{Size, VariantIdx};
|
||||
|
||||
use polonius_engine::Atom;
|
||||
|
@ -1948,6 +1948,29 @@ rustc_index::newtype_index! {
|
|||
}
|
||||
}
|
||||
|
||||
impl SourceScope {
|
||||
/// Finds the original HirId this MIR item came from.
|
||||
/// This is necessary after MIR optimizations, as otherwise we get a HirId
|
||||
/// from the function that was inlined instead of the function call site.
|
||||
pub fn lint_root(
|
||||
self,
|
||||
source_scopes: &IndexVec<SourceScope, SourceScopeData<'tcx>>,
|
||||
) -> Option<HirId> {
|
||||
let mut data = &source_scopes[self];
|
||||
// FIXME(oli-obk): we should be able to just walk the `inlined_parent_scope`, but it
|
||||
// does not work as I thought it would. Needs more investigation and documentation.
|
||||
while data.inlined.is_some() {
|
||||
trace!(?data);
|
||||
data = &source_scopes[data.parent_scope.unwrap()];
|
||||
}
|
||||
trace!(?data);
|
||||
match &data.local_data {
|
||||
ClearCrossCrate::Set(data) => Some(data.lint_root),
|
||||
ClearCrossCrate::Clear => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable, TypeFoldable)]
|
||||
pub struct SourceScopeData<'tcx> {
|
||||
pub span: Span,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue