Don't always run `add_call_guards` pass
It is only needed when `add_retag` runs.
(the pass is run again to split critical edges before codegen, that one is required)
Rollup of 5 pull requests
Successful merges:
- #69573 (tests encoding current behavior for various cases of "binding" to _.)
- #70881 (bootstrap: work around "unused attribute" errors in incremental stdlib rebuilds.)
- #70957 (Normalize MIR locals' types for generator layout computation.)
- #70962 (added machine hooks to track deallocations)
- #70982 (Normalize function signature in function casting check procedure)
Failed merges:
r? @ghost
rustc_middle: return `LocalDefId` where possible in hir::map module
This changes the return type of the following functions to return a `LocalDefId` instead of a `DefId`:
* opt_local_def_id_from_node_id
* opt_local_def_id
* body_owner_def_id
* local_def_id_from_node_id
* get_parent_id
This is another step in the right direction for #70853
This pull request will be followed by another (substantial one) which changes the return type of `local_def_id` function but this change being more invasive, we might want to wait for #70956 or #70961 (or some other form it) to land first.
Use `PredicateObligation`s instead of `Predicate`s
Keep more information about trait binding failures. Use more specific spans by pointing at bindings that introduce obligations.
Subset of #69709.
r? @eddyb
Miri terminator handling: only do progress sanity check for 'Call' terminator
This will still catch mistakes in bad intrinsic/foreign-item shims, which is the main source of errors here.
Fixes https://github.com/rust-lang/rust/issues/70723
r? @oli-obk
Remove unused discriminant reads from MIR bodies
Allow the `SimplifyLocals` pass to remove reads of discriminants if the
read is never used.
Fixes#70531
r? @oli-obk
Miri: make backtrace function names and spans match up
Currently, Miri backtraces are a bit confusing:
```
error: Undefined Behavior: entering unreachable code
--> tests/compile-fail/never_transmute_void.rs:10:11
|
10 | match v {} //~ ERROR entering unreachable code
| ^ entering unreachable code
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
note: inside call to `f` at tests/compile-fail/never_transmute_void.rs:17:5
--> tests/compile-fail/never_transmute_void.rs:17:5
|
17 | f(v); //~ inside call to `f`
| ^^^^
= note: inside call to `main` at /home/r/.rustup/toolchains/miri/lib/rustlib/src/rust/src/libstd/rt.rs:67:34
= note: inside call to closure at /home/r/.rustup/toolchains/miri/lib/rustlib/src/rust/src/libstd/rt.rs:52:73
= note: inside call to closure at /home/r/.rustup/toolchains/miri/lib/rustlib/src/rust/src/libstd/sys_common/backtrace.rs:130:5
```
When reading this like a normal backtrace, one would expect that e.g. the backrace involves the "main" function at "libstd/rt.rs:67:34". But that is not actually where we are in the main function, that is *where the main function is called*.
This is not how backtraces are usually rendered (including e.g. with `RUST_BACKTRACE=1`). Usually we print next to each function name where inside that function the frame is currently executing, not where the *parent* frame is executing. With this PR and the Miri side at https://github.com/rust-lang/miri/pull/1283, the backtrace now looks as follows:
```
error: Undefined Behavior: entering unreachable code
--> tests/compile-fail/never_transmute_void.rs:10:11
|
10 | match v {} //~ ERROR entering unreachable code
| ^ entering unreachable code
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
= note: inside `f` at tests/compile-fail/never_transmute_void.rs:10:11
note: inside `main` at tests/compile-fail/never_transmute_void.rs:17:5
--> tests/compile-fail/never_transmute_void.rs:17:5
|
17 | f(v); //~ inside `main`
| ^^^^
= note: inside closure at /home/r/src/rust/rustc/src/libstd/rt.rs:67:34
= note: inside closure at /home/r/src/rust/rustc/src/libstd/rt.rs:52:73
= note: inside `std::sys_common::backtrace::__rust_begin_short_backtrace::<[closure@DefId(1:6034 ~ std[87db]::rt[0]::lang_start_internal[0]::{{closure}}[0]::{{closure}}[0]) 0:&dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe], i32>` at /home/r/src/rust/rustc/src/libstd/sys_common/backtrace.rs:130:5
```
Now function name and printed line numbers match up in the notes.
This code is partially shared with const-eval, so the change also affects const-eval: instead of printing what is being called at some span, we print which function/constant this span is inside.
With this, we can also remove the `span` field from Miri's stack frames (which used to track the *caller span* of that frame, quite confusing), and then get of a whole lot of `span` arguments that ultimately just served to fill that field (and as a fallback for `caller_location`, which however was never actually used).
r? @oli-obk
Add `-Z dump-mir-dataflow` flag for dumping dataflow results visualization
Previously, to visualize the results of a MIR dataflow pass, one had to add a `#[rustc_mir(borrowck_graphviz_postflow)]` attribute to functions of interest. However, there is no way to specify this attribute on closures and generators, so it was impossible to view results for these MIR bodies.
This PR adds a flag, `-Z dump-mir-dataflow`, which will output the dataflow results for any functions specified in `-Z dump-mir` to the output directory specified by `-Z dump-mir-dir`. This behavior is modeled on the `-Z dump-mir-graphviz` flag.
Make `Visitor::visit_body` take a plain `&Body`
`ReadOnlyBodyAndCache` has replaced `&Body` in many parts of the code base that don't care about basic block predecessors. This includes the MIR `Visitor` trait, which I suspect resulted in many unnecessary changes in #64736. This reverts part of that PR to reduce the number of places where we need to pass a `ReadOnlyBodyAndCache`.
In the long term, we should either give `ReadOnlyBodyAndCache` more ergonomic name and replace all uses of `&mir::Body` with it at the cost of carrying an extra pointer everywhere, or use it only in places that actually need access to the predecessor cache. Perhaps there is an even nicer alternative.
r? @Nashenas88