Skip to content

Commit eeeb021

Browse files
committed
Auto merge of #121232 - RalfJung:miri, r=RalfJung
Miri subtree update r? `@ghost`
2 parents ba824a2 + fd5a84b commit eeeb021

Some content is hidden

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

45 files changed

+2116
-265
lines changed

Diff for: Cargo.lock

-2
Original file line numberDiff line numberDiff line change
@@ -2524,14 +2524,12 @@ dependencies = [
25242524
"aes",
25252525
"colored",
25262526
"ctrlc",
2527-
"env_logger 0.10.2",
25282527
"getrandom",
25292528
"jemalloc-sys",
25302529
"lazy_static",
25312530
"libc",
25322531
"libffi",
25332532
"libloading",
2534-
"log",
25352533
"measureme",
25362534
"rand",
25372535
"regex",

Diff for: src/tools/miri/CONTRIBUTING.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ custom target file, you might have to set `MIRI_NO_STD=1`.
7878
base directory, e.g. `./miri test fail` will run all compile-fail tests). These filters are passed
7979
to `cargo test`, so for multiple filers you need to use `./miri test -- FILTER1 FILTER2`.
8080

81+
#### Fine grained logging
82+
8183
You can get a trace of which MIR statements are being executed by setting the
8284
`MIRI_LOG` environment variable. For example:
8385

