Skip to content

Commit

Permalink
Auto merge of rust-lang#115684 - Enselic:large_assignments-default, r…
Browse files Browse the repository at this point in the history
…=<try>

Set default `move_size_limit` to 4kB for `large_assignments` lint on nightly

Only enable it by default in the nightly compiler. The limit can be changed on a per-crate basis with:

    #![feature(large_assignments)]
    #![move_size_limit = "8192"]

or with

    -Zmove-size-limit=8192

Does the _"enable the lint by default with a 4k threshold"_ step in rust-lang#83518.

TODO:
 - [ ] Figure out how to write a test that tests that the stable compiler still has a default move_size_limit of 0. I suspect it is easy once you know the trick, but I haven't been able to figure out the trick yet.
 - [ ] I found a bug where the lint is duplicated unnecessarily when generic instantiations are involved. See FIXME in the test. We should file an issue about it so we don't forget it. Or at least write a row in the tracking issue.
 - [ ] The compiler seems very slow after this change. Might be tricky to fix..

r? `@oli-obk` who is E-mentor.
  • Loading branch information
bors committed Sep 11, 2023
2 parents 7d1e416 + 84f8c26 commit 9f87deb
Show file tree
Hide file tree
Showing 27 changed files with 213 additions and 20 deletions.
1 change: 1 addition & 0 deletions compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,7 @@ pub fn create_global_ctxt<'tcx>(

