Skip to content

Commit 7ad67e6

Browse files
authored
Rollup merge of #143478 - RalfJung:miri-sync, r=RalfJung
Miri subtree update r? `@ghost`
2 parents 0311159 + a1f4172 commit 7ad67e6

Some content is hidden

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

54 files changed

+1469
-475
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2394,6 +2394,7 @@ dependencies = [
23942394
"regex",
23952395
"rustc_version",
23962396
"serde",
2397+
"serde_json",
23972398
"smallvec",
23982399
"tempfile",
23992400
"tikv-jemalloc-sys",

src/tools/miri/.github/workflows/ci.yml

Lines changed: 62 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,35 +13,82 @@ defaults:
1313
shell: bash
1414

1515
jobs:
16-
build:
16+
test:
17+
name: test (${{ matrix.host_target }})
1718
strategy:
1819
fail-fast: false
1920
matrix:
2021
include:
21-
- os: ubuntu-latest
22-
host_target: x86_64-unknown-linux-gnu
23-
- os: macos-14
24-
host_target: aarch64-apple-darwin
25-
- os: windows-latest
26-
host_target: i686-pc-windows-msvc
22+
- host_target: x86_64-unknown-linux-gnu
23+
os: ubuntu-latest
24+
- host_target: i686-unknown-linux-gnu
25+
os: ubuntu-latest
26+
multiarch: i386
27+
gcc_cross: i686-linux-gnu
28+
- host_target: aarch64-unknown-linux-gnu
29+
os: ubuntu-24.04-arm
30+
- host_target: armv7-unknown-linux-gnueabihf
31+
os: ubuntu-24.04-arm
32+
multiarch: armhf
33+
gcc_cross: arm-linux-gnueabihf
34+
- host_target: riscv64gc-unknown-linux-gnu
35+
os: ubuntu-latest
36+
multiarch: riscv64
37+
gcc_cross: riscv64-linux-gnu
38+
qemu: true
39+
- host_target: s390x-unknown-linux-gnu
40+
os: ubuntu-latest
41+
multiarch: s390x
42+
gcc_cross: s390x-linux-gnu
43+
qemu: true
44+
- host_target: aarch64-apple-darwin
45+
os: macos-latest
46+
- host_target: i686-pc-windows-msvc
47+
os: windows-latest
2748
runs-on: ${{ matrix.os }}
2849
env:
2950
HOST_TARGET: ${{ matrix.host_target }}
3051
steps:
3152
- uses: actions/checkout@v4
53+
- name: install qemu
54+
if: ${{ matrix.qemu }}
55+
run: sudo apt install qemu-user qemu-user-binfmt
56+
- name: install multiarch
57+
if: ${{ matrix.multiarch != '' }}
58+
run: |
59+
# s390x, ppc64el need Ubuntu Ports to be in the mirror list
60+
sudo bash -c "echo 'https://ports.ubuntu.com/ priority:4' >> /etc/apt/apt-mirrors.txt"
61+
# Add architecture
62+
sudo dpkg --add-architecture ${{ matrix.multiarch }}
63+
sudo apt update
64+
# Install needed packages
65+
sudo apt install $(echo "libatomic1: zlib1g-dev:" | sed 's/:/:${{ matrix.multiarch }}/g')
3266
- uses: ./.github/workflows/setup
3367
with:
3468
toolchain_flags: "--host ${{ matrix.host_target }}"
3569

36-
# The `style` job only runs on Linux; this makes sure the Windows-host-specific
37-
# code is also covered by clippy.
38-
- name: Check clippy
39-
if: ${{ matrix.os == 'windows-latest' }}
40-
run: ./miri clippy -- -D warnings
70+
# We set up the cross-compiler *after* the basic setup as setting CC would otherwise
71+
# cause confusion.
72+
- name: install gcc-cross
73+
if: ${{ matrix.gcc_cross != '' }}
74+
run: |
75+
sudo apt install gcc-${{ matrix.gcc_cross }}
76+
echo "Setting environment variables:"
77+
echo "CC_${{ matrix.host_target }}=${{ matrix.gcc_cross }}-gcc" | tee -a $GITHUB_ENV
78+
TARGET_UPPERCASE=$(echo ${{ matrix.host_target }} | tr '[:lower:]-' '[:upper:]_')
79+
echo "CARGO_TARGET_${TARGET_UPPERCASE}_LINKER=${{ matrix.gcc_cross }}-gcc" | tee -a $GITHUB_ENV
4180
42-
- name: Test Miri
81+
# The main test job! We don't run this in qemu as that is quite slow,
82+
# so those targets only get the clippy check below.
83+
- name: test Miri
84+
if: ${{ !matrix.qemu }}
4385
run: ./ci/ci.sh
4486

87+
# The `style` job only runs on Linux; this makes sure the host-specific
88+
# code is also covered by clippy.
89+
- name: clippy
90+
run: ./miri clippy -- -D warnings
91+
4592
style:
4693
name: style checks
4794
runs-on: ubuntu-latest
@@ -51,8 +98,6 @@ jobs:
5198

5299
- name: rustfmt
53100
run: ./miri fmt --check
54-
- name: clippy
55-
run: ./miri clippy -- -D warnings
56101
- name: clippy (no features)
57102
run: ./miri clippy --no-default-features -- -D warnings
58103
- name: clippy (all features)
@@ -73,7 +118,7 @@ jobs:
73118
# ALL THE PREVIOUS JOBS NEED TO BE ADDED TO THE `needs` SECTION OF THIS JOB!
74119
# And they should be added below in `cron-fail-notify` as well.
75120
conclusion:
76-
needs: [build, style, coverage]
121+
needs: [test, style, coverage]
77122
# We need to ensure this job does *not* get skipped if its dependencies fail,
78123
# because a skipped job is considered a success by GitHub. So we have to
79124
# overwrite `if:`. We use `!cancelled()` to ensure the job does still not get run
@@ -135,7 +180,7 @@ jobs:
135180
cron-fail-notify:
136181
name: cronjob failure notification
137182
runs-on: ubuntu-latest
138-
needs: [build, style, coverage]
183+
needs: [test, style, coverage]
139184
if: ${{ github.event_name == 'schedule' && failure() }}
140185
steps:
141186
# Send a Zulip notification

src/tools/miri/.github/workflows/setup/action.yml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ name: "Miri CI setup"
22
description: "Sets up Miri CI"
33
inputs:
44
toolchain_flags:
5+
description: extra flags to pass to rustup-toolchain-install-master
56
required: false
67
default: ''
78
runs:
@@ -31,18 +32,15 @@ runs:
3132
~/.cargo/bin
3233
~/.cargo/.crates.toml
3334
~/.cargo/.crates2.json
34-
key: cargo-${{ runner.os }}-${{ hashFiles('**/Cargo.lock', '.github/workflows/**/*.yml') }}
35-
restore-keys: cargo-${{ runner.os }}
35+
# Bump the version when something here changes that needs a cache reset.
36+
key: cargo-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('**/Cargo.lock') }}-v1
37+
restore-keys: cargo-${{ runner.os }}-${{ runner.arch }}
3638

