Skip to content

Commit 80fb1d3

Browse files
committed
Auto merge of rust-lang#134785 - jieyouxu:rollup-fyefxuq, r=jieyouxu
Rollup of 4 pull requests Successful merges: - rust-lang#134664 (Account for removal of multiline span in suggestion) - rust-lang#134774 (fix default-backtrace-ice test) - rust-lang#134781 (Add more `begin_panic` normalizations to panic backtrace tests) - rust-lang#134784 (Miri subtree update) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 78af7da + 4c933ea commit 80fb1d3

39 files changed

+1526
-732
lines changed

compiler/rustc_driver_impl/src/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1388,7 +1388,9 @@ pub fn install_ice_hook(
13881388
// opt in to less-verbose backtraces by manually setting "RUST_BACKTRACE"
13891389
// (e.g. `RUST_BACKTRACE=1`)
13901390
if env::var_os("RUST_BACKTRACE").is_none() {
1391-
if env!("CFG_RELEASE_CHANNEL") == "dev" {
1391+
// HACK: this check is extremely dumb, but we don't really need it to be smarter since this should only happen in the test suite anyway.
1392+
let ui_testing = std::env::args().any(|arg| arg == "-Zui-testing");
1393+
if env!("CFG_RELEASE_CHANNEL") == "dev" && !ui_testing {
13921394
panic::set_backtrace_style(panic::BacktraceStyle::Short);
13931395
} else {
13941396
panic::set_backtrace_style(panic::BacktraceStyle::Full);

compiler/rustc_errors/src/emitter.rs

+79-7
Original file line numberDiff line numberDiff line change
@@ -2216,6 +2216,11 @@ impl HumanEmitter {
22162216
show_code_change
22172217
{
22182218
for part in parts {
2219+
let snippet = if let Ok(snippet) = sm.span_to_snippet(part.span) {
2220+
snippet
2221+
} else {
2222+
String::new()
2223+
};
22192224
let span_start_pos = sm.lookup_char_pos(part.span.lo()).col_display;
22202225
let span_end_pos = sm.lookup_char_pos(part.span.hi()).col_display;
22212226

@@ -2263,13 +2268,80 @@ impl HumanEmitter {
22632268
}
22642269
if let DisplaySuggestion::Diff = show_code_change {
22652270
// Colorize removal with red in diff format.
2266-
buffer.set_style_range(
2267-
row_num - 2,
2268-
(padding as isize + span_start_pos as isize) as usize,
2269-
(padding as isize + span_end_pos as isize) as usize,
2270-
Style::Removal,
2271-
true,
2272-
);
2271+
2272+
// Below, there's some tricky buffer indexing going on. `row_num` at this
2273+
// point corresponds to:
2274+
//
2275+
// |
2276+
// LL | CODE
2277+
// | ++++ <- `row_num`
2278+
//
2279+
// in the buffer. When we have a diff format output, we end up with
2280+
//
2281+
// |
2282+
// LL - OLDER <- row_num - 2
2283+
// LL + NEWER
2284+
// | <- row_num
2285+
//
2286+
// The `row_num - 2` is to select the buffer line that has the "old version
2287+
// of the diff" at that point. When the removal is a single line, `i` is
2288+
// `0`, `newlines` is `1` so `(newlines - i - 1)` ends up being `0`, so row
2289+
// points at `LL - OLDER`. When the removal corresponds to multiple lines,
2290+
// we end up with `newlines > 1` and `i` being `0..newlines - 1`.
2291+
//
2292+
// |
2293+
// LL - OLDER <- row_num - 2 - (newlines - last_i - 1)
2294+
// LL - CODE
2295+
// LL - BEING
2296+
// LL - REMOVED <- row_num - 2 - (newlines - first_i - 1)
2297+
// LL + NEWER
2298+
// | <- row_num
2299+
2300+
let newlines = snippet.lines().count();
2301+
if newlines > 0 && row_num > newlines {
2302+
// Account for removals where the part being removed spans multiple
2303+
// lines.
2304+
// FIXME: We check the number of rows because in some cases, like in
2305+
// `tests/ui/lint/invalid-nan-comparison-suggestion.rs`, the rendered
2306+
// suggestion will only show the first line of code being replaced. The
2307+
// proper way of doing this would be to change the suggestion rendering
2308+
// logic to show the whole prior snippet, but the current output is not
2309+
// too bad to begin with, so we side-step that issue here.
2310+
for (i, line) in snippet.lines().enumerate() {
2311+
let line = normalize_whitespace(line);
2312+
let row = row_num - 2 - (newlines - i - 1);
2313+
// On the first line, we highlight between the start of the part
2314+
// span, and the end of that line.
2315+
// On the last line, we highlight between the start of the line, and
2316+
// the column of the part span end.
2317+
// On all others, we highlight the whole line.
2318+
let start = if i == 0 {
2319+
(padding as isize + span_start_pos as isize) as usize
2320+
} else {
2321+
padding
2322+
};
2323+
let end = if i == 0 {
2324+
(padding as isize
2325+
+ span_start_pos as isize
2326+
+ line.len() as isize)
2327+
as usize
2328+
} else if i == newlines - 1 {
2329+
(padding as isize + span_end_pos as isize) as usize
2330+
} else {
2331+
(padding as isize + line.len() as isize) as usize
2332+
};
2333+
buffer.set_style_range(row, start, end, Style::Removal, true);
2334+
}
2335+
} else {
2336+
// The removed code fits all in one line.
2337+
buffer.set_style_range(
2338+
row_num - 2,
2339+
(padding as isize + span_start_pos as isize) as usize,
2340+
(padding as isize + span_end_pos as isize) as usize,
2341+
Style::Removal,
2342+
true,
2343+
);
2344+
}
22732345
}
22742346

22752347
// length of the code after substitution

src/tools/miri/CONTRIBUTING.md

+9
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,15 @@ Miri comes with a few benchmarks; you can run `./miri bench` to run them with th
212212
Miri. Note: this will run `./miri install` as a side-effect. Also requires `hyperfine` to be
213213
installed (`cargo install hyperfine`).
214214

215+
To compare the benchmark results with a baseline, do the following:
216+
- Before applying your changes, run `./miri bench --save-baseline=baseline.json`.
217+
- Then do your changes.
218+
- Then run `./miri bench --load-baseline=baseline.json`; the results will include
219+
a comparison with the baseline.
220+
221+
You can run only some of the benchmarks by listing them, e.g. `./miri bench mse`.
222+
The names refer to the folders in `bench-cargo-miri`.
223+
215224
## Configuring `rust-analyzer`
216225

217226
To configure `rust-analyzer` and the IDE for working on Miri, copy one of the provided

src/tools/miri/README.md

+19-7
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,14 @@ Certain parts of the execution are picked randomly by Miri, such as the exact ba
160160
allocations are stored at and the interleaving of concurrently executing threads. Sometimes, it can
161161
be useful to explore multiple different execution, e.g. to make sure that your code does not depend
162162
on incidental "super-alignment" of new allocations and to test different thread interleavings.
163-
This can be done with the `--many-seeds` flag:
163+
This can be done with the `-Zmiri-many-seeds` flag:
164164

165165
```
166-
cargo miri test --many-seeds # tries the seeds in 0..64
167-
cargo miri test --many-seeds=0..16
166+
MIRIFLAGS="-Zmiri-many-seeds" cargo miri test # tries the seeds in 0..64
167+
MIRIFLAGS="-Zmiri-many-seeds=0..16" cargo miri test
168168
```
169169

170-
The default of 64 different seeds is quite slow, so you probably want to specify a smaller range.
170+
The default of 64 different seeds can be quite slow, so you often want to specify a smaller range.
171171

172172
### Running Miri on CI
173173

@@ -294,9 +294,10 @@ environment variable. We first document the most relevant and most commonly used
294294
will always fail and `0.0` means it will never fail. Note that setting it to
295295
`1.0` will likely cause hangs, since it means programs using
296296
`compare_exchange_weak` cannot make progress.
297-
* `-Zmiri-disable-isolation` disables host isolation. As a consequence,
297+
* `-Zmiri-disable-isolation` disables host isolation. As a consequence,
298298
the program has access to host resources such as environment variables, file
299299
systems, and randomness.
300+
This overwrites a previous `-Zmiri-isolation-error`.
300301
* `-Zmiri-disable-leak-backtraces` disables backtraces reports for memory leaks. By default, a
301302
backtrace is captured for every allocation when it is created, just in case it leaks. This incurs
302303
some memory overhead to store data that is almost never used. This flag is implied by
@@ -317,6 +318,15 @@ environment variable. We first document the most relevant and most commonly used
317318
execution with a "permission denied" error being returned to the program.
318319
`warn` prints a full backtrace each time that happens; `warn-nobacktrace` is less
319320
verbose and shown at most once per operation. `hide` hides the warning entirely.
321+
This overwrites a previous `-Zmiri-disable-isolation`.
322+
* `-Zmiri-many-seeds=[<from>]..<to>` runs the program multiple times with different seeds for Miri's
323+
RNG. With different seeds, Miri will make different choices to resolve non-determinism such as the
324+
order in which concurrent threads are scheduled, or the exact addresses assigned to allocations.
325+
This is useful to find bugs that only occur under particular interleavings of concurrent threads,
326+
or that otherwise depend on non-determinism. If the `<from>` part is skipped, it defaults to `0`.
327+
Can be used without a value; in that case the range defaults to `0..64`.
328+
* `-Zmiri-many-seeds-keep-going` tells Miri to really try all the seeds in the given range, even if
329+
a failing seed has already been found. This is useful to determine which fraction of seeds fails.
320330
* `-Zmiri-num-cpus` states the number of available CPUs to be reported by miri. By default, the
321331
number of available CPUs is `1`. Note that this flag does not affect how miri handles threads in
322332
any way.
@@ -339,8 +349,8 @@ environment variable. We first document the most relevant and most commonly used
339349
can increase test coverage by running Miri multiple times with different seeds.
340350
* `-Zmiri-strict-provenance` enables [strict
341351
provenance](https://github.com/rust-lang/rust/issues/95228) checking in Miri. This means that
342-
casting an integer to a pointer yields a result with 'invalid' provenance, i.e., with provenance
343-
that cannot be used for any memory access.
352+
casting an integer to a pointer will stop execution because the provenance of the pointer
353+
cannot be determined.
344354
* `-Zmiri-symbolic-alignment-check` makes the alignment check more strict. By default, alignment is
345355
checked by casting the pointer to an integer, and making sure that is a multiple of the alignment.
346356
This can lead to cases where a program passes the alignment check by pure chance, because things
@@ -429,6 +439,8 @@ to Miri failing to detect cases of undefined behavior in a program.
429439
of Rust will be stricter than Tree Borrows. In other words, if you use Tree Borrows,
430440
even if your code is accepted today, it might be declared UB in the future.
431441
This is much less likely with Stacked Borrows.
442+
Using Tree Borrows currently implies `-Zmiri-strict-provenance` because integer-to-pointer
443+
casts are not supported in this mode, but that may change in the future.
432444
* `-Zmiri-force-page-size=<num>` overrides the default page size for an architecture, in multiples of 1k.
433445
`4` is default for most targets. This value should always be a power of 2 and nonzero.
434446
* `-Zmiri-unique-is-unique` performs additional aliasing checks for `core::ptr::Unique` to ensure

0 commit comments

Comments
 (0)