Perform simple scalar replacement of aggregates (SROA) MIR opt
This is a re-open of https://github.com/rust-lang/rust/pull/85796
I copied the debuginfo implementation (first commit) from `@eddyb's` own SROA PR.
This pass replaces plain field accesses by simple locals when possible.
To be eligible, the replaced locals:
- must not be enums or unions;
- must not be used whole;
- must not have their address taken.
The storage and deinit statements are duplicated on each created local.
cc `@tmiasko` who reviewed the former version of this PR.
interpret: support for per-byte provenance
Also factors the provenance map into its own module.
The third commit does the same for the init mask. I can move it in a separate PR if you prefer.
Fixes https://github.com/rust-lang/miri/issues/2181
r? `@oli-obk`
Rollup of 9 pull requests
Successful merges:
- #103439 (Show note where the macro failed to match)
- #103734 (Adjust stabilization version to 1.65.0 for wasi fds)
- #104148 (Visit attributes of trait impl items during AST validation)
- #104241 (Move most of unwind's build script to lib.rs)
- #104258 (Deduce closure signature from a type alias `impl Trait`'s supertraits)
- #104296 (Walk types more carefully in `ProhibitOpaqueTypes` visitor)
- #104309 (Slightly improve error message for invalid identifier)
- #104316 (Simplify suggestions for errors in generators.)
- #104339 (Add `rustc_deny_explicit_impl`)
Failed merges:
- #103484 (Add `rust` to `let_underscore_lock` example)
r? `@ghost`
`@rustbot` modify labels: rollup
Add `rustc_deny_explicit_impl`
Also adjust `E0322` error message to be more general, since it's used for `DiscriminantKind` and `Pointee` as well.
Also add `rustc_deny_explicit_impl` on the `Tuple` and `Destruct` marker traits.
Walk types more carefully in `ProhibitOpaqueTypes` visitor
The visitor didn't account for the case where you could have `<TAIT as Trait>::Assoc` normalize to itself, in the case of a `type TAIT = impl Trait` with an unconstrained associated type. That causes the visitor to loop on the same type over and over.
Fixes#104291
Deduce closure signature from a type alias `impl Trait`'s supertraits
r? `@oli-obk`
Basically pass the TAIT's bounds through the same method that we're using to deduce a signature from infer var closure bounds.
Does this need a new FCP? I see it as a logical extension of #101834, but happy to rfcbot a new one if it does.
Move most of unwind's build script to lib.rs
Only the android libunwind detection remains in the build script
* Reduces dependence on build scripts for building the standard library
* Reduces dependence on exact target names in favor of using semantic cfg(target_*) usage.
* Keeps almost all code related to linking of the unwinder in one file
Visit attributes of trait impl items during AST validation
Fixes#104140.
This fix might not be backward compatible (in practice) since we now validate more attributes than before.
Should I write more tests?
`@rustbot` label A-attributes
Show note where the macro failed to match
When feeding the wrong tokens, it used to fail with a very generic error that wasn't very helpful. This change tries to help by noting where specifically the matching went wrong.
```rust
macro_rules! uwu {
(a a a b) => {};
}
uwu! { a a a c }
```
```diff
error: no rules expected the token `c`
--> macros.rs:5:14
|
1 | macro_rules! uwu {
| ---------------- when calling this macro
...
4 | uwu! { a a a c }
| ^ no rules expected this token in macro call
|
+note: while trying to match `b`
+ --> macros.rs:2:12
+ |
+2 | (a a a b) => {};
+ | ^
```
Add new MIR constant propagation based on dataflow analysis
The current constant propagation in `rustc_mir_transform/src/const_prop.rs` fails to handle many cases that would be expected from a constant propagation optimization. For example:
```rust
let x = if true { 0 } else { 0 };
```
This pull request adds a new constant propagation MIR optimization pass based on the existing dataflow analysis framework. Since most of the analysis is not unique to constant propagation, a generic framework has been extracted. It works on top of the existing framework and could be reused for other optimzations.
Closes#80038. Closes#81605.
## Todo
### Essential
- [x] [Writes to inactive enum variants](https://github.com/rust-lang/rust/pull/101168#pullrequestreview-1089493974). Resolved by rejecting the registration of places with downcast projections for now. Could be improved by flooding other variants if mutable access to a variant is observed.
- [X] Handle [`StatementKind::CopyNonOverlapping`](https://github.com/rust-lang/rust/pull/101168#discussion_r957774914). Resolved by flooding the destination.
- [x] Handle `UnsafeCell` / `!Freeze` correctly.
- [X] Overflow propagation of `CheckedBinaryOp`: Decided to not propagate if overflow flag is `true` (`false` will still be propagated)
- [x] More documentation in general.
- [x] Arguments for correctness, documentation of necessary assumptions.
- [x] Better performance, or alternatively, require `-Zmir-opt-level=3` for now.
### Extra
- [x] Add explicit unreachability, i.e. upgrading the lattice from $\mathbb{P} \to \mathbb{V}$ to $\set{\bot} \cup (\mathbb{P} \to \mathbb{V})$.
- [x] Use storage statements to improve precision.
- [ ] Consider opening issue for duplicate diagnostics: https://github.com/rust-lang/rust/pull/101168#issuecomment-1276609950
- [ ] Flood moved-from places with $\bot$ (requires some changes for places with tracked projections).
- [ ] Add downcast projections back in.
- [ ] [Algebraic simplifications](https://github.com/rust-lang/rust/pull/101168#discussion_r957967878) (possibly with a shared API; done by old const prop).
- [ ] Propagation through slices / arrays.
- [ ] Find other optimizations that are done by old `const_prop.rs`, but not by this one.
Rollup of 11 pull requests
Successful merges:
- #101967 (Move `unix_socket_abstract` feature API to `SocketAddrExt`.)
- #102470 (Stabilize const char convert)
- #104223 (Recover from function pointer types with generic parameter list)
- #104229 (Don't print full paths in overlap errors)
- #104294 (Don't ICE with inline const errors during MIR build)
- #104332 (Fixed some `_i32` notation in `maybe_uninit`’s doc)
- #104349 (fix some typos in comments)
- #104350 (Fix x finding Python on Windows)
- #104356 (interpret: make check_mplace public)
- #104364 (rustdoc: Resolve doc links in external traits having local impls)
- #104378 (Bump chalk to v0.87)
Failed merges:
r? `@ghost`
`@rustbot` modify labels: rollup
rustdoc: fix corner case in search keyboard commands
This fixes a bug when that shows up in nightly and in stable where:
* Search something
* Press down: first result is highlighted
* Press down: second result is highlighted
* Press down: third result is highlighted
* Press right: first result of second tab is highlighted
* Press left: third result of first tab is highlighted
* Press up: second result is highlighted
* Press up: first result is highlighted
* Press up: Search box is highlighted
* Press down: **third result** is highlighted, where it ought to highlight the first result
Fix missing minification for static files
It's a fix for https://github.com/rust-lang/rust/pull/101702.
The problem was that `Path::ends_with` doesn't do what we thought it does: it checks if the entire item is the last path part, no just if the "path string" ends with the given argument. So instead, I just used the `extension()` method to get the information we want.
cc `@jsha`
r? `@notriddle`
PS: Is it worth it to add a CI test to ensure that the minification was performed on JS and CSS files or not?
Remove unused symbols and diagnostic items
As the title suggests, this removes unused symbols from `sym::` and `#[rustc_diagnostic_item]` annotations that weren't mentioned anywhere.
Originally I tried to use grep, to find symbols and item names that are never mentioned via `sym::name`, however this produced a lot of false positives (?), for example clippy matching on `Symbol::as_str` or macros "implicitly" adding `sym::`. I ended up fixing all these false positives (?) by hand, but tbh I'm not sure if it was worth it...
Update compiler-builtins
This was originally a part of https://github.com/rust-lang/rust/pull/100316. However, extracting it to a seperate PR should help with any extra testing that might be needed.
Signed-off-by: Ayush Singh <ayushsingh1325@gmail.com>
Wrap bundled static libraries into object files
Fixes#103044 (not sure, couldn't test locally)
Bundled static libraries should be wrapped into object files as it's done for metadata file.
r? `@petrochenkov`