Rollup of 8 pull requests
Successful merges:
- #95836 (Use `rust_out{exe_suffix}` for doctests)
- #104882 (notify lcnr on changes to `ObligationCtxt`)
- #104892 (Explain how to get the discriminant out of a `#[repr(T)] enum` with payload)
- #104917 (Allow non-org members to label `requires-debug-assertions`)
- #104931 (Pretty-print generators with their `generator_kind`)
- #104934 (Remove redundant `all` in cfg)
- #104944 (Support unit tests for jsondoclint)
- #104946 (rustdoc: improve popover focus handling JS)
Failed merges:
r? `@ghost`
`@rustbot` modify labels: rollup
rustdoc: improve popover focus handling JS
This commit fixes a few inconsistencies and erratic behavior from the notable traits, settings, and sidebar popups:
* It makes it so that pressing Escape closes the mobile sidebar. This is a bit difficult to do on iPhone, but on other setups like desktop tiling window managers, it's easy and makes sense.
* It makes sure that pressing escape while a notable trait popover is open focuses the popover's toggle button, instead of leaving nothing focused, since that makes more sense with keyboard navigation. Clicking the settings, help, or sidebar buttons, however, will not focus the notable trait popover toggle button.
* It ensures that notable trait and settings popovers are exclusive with the mobile sidebar. Nothing should ever overlap a popover, and there should never be more than one popover open at once.
Remove redundant `all` in cfg
This appears to have been accidentally left in after removing the other branches 45bf1ed1a1
(hat tip to kangalioo for the git archaeology)
Pretty-print generators with their `generator_kind`
After removing `GenFuture`, I special-cased async generators to pretty-print as `impl Future<Output = X>` mainly to avoid too much diagnostics changes originally.
This now reverses that change so that async fn/blocks are pretty-printed as `[$async-type@$source-position]` in various diagnostics, and updates the tests that this touches.
Allow non-org members to label `requires-debug-assertions`
`jruderman` tried to add this in #104916, for example. I think I've seen this happen before as well.
notify lcnr on changes to `ObligationCtxt`
Right now the `ObligationCtxt` has an API which should prevent leaking any important details of the trait solver. This allows us to freely use it without having to worry about causing issues for the [trait solver rewrite](https://github.com/orgs/rust-lang/projects/26/views/1).
I would like to keep it this way ^^
Use `rust_out{exe_suffix}` for doctests
This was mentioned as an issue to me by ````@bruxisma.```` There are 3 separate instances where "rust_out" can become part of the name of a Rust executable, so I am mostly just hoping that this fixes the problem, given that the other sites which it can slip in seem to be well-behaved.
Separate lifetime ident from lifetime resolution in HIR
Drive-by: change how suggested generic args are computed.
Fixes https://github.com/rust-lang/rust/issues/103815
I recommend reviewing commit-by-commit.
Fix Dest Prop
Closes#82678, #79191 .
This was not originally a total re-write of the pass but is has gradually turned into one. Notable changes:
1. Significant improvements to documentation all around. The top of the file has been extended with a more precise argument for soundness. The code should be fairly readable, and I've done my best to add useful comments wherever possible. I would very much like for the bus factor to not be one on this code.
3. Improved handling of conflicts that are not visible in normal dataflow. This was the cause of #79191. Handling this correctly requires us to make decision about the semantics and specifically evaluation order of basically all MIR constructs (see specifically #68364#71117. The way this is implemented is based on my preferred resolution to these questions around the semantics of assignment statements.
4. Some re-architecting to improve performance. More details below.
5. Possible future improvements to this optimization are documented, and the code is written with the needs of those improvements in mind. The hope is that adding support for more precise analyses will not require a full re-write of this opt, but just localized changes.
### Regarding Performance
The previous approach had some performance issues; letting `l` be the number of locals and `s` be the number of statements/terminators, the runtime of the pass was `O(l^2 * s)`, both in theory and in practice. This version is smarter about not calculating unnecessary things and doing more caching. Our runtime is now dominated by one invocation of `MaybeLiveLocals` for each "round," and the number of rounds is less than 5 in over 90% of cases. This means it's linear-ish in practice.
r? `@oli-obk` who reviewed the last version of this, but review from anyone else would be more than welcome
This will use rust_out.exe for doctests on Windows,
rust_out.wasm for doctests in the wasm case, and
also handles cross-compiling or user-provided targets.
This fixes a number of correctness issues from the previous version. Additionally, we use a new
strategy which has much better performance charactersitics and also finds more opportunities to
apply the optimization.
Stop peeling the last iteration of the loop in `Vec::resize_with`
`resize_with` uses the `ExtendWith` code that peels the last iteration:
341d8b8a2c/library/alloc/src/vec/mod.rs (L2525-L2529)
But that's kinda weird for `ExtendFunc` because it does the same thing on the last iteration anyway:
341d8b8a2c/library/alloc/src/vec/mod.rs (L2494-L2502)
So this just has it use the normal `extend`-from-`TrustedLen` code instead.
r? `@ghost`
Revert "Don't set `is_preview` for clippy and rustfmt"
This reverts commit fb3e724d76, which broke `rustup update` for anyone with clippy or rustfmt installed.
Fixes https://github.com/rust-lang/rust/issues/104930.
r? `@Mark-Simulacrum`
`@bors` p=50 fixes nightly
After removing `GenFuture`, I special-cased async generators to pretty-print as `impl Future<Output = X>` mainly to avoid too much diagnostics changes originally.
This now reverses that change so that async fn/blocks are pretty-printed as `[$movability `async` $something@$source-position]` in various diagnostics, and updates the tests that this touches.
Rollup of 7 pull requests
Successful merges:
- #104786 (Use the power of adding helper function to simplify code w/ `Mutability`)
- #104788 (Do not record unresolved const vars in generator interior)
- #104909 (Rename `normalize_opaque_types` to `reveal_opaque_types_in_bounds`)
- #104921 (Remove unnecessary binder from `get_impl_future_output_ty`)
- #104924 (jsondoclint: Accept trait alias is places where trait expected.)
- #104928 (rustdoc: use flexbox CSS to align sidebar button instead of position)
- #104943 (jsondoclint: Handle using enum variants and glob using enums.)
Failed merges:
r? `@ghost`
`@rustbot` modify labels: rollup
This commit fixes a few inconsistencies and erratic behavior from the
notable traits, settings, and sidebar popups:
* It makes it so that pressing Escape closes the mobile sidebar.
This is a bit difficult to do on iPhone, but on other setups like
desktop tiling window managers, it's easy and makes sense.
* It makes sure that pressing escape while a notable trait popover is
open focuses the popover's toggle button, instead of leaving nothing
focused, since that makes more sense with keyboard navigation. Clicking
the settings, help, or sidebar buttons, however, will not focus the
notable trait popover toggle button.
* It ensures that notable trait and settings popovers are exclusive
with the mobile sidebar. Nothing should ever overlap a popover, and
there should never be more than one popover open at once.
jsondoclint: Handle using enum variants and glob using enums.
More work on jsondoclint for `core.json`
Closes#104942
r? `@GuillaumeGomez`
`@rustbot` modify labels: +A-testsuite
jsondoclint: Accept trait alias is places where trait expected.
More work to make `jsondoclint` work for `core.json`
Closes#104923
r? `@GuillaumeGomez`
`@rustbot` modify labels: +A-testsuite
Remove unnecessary binder from `get_impl_future_output_ty`
We never construct an `async fn` with a higher-ranked `impl Future` bound anyways, and basically all the call-sites already skip the binder.
Rename `normalize_opaque_types` to `reveal_opaque_types_in_bounds`
1. The query name is a bit misleading, since it doesn't do any associated type normalization, and
2. since it only takes a predicate list, it sounds a bit more powerful than it actually is.
Do not record unresolved const vars in generator interior
Don't record types in the generator interior when we see unresolved const variables.
We already do this for associated types -- this is important to avoid unresolved inference variables in the generator results during writeback, since the writeback results get stable hashed in incremental mode.
Fixes#104787
Remove AscribeUserTypeCx
r? ``@compiler-errors``
This basically inlines `AscribeUserTypeCx::relate_mir_and_user_ty` into `type_op_ascribe_user_type_with_span` which is the only place where it's used and makes direct use of `ObligationCtxt` API.
Unsupported query error now specifies if its unsupported for local or external crate
Fixes#101666.
I had to move `keys.rs` from `rustc_query_impl` to `rustc_middle`. I don't know if that is problematic. I couldn't think of any other way to get the needed information inside `rustc_middle`.
r? ```@jyn514```
Refine `instruction_set` MIR inline rules
Previously an exact match of the `instruction_set` attribute was required for an MIR inline to be considered. This change checks for an exact match *only* if the callee sets an `instruction_set` in the first place. When the callee does not declare an instruction set then it is considered to be platform agnostic code and it's allowed to be inline'd into the caller.
cc ``@oli-obk``
[Edit] Zulip Context: https://rust-lang.zulipchat.com/#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/What.20exactly.20does.20the.20MIR.20optimizer.20do.3F
Manually implement PartialEq for Option<T> and specialize non-nullable types
This PR manually implements `PartialEq` and `StructuralPartialEq` for `Option`, which seems to produce slightly better codegen than the automatically derived implementation.
It also allows specializing on the `core::num::NonZero*` and `core::ptr::NonNull` types, taking advantage of the niche optimization by transmuting the `Option<T>` to `T` to be compared directly, which can be done in just two instructions.
A comparison of the original, new and specialized code generation is available [here](https://godbolt.org/z/dE4jxdYsa).