@@ -94,9 +96,16 @@ stacked borrows implementation:
9496
MIRI_LOG=rustc_mir::interpret=info,miri::stacked_borrows ./miri run tests/pass/vec.rs
9597
```
9698

97-
In addition, you can set `MIRI_BACKTRACE=1` to get a backtrace of where an
99+
Note that you will only get `info`, `warn` or `error` messages if you use a prebuilt compiler.
100+
In order to get `debug` and `trace` level messages, you need to build miri with a locally built
101+
compiler that has `debug=true` set in `config.toml`.
102+
103+
#### Debugging error messages
104+
105+
You can set `MIRI_BACKTRACE=1` to get a backtrace of where an
98106
evaluation error was originally raised.
99107

108+
100109
### UI testing
101110

102111
We use ui-testing in Miri, meaning we generate `.stderr` and `.stdout` files for the output

Diff for: src/tools/miri/Cargo.lock

-56
Original file line numberDiff line numberDiff line change
@@ -273,19 +273,6 @@ version = "0.3.6"
273273
source = "registry+https://github.com/rust-lang/crates.io-index"
274274
checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f"
275275

276-
[[package]]
277-
name = "env_logger"
278-
version = "0.10.1"
279-
source = "registry+https://github.com/rust-lang/crates.io-index"
280-
checksum = "95b3f3e67048839cb0d0781f445682a35113da7121f7c949db0e2be96a4fbece"
281-
dependencies = [
282-
"humantime",
283-
"is-terminal",
284-
"log",
285-
"regex",
286-
"termcolor",
287-
]
288-
289276
[[package]]
290277
name = "errno"
291278
version = "0.3.8"
@@ -339,18 +326,6 @@ version = "0.28.1"
339326
source = "registry+https://github.com/rust-lang/crates.io-index"
340327
checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253"
341328

342-
[[package]]
343-
name = "hermit-abi"
344-
version = "0.3.3"
345-
source = "registry+https://github.com/rust-lang/crates.io-index"
346-
checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7"
347-
348-
[[package]]
349-
name = "humantime"
350-
version = "2.1.0"
351-
source = "registry+https://github.com/rust-lang/crates.io-index"
352-
checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
353-
354329
[[package]]
355330
name = "indenter"
356331
version = "0.3.3"
@@ -388,17 +363,6 @@ dependencies = [
388363
"cfg-if",
389364
]
390365

391-
[[package]]
392-
name = "is-terminal"
393-
version = "0.4.10"
394-
source = "registry+https://github.com/rust-lang/crates.io-index"
395-
checksum = "0bad00257d07be169d870ab665980b06cdb366d792ad690bf2e76876dc503455"
396-
dependencies = [
397-
"hermit-abi",
398-
"rustix",
399-
"windows-sys 0.52.0",
400-
]
401-
402366
[[package]]
403367
name = "itoa"
404368
version = "1.0.10"
@@ -529,14 +493,12 @@ dependencies = [
529493
"aes",
530494
"colored",
531495
"ctrlc",
532-
"env_logger",
533496
"getrandom",
534497
"jemalloc-sys",
535498
"lazy_static",
536499
"libc",
537500
"libffi",
538501
"libloading",
539-
"log",
540502
"measureme",
541503
"rand",
542504
"regex",
@@ -875,15 +837,6 @@ dependencies = [
875837
"windows-sys 0.52.0",
876838
]
877839

878-
[[package]]
879-
name = "termcolor"
880-
version = "1.4.0"
881-
source = "registry+https://github.com/rust-lang/crates.io-index"
882-
checksum = "ff1bc3d3f05aff0403e8ac0d92ced918ec05b666a43f83297ccef5bea8a3d449"
883-
dependencies = [
884-
"winapi-util",
885-
]
886-
887840
[[package]]
888841
name = "thiserror"
889842
version = "1.0.56"
@@ -1034,15 +987,6 @@ version = "0.4.0"
1034987
source = "registry+https://github.com/rust-lang/crates.io-index"
1035988
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
1036989

1037-
[[package]]
1038-
name = "winapi-util"
1039-
version = "0.1.6"
1040-
source = "registry+https://github.com/rust-lang/crates.io-index"
1041-
checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596"
1042-
dependencies = [
1043-
"winapi",
1044-
]
1045-
1046990
[[package]]
1047991
name = "winapi-x86_64-pc-windows-gnu"
1048992
version = "0.4.0"

Diff for: src/tools/miri/Cargo.toml

-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ doctest = false # and no doc tests
1919

2020
[dependencies]
2121
getrandom = { version = "0.2", features = ["std"] }
22-
env_logger = "0.10"
23-
log = "0.4"
2422
rand = "0.8"
2523
smallvec = "1.7"
2624
aes = { version = "0.8.3", features = ["hazmat"] }

Diff for: src/tools/miri/README.md

+2-5
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,8 @@ assume the right toolchain is pinned via `rustup override set nightly` or
108108

109109
Now you can run your project in Miri:
110110

111-
1. Run `cargo clean` to eliminate any cached dependencies. Miri needs your
112-
dependencies to be compiled the right way, that would not happen if they have
113-
previously already been compiled.
114-
2. To run all tests in your project through Miri, use `cargo miri test`.
115-
3. If you have a binary project, you can run it through Miri using `cargo miri run`.
111+
- To run all tests in your project through Miri, use `cargo miri test`.
112+
- If you have a binary project, you can run it through Miri using `cargo miri run`.
116113

117114
The first time you run Miri, it will perform some extra setup and install some
118115
dependencies. It will ask you for confirmation before installing anything.

Diff for: src/tools/miri/ci/ci.sh

+3-2
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,9 @@ case $HOST_TARGET in
121121
MIRI_TEST_TARGET=aarch64-apple-darwin run_tests
122122
MIRI_TEST_TARGET=i686-pc-windows-gnu run_tests
123123
# Some targets are only partially supported.
124-
MIRI_TEST_TARGET=x86_64-unknown-freebsd run_tests_minimal hello integer vec panic/panic concurrency/simple pthread-threadname libc-getentropy libc-getrandom libc-misc libc-fs atomic env align
125-
MIRI_TEST_TARGET=i686-unknown-freebsd run_tests_minimal hello integer vec panic/panic concurrency/simple pthread-threadname libc-getentropy libc-getrandom libc-misc libc-fs atomic env align
124+
MIRI_TEST_TARGET=x86_64-unknown-freebsd run_tests_minimal hello integer vec panic/panic concurrency/simple pthread-threadname libc-getentropy libc-getrandom libc-misc libc-fs atomic env align num_cpus
125+
MIRI_TEST_TARGET=i686-unknown-freebsd run_tests_minimal hello integer vec panic/panic concurrency/simple pthread-threadname libc-getentropy libc-getrandom libc-misc libc-fs atomic env align num_cpus
126+
126127
MIRI_TEST_TARGET=aarch64-linux-android run_tests_minimal hello integer vec panic/panic
127128
MIRI_TEST_TARGET=wasm32-wasi run_tests_minimal no_std integer strings wasm
128129
MIRI_TEST_TARGET=wasm32-unknown-unknown run_tests_minimal no_std integer strings wasm

Diff for: src/tools/miri/rust-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
dd2559e08e1530806740931037d6bb83ef956161
1+
4316d0c6252cb1f833e582dfa68adb98efd5ddfb

Diff for: src/tools/miri/src/bin/miri.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
clippy::useless_format,
66
clippy::field_reassign_with_default,
77
rustc::diagnostic_outside_of_impl,
8-
rustc::untranslatable_diagnostic,
8+
rustc::untranslatable_diagnostic
99
)]
1010

1111
extern crate rustc_data_structures;
@@ -16,14 +16,14 @@ extern crate rustc_log;
1616
extern crate rustc_metadata;
1717
extern crate rustc_middle;
1818
extern crate rustc_session;
19+
#[macro_use]
20+
extern crate tracing;
1921

2022
use std::env::{self, VarError};
2123
use std::num::NonZero;
2224
use std::path::PathBuf;
2325
use std::str::FromStr;
2426

25-
use log::debug;
26-
2727
use rustc_data_structures::sync::Lrc;
2828
use rustc_driver::Compilation;
2929
use rustc_hir::{self as hir, Node};
@@ -200,7 +200,7 @@ fn rustc_logger_config() -> rustc_log::LoggerConfig {
200200
// CTFE-related. Otherwise, we use it verbatim for `RUSTC_LOG`.
201201
// This way, if you set `MIRI_LOG=trace`, you get only the right parts of
202202
// rustc traced, but you can also do `MIRI_LOG=miri=trace,rustc_const_eval::interpret=debug`.
203-
if log::Level::from_str(&var).is_ok() {
203+
if tracing::Level::from_str(&var).is_ok() {
204204
cfg.filter = Ok(format!(
205205
"rustc_middle::mir::interpret={var},rustc_const_eval::interpret={var}"
206206
));
@@ -218,10 +218,6 @@ fn rustc_logger_config() -> rustc_log::LoggerConfig {
218218
}
219219

220220
fn init_early_loggers(early_dcx: &EarlyDiagCtxt) {
221-
// Note that our `extern crate log` is *not* the same as rustc's; as a result, we have to
222-
// initialize them both, and we always initialize `miri`'s first.
223-
let env = env_logger::Env::new().filter("MIRI_LOG").write_style("MIRI_LOG_STYLE");
224-
env_logger::init_from_env(env);
225221
// Now for rustc. We only initialize `rustc` if the env var is set (so the user asked for it).
226222
// If it is not set, we avoid initializing now so that we can initialize later with our custom
227223
// settings, and *not* log anything for what happens before `miri` gets started.

Diff for: src/tools/miri/src/borrow_tracker/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use std::cell::RefCell;
22
use std::fmt;
33
use std::num::NonZero;
44

5-
use log::trace;
65
use smallvec::SmallVec;
76

87
use rustc_data_structures::fx::{FxHashMap, FxHashSet};

Diff for: src/tools/miri/src/borrow_tracker/stacked_borrows/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ use std::cmp;
99
use std::fmt::Write;
1010
use std::mem;
1111

12-
use log::trace;
13-
1412
use rustc_data_structures::fx::FxHashSet;
1513
use rustc_middle::mir::{Mutability, RetagKind};
1614
use rustc_middle::ty::{self, layout::HasParamEnv, Ty};

Diff for: src/tools/miri/src/borrow_tracker/stacked_borrows/stack.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ impl<'tcx> Stack {
385385
let upper = unique_range.end;
386386
for item in &mut self.borrows[lower..upper] {
387387
if item.perm() == Permission::Unique {
388-
log::trace!("access: disabling item {:?}", item);
388+
trace!("access: disabling item {:?}", item);
389389
visitor(*item)?;
390390
item.set_permission(Permission::Disabled);
391391
// Also update all copies of this item in the cache.

Diff for: src/tools/miri/src/borrow_tracker/tree_borrows/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use log::trace;
2-
31
use rustc_target::abi::{Abi, Size};
42

53
use crate::borrow_tracker::{AccessKind, GlobalState, GlobalStateInner, ProtectorKind};

Diff for: src/tools/miri/src/concurrency/data_race.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ impl MemoryCellClocks {
466466
index: VectorIdx,
467467
access_size: Size,
468468
) -> Result<(), DataRace> {
469-
log::trace!("Atomic read with vectors: {:#?} :: {:#?}", self, thread_clocks);
469+
trace!("Atomic read with vectors: {:#?} :: {:#?}", self, thread_clocks);
470470
let atomic = self.atomic_access(thread_clocks, access_size)?;
471471
atomic.read_vector.set_at_index(&thread_clocks.clock, index);
472472
// Make sure the last non-atomic write and all non-atomic reads were before this access.
@@ -485,7 +485,7 @@ impl MemoryCellClocks {
485485
index: VectorIdx,
486486
access_size: Size,
487487
) -> Result<(), DataRace> {
488-
log::trace!("Atomic write with vectors: {:#?} :: {:#?}", self, thread_clocks);
488+
trace!("Atomic write with vectors: {:#?} :: {:#?}", self, thread_clocks);
489489
let atomic = self.atomic_access(thread_clocks, access_size)?;
490490
atomic.write_vector.set_at_index(&thread_clocks.clock, index);
491491
// Make sure the last non-atomic write and all non-atomic reads were before this access.
@@ -504,7 +504,7 @@ impl MemoryCellClocks {
504504
index: VectorIdx,
505505
current_span: Span,
506506
) -> Result<(), DataRace> {
507-
log::trace!("Unsynchronized read with vectors: {:#?} :: {:#?}", self, thread_clocks);
507+
trace!("Unsynchronized read with vectors: {:#?} :: {:#?}", self, thread_clocks);
508508
if !current_span.is_dummy() {
509509
thread_clocks.clock[index].span = current_span;
510510
}
@@ -533,7 +533,7 @@ impl MemoryCellClocks {
533533
write_type: NaWriteType,
534534
current_span: Span,
535535
) -> Result<(), DataRace> {
536-
log::trace!("Unsynchronized write with vectors: {:#?} :: {:#?}", self, thread_clocks);
536+
trace!("Unsynchronized write with vectors: {:#?} :: {:#?}", self, thread_clocks);
537537
if !current_span.is_dummy() {
538538
thread_clocks.clock[index].span = current_span;
539539
}
@@ -743,7 +743,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriInterpCxExt<'mir, 'tcx> {
743743
&this.machine.threads,
744744
current_span,
745745
|index, mut clocks| {
746-
log::trace!("Atomic fence on {:?} with ordering {:?}", index, atomic);
746+
trace!("Atomic fence on {:?} with ordering {:?}", index, atomic);
747747

748748
// Apply data-race detection for the current fences
749749
// this treats AcqRel and SeqCst as the same as an acquire
@@ -841,7 +841,7 @@ impl VClockAlloc {
841841
// Find an index, if one exists where the value
842842
// in `l` is greater than the value in `r`.
843843
fn find_gt_index(l: &VClock, r: &VClock) -> Option<VectorIdx> {
844-
log::trace!("Find index where not {:?} <= {:?}", l, r);
844+
trace!("Find index where not {:?} <= {:?}", l, r);
845845
let l_slice = l.as_slice();
846846
let r_slice = r.as_slice();
847847
l_slice
@@ -1270,7 +1270,7 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: MiriInterpCxExt<'mir, 'tcx> {
12701270
// Load and log the atomic operation.
12711271
// Note that atomic loads are possible even from read-only allocations, so `get_alloc_extra_mut` is not an option.
12721272
let alloc_meta = this.get_alloc_extra(alloc_id)?.data_race.as_ref().unwrap();
1273-
log::trace!(
1273+
trace!(
12741274
"Atomic op({}) with ordering {:?} on {:?} (size={})",
12751275
access.description(),
12761276
&atomic,
@@ -1311,11 +1311,11 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: MiriInterpCxExt<'mir, 'tcx> {
13111311
)?;
13121312

13131313
// Log changes to atomic memory.
1314-
if log::log_enabled!(log::Level::Trace) {
1314+
if tracing::enabled!(tracing::Level::TRACE) {
13151315
for (_offset, mem_clocks) in
13161316
alloc_meta.alloc_ranges.borrow().iter(base_offset, size)
13171317
{
1318-
log::trace!(
1318+
trace!(
13191319
"Updated atomic memory({:?}, size={}) to {:#?}",
13201320
place.ptr(),
13211321
size.bytes(),
@@ -1530,7 +1530,7 @@ impl GlobalState {
15301530
vector_info.push(thread)
15311531
};
15321532

1533-
log::trace!("Creating thread = {:?} with vector index = {:?}", thread, created_index);
1533+
trace!("Creating thread = {:?} with vector index = {:?}", thread, created_index);
15341534

15351535
// Mark the chosen vector index as in use by the thread.
15361536
thread_info[thread].vector_index = Some(created_index);

0 commit comments

Comments
 (0)