Skip to content

Commit 116d973

Browse files
committed
Auto merge of rust-lang#136614 - workingjubilee:rollup-vm143qj, r=workingjubilee
Rollup of 9 pull requests Successful merges: - rust-lang#135439 (Make `-O` mean `OptLevel::Aggressive`) - rust-lang#136193 (Implement pattern type ffi checks) - rust-lang#136235 (Pretty print pattern type values with transmute if they don't satisfy their pattern) - rust-lang#136311 (Ensure that we never try to monomorphize the upcasting or vtable calls of impossible dyn types) - rust-lang#136315 (Use short ty string for binop and unop errors) - rust-lang#136393 (Fix accidentally not emitting overflowing literals lints anymore in patterns) - rust-lang#136530 (Implement `x perf` directly in bootstrap) - rust-lang#136580 (Couple of changes to run rustc in miri) - rust-lang#136589 (Enable "jump to def" feature on rustc docs) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 5958825 + 932bb59 commit 116d973

File tree

68 files changed

+4214
-582
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+4214
-582
lines changed

Cargo.lock

-7
Original file line numberDiff line numberDiff line change
@@ -3287,13 +3287,6 @@ dependencies = [
32873287
"tikv-jemalloc-sys",
32883288
]
32893289

3290-
[[package]]
3291-
name = "rustc-perf-wrapper"
3292-
version = "0.1.0"
3293-
dependencies = [
3294-
"clap",
3295-
]
3296-
32973290
[[package]]
32983291
name = "rustc-rayon"
32993292
version = "0.5.1"

Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ members = [
4545
"src/tools/rustdoc-gui-test",
4646
"src/tools/opt-dist",
4747
"src/tools/coverage-dump",
48-
"src/tools/rustc-perf-wrapper",
4948
"src/tools/wasm-component-ld",
5049
"src/tools/features-status-dump",
5150
]