37-
- name: Install rustup-toolchain-install-master
39+
- name: Install the tools we need
3840
if: steps.cache.outputs.cache-hit != 'true'
3941
run: cargo install -f rustup-toolchain-install-master hyperfine
4042
shell: bash
4143

42-
- name: Install nightly toolchain
43-
run: rustup toolchain install nightly --profile minimal
44-
shell: bash
45-
4644
- name: Install "master" toolchain
4745
run: |
4846
if [[ ${{ github.event_name }} == 'schedule' ]]; then

src/tools/miri/CONTRIBUTING.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,15 @@ compiler that has `debug=true` set in `bootstrap.toml`.
158158
You can set `MIRI_BACKTRACE=1` to get a backtrace of where an
159159
evaluation error was originally raised.
160160

161+
#### Tracing
162+
163+
You can generate a Chrome trace file from a Miri execution by passing `--features=tracing` during the
164+
build and then setting `MIRI_TRACING=1` when running Miri. This will generate a `.json` file that
165+
you can visualize in [Perfetto](https://ui.perfetto.dev/). For example:
166+
167+
```sh
168+
MIRI_TRACING=1 ./miri run --features=tracing tests/pass/hello.rs
169+
```
161170

162171
### UI testing
163172

src/tools/miri/Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,7 @@ dependencies = [
627627
"regex",
628628
"rustc_version",
629629
"serde",
630+
"serde_json",
630631
"smallvec",
631632
"tempfile",
632633
"tikv-jemalloc-sys",

src/tools/miri/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ chrono = { version = "0.4.38", default-features = false }
2727
chrono-tz = "0.10"
2828
directories = "6"
2929
bitflags = "2.6"
30+
serde_json = { version = "1.0", optional = true }
3031

3132
# Copied from `compiler/rustc/Cargo.toml`.
3233
# But only for some targets, it fails for others. Rustc configures this in its CI, but we can't
@@ -67,6 +68,7 @@ default = ["stack-cache"]
6768
genmc = []
6869
stack-cache = []
6970
stack-cache-consistency-check = ["stack-cache"]
71+
tracing = ["serde_json"]
7072

7173
[lints.rust.unexpected_cfgs]
7274
level = "warn"

src/tools/miri/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ instance:
1111
* Not sufficiently aligned memory accesses and references
1212
* Violation of basic type invariants (a `bool` that is not 0 or 1, for example,
1313
or an invalid enum discriminant)
14+
* Data races and emulation of *some* weak memory effects, i.e.,
15+
atomic reads can return outdated values
1416
* **Experimental**: Violations of the [Stacked Borrows] rules governing aliasing
1517
for reference types
1618
* **Experimental**: Violations of the [Tree Borrows] aliasing rules, as an optional
1719
alternative to [Stacked Borrows]
18-
* **Experimental**: Data races and emulation of weak memory effects, i.e.,
19-
atomic reads can return outdated values.
2020

2121
On top of that, Miri will also tell you about memory leaks: when there is memory
2222
still allocated at the end of the execution, and that memory is not reachable

src/tools/miri/ci/ci.sh

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -143,42 +143,53 @@ case $HOST_TARGET in
143143
GC_STRESS=1 MIR_OPT=1 MANY_SEEDS=64 TEST_BENCH=1 CARGO_MIRI_ENV=1 run_tests
144144
# Extra tier 1
145145
MANY_SEEDS=64 TEST_TARGET=i686-unknown-linux-gnu run_tests
146-
MANY_SEEDS=64 TEST_TARGET=aarch64-unknown-linux-gnu run_tests
147146
MANY_SEEDS=64 TEST_TARGET=x86_64-apple-darwin run_tests
148147
MANY_SEEDS=64 TEST_TARGET=x86_64-pc-windows-gnu run_tests
148+
;;
149+
i686-unknown-linux-gnu)
150+
# Host
151+
# Without GC_STRESS as this is a slow runner.
152+
MIR_OPT=1 MANY_SEEDS=64 TEST_BENCH=1 CARGO_MIRI_ENV=1 run_tests
153+
# Partially supported targets (tier 2)
154+
BASIC="empty_main integer heap_alloc libc-mem vec string btreemap" # ensures we have the basics: pre-main code, system allocator
155+
UNIX="hello 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
156+
TEST_TARGET=aarch64-linux-android run_tests_minimal $BASIC $UNIX time hashmap random thread sync concurrency epoll eventfd
157+
TEST_TARGET=wasm32-wasip2 run_tests_minimal $BASIC wasm
158+
TEST_TARGET=wasm32-unknown-unknown run_tests_minimal no_std empty_main wasm # this target doesn't really have std
159+
TEST_TARGET=thumbv7em-none-eabihf run_tests_minimal no_std
160+
;;
161+
aarch64-unknown-linux-gnu)
162+
# Host
163+
GC_STRESS=1 MIR_OPT=1 MANY_SEEDS=64 TEST_BENCH=1 CARGO_MIRI_ENV=1 run_tests
149164
# Extra tier 1 candidate
150165
MANY_SEEDS=64 TEST_TARGET=aarch64-pc-windows-msvc run_tests
166+
# Extra tier 2
167+
MANY_SEEDS=16 TEST_TARGET=arm-unknown-linux-gnueabi run_tests # 32bit ARM
168+
MANY_SEEDS=16 TEST_TARGET=aarch64-pc-windows-gnullvm run_tests # gnullvm ABI
169+
MANY_SEEDS=16 TEST_TARGET=s390x-unknown-linux-gnu run_tests # big-endian architecture of choice
170+
# Custom target JSON file
171+
TEST_TARGET=tests/x86_64-unknown-kernel.json MIRI_NO_STD=1 run_tests_minimal no_std
172+
;;
173+
armv7-unknown-linux-gnueabihf)
174+
# Host
175+
GC_STRESS=1 MIR_OPT=1 MANY_SEEDS=64 TEST_BENCH=1 CARGO_MIRI_ENV=1 run_tests
151176
;;
152177
aarch64-apple-darwin)
153178
# Host
154179
GC_STRESS=1 MIR_OPT=1 MANY_SEEDS=64 TEST_BENCH=1 CARGO_MIRI_ENV=1 run_tests
155180
# Extra tier 1
156181
MANY_SEEDS=64 TEST_TARGET=i686-pc-windows-gnu run_tests
157182
MANY_SEEDS=64 TEST_TARGET=x86_64-pc-windows-msvc CARGO_MIRI_ENV=1 run_tests
158-
# Extra tier 2
159-
MANY_SEEDS=16 TEST_TARGET=arm-unknown-linux-gnueabi run_tests # 32bit ARM
160-
MANY_SEEDS=16 TEST_TARGET=aarch64-pc-windows-gnullvm run_tests # gnullvm ABI
161-
MANY_SEEDS=16 TEST_TARGET=s390x-unknown-linux-gnu run_tests # big-endian architecture of choice
162183
# Not officially supported tier 2
163184
MANY_SEEDS=16 TEST_TARGET=mips-unknown-linux-gnu run_tests # a 32bit big-endian target, and also a target without 64bit atomics
164185
MANY_SEEDS=16 TEST_TARGET=x86_64-unknown-illumos run_tests
165186
MANY_SEEDS=16 TEST_TARGET=x86_64-pc-solaris run_tests
166187
MANY_SEEDS=16 TEST_TARGET=x86_64-unknown-freebsd run_tests
167188
MANY_SEEDS=16 TEST_TARGET=i686-unknown-freebsd run_tests
168-
# Partially supported targets (tier 2)
169-
BASIC="empty_main integer heap_alloc libc-mem vec string btreemap" # ensures we have the basics: pre-main code, system allocator
170-
UNIX="hello 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
171-
TEST_TARGET=aarch64-linux-android run_tests_minimal $BASIC $UNIX time hashmap random thread sync concurrency epoll eventfd
172-
TEST_TARGET=wasm32-wasip2 run_tests_minimal $BASIC wasm
173-
TEST_TARGET=wasm32-unknown-unknown run_tests_minimal no_std empty_main wasm # this target doesn't really have std
174-
TEST_TARGET=thumbv7em-none-eabihf run_tests_minimal no_std
175-
# Custom target JSON file
176-
TEST_TARGET=tests/x86_64-unknown-kernel.json MIRI_NO_STD=1 run_tests_minimal no_std
177189
;;
178190
i686-pc-windows-msvc)
179191
# Host
180-
# Without GC_STRESS and with reduced many-seeds count as this is the slowest runner.
181-
# (The macOS runner checks windows-msvc with full many-seeds count.)
192+
# Without GC_STRESS as this is the slowest runner.
182193
MIR_OPT=1 MANY_SEEDS=64 TEST_BENCH=1 run_tests
183194
# Extra tier 1
184195
# We really want to ensure a Linux target works on a Windows host,

