Skip to content

Commit 7bb0ef4

Browse files
committed
Auto merge of #126193 - RalfJung:miri-sync, r=RalfJung
Miri subtree update r? `@ghost`
2 parents 212841e + ad85a20 commit 7bb0ef4

Some content is hidden

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

89 files changed

+1500
-1087
lines changed

src/tools/miri/CONTRIBUTING.md

+18-3
Original file line numberDiff line numberDiff line change
@@ -223,15 +223,15 @@ will eventually sync those changes back into this repository.
223223
When working on Miri in the rustc tree, here's how you can run tests:
224224

225225
```
226-
./x.py test miri --stage 0
226+
./x.py test miri
227227
```
228228

229229
`--bless` will work, too.
230230

231231
You can also directly run Miri on a Rust source file:
232232

233233
```
234-
./x.py run miri --stage 0 --args src/tools/miri/tests/pass/hello.rs
234+
./x.py run miri --stage 1 --args src/tools/miri/tests/pass/hello.rs
235235
```
236236

237237
## Advanced topic: Syncing with the rustc repo
@@ -287,7 +287,22 @@ https. Add the following to your `.gitconfig`:
287287
pushInsteadOf = https://github.com./
288288
```
289289

290-
## Internal environment variables
290+
## Further environment variables
291+
292+
The following environment variables are relevant to `./miri`:
293+
294+
* `MIRI_AUTO_OPS` indicates whether the automatic execution of rustfmt, clippy and toolchain setup
295+
(as controlled by the `./auto-*` files) should be skipped. If it is set to `no`, they are skipped.
296+
This is used to allow automated IDE actions to avoid the auto ops.
297+
* `MIRI_LOG`, `MIRI_BACKTRACE` control logging and backtrace printing during Miri executions.
298+
* `MIRI_TEST_THREADS` (recognized by `./miri test`) sets the number of threads to use for running
299+
tests. By default, the number of cores is used.
300+
* `MIRI_SKIP_UI_CHECKS` (recognized by `./miri test`) disables checking that the `stderr` or
301+
`stdout` files match the actual output.
302+
303+
Furthermore, the usual environment variables recognized by `cargo miri` also work for `./miri`, e.g.
304+
`MIRI_LIB_SRC`. Note that `MIRIFLAGS` is ignored by `./miri test` as each test controls the flags it
305+
is run with.
291306

292307
The following environment variables are *internal* and must not be used by
293308
anyone but Miri itself. They are used to communicate between different Miri

src/tools/miri/README.md

+6-15
Original file line numberDiff line numberDiff line change
@@ -448,28 +448,19 @@ Some native rustc `-Z` flags are also very relevant for Miri:
448448
* `-Zmir-emit-retag` controls whether `Retag` statements are emitted. Miri
449449
enables this per default because it is needed for [Stacked Borrows] and [Tree Borrows].
450450

451-
Moreover, Miri recognizes some environment variables (unless noted otherwise, these are supported
452-
by all intended entry points, i.e. `cargo miri` and `./miri {test,run}`):
453-
454-
* `MIRI_AUTO_OPS` indicates whether the automatic execution of rustfmt, clippy and toolchain setup
455-
should be skipped. If it is set to `no`, they are skipped. This is used to allow automated IDE
456-
actions to avoid the auto ops.
457-
* `MIRI_LOG`, `MIRI_BACKTRACE` control logging and backtrace printing during
458-
Miri executions, also [see "Testing the Miri driver" in `CONTRIBUTING.md`][testing-miri].
451+
Moreover, Miri recognizes some environment variables:
452+
459453
* `MIRIFLAGS` defines extra flags to be passed to Miri.
460454
* `MIRI_LIB_SRC` defines the directory where Miri expects the sources of the standard library that
461455
it will build and use for interpretation. This directory must point to the `library` subdirectory
462456
of a `rust-lang/rust` repository checkout.
463-
* `MIRI_SYSROOT` indicates the sysroot to use. When using `cargo miri`, this skips the automatic
457+
* `MIRI_SYSROOT` indicates the sysroot to use. When using `cargo miri test`/`cargo miri run`, this skips the automatic
464458
setup -- only set this if you do not want to use the automatically created sysroot. When invoking
465459
`cargo miri setup`, this indicates where the sysroot will be put.
466-
* `MIRI_TEST_THREADS` (recognized by `./miri test`): set the number of threads to use for running tests.
467-
By default, the number of cores is used.
468460
* `MIRI_NO_STD` makes sure that the target's sysroot is built without libstd. This allows testing
469-
and running no_std programs. (Miri has a heuristic to detect no-std targets based on the target
470-
name; this environment variable is only needed when that heuristic fails.)
471-
* `MIRI_SKIP_UI_CHECKS` (recognized by `./miri test`): don't check whether the
472-
`stderr` or `stdout` files match the actual output.
461+
and running no_std programs. This should *not usually be used*; Miri has a heuristic to detect
462+
no-std targets based on the target name. Setting this on a target that does support libstd can
463+
lead to confusing results.
473464

474465
[testing-miri]: CONTRIBUTING.md#testing-the-miri-driver
475466

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# This file is automatically @generated by Cargo.
2+
# It is not intended for manual editing.
3+
version = 3
4+
5+
[[package]]
6+
name = "big-allocs"
7+
version = "0.1.0"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "big-allocs"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//! This is a regression test for https://github.com./rust-lang/miri/issues/3637.
2+
//! `Allocation`s are backed by a `Box<[u8]>`, which we create using `alloc_zeroed`, which should
3+
//! make very large allocations cheap. But then we also need to not clone those `Allocation`s, or
4+
//! we end up slow anyway.
5+
6+
fn main() {
7+
// We can't use too big of an allocation or this code will encounter an allocation failure in
8+
// CI. Since the allocation can't be huge, we need to do a few iterations so that the effect
9+
// we're trying to measure is clearly visible above the interpreter's startup time.
10+
for _ in 0..10 {
11+
drop(Vec::<u8>::with_capacity(512 * 1024 * 1024));
12+
}
13+
}

src/tools/miri/cargo-miri/src/main.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
#![allow(clippy::useless_format, clippy::derive_partial_eq_without_eq, rustc::internal)]
22

3-
#[macro_use]
4-
mod util;
5-
63
mod arg;
74
mod phases;
85
mod setup;
6+
mod util;
97

108
use std::{env, iter};
119

1210
use crate::phases::*;
11+
use crate::util::show_error;
1312

1413
/// Returns `true` if our flags look like they may be for rustdoc, i.e., this is cargo calling us to
1514
/// be rustdoc. It's hard to be sure as cargo does not have a RUSTDOC_WRAPPER or an env var that

src/tools/miri/cargo-miri/src/util.rs

+12-13
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::collections::HashMap;
12
use std::env;
23
use std::ffi::OsString;
34
use std::fs::File;
@@ -11,14 +12,15 @@ use serde::{Deserialize, Serialize};
1112

1213
pub use crate::arg::*;
1314

14-
pub fn show_error(msg: &impl std::fmt::Display) -> ! {
15+
pub fn show_error_(msg: &impl std::fmt::Display) -> ! {
1516
eprintln!("fatal error: {msg}");
1617
std::process::exit(1)
1718
}
1819

1920
macro_rules! show_error {
20-
($($tt:tt)*) => { crate::util::show_error(&format_args!($($tt)*)) };
21+
($($tt:tt)*) => { crate::util::show_error_(&format_args!($($tt)*)) };
2122
}
23+
pub(crate) use show_error;
2224

2325
/// The information to run a crate with the given environment.
2426
#[derive(Clone, Serialize, Deserialize)]
@@ -232,21 +234,18 @@ pub fn get_cargo_metadata() -> Metadata {
232234
}
233235

234236
/// Pulls all the crates in this workspace from the cargo metadata.
235-
/// Workspace members are emitted like "miri 0.1.0 (path+file:///path/to/miri)"
236237
/// Additionally, somewhere between cargo metadata and TyCtxt, '-' gets replaced with '_' so we
237238
/// make that same transformation here.
238239
pub fn local_crates(metadata: &Metadata) -> String {
239240
assert!(!metadata.workspace_members.is_empty());
240-
let mut local_crates = String::new();
241-
for member in &metadata.workspace_members {
242-
let name = member.repr.split(' ').next().unwrap();
243-
let name = name.replace('-', "_");
244-
local_crates.push_str(&name);
245-
local_crates.push(',');
246-
}
247-
local_crates.pop(); // Remove the trailing ','
248-
249-
local_crates
241+
let package_name_by_id: HashMap<_, _> =
242+
metadata.packages.iter().map(|package| (&package.id, package.name.as_str())).collect();
243+
metadata
244+
.workspace_members
245+
.iter()
246+
.map(|id| package_name_by_id[id].replace('-', "_"))
247+
.collect::<Vec<_>>()
248+
.join(",")
250249
}
251250

252251
/// Debug-print a command that is going to be run.

src/tools/miri/ci/ci.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ case $HOST_TARGET in
148148
UNIX="panic/panic panic/unwind concurrency/simple atomic libc-mem libc-misc libc-random env num_cpus" # the things that are very similar across all Unixes, and hence easily supported there
149149
TEST_TARGET=x86_64-unknown-freebsd run_tests_minimal $BASIC $UNIX threadname libc-time fs
150150
TEST_TARGET=i686-unknown-freebsd run_tests_minimal $BASIC $UNIX threadname libc-time fs
151-
TEST_TARGET=x86_64-unknown-illumos run_tests_minimal $BASIC $UNIX threadname pthread-sync libc-time
152-
TEST_TARGET=x86_64-pc-solaris run_tests_minimal $BASIC $UNIX threadname pthread-sync libc-time
151+
TEST_TARGET=x86_64-unknown-illumos run_tests_minimal $BASIC $UNIX threadname pthread-sync available-parallelism libc-time
152+
TEST_TARGET=x86_64-pc-solaris run_tests_minimal $BASIC $UNIX threadname pthread-sync available-parallelism libc-time
153153
TEST_TARGET=aarch64-linux-android run_tests_minimal $BASIC $UNIX
154154
TEST_TARGET=wasm32-wasip2 run_tests_minimal empty_main wasm heap_alloc libc-mem
155155
TEST_TARGET=wasm32-unknown-unknown run_tests_minimal empty_main wasm

src/tools/miri/rust-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
21e6de7eb64c09102de3f100420a09edc1a2a8d7
1+
565cadb514d35e7b851540edbc172af0f606014f

src/tools/miri/src/alloc_addresses/mod.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
257257
Ok(())
258258
}
259259

260-
fn ptr_from_addr_cast(&self, addr: u64) -> InterpResult<'tcx, Pointer<Option<Provenance>>> {
260+
fn ptr_from_addr_cast(&self, addr: u64) -> InterpResult<'tcx, Pointer> {
261261
trace!("Casting {:#x} to a pointer", addr);
262262

263263
let ecx = self.eval_context_ref();
@@ -297,10 +297,10 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
297297
/// Convert a relative (tcx) pointer to a Miri pointer.
298298
fn adjust_alloc_root_pointer(
299299
&self,
300-
ptr: Pointer<CtfeProvenance>,
300+
ptr: interpret::Pointer<CtfeProvenance>,
301301
tag: BorTag,
302302
kind: MemoryKind,
303-
) -> InterpResult<'tcx, Pointer<Provenance>> {
303+
) -> InterpResult<'tcx, interpret::Pointer<Provenance>> {
304304
let ecx = self.eval_context_ref();
305305

306306
let (prov, offset) = ptr.into_parts(); // offset is relative (AllocId provenance)
@@ -310,12 +310,15 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
310310
// Add offset with the right kind of pointer-overflowing arithmetic.
311311
let dl = ecx.data_layout();
312312
let absolute_addr = dl.overflowing_offset(base_addr, offset.bytes()).0;
313-
Ok(Pointer::new(Provenance::Concrete { alloc_id, tag }, Size::from_bytes(absolute_addr)))
313+
Ok(interpret::Pointer::new(
314+
Provenance::Concrete { alloc_id, tag },
315+
Size::from_bytes(absolute_addr),
316+
))
314317
}
315318

316319
/// When a pointer is used for a memory access, this computes where in which allocation the
317320
/// access is going.
318-
fn ptr_get_alloc(&self, ptr: Pointer<Provenance>) -> Option<(AllocId, Size)> {
321+
fn ptr_get_alloc(&self, ptr: interpret::Pointer<Provenance>) -> Option<(AllocId, Size)> {
319322
let ecx = self.eval_context_ref();
320323

321324
let (tag, addr) = ptr.into_parts(); // addr is absolute (Tag provenance)

src/tools/miri/src/bin/miri.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
)]
99

1010
// Some "regular" crates we want to share with rustc
11-
#[macro_use]
1211
extern crate tracing;
1312

1413
// The rustc crates we need
@@ -26,6 +25,8 @@ use std::num::NonZero;
2625
use std::path::PathBuf;
2726
use std::str::FromStr;
2827

28+
use tracing::debug;
29+
2930
use rustc_data_structures::sync::Lrc;
3031
use rustc_driver::Compilation;
3132
use rustc_hir::{self as hir, Node};

src/tools/miri/src/borrow_tracker/mod.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
281281
fn retag_ptr_value(
282282
&mut self,
283283
kind: RetagKind,
284-
val: &ImmTy<'tcx, Provenance>,
285-
) -> InterpResult<'tcx, ImmTy<'tcx, Provenance>> {
284+
val: &ImmTy<'tcx>,
285+
) -> InterpResult<'tcx, ImmTy<'tcx>> {
286286
let this = self.eval_context_mut();
287287
let method = this.machine.borrow_tracker.as_ref().unwrap().borrow().borrow_tracker_method;
288288
match method {
@@ -294,7 +294,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
294294
fn retag_place_contents(
295295
&mut self,
296296
kind: RetagKind,
297-
place: &PlaceTy<'tcx, Provenance>,
297+
place: &PlaceTy<'tcx>,
298298
) -> InterpResult<'tcx> {
299299
let this = self.eval_context_mut();
300300
let method = this.machine.borrow_tracker.as_ref().unwrap().borrow().borrow_tracker_method;
@@ -304,10 +304,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
304304
}
305305
}
306306

307-
fn protect_place(
308-
&mut self,
309-
place: &MPlaceTy<'tcx, Provenance>,
310-
) -> InterpResult<'tcx, MPlaceTy<'tcx, Provenance>> {
307+
fn protect_place(&mut self, place: &MPlaceTy<'tcx>) -> InterpResult<'tcx, MPlaceTy<'tcx>> {
311308
let this = self.eval_context_mut();
312309
let method = this.machine.borrow_tracker.as_ref().unwrap().borrow().borrow_tracker_method;
313310
match method {
@@ -327,7 +324,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
327324

328325
fn give_pointer_debug_name(
329326
&mut self,
330-
ptr: Pointer<Option<Provenance>>,
327+
ptr: Pointer,
331328
nth_parent: u8,
332329
name: &str,
333330
) -> InterpResult<'tcx> {

src/tools/miri/src/borrow_tracker/stacked_borrows/diagnostics.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,7 @@ impl<'ecx, 'tcx> DiagnosticCxBuilder<'ecx, 'tcx> {
149149
DiagnosticCxBuilder { machine, operation }
150150
}
151151

152-
pub fn read(
153-
machine: &'ecx MiriMachine<'tcx>,
154-
tag: ProvenanceExtra,
155-
range: AllocRange,
156-
) -> Self {
152+
pub fn read(machine: &'ecx MiriMachine<'tcx>, tag: ProvenanceExtra, range: AllocRange) -> Self {
157153
let operation = Operation::Access(AccessOp { kind: AccessKind::Read, tag, range });
158154
DiagnosticCxBuilder { machine, operation }
159155
}

0 commit comments

Comments
 (0)