Skip to content

Commit d490003

Browse files
authored
Rustc pull
2 parents fdb5090 + 1f1eb66 commit d490003

Some content is hidden

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

56 files changed

+144
-197
lines changed

ci/ci.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ function endgroup {
1414
begingroup "Building Miri"
1515

1616
# Global configuration
17-
export RUSTFLAGS="-D warnings"
17+
# We are getting some odd linker warnings on macOS, make sure they do not fail the build.
18+
# (See <https://github.com/rust-lang/rust/issues/136086>.)
19+
export RUSTFLAGS="-D warnings -A linker-messages"
1820
export CARGO_INCREMENTAL=0
1921
export CARGO_EXTRA_FLAGS="--locked"
2022

rust-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
01706e1a34c87656fcbfce198608f4cd2ac6461a
1+
2f0ad2a71e4a4528bb80bcb24bf8fa4e50cb87c2

src/bin/miri.rs

+24-31
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@ use std::num::NonZero;
2929
use std::ops::Range;
3030
use std::path::PathBuf;
3131
use std::str::FromStr;
32-
use std::sync::atomic::{AtomicI32, Ordering};
33-
use std::sync::{Arc, Once};
32+
use std::sync::Once;
33+
use std::sync::atomic::{AtomicI32, AtomicU32, Ordering};
3434

3535
use miri::{
36-
BacktraceStyle, BorrowTrackerMethod, MiriConfig, ProvenanceMode, RetagFields, ValidationMode,
36+
BacktraceStyle, BorrowTrackerMethod, MiriConfig, MiriEntryFnType, ProvenanceMode, RetagFields,
37+
ValidationMode,
3738
};
3839
use rustc_abi::ExternAbi;
3940
use rustc_data_structures::sync;
@@ -51,7 +52,7 @@ use rustc_middle::query::LocalCrate;
5152
use rustc_middle::traits::{ObligationCause, ObligationCauseCode};
5253
use rustc_middle::ty::{self, Ty, TyCtxt};
5354
use rustc_middle::util::Providers;
54-
use rustc_session::config::{CrateType, EntryFnType, ErrorOutputType, OptLevel};
55+
use rustc_session::config::{CrateType, ErrorOutputType, OptLevel};
5556
use rustc_session::search_paths::PathKind;
5657
use rustc_session::{CtfeBacktrace, EarlyDiagCtxt};
5758
use rustc_span::def_id::DefId;
@@ -73,9 +74,9 @@ impl MiriCompilerCalls {
7374
}
7475
}
7576