compiler/rustc_codegen_cranelift/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ fn build_isa(sess: &Session) -> Arc<dyn TargetIsa + 'static> {
290290
flags_builder.set("opt_level", "none").unwrap();
291291
}
292292
OptLevel::Less
293-
| OptLevel::Default
293+
| OptLevel::More
294294
| OptLevel::Size
295295
| OptLevel::SizeMin
296296
| OptLevel::Aggressive => {

compiler/rustc_codegen_gcc/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ fn to_gcc_opt_level(optlevel: Option<OptLevel>) -> OptimizationLevel {
476476
Some(level) => match level {
477477
OptLevel::No => OptimizationLevel::None,
478478
OptLevel::Less => OptimizationLevel::Limited,
479-
OptLevel::Default => OptimizationLevel::Standard,
479+
OptLevel::More => OptimizationLevel::Standard,
480480
OptLevel::Aggressive => OptimizationLevel::Aggressive,
481481
OptLevel::Size | OptLevel::SizeMin => OptimizationLevel::Limited,
482482
},

compiler/rustc_codegen_llvm/src/back/write.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ fn to_llvm_opt_settings(cfg: config::OptLevel) -> (llvm::CodeGenOptLevel, llvm::
138138
match cfg {
139139
No => (llvm::CodeGenOptLevel::None, llvm::CodeGenOptSizeNone),
140140
Less => (llvm::CodeGenOptLevel::Less, llvm::CodeGenOptSizeNone),
141-
Default => (llvm::CodeGenOptLevel::Default, llvm::CodeGenOptSizeNone),
141+
More => (llvm::CodeGenOptLevel::Default, llvm::CodeGenOptSizeNone),
142142
Aggressive => (llvm::CodeGenOptLevel::Aggressive, llvm::CodeGenOptSizeNone),
143143
Size => (llvm::CodeGenOptLevel::Default, llvm::CodeGenOptSizeDefault),
144144
SizeMin => (llvm::CodeGenOptLevel::Default, llvm::CodeGenOptSizeAggressive),
@@ -150,7 +150,7 @@ fn to_pass_builder_opt_level(cfg: config::OptLevel) -> llvm::PassBuilderOptLevel
150150
match cfg {
151151
No => llvm::PassBuilderOptLevel::O0,
152152
Less => llvm::PassBuilderOptLevel::O1,
153-
Default => llvm::PassBuilderOptLevel::O2,
153+
More => llvm::PassBuilderOptLevel::O2,
154154
Aggressive => llvm::PassBuilderOptLevel::O3,
155155
Size => llvm::PassBuilderOptLevel::Os,
156156
SizeMin => llvm::PassBuilderOptLevel::Oz,

compiler/rustc_codegen_ssa/src/back/linker.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ impl<'a> GccLinker<'a> {
410410
let opt_level = match self.sess.opts.optimize {
411411
config::OptLevel::No => "O0",
412412
config::OptLevel::Less => "O1",
413-
config::OptLevel::Default | config::OptLevel::Size | config::OptLevel::SizeMin => "O2",
413+
config::OptLevel::More | config::OptLevel::Size | config::OptLevel::SizeMin => "O2",
414414
config::OptLevel::Aggressive => "O3",
415415
};
416416

@@ -685,7 +685,7 @@ impl<'a> Linker for GccLinker<'a> {
685685

686686
// GNU-style linkers support optimization with -O. GNU ld doesn't
687687
// need a numeric argument, but other linkers do.
688-
if self.sess.opts.optimize == config::OptLevel::Default
688+
if self.sess.opts.optimize == config::OptLevel::More
689689
|| self.sess.opts.optimize == config::OptLevel::Aggressive
690690
{
691691
self.link_arg("-O1");
@@ -1213,7 +1213,7 @@ impl<'a> Linker for EmLinker<'a> {
12131213
self.cc_arg(match self.sess.opts.optimize {
12141214
OptLevel::No => "-O0",
12151215
OptLevel::Less => "-O1",
1216-
OptLevel::Default => "-O2",
1216+
OptLevel::More => "-O2",
12171217
OptLevel::Aggressive => "-O3",
12181218
OptLevel::Size => "-Os",
12191219
OptLevel::SizeMin => "-Oz",
@@ -1384,7 +1384,7 @@ impl<'a> Linker for WasmLd<'a> {
13841384
self.link_arg(match self.sess.opts.optimize {
13851385
OptLevel::No => "-O0",
13861386
OptLevel::Less => "-O1",
1387-
OptLevel::Default => "-O2",
1387+
OptLevel::More => "-O2",
13881388
OptLevel::Aggressive => "-O3",
13891389
// Currently LLD doesn't support `Os` and `Oz`, so pass through `O2`
13901390
// instead.
@@ -1451,7 +1451,7 @@ impl<'a> WasmLd<'a> {
14511451
let opt_level = match self.sess.opts.optimize {
14521452
config::OptLevel::No => "O0",
14531453
config::OptLevel::Less => "O1",
1454-
config::OptLevel::Default => "O2",
1454+
config::OptLevel::More => "O2",
14551455
config::OptLevel::Aggressive => "O3",
14561456
// wasm-ld only handles integer LTO opt levels. Use O2
14571457
config::OptLevel::Size | config::OptLevel::SizeMin => "O2",
@@ -1525,7 +1525,7 @@ impl<'a> Linker for L4Bender<'a> {
15251525
fn optimize(&mut self) {
15261526
// GNU-style linkers support optimization with -O. GNU ld doesn't
15271527
// need a numeric argument, but other linkers do.
1528-
if self.sess.opts.optimize == config::OptLevel::Default
1528+
if self.sess.opts.optimize == config::OptLevel::More
15291529
|| self.sess.opts.optimize == config::OptLevel::Aggressive
15301530
{
15311531
self.link_arg("-O1");
@@ -1929,7 +1929,7 @@ impl<'a> Linker for LlbcLinker<'a> {
19291929
match self.sess.opts.optimize {
19301930
OptLevel::No => "-O0",
19311931
OptLevel::Less => "-O1",
1932-
OptLevel::Default => "-O2",
1932+
OptLevel::More => "-O2",
19331933
OptLevel::Aggressive => "-O3",
19341934
OptLevel::Size => "-Os",
19351935
OptLevel::SizeMin => "-Oz",
@@ -2006,7 +2006,7 @@ impl<'a> Linker for BpfLinker<'a> {
20062006
self.link_arg(match self.sess.opts.optimize {
20072007
OptLevel::No => "-O0",
20082008
OptLevel::Less => "-O1",
2009-
OptLevel::Default => "-O2",
2009+
OptLevel::More => "-O2",
20102010
OptLevel::Aggressive => "-O3",
20112011
OptLevel::Size => "-Os",
20122012
OptLevel::SizeMin => "-Oz",

compiler/rustc_codegen_ssa/src/back/write.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ impl ModuleConfig {
236236
// Copy what clang does by turning on loop vectorization at O2 and
237237
// slp vectorization at O3.
238238
vectorize_loop: !sess.opts.cg.no_vectorize_loops
239-
&& (sess.opts.optimize == config::OptLevel::Default
239+
&& (sess.opts.optimize == config::OptLevel::More
240240
|| sess.opts.optimize == config::OptLevel::Aggressive),
241241
vectorize_slp: !sess.opts.cg.no_vectorize_slp
242242
&& sess.opts.optimize == config::OptLevel::Aggressive,
@@ -260,7 +260,7 @@ impl ModuleConfig {
260260
MergeFunctions::Trampolines | MergeFunctions::Aliases => {
261261
use config::OptLevel::*;
262262
match sess.opts.optimize {
263-
Aggressive | Default | SizeMin | Size => true,
263+
Aggressive | More | SizeMin | Size => true,
264264
Less | No => false,
265265
}
266266
}

compiler/rustc_codegen_ssa/src/base.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1053,12 +1053,12 @@ pub(crate) fn provide(providers: &mut Providers) {
10531053
config::OptLevel::No => return config::OptLevel::No,
10541054
// If globally optimise-speed is already specified, just use that level.
10551055
config::OptLevel::Less => return config::OptLevel::Less,
1056-
config::OptLevel::Default => return config::OptLevel::Default,
1056+
config::OptLevel::More => return config::OptLevel::More,
10571057
config::OptLevel::Aggressive => return config::OptLevel::Aggressive,
10581058
// If globally optimize-for-size has been requested, use -O2 instead (if optimize(size)
10591059
// are present).
1060-
config::OptLevel::Size => config::OptLevel::Default,
1061-
config::OptLevel::SizeMin => config::OptLevel::Default,
1060+
config::OptLevel::Size => config::OptLevel::More,
1061+
config::OptLevel::SizeMin => config::OptLevel::More,
10621062
};
10631063

10641064
let defids = tcx.collect_and_partition_mono_items(cratenum).all_mono_items;

compiler/rustc_const_eval/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ pub fn provide(providers: &mut Providers) {
5151
providers.check_validity_requirement = |tcx, (init_kind, param_env_and_ty)| {
5252
util::check_validity_requirement(tcx, init_kind, param_env_and_ty)
5353
};
54+
providers.hooks.validate_scalar_in_layout =
55+
|tcx, scalar, layout| util::validate_scalar_in_layout(tcx, scalar, layout);
5456
}
5557

5658
/// `rustc_driver::main` installs a handler that will set this to `true` if

compiler/rustc_const_eval/src/util/check_validity_requirement.rs

+41-13
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
use rustc_abi::{BackendRepr, FieldsShape, Scalar, Variants};
2-
use rustc_middle::bug;
32
use rustc_middle::ty::layout::{
43
HasTyCtxt, LayoutCx, LayoutError, LayoutOf, TyAndLayout, ValidityRequirement,
54
};
6-
use rustc_middle::ty::{PseudoCanonicalInput, Ty, TyCtxt};
5+
use rustc_middle::ty::{PseudoCanonicalInput, ScalarInt, Ty, TyCtxt};
6+
use rustc_middle::{bug, ty};
7+
use rustc_span::DUMMY_SP;
78

89
use crate::const_eval::{CanAccessMutGlobal, CheckAlignment, CompileTimeMachine};
910
use crate::interpret::{InterpCx, MemoryKind};
@@ -34,7 +35,7 @@ pub fn check_validity_requirement<'tcx>(
3435

3536
let layout_cx = LayoutCx::new(tcx, input.typing_env);
3637
if kind == ValidityRequirement::Uninit || tcx.sess.opts.unstable_opts.strict_init_checks {
37-
check_validity_requirement_strict(layout, &layout_cx, kind)
38+
Ok(check_validity_requirement_strict(layout, &layout_cx, kind))
3839
} else {
3940
check_validity_requirement_lax(layout, &layout_cx, kind)
4041
}
@@ -46,10 +47,10 @@ fn check_validity_requirement_strict<'tcx>(
4647
ty: TyAndLayout<'tcx>,
4748
cx: &LayoutCx<'tcx>,
4849
kind: ValidityRequirement,
49-
) -> Result<bool, &'tcx LayoutError<'tcx>> {
50+
) -> bool {
5051
let machine = CompileTimeMachine::new(CanAccessMutGlobal::No, CheckAlignment::Error);
5152

52-
let mut cx = InterpCx::new(cx.tcx(), rustc_span::DUMMY_SP, cx.typing_env, machine);
53+
let mut cx = InterpCx::new(cx.tcx(), DUMMY_SP, cx.typing_env, machine);
5354

5455
let allocated = cx
5556
.allocate(ty, MemoryKind::Machine(crate::const_eval::MemoryKind::Heap))
@@ -69,14 +70,13 @@ fn check_validity_requirement_strict<'tcx>(
6970
// due to this.
7071
// The value we are validating is temporary and discarded at the end of this function, so
7172
// there is no point in reseting provenance and padding.
72-
Ok(cx
73-
.validate_operand(
74-
&allocated.into(),
75-
/*recursive*/ false,
76-
/*reset_provenance_and_padding*/ false,
77-
)
78-
.discard_err()
79-
.is_some())
73+
cx.validate_operand(
74+
&allocated.into(),
75+
/*recursive*/ false,
76+
/*reset_provenance_and_padding*/ false,
77+
)
78+
.discard_err()
79+
.is_some()
8080
}
8181

8282
/// Implements the 'lax' (default) version of the [`check_validity_requirement`] checks; see that
@@ -168,3 +168,31 @@ fn check_validity_requirement_lax<'tcx>(
168168

169169
Ok(true)
170170
}
171+
172+
pub(crate) fn validate_scalar_in_layout<'tcx>(
173+
tcx: TyCtxt<'tcx>,
174+
scalar: ScalarInt,
175+
ty: Ty<'tcx>,
176+
) -> bool {
177+
let machine = CompileTimeMachine::new(CanAccessMutGlobal::No, CheckAlignment::Error);
178+
179+
let typing_env = ty::TypingEnv::fully_monomorphized();
180+
let mut cx = InterpCx::new(tcx, DUMMY_SP, typing_env, machine);
181+
182+
let Ok(layout) = cx.layout_of(ty) else {
183+
bug!("could not compute layout of {scalar:?}:{ty:?}")
184+
};
185+
let allocated = cx
186+
.allocate(layout, MemoryKind::Machine(crate::const_eval::MemoryKind::Heap))
187+
.expect("OOM: failed to allocate for uninit check");
188+
189+
cx.write_scalar(scalar, &allocated).unwrap();
190+
191+
cx.validate_operand(
192+
&allocated.into(),
193+
/*recursive*/ false,
194+
/*reset_provenance_and_padding*/ false,
195+
)
196+
.discard_err()
197+
.is_some()
198+
}

compiler/rustc_const_eval/src/util/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ mod type_name;
88

99
pub use self::alignment::{is_disaligned, is_within_packed};
1010
pub use self::check_validity_requirement::check_validity_requirement;
11+
pub(crate) use self::check_validity_requirement::validate_scalar_in_layout;
1112
pub use self::compare_types::{relate_types, sub_types};
1213
pub use self::type_name::type_name;
1314

compiler/rustc_data_structures/src/memmap.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ use std::io;
33
use std::ops::{Deref, DerefMut};
44

55
/// A trivial wrapper for [`memmap2::Mmap`] (or `Vec<u8>` on WASM).
6-
#[cfg(not(target_arch = "wasm32"))]
6+
#[cfg(not(any(miri, target_arch = "wasm32")))]
77
pub struct Mmap(memmap2::Mmap);
88

9-
#[cfg(target_arch = "wasm32")]
9+
#[cfg(any(miri, target_arch = "wasm32"))]
1010
pub struct Mmap(Vec<u8>);
1111

12-
#[cfg(not(target_arch = "wasm32"))]
12+
#[cfg(not(any(miri, target_arch = "wasm32")))]
1313
impl Mmap {
1414
/// # Safety
1515
///
@@ -29,7 +29,7 @@ impl Mmap {
2929
}
3030
}
3131

32-
#[cfg(target_arch = "wasm32")]
32+
#[cfg(any(miri, target_arch = "wasm32"))]
3333
impl Mmap {
3434
#[inline]
3535
pub unsafe fn map(mut file: File) -> io::Result<Self> {
@@ -56,13 +56,13 @@ impl AsRef<[u8]> for Mmap {
5656
}
5757
}
5858

59-
#[cfg(not(target_arch = "wasm32"))]
59+
#[cfg(not(any(miri, target_arch = "wasm32")))]
6060
pub struct MmapMut(memmap2::MmapMut);
6161

62-
#[cfg(target_arch = "wasm32")]
62+
#[cfg(any(miri, target_arch = "wasm32"))]
6363
pub struct MmapMut(Vec<u8>);
6464

65-
#[cfg(not(target_arch = "wasm32"))]
65+
#[cfg(not(any(miri, target_arch = "wasm32")))]
6666
impl MmapMut {
6767
#[inline]
6868
pub fn map_anon(len: usize) -> io::Result<Self> {
@@ -82,7 +82,7 @@ impl MmapMut {
8282
}
8383
}
8484

85-
#[cfg(target_arch = "wasm32")]
85+
#[cfg(any(miri, target_arch = "wasm32"))]
8686
impl MmapMut {
8787
#[inline]
8888
pub fn map_anon(len: usize) -> io::Result<Self> {

compiler/rustc_data_structures/src/stack.rs

+12
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@ const STACK_PER_RECURSION: usize = 16 * 1024 * 1024; // 16MB
1717
///
1818
/// Should not be sprinkled around carelessly, as it causes a little bit of overhead.
1919
#[inline]
20+
#[cfg(not(miri))]
2021
pub fn ensure_sufficient_stack<R>(f: impl FnOnce() -> R) -> R {
2122
stacker::maybe_grow(RED_ZONE, STACK_PER_RECURSION, f)
2223
}
24+
25+
/// Grows the stack on demand to prevent stack overflow. Call this in strategic locations
26+
/// to "break up" recursive calls. E.g. almost any call to `visit_expr` or equivalent can benefit
27+
/// from this.
28+
///
29+
/// Should not be sprinkled around carelessly, as it causes a little bit of overhead.
30+
#[cfg(miri)]
31+
#[inline]
32+
pub fn ensure_sufficient_stack<R>(f: impl FnOnce() -> R) -> R {
33+
f()
34+
}

compiler/rustc_driver_impl/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ pub mod pretty;
8989
#[macro_use]
9090
mod print;
9191
mod session_diagnostics;
92-
#[cfg(all(unix, any(target_env = "gnu", target_os = "macos")))]
92+
#[cfg(all(not(miri), unix, any(target_env = "gnu", target_os = "macos")))]
9393
mod signal_handler;
9494

95-
#[cfg(not(all(unix, any(target_env = "gnu", target_os = "macos"))))]
95+
#[cfg(not(all(not(miri), unix, any(target_env = "gnu", target_os = "macos"))))]
9696
mod signal_handler {
9797
/// On platforms which don't support our signal handler's requirements,
9898
/// simply use the default signal handler provided by std.
@@ -1474,7 +1474,7 @@ pub fn init_logger(early_dcx: &EarlyDiagCtxt, cfg: rustc_log::LoggerConfig) {
14741474
/// Install our usual `ctrlc` handler, which sets [`rustc_const_eval::CTRL_C_RECEIVED`].
14751475
/// Making this handler optional lets tools can install a different handler, if they wish.
14761476
pub fn install_ctrlc_handler() {
1477-
#[cfg(not(target_family = "wasm"))]
1477+
#[cfg(all(not(miri), not(target_family = "wasm")))]
14781478
ctrlc::set_handler(move || {
14791479
// Indicate that we have been signaled to stop, then give the rest of the compiler a bit of
14801480
// time to check CTRL_C_RECEIVED and run its own shutdown logic, but after a short amount

compiler/rustc_errors/src/emitter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1764,7 +1764,7 @@ impl HumanEmitter {
17641764

17651765
let column_width = if let Some(width) = self.diagnostic_width {
17661766
width.saturating_sub(code_offset)
1767-
} else if self.ui_testing {
1767+
} else if self.ui_testing || cfg!(miri) {
17681768
DEFAULT_COLUMN_WIDTH
17691769
} else {
17701770
termize::dimensions()

0 commit comments

Comments
 (0)