Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

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

Lines changed: 0 additions & 7 deletions
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 8 additions & 8 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 41 additions & 13 deletions
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+
}

0 commit comments

Comments
 (0)