sess.time("setup_global_ctxt", || {
gcx_cell.get_or_init(move || {
#[allow(large_assignments)]
TyCtxt::create_global_ctxt(
sess,
crate_types,
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_interface/src/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ pub struct Queries<'tcx> {

impl<'tcx> Queries<'tcx> {
pub fn new(compiler: &'tcx Compiler) -> Queries<'tcx> {
#[allow(large_assignments)]
Queries {
compiler,
gcx_cell: OnceLock::new(),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_interface/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![allow(rustc::bad_opt_access)]
#![allow(rustc::bad_opt_access, large_assignments)]
use crate::interface::parse_cfgspecs;

use rustc_data_structures::fx::FxHashSet;
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_interface/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ pub fn create_session(
sess.parse_sess.config = cfg;
sess.parse_sess.check_config = check_cfg;

#[allow(large_assignments)]
(sess, codegen_backend)
}

Expand Down
10 changes: 9 additions & 1 deletion compiler/rustc_middle/src/middle/limits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,15 @@ pub fn provide(providers: &mut Providers) {
tcx.hir().krate_attrs(),
tcx.sess,
sym::move_size_limit,
tcx.sess.opts.unstable_opts.move_size_limit.unwrap_or(0),
// The check is enabled by default in nightly compilers without
// needing `#![feature(large_assignments)]` with a limit of 4096
// bytes. But if the user wants to use adjust `#![move_size_limit]`,
// then `#![feature(large_assignments)]` is needed.
tcx.sess.opts.unstable_opts.move_size_limit.unwrap_or(if tcx.sess.is_nightly_build() {
4096
} else {
0
}),
),
type_length_limit: get_limit(
tcx.hir().krate_attrs(),
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,7 @@ impl<'tcx> TyCtxt<'tcx> {
let common_lifetimes = CommonLifetimes::new(&interners);
let common_consts = CommonConsts::new(&interners, &common_types);

#[allow(large_assignments)]
GlobalCtxt {
sess: s,
crate_types,
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_query_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ pub fn query_system<'tcx>(
on_disk_cache: Option<OnDiskCache<'tcx>>,
incremental: bool,
) -> QuerySystem<'tcx> {
#[allow(large_assignments)]
QuerySystem {
states: Default::default(),
arenas: Default::default(),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_session/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1318,7 +1318,7 @@ fn default_emitter(
}

// JUSTIFICATION: literally session construction
#[allow(rustc::bad_opt_access)]
#[allow(rustc::bad_opt_access, large_assignments)]
pub fn build_session(
handler: &EarlyErrorHandler,
sopts: config::Options,
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_target/src/spec/apple/tests.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(large_assignments)]

use crate::spec::{
aarch64_apple_darwin, aarch64_apple_ios_sim, aarch64_apple_watchos_sim, i686_apple_darwin,
x86_64_apple_darwin, x86_64_apple_ios, x86_64_apple_tvos, x86_64_apple_watchos_sim,
Expand Down
2 changes: 2 additions & 0 deletions library/alloc/benches/vec_deque.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(large_assignments)]

use core::iter::Iterator;
use std::{
collections::{vec_deque, VecDeque},
Expand Down
1 change: 1 addition & 0 deletions library/alloc/src/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,7 @@ impl<T, A: Allocator> Box<mem::MaybeUninit<T>, A> {
///
/// ```
/// #![feature(new_uninit)]
/// #![allow(large_assignments)]
///
/// let big_box = Box::<[usize; 1024]>::new_uninit();
///
Expand Down
2 changes: 2 additions & 0 deletions library/core/benches/array.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(large_assignments)]

use test::black_box;
use test::Bencher;

Expand Down
2 changes: 2 additions & 0 deletions library/core/benches/iter.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(large_assignments)]

use core::borrow::Borrow;
use core::iter::*;
use core::mem;
Expand Down
1 change: 1 addition & 0 deletions library/core/src/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2042,6 +2042,7 @@ impl<T> UnsafeCell<T> {
#[rustc_const_stable(feature = "const_unsafe_cell_new", since = "1.32.0")]
#[inline(always)]
pub const fn new(value: T) -> UnsafeCell<T> {
#[allow(large_assignments)]
UnsafeCell { value }
}

Expand Down
1 change: 1 addition & 0 deletions library/core/src/convert/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,7 @@ where
/// <code>[From]&lt;T&gt; for U</code> chooses to do.
#[inline]
fn into(self) -> U {
#[allow(large_assignments)]
U::from(self)
}
}
Expand Down
1 change: 1 addition & 0 deletions library/core/src/hint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ pub fn spin_loop() {
#[stable(feature = "bench_black_box", since = "1.66.0")]
#[rustc_const_unstable(feature = "const_black_box", issue = "none")]
pub const fn black_box<T>(dummy: T) -> T {
#[allow(large_assignments)]
crate::intrinsics::black_box(dummy)
}

Expand Down
3 changes: 3 additions & 0 deletions library/core/src/mem/maybe_uninit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ use crate::slice;
/// unnecessary moves.
///
/// ```
/// ##![allow(large_assignments)]
/// use std::mem::MaybeUninit;
///
/// unsafe fn make_vec(out: *mut Vec<i32>) {
Expand All @@ -117,6 +118,7 @@ use crate::slice;
/// `MaybeUninit<T>` can be used to initialize a large array element-by-element:
///
/// ```
/// ##![allow(large_assignments)]
/// use std::mem::{self, MaybeUninit};
///
/// let data = {
Expand Down Expand Up @@ -145,6 +147,7 @@ use crate::slice;
/// be found in low-level datastructures.
///
/// ```
/// ##![allow(large_assignments)]
/// use std::mem::MaybeUninit;
///
/// // Create an uninitialized array of `MaybeUninit`. The `assume_init` is
Expand Down
50 changes: 49 additions & 1 deletion tests/ui/async-await/large_moves.attribute.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,60 @@ LL | let _ = NotBox::new([0; 9999]);
= note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`

error: moving 9999 bytes
--> $DIR/large_moves.rs:63:13
|
LL | data,
| ^^^^ value moved from here
|
= note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`

error: moving 1500 bytes
--> $DIR/large_moves.rs:37:13
|
LL | let _ = NotBox::new([0; 1500]);
| ^^^^^^^^^^^^^^^^^^^^^^ value moved from here
|
= note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`

error: moving 2500 bytes
--> $DIR/large_moves.rs:41:13
|
LL | let _ = NotBox::new([0; 2500]);
| ^^^^^^^^^^^^^^^^^^^^^^ value moved from here
|
= note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`

error: moving 5000 bytes
--> $DIR/large_moves.rs:47:13
|
LL | let _ = NotBox::new([0; 5000]);
| ^^^^^^^^^^^^^^^^^^^^^^ value moved from here
|
= note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`

error: moving 1500 bytes
--> $DIR/large_moves.rs:63:13
|
LL | data,
| ^^^^ value moved from here
|
= note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`

error: moving 2500 bytes
--> $DIR/large_moves.rs:63:13
|
LL | data,
| ^^^^ value moved from here
|
= note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`

error: moving 5000 bytes
--> $DIR/large_moves.rs:63:13
|
LL | data,
| ^^^^ value moved from here
|
= note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`

error: aborting due to 4 previous errors
error: aborting due to 10 previous errors

55 changes: 55 additions & 0 deletions tests/ui/async-await/large_moves.nothing.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
error: moving 10024 bytes
--> $DIR/large_moves.rs:21:14
|
LL | let z = (x, 42);
| ^ value moved from here
|
= note: The current maximum size is 4096, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`
note: the lint level is defined here
--> $DIR/large_moves.rs:1:9
|
LL | #![deny(large_assignments)]
| ^^^^^^^^^^^^^^^^^

error: moving 10024 bytes
--> $DIR/large_moves.rs:22:13
|
LL | let a = z.0;
| ^^^ value moved from here
|
= note: The current maximum size is 4096, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`

error: moving 9999 bytes
--> $DIR/large_moves.rs:27:13
|
LL | let _ = NotBox::new([0; 9999]);
| ^^^^^^^^^^^^^^^^^^^^^^ value moved from here
|
= note: The current maximum size is 4096, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`

error: moving 9999 bytes
--> $DIR/large_moves.rs:63:13
|
LL | data,
| ^^^^ value moved from here
|
= note: The current maximum size is 4096, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`

error: moving 5000 bytes
--> $DIR/large_moves.rs:47:13
|
LL | let _ = NotBox::new([0; 5000]);
| ^^^^^^^^^^^^^^^^^^^^^^ value moved from here
|
= note: The current maximum size is 4096, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`

error: moving 5000 bytes
--> $DIR/large_moves.rs:63:13
|
LL | data,
| ^^^^ value moved from here
|
= note: The current maximum size is 4096, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`

error: aborting due to 6 previous errors

42 changes: 37 additions & 5 deletions tests/ui/async-await/large_moves.option.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error: moving 10024 bytes
LL | let z = (x, 42);
| ^ value moved from here
|
= note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`
= note: The current maximum size is 2000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`
note: the lint level is defined here
--> $DIR/large_moves.rs:1:9
|
Expand All @@ -17,23 +17,55 @@ error: moving 10024 bytes
LL | let a = z.0;
| ^^^ value moved from here
|
= note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`
= note: The current maximum size is 2000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`

error: moving 9999 bytes
--> $DIR/large_moves.rs:27:13
|
LL | let _ = NotBox::new([0; 9999]);
| ^^^^^^^^^^^^^^^^^^^^^^ value moved from here
|
= note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`
= note: The current maximum size is 2000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`

error: moving 9999 bytes
--> $DIR/large_moves.rs:63:13
|
LL | data,
| ^^^^ value moved from here
|
= note: The current maximum size is 2000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`

error: moving 2500 bytes
--> $DIR/large_moves.rs:41:13
|
LL | let _ = NotBox::new([0; 2500]);
| ^^^^^^^^^^^^^^^^^^^^^^ value moved from here
|
= note: The current maximum size is 2000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`

error: moving 5000 bytes
--> $DIR/large_moves.rs:47:13
|
LL | let _ = NotBox::new([0; 5000]);
| ^^^^^^^^^^^^^^^^^^^^^^ value moved from here
|
= note: The current maximum size is 2000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`

error: moving 2500 bytes
--> $DIR/large_moves.rs:63:13
|
LL | data,
| ^^^^ value moved from here
|
= note: The current maximum size is 2000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`

error: moving 5000 bytes
--> $DIR/large_moves.rs:63:13
|
LL | data,
| ^^^^ value moved from here
|
= note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`
= note: The current maximum size is 2000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`

error: aborting due to 4 previous errors
error: aborting due to 8 previous errors

Loading

0 comments on commit 9f87deb

Please sign in to comment.