76-
fn entry_fn(tcx: TyCtxt<'_>) -> (DefId, EntryFnType) {
77-
if let Some(entry_def) = tcx.entry_fn(()) {
78-
return entry_def;
77+
fn entry_fn(tcx: TyCtxt<'_>) -> (DefId, MiriEntryFnType) {
78+
if let Some((def_id, entry_type)) = tcx.entry_fn(()) {
79+
return (def_id, MiriEntryFnType::Rustc(entry_type));
7980
}
8081
// Look for a symbol in the local crate named `miri_start`, and treat that as the entry point.
8182
let sym = tcx.exported_symbols(LOCAL_CRATE).iter().find_map(|(sym, _)| {
@@ -102,7 +103,7 @@ fn entry_fn(tcx: TyCtxt<'_>) -> (DefId, EntryFnType) {
102103
.is_ok();
103104

104105
if correct_func_sig {
105-
(*id, EntryFnType::Start)
106+
(*id, MiriEntryFnType::MiriStart)
106107
} else {
107108
tcx.dcx().fatal(
108109
"`miri_start` must have the following signature:\n\
@@ -182,7 +183,8 @@ impl rustc_driver::Callbacks for MiriCompilerCalls {
182183
if let Some(many_seeds) = self.many_seeds.take() {
183184
assert!(config.seed.is_none());
184185
let exit_code = sync::IntoDynSyncSend(AtomicI32::new(rustc_driver::EXIT_SUCCESS));
185-
sync::par_for_each_in(many_seeds.seeds, |seed| {
186+
let num_failed = sync::IntoDynSyncSend(AtomicU32::new(0));
187+
sync::par_for_each_in(many_seeds.seeds.clone(), |seed| {
186188
let mut config = config.clone();
187189
config.seed = Some(seed.into());
188190
eprintln!("Trying seed: {seed}");
@@ -196,8 +198,13 @@ impl rustc_driver::Callbacks for MiriCompilerCalls {
196198
std::process::exit(return_code);
197199
}
198200
exit_code.store(return_code, Ordering::Relaxed);
201+
num_failed.fetch_add(1, Ordering::Relaxed);
199202
}
200203
});
204+
let num_failed = num_failed.0.into_inner();
205+
if num_failed > 0 {
206+
eprintln!("{num_failed}/{total} SEEDS FAILED", total = many_seeds.seeds.count());
207+
}
201208
std::process::exit(exit_code.0.into_inner());
202209
} else {
203210
let return_code = miri::eval_entry(tcx, entry_def_id, entry_type, config)
@@ -370,13 +377,10 @@ fn init_late_loggers(early_dcx: &EarlyDiagCtxt, tcx: TyCtxt<'_>) {
370377
fn run_compiler_and_exit(
371378
args: &[String],
372379
callbacks: &mut (dyn rustc_driver::Callbacks + Send),
373-
using_internal_features: Arc<std::sync::atomic::AtomicBool>,
374380
) -> ! {
375381
// Invoke compiler, and handle return code.
376382
let exit_code = rustc_driver::catch_with_exit_code(move || {
377-
rustc_driver::RunCompiler::new(args, callbacks)
378-
.set_using_internal_features(using_internal_features)
379-
.run();
383+
rustc_driver::run_compiler(args, callbacks);
380384
Ok(())
381385
});
382386
std::process::exit(exit_code)
@@ -467,8 +471,7 @@ fn main() {
467471
// If the environment asks us to actually be rustc, then do that.
468472
if let Some(crate_kind) = env::var_os("MIRI_BE_RUSTC") {
469473
// Earliest rustc setup.
470-
let using_internal_features =
471-
rustc_driver::install_ice_hook(rustc_driver::DEFAULT_BUG_REPORT_URL, |_| ());
474+
rustc_driver::install_ice_hook(rustc_driver::DEFAULT_BUG_REPORT_URL, |_| ());
472475
rustc_driver::init_rustc_env_logger(&early_dcx);
473476

474477
let target_crate = if crate_kind == "target" {
@@ -492,16 +495,11 @@ fn main() {
492495
}
493496

494497
// We cannot use `rustc_driver::main` as we want it to use `args` as the CLI arguments.
495-
run_compiler_and_exit(
496-
&args,
497-
&mut MiriBeRustCompilerCalls { target_crate },
498-
using_internal_features,
499-
)
498+
run_compiler_and_exit(&args, &mut MiriBeRustCompilerCalls { target_crate })
500499
}
501500

502501
// Add an ICE bug report hook.
503-
let using_internal_features =
504-
rustc_driver::install_ice_hook("https://github.com/rust-lang/miri/issues/new", |_| ());
502+
rustc_driver::install_ice_hook("https://github.com/rust-lang/miri/issues/new", |_| ());
505503

506504
// Init loggers the Miri way.
507505
init_early_loggers(&early_dcx);
@@ -725,19 +723,14 @@ fn main() {
725723

726724
// Ensure we have parallelism for many-seeds mode.
727725
if many_seeds.is_some() && !rustc_args.iter().any(|arg| arg.starts_with("-Zthreads=")) {
728-
rustc_args.push(format!(
729-
"-Zthreads={}",
730-
std::thread::available_parallelism().map_or(1, |n| n.get())
731-
));
726+
// Clamp to 8 threads; things get a lot less efficient beyond that due to lock contention.
727+
let threads = std::thread::available_parallelism().map_or(1, |n| n.get()).min(8);
728+
rustc_args.push(format!("-Zthreads={threads}"));
732729
}
733730
let many_seeds =
734731
many_seeds.map(|seeds| ManySeedsConfig { seeds, keep_going: many_seeds_keep_going });
735732

736733
debug!("rustc arguments: {:?}", rustc_args);
737734
debug!("crate arguments: {:?}", miri_config.args);
738-
run_compiler_and_exit(
739-
&rustc_args,
740-
&mut MiriCompilerCalls::new(miri_config, many_seeds),
741-
using_internal_features,
742-
)
735+
run_compiler_and_exit(&rustc_args, &mut MiriCompilerCalls::new(miri_config, many_seeds))
743736
}

src/eval.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ use crate::diagnostics::report_leaks;
1919
use crate::shims::tls;
2020
use crate::*;
2121

22+
#[derive(Copy, Clone, Debug)]
23+
pub enum MiriEntryFnType {
24+
MiriStart,
25+
Rustc(EntryFnType),
26+
}
27+
2228
/// When the main thread would exit, we will yield to any other thread that is ready to execute.
2329
/// But we must only do that a finite number of times, or a background thread running `loop {}`
2430
/// will hang the program.
@@ -272,7 +278,7 @@ impl<'tcx> MainThreadState<'tcx> {
272278
pub fn create_ecx<'tcx>(
273279
tcx: TyCtxt<'tcx>,
274280
entry_id: DefId,
275-
entry_type: EntryFnType,
281+
entry_type: MiriEntryFnType,
276282
config: &MiriConfig,
277283
) -> InterpResult<'tcx, InterpCx<'tcx, MiriMachine<'tcx>>> {
278284
let typing_env = ty::TypingEnv::fully_monomorphized();
@@ -300,7 +306,7 @@ pub fn create_ecx<'tcx>(
300306
// Setup first stack frame.
301307
let entry_instance = ty::Instance::mono(tcx, entry_id);
302308

303-
// First argument is constructed later, because it's skipped if the entry function uses #[start].
309+
// First argument is constructed later, because it's skipped for `miri_start.`
304310

305311
// Second argument (argc): length of `config.args`.
306312
let argc =
@@ -373,11 +379,9 @@ pub fn create_ecx<'tcx>(
373379
// Call start function.
374380

375381
match entry_type {
376-
EntryFnType::Main { .. } => {
382+
MiriEntryFnType::Rustc(EntryFnType::Main { .. }) => {
377383
let start_id = tcx.lang_items().start_fn().unwrap_or_else(|| {
378-
tcx.dcx().fatal(
379-
"could not find start function. Make sure the entry point is marked with `#[start]`."
380-
);
384+
tcx.dcx().fatal("could not find start lang item");
381385
});
382386
let main_ret_ty = tcx.fn_sig(entry_id).no_bound_vars().unwrap().output();
383387
let main_ret_ty = main_ret_ty.no_bound_vars().unwrap();
@@ -413,7 +417,7 @@ pub fn create_ecx<'tcx>(
413417
StackPopCleanup::Root { cleanup: true },
414418
)?;
415419
}
416-
EntryFnType::Start => {
420+
MiriEntryFnType::MiriStart => {
417421
ecx.call_function(
418422
entry_instance,
419423
ExternAbi::Rust,
@@ -434,7 +438,7 @@ pub fn create_ecx<'tcx>(
434438
pub fn eval_entry<'tcx>(
435439
tcx: TyCtxt<'tcx>,
436440
entry_id: DefId,
437-
entry_type: EntryFnType,
441+
entry_type: MiriEntryFnType,
438442
config: MiriConfig,
439443
) -> Option<i32> {
440444
// Copy setting before we move `config`.

src/helpers.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ fn try_resolve_did(tcx: TyCtxt<'_>, path: &[&str], namespace: Option<Namespace>)
3838
item: DefId,
3939
name: &'a str,
4040
) -> impl Iterator<Item = DefId> + 'a {
41+
let name = Symbol::intern(name);
4142
tcx.module_children(item)
4243
.iter()
43-
.filter(move |item| item.ident.name.as_str() == name)
44+
.filter(move |item| item.ident.name == name)
4445
.map(move |item| item.res.def_id())
4546
}
4647

src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ pub use crate::diagnostics::{
135135
EvalContextExt as _, NonHaltingDiagnostic, TerminationInfo, report_error,
136136
};
137137
pub use crate::eval::{
138-
AlignmentCheck, BacktraceStyle, IsolatedOp, MiriConfig, RejectOpWith, ValidationMode,
139-
create_ecx, eval_entry,
138+
AlignmentCheck, BacktraceStyle, IsolatedOp, MiriConfig, MiriEntryFnType, RejectOpWith,
139+
ValidationMode, create_ecx, eval_entry,
140140
};
141141
pub use crate::helpers::{AccessKind, EvalContextExt as _};
142142
pub use crate::intrinsics::EvalContextExt as _;

test-cargo-miri/no-std-smoke/src/main.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copied from tests/pass/no-std.rs
22

3-
#![feature(start)]
43
#![no_std]
4+
#![no_main]
55

66
// Plumbing to let us use `writeln!` to host stdout:
77

@@ -22,8 +22,8 @@ impl Write for Host {
2222
}
2323
}
2424

25-
#[start]
26-
fn start(_: isize, _: *const *const u8) -> isize {
25+
#[no_mangle]
26+
fn miri_start(_: isize, _: *const *const u8) -> isize {
2727
writeln!(Host, "hello, world!").unwrap();
2828
0
2929
}

tests/fail/alloc/alloc_error_handler_custom.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
//@compile-flags: -Cpanic=abort
2-
#![feature(start, core_intrinsics)]
2+
#![feature(core_intrinsics)]
33
#![feature(alloc_error_handler)]
44
#![feature(allocator_api)]
55
#![no_std]
6+
#![no_main]
67

78
extern crate alloc;
89

@@ -43,7 +44,7 @@ mod plumbing {
4344
static GLOBAL: NoAlloc = NoAlloc;
4445
}
4546

46-
#[start]
47-
fn start(_: isize, _: *const *const u8) -> isize {
47+
#[no_mangle]
48+
fn miri_start(_argc: isize, _argv: *const *const u8) -> isize {
4849
handle_alloc_error(Layout::for_value(&0));
4950
}

tests/fail/alloc/alloc_error_handler_custom.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ LL | fn alloc_error_handler(layout: Layout) -> ! {
1616
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1717
= note: inside `alloc::alloc::handle_alloc_error::rt_error` at RUSTLIB/alloc/src/alloc.rs:LL:CC
1818
= note: inside `alloc::alloc::handle_alloc_error` at RUSTLIB/alloc/src/alloc.rs:LL:CC
19-
note: inside `start`
19+
note: inside `miri_start`
2020
--> tests/fail/alloc/alloc_error_handler_custom.rs:LL:CC
2121
|
2222
LL | handle_alloc_error(Layout::for_value(&0));

tests/fail/alloc/alloc_error_handler_no_std.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
//@compile-flags: -Cpanic=abort
2-
#![feature(start, core_intrinsics)]
2+
#![feature(core_intrinsics)]
33
#![feature(alloc_error_handler)]
44
#![feature(allocator_api)]
55
#![no_std]
6+
#![no_main]
67

78
extern crate alloc;
89

@@ -41,7 +42,7 @@ mod plumbing {
4142
static GLOBAL: NoAlloc = NoAlloc;
4243
}
4344

44-
#[start]
45-
fn start(_: isize, _: *const *const u8) -> isize {
45+
#[no_mangle]
46+
fn miri_start(_argc: isize, _argv: *const *const u8) -> isize {
4647
handle_alloc_error(Layout::for_value(&0));
4748
}

tests/fail/alloc/alloc_error_handler_no_std.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ LL | core::intrinsics::abort();
1212
= note: inside `alloc::alloc::__alloc_error_handler::__rdl_oom` at RUSTLIB/alloc/src/alloc.rs:LL:CC
1313
= note: inside `alloc::alloc::handle_alloc_error::rt_error` at RUSTLIB/alloc/src/alloc.rs:LL:CC
1414
= note: inside `alloc::alloc::handle_alloc_error` at RUSTLIB/alloc/src/alloc.rs:LL:CC
15-
note: inside `start`
15+
note: inside `miri_start`
1616
--> tests/fail/alloc/alloc_error_handler_no_std.rs:LL:CC
1717
|
1818
LL | handle_alloc_error(Layout::for_value(&0));

tests/fail/alloc/no_global_allocator.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
//@normalize-stderr-test: "OS `.*`" -> "$$OS"
33
// Make sure we pretend the allocation symbols don't exist when there is no allocator
44

5-
#![feature(start)]
65
#![no_std]
6+
#![no_main]
77

88
extern "Rust" {
99
fn __rust_alloc(size: usize, align: usize) -> *mut u8;
1010
}
1111

12-
#[start]
13-
fn start(_: isize, _: *const *const u8) -> isize {
12+
#[no_mangle]
13+
fn miri_start(_argc: isize, _argv: *const *const u8) -> isize {
1414
unsafe {
1515
__rust_alloc(1, 1); //~ERROR: unsupported operation: can't call foreign function `__rust_alloc`
1616
}

tests/fail/alloc/no_global_allocator.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | __rust_alloc(1, 1);
77
= help: if this is a basic API commonly used on this target, please report an issue with Miri
88
= help: however, note that Miri does not aim to support every FFI function out there; for instance, we will not support APIs for things such as GUIs, scripting languages, or databases
99
= note: BACKTRACE:
10-
= note: inside `start` at tests/fail/alloc/no_global_allocator.rs:LL:CC
10+
= note: inside `miri_start` at tests/fail/alloc/no_global_allocator.rs:LL:CC
1111

1212
error: aborting due to 1 previous error
1313

tests/fail/intrinsics/copy_overlapping.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
#![feature(intrinsics)]
22

33
// Directly call intrinsic to avoid debug assertions in libstd
4-
extern "rust-intrinsic" {
5-
fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize);
6-
}
4+
#[rustc_intrinsic]
5+
unsafe fn copy_nonoverlapping<T>(_src: *const T, _dst: *mut T, _count: usize);
76

87
fn main() {
98
let mut data = [0u8; 16];

tests/fail/intrinsics/copy_unaligned.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
#![feature(intrinsics)]
22

33
// Directly call intrinsic to avoid debug assertions in libstd
4-
extern "rust-intrinsic" {
5-
fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize);
6-
}
4+
#[rustc_intrinsic]
5+
unsafe fn copy_nonoverlapping<T>(_src: *const T, _dst: *mut T, _count: usize);
76

87
fn main() {
98
let mut data = [0u16; 8];

tests/fail/intrinsics/ctlz_nonzero.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
#![feature(intrinsics)]
22

33
mod rusti {
4-
extern "rust-intrinsic" {
5-
pub fn ctlz_nonzero<T>(x: T) -> u32;
6-
}
4+
#[rustc_intrinsic]
5+
pub unsafe fn ctlz_nonzero<T>(_x: T) -> u32;
76
}
87

98
pub fn main() {

tests/fail/intrinsics/cttz_nonzero.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
#![feature(intrinsics)]
22

33
mod rusti {
4-
extern "rust-intrinsic" {
5-
pub fn cttz_nonzero<T>(x: T) -> u32;
6-
}
4+
#[rustc_intrinsic]
5+
pub unsafe fn cttz_nonzero<T>(_x: T) -> u32;
76
}
87

98
pub fn main() {

0 commit comments

Comments
 (0)