Skip to content

Commit 6c2c0c2

Browse files
committed
Auto merge of #17460 - lnicola:sync-from-rust, r=lnicola
minor: Sync from rust
2 parents 796d4e3 + f5e02ad commit 6c2c0c2

File tree

224 files changed

+6387
-3927
lines changed

Some content is hidden

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

224 files changed

+6387
-3927
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ tex/*/out
55
*.out
66
*.rs.bk
77
.vscode
8+
.helix
89
*.mm_profdata
910
perf.data
1011
perf.data.old

CONTRIBUTING.md

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

README.md

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,21 @@ platform. For example `cargo miri test --target s390x-unknown-linux-gnu`
151151
will run your test suite on a big-endian target, which is useful for testing
152152
endian-sensitive code.
153153

154+
### Testing multiple different executions
155+
156+
Certain parts of the execution are picked randomly by Miri, such as the exact base address
157+
allocations are stored at and the interleaving of concurrently executing threads. Sometimes, it can
158+
be useful to explore multiple different execution, e.g. to make sure that your code does not depend
159+
on incidental "super-alignment" of new allocations and to test different thread interleavings.
160+
This can be done with the `--many-seeds` flag:
161+
162+
```
163+
cargo miri test --many-seeds # tries the seeds in 0..64
164+
cargo miri test --many-seeds=0..16
165+
```
166+
167+
The default of 64 different seeds is quite slow, so you probably want to specify a smaller range.
168+
154169
### Running Miri on CI
155170

156171
When running Miri on CI, use the following snippet to install a nightly toolchain with the Miri
@@ -183,23 +198,6 @@ Here is an example job for GitHub Actions:
183198
The explicit `cargo miri setup` helps to keep the output of the actual test step
184199
clean.
185200

186-
### Testing for alignment issues
187-
188-
Miri can sometimes miss misaligned accesses since allocations can "happen to be"
189-
aligned just right. You can use `-Zmiri-symbolic-alignment-check` to definitely
190-
catch all such issues, but that flag will also cause false positives when code
191-
does manual pointer arithmetic to account for alignment. Another alternative is
192-
to call Miri with various values for `-Zmiri-seed`; that will alter the
193-
randomness that is used to determine allocation base addresses. The following
194-
snippet calls Miri in a loop with different values for the seed:
195-
196-
```
197-
for SEED in $(seq 0 255); do
198-
echo "Trying seed: $SEED"
199-
MIRIFLAGS=-Zmiri-seed=$SEED cargo miri test || { echo "Failing seed: $SEED"; break; };
200-
done
201-
```
202-
203201
### Supported targets
204202

205203
Miri does not support all targets supported by Rust. The good news, however, is
@@ -448,28 +446,19 @@ Some native rustc `-Z` flags are also very relevant for Miri:
448446
* `-Zmir-emit-retag` controls whether `Retag` statements are emitted. Miri
449447
enables this per default because it is needed for [Stacked Borrows] and [Tree Borrows].
450448

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}`):
449+
Moreover, Miri recognizes some environment variables:
453450

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].
459451
* `MIRIFLAGS` defines extra flags to be passed to Miri.
460452
* `MIRI_LIB_SRC` defines the directory where Miri expects the sources of the standard library that
461453
it will build and use for interpretation. This directory must point to the `library` subdirectory
462454
of a `rust-lang/rust` repository checkout.
463-
* `MIRI_SYSROOT` indicates the sysroot to use. When using `cargo miri`, this skips the automatic
455+
* `MIRI_SYSROOT` indicates the sysroot to use. When using `cargo miri test`/`cargo miri run`, this skips the automatic
464456
setup -- only set this if you do not want to use the automatically created sysroot. When invoking
465457
`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.
468458
* `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.
459+
and running no_std programs. This should *not usually be used*; Miri has a heuristic to detect
460+
no-std targets based on the target name. Setting this on a target that does support libstd can
461+
lead to confusing results.
473462

474463
[testing-miri]: CONTRIBUTING.md#testing-the-miri-driver
475464

bench-cargo-miri/big-allocs/Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 0 deletions
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]
Lines changed: 13 additions & 0 deletions
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+
}

cargo-miri/Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cargo-miri/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ directories = "5"
1818
rustc_version = "0.4"
1919
serde_json = "1.0.40"
2020
cargo_metadata = "0.18.0"
21-
rustc-build-sysroot = "0.4.6"
21+
rustc-build-sysroot = "0.5.2"
2222

2323
# Enable some feature flags that dev-dependencies need but dependencies
2424
# do not. This makes `./miri install` after `./miri build` faster.

cargo-miri/src/main.rs

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

0 commit comments

Comments
 (0)