src/tools/miri/etc/rust_analyzer_helix.toml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,21 @@ linkedProjects = [
99
]
1010

1111
[language-server.rust-analyzer.config.check]
12-
invocationLocation = "root"
1312
invocationStrategy = "once"
1413
overrideCommand = [
15-
"env",
16-
"MIRI_AUTO_OPS=no",
1714
"./miri",
1815
"clippy", # make this `check` when working with a locally built rustc
1916
"--message-format=json",
2017
]
2118

19+
[language-server.rust-analyzer.config.cargo.extraEnv]
20+
MIRI_AUTO_OPS = "no"
21+
MIRI_IN_RA = "1"
22+
2223
# Contrary to what the name suggests, this also affects proc macros.
23-
[language-server.rust-analyzer.config.buildScripts]
24-
invocationLocation = "root"
24+
[language-server.rust-analyzer.config.cargo.buildScripts]
2525
invocationStrategy = "once"
2626
overrideCommand = [
27-
"env",
28-
"MIRI_AUTO_OPS=no",
2927
"./miri",
3028
"check",
3129
"--message-format=json",

src/tools/miri/miri

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,24 @@
22
set -e
33
# We want to call the binary directly, so we need to know where it ends up.
44
ROOT_DIR="$(dirname "$0")"
5-
MIRI_SCRIPT_TARGET_DIR="$ROOT_DIR"/miri-script/target
6-
TOOLCHAIN="+nightly"
5+
TARGET_DIR="$ROOT_DIR"/miri-script/target
6+
# Prepare cargo invocation.
7+
# We have to overwrite the toolchain since `+miri` might be activated and not installed.
8+
TOOLCHAIN="+stable"
9+
CARGO_FLAGS=("-q")
710
# If we are being invoked for RA, use JSON output and the default toolchain (to make proc-macros
811
# work in RA). This needs a different target dir to avoid mixing up the builds.
12+
# Also set `-Zroot-dir` so that RA can identify where the error occurred.
913
if [ -n "$MIRI_IN_RA" ]; then
10-
MESSAGE_FORMAT="--message-format=json"
1114
TOOLCHAIN=""
12-
MIRI_SCRIPT_TARGET_DIR="$MIRI_SCRIPT_TARGET_DIR"/ra
15+
CARGO_FLAGS+=("--message-format=json" "-Zroot-dir=$ROOT_DIR")
16+
TARGET_DIR="$ROOT_DIR"/target
1317
fi
14-
# We need a nightly toolchain, for `-Zroot-dir`.
15-
cargo $TOOLCHAIN build $CARGO_EXTRA_FLAGS --manifest-path "$ROOT_DIR"/miri-script/Cargo.toml \
16-
-Zroot-dir="$ROOT_DIR" \
17-
-q --target-dir "$MIRI_SCRIPT_TARGET_DIR" $MESSAGE_FORMAT || \
18-
( echo "Failed to build miri-script. Is the 'nightly' toolchain installed?"; exit 1 )
19-
# Instead of doing just `cargo run --manifest-path .. $@`, we invoke miri-script binary directly. Invoking `cargo run` goes through
20-
# rustup (that sets it's own environmental variables), which is undesirable.
21-
"$MIRI_SCRIPT_TARGET_DIR"/debug/miri-script "$@"
18+
# Run cargo.
19+
cargo $TOOLCHAIN build --manifest-path "$ROOT_DIR"/miri-script/Cargo.toml \
20+
--target-dir "$TARGET_DIR" "${CARGO_FLAGS[@]}" || \
21+
( echo "Failed to build miri-script. Is the 'stable' toolchain installed?"; exit 1 )
22+
# Instead of doing just `cargo run --manifest-path .. $@`, we invoke miri-script binary directly.
23+
# Invoking `cargo run` goes through rustup (that sets it's own environmental variables), which is
24+
# undesirable.
25+
"$TARGET_DIR"/debug/miri-script "$@"

src/tools/miri/miri-script/src/commands.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,6 @@ impl Command {
231231
cmd!(sh, "rustup override set miri").run()?;
232232
// Cleanup.
233233
cmd!(sh, "cargo clean").run()?;
234-
// Call `cargo metadata` on the sources in case that changes the lockfile
235-
// (which fails under some setups when it is done from inside vscode).
236-
let sysroot = cmd!(sh, "rustc --print sysroot").read()?;
237-
let sysroot = sysroot.trim();
238-
cmd!(sh, "cargo metadata --format-version 1 --manifest-path {sysroot}/lib/rustlib/rustc-src/rust/compiler/rustc/Cargo.toml").ignore_stdout().run()?;
239234
Ok(())
240235
}
241236

@@ -707,9 +702,12 @@ impl Command {
707702
let mut early_flags = Vec::<OsString>::new();
708703

709704
// In `dep` mode, the target is already passed via `MIRI_TEST_TARGET`
710-
if !dep && let Some(target) = &target {
711-
early_flags.push("--target".into());
712-
early_flags.push(target.into());
705+
#[expect(clippy::collapsible_if)] // we need to wait until this is stable
706+
if !dep {
707+
if let Some(target) = &target {
708+
early_flags.push("--target".into());
709+
early_flags.push(target.into());
710+
}
713711
}
714712
early_flags.push("--edition".into());
715713
early_flags.push(edition.as_deref().unwrap_or("2021").into());
@@ -737,8 +735,11 @@ impl Command {
737735
// Add Miri flags
738736
let mut cmd = cmd.args(&miri_flags).args(&early_flags).args(&flags);
739737
// For `--dep` we also need to set the target in the env var.
740-
if dep && let Some(target) = &target {
741-
cmd = cmd.env("MIRI_TEST_TARGET", target);
738+
#[expect(clippy::collapsible_if)] // we need to wait until this is stable
739+
if dep {
740+
if let Some(target) = &target {
741+
cmd = cmd.env("MIRI_TEST_TARGET", target);
742+
}
742743
}
743744
// Finally, run the thing.
744745
Ok(cmd.run()?)

0 commit comments

Comments
 (0)