Skip to content

Commit e9493d6

Browse files
committedNov 16, 2022
Auto merge of #104456 - RalfJung:miri, r=RalfJung
update Miri Not a huge sync, but there was a conflict and [josh](https://github.com/josh-project/josh/) seems to prefer those to be merged back ASAP.
2 parents e69336e + 157b2d5 commit e9493d6

File tree

22 files changed

+347
-374
lines changed

22 files changed

+347
-374
lines changed
 

‎Cargo.lock

+39-39
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,18 @@ dependencies = [
214214
"regex-automata",
215215
]
216216

217+
[[package]]
218+
name = "bstr"
219+
version = "1.0.1"
220+
source = "registry+https://github.com/rust-lang/crates.io-index"
221+
checksum = "fca0852af221f458706eb0725c03e4ed6c46af9ac98e6a689d5e634215d594dd"
222+
dependencies = [
223+
"memchr",
224+
"once_cell",
225+
"regex-automata",
226+
"serde",
227+
]
228+
217229
[[package]]
218230
name = "build-manifest"
219231
version = "0.1.0"
@@ -919,25 +931,11 @@ dependencies = [
919931
"cfg-if 1.0.0",
920932
]
921933

922-
[[package]]
923-
name = "crossbeam"
924-
version = "0.8.1"
925-
source = "registry+https://github.com/rust-lang/crates.io-index"
926-
checksum = "4ae5588f6b3c3cb05239e90bd110f257254aecd01e4635400391aeae07497845"
927-
dependencies = [
928-
"cfg-if 1.0.0",
929-
"crossbeam-channel",
930-
"crossbeam-deque",
931-
"crossbeam-epoch",
932-
"crossbeam-queue",
933-
"crossbeam-utils",
934-
]
935-
936934
[[package]]
937935
name = "crossbeam-channel"
938-
version = "0.5.4"
936+
version = "0.5.6"
939937
source = "registry+https://github.com/rust-lang/crates.io-index"
940-
checksum = "5aaa7bd5fb665c6864b5f963dd9097905c54125909c7aa94c9e18507cdbe6c53"
938+
checksum = "c2dd04ddaf88237dc3b8d8f9a3c1004b506b54b3313403944054d23c0870c521"
941939
dependencies = [
942940
"cfg-if 1.0.0",
943941
"crossbeam-utils",
@@ -967,16 +965,6 @@ dependencies = [
967965
"scopeguard",
968966
]
969967

970-
[[package]]
971-
name = "crossbeam-queue"
972-
version = "0.3.5"
973-
source = "registry+https://github.com/rust-lang/crates.io-index"
974-
checksum = "1f25d8400f4a7a5778f0e4e52384a48cbd9b5c495d110786187fc750075277a2"
975-
dependencies = [
976-
"cfg-if 1.0.0",
977-
"crossbeam-utils",
978-
]
979-
980968
[[package]]
981969
name = "crossbeam-utils"
982970
version = "0.8.8"
@@ -1260,6 +1248,15 @@ version = "0.2.0"
12601248
source = "registry+https://github.com/rust-lang/crates.io-index"
12611249
checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7"
12621250

1251+
[[package]]
1252+
name = "fastrand"
1253+
version = "1.8.0"
1254+
source = "registry+https://github.com/rust-lang/crates.io-index"
1255+
checksum = "a7a407cfaa3385c4ae6b23e84623d48c2798d06e3e6a1878f7f59f17b3f86499"
1256+
dependencies = [
1257+
"instant",
1258+
]
1259+
12631260
[[package]]
12641261
name = "filetime"
12651262
version = "0.2.14"
@@ -1584,7 +1581,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
15841581
checksum = "0a1e17342619edbc21a964c2afbeb6c820c6a2560032872f397bb97ea127bd0a"
15851582
dependencies = [
15861583
"aho-corasick",
1587-
"bstr",
1584+
"bstr 0.2.17",
15881585
"fnv",
15891586
"log",
15901587
"regex",
@@ -2341,17 +2338,17 @@ dependencies = [
23412338

23422339
[[package]]
23432340
name = "once_cell"
2344-
version = "1.12.0"
2341+
version = "1.16.0"
23452342
source = "registry+https://github.com/rust-lang/crates.io-index"
2346-
checksum = "7709cef83f0c1f58f666e746a08b21e0085f7440fa6a29cc194d68aac97a4225"
2343+
checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860"
23472344

23482345
[[package]]
23492346
name = "opener"
23502347
version = "0.5.0"
23512348
source = "registry+https://github.com/rust-lang/crates.io-index"
23522349
checksum = "4ea3ebcd72a54701f56345f16785a6d3ac2df7e986d273eb4395c0b01db17952"
23532350
dependencies = [
2354-
"bstr",
2351+
"bstr 0.2.17",
23552352
"winapi",
23562353
]
23572354

@@ -3008,9 +3005,9 @@ dependencies = [
30083005

30093006
[[package]]
30103007
name = "rustc-build-sysroot"
3011-
version = "0.3.3"
3008+
version = "0.4.0"
30123009
source = "registry+https://github.com/rust-lang/crates.io-index"
3013-
checksum = "ec5f3689b6c560d6a3a17fcbe54204cd870b4fcf46342d60de16715b660d2c92"
3010+
checksum = "20c4b4625eeb148cccf82d5e9b90ad7fab3b11a0204cf75cc7fa04981a0fdffd"
30143011
dependencies = [
30153012
"anyhow",
30163013
"rustc_version",
@@ -3098,9 +3095,10 @@ dependencies = [
30983095
name = "rustc-workspace-hack"
30993096
version = "1.0.0"
31003097
dependencies = [
3101-
"bstr",
3098+
"bstr 0.2.17",
31023099
"clap 3.2.20",
31033100
"libz-sys",
3101+
"rand 0.8.5",
31043102
"regex",
31053103
"serde_json",
31063104
"syn",
@@ -4767,13 +4765,13 @@ dependencies = [
47674765

47684766
[[package]]
47694767
name = "tempfile"
4770-
version = "3.2.0"
4768+
version = "3.3.0"
47714769
source = "registry+https://github.com/rust-lang/crates.io-index"
4772-
checksum = "dac1c663cfc93810f88aed9b8941d48cabf856a1b111c29a40439018d870eb22"
4770+
checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4"
47734771
dependencies = [
47744772
"cfg-if 1.0.0",
4773+
"fastrand",
47754774
"libc",
4776-
"rand 0.8.5",
47774775
"redox_syscall",
47784776
"remove_dir_all",
47794777
"winapi",
@@ -5119,20 +5117,22 @@ checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c"
51195117

51205118
[[package]]
51215119
name = "ui_test"
5122-
version = "0.3.1"
5120+
version = "0.4.0"
51235121
source = "registry+https://github.com/rust-lang/crates.io-index"
5124-
checksum = "7d1f546a5883ae78da735bba529ec1116661e2f73582f23920d994dc97da3a22"
5122+
checksum = "bf4559da3fe6b481f8674a29379677cb9606cd6f75fc254a2c9834c55638503d"
51255123
dependencies = [
5124+
"bstr 1.0.1",
51265125
"cargo_metadata 0.15.0",
51275126
"color-eyre",
51285127
"colored",
5129-
"crossbeam",
5128+
"crossbeam-channel",
51305129
"diff",
51315130
"lazy_static",
51325131
"regex",
51335132
"rustc_version",
51345133
"serde",
51355134
"serde_json",
5135+
"tempfile",
51365136
]
51375137

51385138
[[package]]

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ jobs:
6767
shell: bash
6868
run: |
6969
if [[ ${{ github.event_name }} == 'schedule' ]]; then
70-
./miri toolchain HEAD --host ${{ matrix.host_target }}
71-
else
72-
./miri toolchain "" --host ${{ matrix.host_target }}
70+
echo "Building against latest rustc git version"
71+
git ls-remote https://github.com/rust-lang/rust/ HEAD | cut -f 1 > rust-version
7372
fi
73+
./miri toolchain --host ${{ matrix.host_target }}
7474
7575
- name: Show Rust version
7676
run: |

‎src/tools/miri/CONTRIBUTING.md

+9-24
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ is set the `MIRI_LIB_SRC` environment variable to the `library` folder of a
150150
`rust-lang/rust` repository checkout. Note that changing files in that directory
151151
does not automatically trigger a re-build of the standard library; you have to
152152
clear the Miri build cache manually (on Linux, `rm -rf ~/.cache/miri`;
153-
and on Windows, `rmdir /S "%LOCALAPPDATA%\rust-lang\miri\cache"`).
153+
on Windows, `rmdir /S "%LOCALAPPDATA%\rust-lang\miri\cache"`;
154+
and on macOS, `rm -rf ~/Library/Caches/org.rust-lang.miri`).
154155

155156
### Benchmarking
156157

@@ -208,23 +209,6 @@ We described above the simplest way to get a working build environment for Miri,
208209
which is to use the version of rustc indicated by `rustc-version`. But
209210
sometimes, that is not enough.
210211

211-
### Updating `rustc-version`
212-
213-
The `rustc-version` file is regularly updated to keep Miri close to the latest
214-
version of rustc. Usually, new contributors do not have to worry about this. But
215-
sometimes a newer rustc is needed for a patch, and sometimes Miri needs fixing
216-
for changes in rustc. In both cases, `rustc-version` needs updating.
217-
218-
To update the `rustc-version` file and install the latest rustc, you can run:
219-
```
220-
./miri toolchain HEAD
221-
```
222-
223-
Now edit Miri until `./miri test` passes, and submit a PR. Generally, it is
224-
preferred to separate updating `rustc-version` and doing what it takes to get
225-
Miri working again, from implementing new features that rely on the updated
226-
rustc. This avoids blocking all Miri development on landing a big PR.
227-
228212
### Building Miri with a locally built rustc
229213

230214
[building Miri with a locally built rustc]: #building-miri-with-a-locally-built-rustc
@@ -282,13 +266,13 @@ With this, you should now have a working development setup! See
282266
## Advanced topic: Syncing with the rustc repo
283267

284268
We use the [`josh` proxy](https://github.com/josh-project/josh) to transmit
285-
changes between the rustc and Miri repositories. For now, a fork of josh needs to be built
286-
from source. This downloads and runs josh:
269+
changes between the rustc and Miri repositories. For now, the latest git version
270+
of josh needs to be built from source. This downloads and runs josh:
287271

288272
```sh
289-
git clone https://github.com/RalfJung/josh
273+
git clone https://github.com/josh-project/josh
290274
cd josh
291-
cargo run --release -p josh-proxy -- --local=$(pwd)/local --remote=https://github.com --no-background
275+
cargo run --release -p josh-proxy -- --local=local --remote=https://github.com --no-background
292276
```
293277

294278
### Importing changes from the rustc repo
@@ -298,9 +282,10 @@ We assume we start on an up-to-date master branch in the Miri repo.
298282

299283
```sh
300284
# Fetch and merge rustc side of the history. Takes ca 5 min the first time.
285+
# This will also update the 'rustc-version' file.
301286
./miri rustc-pull
302-
# Update toolchain reference and apply formatting.
303-
./miri toolchain HEAD && ./miri fmt
287+
# Update local toolchain and apply formatting.
288+
./miri toolchain && ./miri fmt
304289
git commit -am "rustup"
305290
```
306291

‎src/tools/miri/Cargo.lock

+55-61
Original file line numberDiff line numberDiff line change

‎src/tools/miri/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ libloading = "0.7"
4040

4141
[dev-dependencies]
4242
colored = "2"
43-
ui_test = "0.3.1"
43+
ui_test = "0.4"
4444
rustc_version = "0.4"
4545
# Features chosen to match those required by env_logger, to avoid rebuilds
4646
regex = { version = "1.5.5", default-features = false, features = ["perf", "std"] }

‎src/tools/miri/README.md

+12-1
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,9 @@ Moreover, Miri recognizes some environment variables:
432432
must point to the `library` subdirectory of a `rust-lang/rust` repository
433433
checkout. Note that changing files in that directory does not automatically
434434
trigger a re-build of the standard library; you have to clear the Miri build
435-
cache manually (on Linux, `rm -rf ~/.cache/miri`).
435+
cache manually (on Linux, `rm -rf ~/.cache/miri`;
436+
on Windows, `rmdir /S "%LOCALAPPDATA%\rust-lang\miri\cache"`;
437+
and on macOS, `rm -rf ~/Library/Caches/org.rust-lang.miri`).
436438
* `MIRI_SYSROOT` (recognized by `cargo miri` and the Miri driver) indicates the sysroot to use. When
437439
using `cargo miri`, this skips the automatic setup -- only set this if you do not want to use the
438440
automatically created sysroot. For directly invoking the Miri driver, this variable (or a
@@ -568,6 +570,15 @@ extern "Rust" {
568570
/// program) the contents of a section of program memory, as bytes. Bytes
569571
/// written using this function will emerge from the interpreter's stderr.
570572
fn miri_write_to_stderr(bytes: &[u8]);
573+
574+
/// Miri-provided extern function to allocate memory from the interpreter.
575+
///
576+
/// This is useful when no fundamental way of allocating memory is
577+
/// available, e.g. when using `no_std` + `alloc`.
578+
fn miri_alloc(size: usize, align: usize) -> *mut u8;
579+
580+
/// Miri-provided extern function to deallocate memory.
581+
fn miri_dealloc(ptr: *mut u8, size: usize, align: usize);
571582
}
572583
```
573584

‎src/tools/miri/cargo-miri/Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change

‎src/tools/miri/cargo-miri/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ directories = "4"
1818
rustc_version = "0.4"
1919
serde_json = "1.0.40"
2020
cargo_metadata = "0.15.0"
21-
rustc-build-sysroot = "0.3.3"
21+
rustc-build-sysroot = "0.4"
2222

2323
# A noop dependency that changes in the Rust repository, it's a bit of a hack.
2424
# See the `src/tools/rustc-workspace-hack/README.md` file in `rust-lang/rust`

‎src/tools/miri/cargo-miri/src/setup.rs

+19-11
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::ffi::OsStr;
55
use std::path::PathBuf;
66
use std::process::{self, Command};
77

8-
use rustc_build_sysroot::{BuildMode, Sysroot, SysrootConfig};
8+
use rustc_build_sysroot::{BuildMode, SysrootBuilder, SysrootConfig};
99
use rustc_version::VersionMeta;
1010

1111
use crate::util::*;
@@ -70,9 +70,11 @@ pub fn setup(subcommand: &MiriCommand, target: &str, rustc_version: &VersionMeta
7070
let sysroot_config = if std::env::var_os("MIRI_NO_STD").is_some() {
7171
SysrootConfig::NoStd
7272
} else {
73-
SysrootConfig::WithStd { std_features: &["panic_unwind", "backtrace"] }
73+
SysrootConfig::WithStd {
74+
std_features: ["panic_unwind", "backtrace"].into_iter().map(Into::into).collect(),
75+
}
7476
};
75-
let cargo_cmd = || {
77+
let cargo_cmd = {
7678
let mut command = cargo();
7779
// Use Miri as rustc to build a libstd compatible with us (and use the right flags).
7880
// However, when we are running in bootstrap, we cannot just overwrite `RUSTC`,
@@ -106,13 +108,14 @@ pub fn setup(subcommand: &MiriCommand, target: &str, rustc_version: &VersionMeta
106108
command.stdout(process::Stdio::null());
107109
command.stderr(process::Stdio::null());
108110
}
109-
// Disable debug assertions in the standard library -- Miri is already slow enough.
110-
// But keep the overflow checks, they are cheap. This completely overwrites flags
111-
// the user might have set, which is consistent with normal `cargo build` that does
112-
// not apply `RUSTFLAGS` to the sysroot either.
113-
let rustflags = vec!["-Cdebug-assertions=off".into(), "-Coverflow-checks=on".into()];
114-
(command, rustflags)
111+
112+
command
115113
};
114+
// Disable debug assertions in the standard library -- Miri is already slow enough.
115+
// But keep the overflow checks, they are cheap. This completely overwrites flags
116+
// the user might have set, which is consistent with normal `cargo build` that does
117+
// not apply `RUSTFLAGS` to the sysroot either.
118+
let rustflags = &["-Cdebug-assertions=off", "-Coverflow-checks=on"];
116119
// Make sure all target-level Miri invocations know their sysroot.
117120
std::env::set_var("MIRI_SYSROOT", &sysroot_dir);
118121

@@ -124,8 +127,13 @@ pub fn setup(subcommand: &MiriCommand, target: &str, rustc_version: &VersionMeta
124127
// We want to be quiet, but still let the user know that something is happening.
125128
eprint!("Preparing a sysroot for Miri (target: {target})... ");
126129
}
127-
Sysroot::new(&sysroot_dir, target)
128-
.build_from_source(&rust_src, BuildMode::Check, sysroot_config, rustc_version, cargo_cmd)
130+
SysrootBuilder::new(&sysroot_dir, target)
131+
.build_mode(BuildMode::Check)
132+
.rustc_version(rustc_version.clone())
133+
.sysroot_config(sysroot_config)
134+
.rustflags(rustflags)
135+
.cargo(cargo_cmd)
136+
.build_from_source(&rust_src)
129137
.unwrap_or_else(|_| {
130138
if only_setup {
131139
show_error!("failed to build sysroot, see error details above")

‎src/tools/miri/miri

+34-31
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,21 @@ many different seeds.
4242
Runs the benchmarks from bench-cargo-miri in hyperfine. hyperfine needs to be installed.
4343
<benches> can explicitly list the benchmarks to run; by default, all of them are run.
4444
45+
./miri toolchain <flags>:
46+
Update and activate the rustup toolchain 'miri' to the commit given in the
47+
`rust-version` file.
48+
`rustup-toolchain-install-master` must be installed for this to work. Any extra
49+
flags are passed to `rustup-toolchain-install-master`.
50+
4551
./miri rustc-pull:
46-
Pull and merge Miri changes from the rustc repo.
52+
Pull and merge Miri changes from the rustc repo. The fetched commit is stored in
53+
the `rust-version` file, so the next `./miri toolchain` will install the rustc
54+
we just pulled.
4755
4856
./miri rustc-push <github user> <branch>:
49-
Push Miri changes back to the rustc repo. This will update the 'master' branch
50-
in the Rust fork of the given user to upstream. It will also pull a copy of the
51-
rustc history into the Miri repo, unless you set the RUSTC_GIT env var to an
52-
existing clone of the rustc repo.
53-
54-
./miri toolchain <commit> <flags>:
55-
Update and activate the rustup toolchain 'miri'. If no commit is given, updates
56-
to the commit given in the `rust-version` file. If the commit is `HEAD`, updates
57-
to the latest upstream rustc commit.
58-
`rustup-toolchain-install-master` must be installed for this to work. Any extra
59-
flags are passed to `rustup-toolchain-install-master`.
57+
Push Miri changes back to the rustc repo. This will pull a copy of the rustc
58+
history into the Miri repo, unless you set the RUSTC_GIT env var to an existing
59+
clone of the rustc repo.
6060
6161
ENVIRONMENT VARIABLES
6262
@@ -78,29 +78,20 @@ shift
7878
# macOS does not have a useful readlink/realpath so we have to use Python instead...
7979
MIRIDIR=$(python3 -c 'import os, sys; print(os.path.dirname(os.path.realpath(sys.argv[1])))' "$0")
8080
# Used for rustc syncs.
81-
JOSH_FILTER=":at_commit=75dd959a3a40eb5b4574f8d2e23aa6efbeb33573[:prefix=src/tools/miri]:/src/tools/miri"
81+
JOSH_FILTER=":rev(75dd959a3a40eb5b4574f8d2e23aa6efbeb33573:prefix=src/tools/miri):/src/tools/miri"
8282
# Needed for `./miri bench`.
8383
TOOLCHAIN=$(cd "$MIRIDIR"; rustup show active-toolchain | head -n 1 | cut -d ' ' -f 1)
8484

8585
## Early commands, that don't do auto-things and don't want the environment-altering things happening below.
8686
case "$COMMAND" in
8787
toolchain)
8888
cd "$MIRIDIR"
89+
NEW_COMMIT=$(cat rust-version)
8990
# Make sure rustup-toolchain-install-master is installed.
9091
if ! which rustup-toolchain-install-master >/dev/null; then
9192
echo "Please install rustup-toolchain-install-master by running 'cargo install rustup-toolchain-install-master'"
9293
exit 1
9394
fi
94-
# Determine new commit.
95-
if [[ "$1" == "" ]]; then
96-
NEW_COMMIT=$(cat rust-version)
97-
elif [[ "$1" == "HEAD" ]]; then
98-
NEW_COMMIT=$(git ls-remote https://github.com/rust-lang/rust/ HEAD | cut -f 1)
99-
else
100-
NEW_COMMIT="$1"
101-
fi
102-
echo "$NEW_COMMIT" > rust-version
103-
shift || true # don't fail if shifting fails because no commit was given
10495
# Check if we already are at that commit.
10596
CUR_COMMIT=$(rustc +miri --version -v 2>/dev/null | grep "^commit-hash: " | cut -d " " -f 2)
10697
if [[ "$CUR_COMMIT" == "$NEW_COMMIT" ]]; then
@@ -122,8 +113,18 @@ toolchain)
122113
;;
123114
rustc-pull)
124115
cd "$MIRIDIR"
116+
FETCH_COMMIT=$(git ls-remote https://github.com/rust-lang/rust/ HEAD | cut -f 1)
117+
# We can't pull from a commit with josh
118+
# (https://github.com/josh-project/josh/issues/1034), so we just hope that
119+
# nothing gets merged into rustc *during* this pull.
125120
git fetch http://localhost:8000/rust-lang/rust.git$JOSH_FILTER.git master
121+
# Just verify that `master` didn't move.
122+
if [[ $FETCH_COMMIT != $(git ls-remote https://github.com/rust-lang/rust/ HEAD | cut -f 1) ]]; then
123+
echo "Looks like something got merged into Rust *while we were pulling*. Aborting. Please try again."
124+
fi
125+
echo "$FETCH_COMMIT" > rust-version # do this *before* merging as merging will fail in case of conflicts
126126
git merge FETCH_HEAD --no-ff -m "Merge from rustc"
127+
git commit rust-version --amend -m "Merge from rustc"
127128
exit 0
128129
;;
129130
rustc-push)
@@ -145,19 +146,21 @@ rustc-push)
145146
fi
146147
cd "$MIRIDIR"
147148
fi
148-
# Prepare the branches. For reliable pushing we need to push to a non-existent branch
149-
# and set `-o base` to a branch that holds current rustc master.
150-
echo "Preparing $USER/rust..."
151-
if git fetch https://github.com/$USER/rust $BRANCH &>/dev/null; then
152-
echo "The '$BRANCH' seems to already exist in $USER/rust. Please delete it and try again."
149+
# Prepare the branch. Pushing works much better if we use as base exactly
150+
# the commit that we pulled from last time, so we use the `rust-version`
151+
# file as a good approximation of that.
152+
BASE=$(cat "$MIRIDIR/rust-version")
153+
echo "Preparing $USER/rust (base: $BASE)..."
154+
if git fetch "https://github.com/$USER/rust" "$BRANCH" &>/dev/null; then
155+
echo "The branch '$BRANCH' seems to already exist in 'https://github.com/$USER/rust'. Please delete it and try again."
153156
exit 1
154157
fi
155-
git fetch https://github.com/rust-lang/rust master
156-
git push https://github.com/$USER/rust FETCH_HEAD:master
158+
git fetch https://github.com/rust-lang/rust $BASE
159+
git push https://github.com/$USER/rust $BASE:refs/heads/$BRANCH -f
157160
# Do the actual push.
158161
cd "$MIRIDIR"
159162
echo "Pushing Miri changes..."
160-
git push http://localhost:8000/$USER/rust.git$JOSH_FILTER.git HEAD:$BRANCH -o base=master
163+
git push http://localhost:8000/$USER/rust.git$JOSH_FILTER.git HEAD:$BRANCH
161164
exit 0
162165
;;
163166
many-seeds)

‎src/tools/miri/rust-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
b03502b35d111bef0399a66ab3cc765f0802e8ba
1+
101e1822c3e54e63996c8aaa014d55716f3937eb

‎src/tools/miri/src/concurrency/data_race.rs

+5-29
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ use std::{
4949
use rustc_ast::Mutability;
5050
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
5151
use rustc_index::vec::{Idx, IndexVec};
52-
use rustc_middle::{mir, ty::layout::TyAndLayout};
52+
use rustc_middle::mir;
5353
use rustc_target::abi::{Align, Size};
5454

5555
use crate::*;
@@ -440,33 +440,6 @@ impl MemoryCellClocks {
440440
/// Evaluation context extensions.
441441
impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for MiriInterpCx<'mir, 'tcx> {}
442442
pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriInterpCxExt<'mir, 'tcx> {
443-
/// Atomic variant of read_scalar_at_offset.
444-
fn read_scalar_at_offset_atomic(
445-
&self,
446-
op: &OpTy<'tcx, Provenance>,
447-
offset: u64,
448-
layout: TyAndLayout<'tcx>,
449-
atomic: AtomicReadOrd,
450-
) -> InterpResult<'tcx, Scalar<Provenance>> {
451-
let this = self.eval_context_ref();
452-
let value_place = this.deref_operand_and_offset(op, offset, layout)?;
453-
this.read_scalar_atomic(&value_place, atomic)
454-
}
455-
456-
/// Atomic variant of write_scalar_at_offset.
457-
fn write_scalar_at_offset_atomic(
458-
&mut self,
459-
op: &OpTy<'tcx, Provenance>,
460-
offset: u64,
461-
value: impl Into<Scalar<Provenance>>,
462-
layout: TyAndLayout<'tcx>,
463-
atomic: AtomicWriteOrd,
464-
) -> InterpResult<'tcx> {
465-
let this = self.eval_context_mut();
466-
let value_place = this.deref_operand_and_offset(op, offset, layout)?;
467-
this.write_scalar_atomic(value.into(), &value_place, atomic)
468-
}
469-
470443
/// Perform an atomic read operation at the memory location.
471444
fn read_scalar_atomic(
472445
&self,
@@ -713,7 +686,10 @@ impl VClockAlloc {
713686
let (alloc_timestamp, alloc_index) = match kind {
714687
// User allocated and stack memory should track allocation.
715688
MemoryKind::Machine(
716-
MiriMemoryKind::Rust | MiriMemoryKind::C | MiriMemoryKind::WinHeap,
689+
MiriMemoryKind::Rust
690+
| MiriMemoryKind::Miri
691+
| MiriMemoryKind::C
692+
| MiriMemoryKind::WinHeap,
717693
)
718694
| MemoryKind::Stack => {
719695
let (alloc_index, clocks) = global.current_thread_state(thread_mgr);

‎src/tools/miri/src/concurrency/sync.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,9 @@ impl<'mir, 'tcx: 'mir> EvalContextExtPriv<'mir, 'tcx> for crate::MiriInterpCx<'m
193193
pub(super) trait EvalContextExtPriv<'mir, 'tcx: 'mir>:
194194
crate::MiriInterpCxExt<'mir, 'tcx>
195195
{
196+
/// Lazily initialize the ID of this Miri sync structure.
197+
/// ('0' indicates uninit.)
196198
#[inline]
197-
// Miri sync structures contain zero-initialized ids stored at some offset behind a pointer
198199
fn get_or_create_id<Id: SyncId>(
199200
&mut self,
200201
next_id: Id,
@@ -205,6 +206,7 @@ pub(super) trait EvalContextExtPriv<'mir, 'tcx: 'mir>:
205206
let value_place =
206207
this.deref_operand_and_offset(lock_op, offset, this.machine.layouts.u32)?;
207208

209+
// Since we are lazy, this update has to be atomic.
208210
let (old, success) = this
209211
.atomic_compare_exchange_scalar(
210212
&value_place,

‎src/tools/miri/src/helpers.rs

+4-13
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
668668
layout: TyAndLayout<'tcx>,
669669
) -> InterpResult<'tcx, MPlaceTy<'tcx, Provenance>> {
670670
let this = self.eval_context_ref();
671-
let op_place = this.deref_operand(op)?;
671+
let op_place = this.deref_operand(op)?; // FIXME: we still deref with the original type!
672672
let offset = Size::from_bytes(offset);
673673

674674
// Ensure that the access is within bounds.
@@ -688,25 +688,16 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
688688
this.read_scalar(&value_place.into())
689689
}
690690

691-
fn write_immediate_at_offset(
692-
&mut self,
693-
op: &OpTy<'tcx, Provenance>,
694-
offset: u64,
695-
value: &ImmTy<'tcx, Provenance>,
696-
) -> InterpResult<'tcx, ()> {
697-
let this = self.eval_context_mut();
698-
let value_place = this.deref_operand_and_offset(op, offset, value.layout)?;
699-
this.write_immediate(**value, &value_place.into())
700-
}
701-
702691
fn write_scalar_at_offset(
703692
&mut self,
704693
op: &OpTy<'tcx, Provenance>,
705694
offset: u64,
706695
value: impl Into<Scalar<Provenance>>,
707696
layout: TyAndLayout<'tcx>,
708697
) -> InterpResult<'tcx, ()> {
709-
self.write_immediate_at_offset(op, offset, &ImmTy::from_scalar(value.into(), layout))
698+
let this = self.eval_context_mut();
699+
let value_place = this.deref_operand_and_offset(op, offset, layout)?;
700+
this.write_scalar(value, &value_place.into())
710701
}
711702

712703
/// Parse a `timespec` struct and return it as a `std::time::Duration`. It returns `None`

‎src/tools/miri/src/machine.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ impl VisitTags for FrameData<'_> {
7777
pub enum MiriMemoryKind {
7878
/// `__rust_alloc` memory.
7979
Rust,
80+
/// `miri_alloc` memory.
81+
Miri,
8082
/// `malloc` memory.
8183
C,
8284
/// Windows `HeapAlloc` memory.
@@ -110,7 +112,7 @@ impl MayLeak for MiriMemoryKind {
110112
fn may_leak(self) -> bool {
111113
use self::MiriMemoryKind::*;
112114
match self {
113-
Rust | C | WinHeap | Runtime => false,
115+
Rust | Miri | C | WinHeap | Runtime => false,
114116
Machine | Global | ExternStatic | Tls => true,
115117
}
116118
}
@@ -121,6 +123,7 @@ impl fmt::Display for MiriMemoryKind {
121123
use self::MiriMemoryKind::*;
122124
match self {
123125
Rust => write!(f, "Rust heap"),
126+
Miri => write!(f, "Miri bare-metal heap"),
124127
C => write!(f, "C heap"),
125128
WinHeap => write!(f, "Windows heap"),
126129
Machine => write!(f, "machine-managed memory"),

‎src/tools/miri/src/shims/foreign_items.rs

+38-8
Original file line numberDiff line numberDiff line change
@@ -513,22 +513,37 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
513513
}
514514

515515
// Rust allocation
516-
"__rust_alloc" => {
516+
"__rust_alloc" | "miri_alloc" => {
517517
let [size, align] = this.check_shim(abi, Abi::Rust, link_name, args)?;
518518
let size = this.read_scalar(size)?.to_machine_usize(this)?;
519519
let align = this.read_scalar(align)?.to_machine_usize(this)?;
520520

521-
return this.emulate_allocator(Symbol::intern("__rg_alloc"), |this| {
521+
let default = |this: &mut MiriInterpCx<'mir, 'tcx>| {
522522
Self::check_alloc_request(size, align)?;
523523

524+
let memory_kind = match link_name.as_str() {
525+
"__rust_alloc" => MiriMemoryKind::Rust,
526+
"miri_alloc" => MiriMemoryKind::Miri,
527+
_ => unreachable!(),
528+
};
529+
524530
let ptr = this.allocate_ptr(
525531
Size::from_bytes(size),
526532
Align::from_bytes(align).unwrap(),
527-
MiriMemoryKind::Rust.into(),
533+
memory_kind.into(),
528534
)?;
529535

530536
this.write_pointer(ptr, dest)
531-
});
537+
};
538+
539+
match link_name.as_str() {
540+
"__rust_alloc" => return this.emulate_allocator(Symbol::intern("__rg_alloc"), default),
541+
"miri_alloc" => {
542+
default(this)?;
543+
return Ok(EmulateByNameResult::NeedsJumping);
544+
},
545+
_ => unreachable!(),
546+
}
532547
}
533548
"__rust_alloc_zeroed" => {
534549
let [size, align] = this.check_shim(abi, Abi::Rust, link_name, args)?;
@@ -549,20 +564,35 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
549564
this.write_pointer(ptr, dest)
550565
});
551566
}
552-
"__rust_dealloc" => {
567+
"__rust_dealloc" | "miri_dealloc" => {
553568
let [ptr, old_size, align] = this.check_shim(abi, Abi::Rust, link_name, args)?;
554569
let ptr = this.read_pointer(ptr)?;
555570
let old_size = this.read_scalar(old_size)?.to_machine_usize(this)?;
556571
let align = this.read_scalar(align)?.to_machine_usize(this)?;
557572

558-
return this.emulate_allocator(Symbol::intern("__rg_dealloc"), |this| {
573+
let default = |this: &mut MiriInterpCx<'mir, 'tcx>| {
574+
let memory_kind = match link_name.as_str() {
575+
"__rust_dealloc" => MiriMemoryKind::Rust,
576+
"miri_dealloc" => MiriMemoryKind::Miri,
577+
_ => unreachable!(),
578+
};
579+
559580
// No need to check old_size/align; we anyway check that they match the allocation.
560581
this.deallocate_ptr(
561582
ptr,
562583
Some((Size::from_bytes(old_size), Align::from_bytes(align).unwrap())),
563-
MiriMemoryKind::Rust.into(),
584+
memory_kind.into(),
564585
)
565-
});
586+
};
587+
588+
match link_name.as_str() {
589+
"__rust_dealloc" => return this.emulate_allocator(Symbol::intern("__rg_dealloc"), default),
590+
"miri_dealloc" => {
591+
default(this)?;
592+
return Ok(EmulateByNameResult::NeedsJumping);
593+
}
594+
_ => unreachable!(),
595+
}
566596
}
567597
"__rust_realloc" => {
568598
let [ptr, old_size, align, new_size] = this.check_shim(abi, Abi::Rust, link_name, args)?;

‎src/tools/miri/src/shims/unix/sync.rs

+82-133
Large diffs are not rendered by default.

‎src/tools/miri/tests/compiletest.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use colored::*;
2-
use regex::Regex;
2+
use regex::bytes::Regex;
33
use std::path::{Path, PathBuf};
44
use std::{env, process::Command};
55
use ui_test::{color_eyre::Result, Config, Mode, OutputConflictHandling};
@@ -129,8 +129,8 @@ fn run_tests(mode: Mode, path: &str, target: &str, with_dependencies: bool) -> R
129129

130130
macro_rules! regexes {
131131
($name:ident: $($regex:expr => $replacement:expr,)*) => {lazy_static::lazy_static! {
132-
static ref $name: Vec<(Regex, &'static str)> = vec![
133-
$((Regex::new($regex).unwrap(), $replacement),)*
132+
static ref $name: Vec<(Regex, &'static [u8])> = vec![
133+
$((Regex::new($regex).unwrap(), $replacement.as_bytes()),)*
134134
];
135135
}};
136136
}

‎src/tools/miri/tests/fail/memleak_rc.stderr

-11
This file was deleted.
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#![feature(lang_items, start)]
2+
#![no_std]
3+
// windows tls dtors go through libstd right now, thus this test
4+
// cannot pass. When windows tls dtors go through the special magic
5+
// windows linker section, we can run this test on windows again.
6+
//@ignore-target-windows: no-std not supported on Windows
7+
8+
extern "Rust" {
9+
fn miri_alloc(size: usize, align: usize) -> *mut u8;
10+
fn miri_dealloc(ptr: *mut u8, size: usize, align: usize);
11+
}
12+
13+
#[start]
14+
fn start(_: isize, _: *const *const u8) -> isize {
15+
unsafe {
16+
let ptr = miri_alloc(123, 1);
17+
core::ptr::write_bytes(ptr, 0u8, 123);
18+
miri_dealloc(ptr, 123, 1);
19+
}
20+
0
21+
}
22+
23+
#[panic_handler]
24+
fn panic_handler(_: &core::panic::PanicInfo) -> ! {
25+
loop {}
26+
}
27+
28+
#[lang = "eh_personality"]
29+
fn eh_personality() {}

‎src/tools/rustc-workspace-hack/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ regex = { version = "1.5.6" }
8282
serde_json = { version = "1.0.31", features = ["raw_value", "unbounded_depth"] }
8383
syn = { version = "1", features = ['full', 'visit'] }
8484
url = { version = "2.0", features = ['serde'] }
85+
# Ensure default features of rand, which are disabled in some scenarios.
86+
rand = { version = "0.8.5" }
8587

8688
[target.'cfg(not(windows))'.dependencies]
8789
openssl = { version = "0.10.35", optional = true }

‎src/tools/tidy/src/deps.rs

+1
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[
117117
"env_logger",
118118
"expect-test",
119119
"fallible-iterator", // dependency of `thorin`
120+
"fastrand",
120121
"filetime",
121122
"fixedbitset",
122123
"flate2",

0 commit comments

Comments
 (0)
Please sign in to comment.