Commit Graph

2735 Commits

Author SHA1 Message Date
Stuart Cook
3b22c21dd8
Rollup merge of #140847 - Zalathar:unused-local-file, r=SparrowLii
coverage: Detect unused local file IDs to avoid an LLVM assertion

Each function's coverage metadata contains a *local file table* that maps local file IDs (used by the function's mapping regions) to global file IDs (shared by all functions in the same CGU).

LLVM requires all local file IDs to have at least one mapping region, and has an assertion that will fail if it detects a local file ID with no regions. To make sure that assertion doesn't fire, we need to detect and skip functions whose metadata would trigger it.

(This can't actually happen yet, because currently all of a function's spans must belong to the same file and expansion. But this will be an important edge case when adding expansion region support.)
2025-05-19 21:10:42 +10:00
Stuart Cook
599b08ada8
Rollup merge of #140874 - mejrs:rads, r=WaffleLapkin
make `rustc_attr_parsing` less dominant in the rustc crate graph

It has/had a glob re-export of `rustc_attr_data_structures`, which is a crate much lower in the graph, and a lot of crates were using it *just* (or *mostly*) for that re-export, while they can rely on `rustc_attr_data_structures` directly.

Previous graph:
![graph_1](https://github.com/user-attachments/assets/f4a5f13c-4222-4903-b56d-28c83511fcbd)

Graph with this PR:
![graph_2](https://github.com/user-attachments/assets/1e053d9c-75cc-402b-84df-86229c98277a)

The first commit keeps the re-export, and just changes the dependency if possible. The second commit is the "breaking change" which removes the re-export, and "explicitly" adds the `rustc_attr_data_structures` dependency where needed. It also switches over some src/tools/*.

The second commit is actually a lot more involved than I expected. Please let me know if it's a better idea to back it out and just keep the first commit.
2025-05-19 13:24:54 +10:00
León Orell Valerian Liehr
50b20b73da
Rollup merge of #141218 - dianqk:gvn-overlapping, r=oli-obk
gvn: avoid creating overlapping assignments

Quick fix #141038, as I couldn't find a way to avoid in-place modification. I'm considering handling all `ravlue` modifications within the `visit_statement` function.

r? mir-opt
2025-05-18 18:44:14 +02:00
León Orell Valerian Liehr
3af0c43f06
Rollup merge of #140926 - azhogin:azhogin/async-drop-coroutine-layout-returns-layout-error, r=oli-obk
Return value of coroutine_layout fn changed to Result with LayoutError

Continue of https://github.com/rust-lang/rust/pull/140902:
`coroutine_layout` fn is now returns `Result` with `LayoutError` to have consistent error with `layout_of_uncached`.
`async_drop_coroutine_layout` fn is now return `LayoutError::TooGeneric` in case of not-fully-specialized `async_drop_in_place<T>::{closure}` coroutine.
2025-05-18 18:44:12 +02:00
dianqk
d2e5a3d131
gvn: avoid creating overlapping assignments 2025-05-18 18:42:00 +08:00
Matthias Krüger
8e30998c18
Rollup merge of #141051 - compiler-errors:less-erase, r=nnethercote
Remove some unnecessary erases

Some nits I pulled out of https://github.com/rust-lang/rust/pull/140814.
2025-05-17 10:33:10 +02:00
Pietro Albini
2ce08ca5d6
update cfg(bootstrap) 2025-05-12 15:33:37 +02:00
Andrew Zhogin
ba80d820e5 Return value of coroutine_layout fn changed to Result with LayoutError 2025-05-11 23:53:13 +07:00
mejrs
684b7b70f4 don't depend on rustc_attr_parsing if rustc_data_structures will do 2025-05-09 23:16:55 +02:00
Zalathar
339556eb02 coverage: Enlarge empty spans during MIR instrumentation, not codegen
This allows us to assume that coverage spans will only be discarded during
codegen in very unusual situations.
2025-05-10 00:24:01 +10:00
Michael Goulet
292ecd5242 Remove some unnecessary erases 2025-05-08 16:20:57 +00:00
bendn
3b4c4938c5
add signed integers to unnecessary_lints to ensure feature parity with clippy 2025-05-08 23:16:49 +07:00
Guillaume Gomez
82c99c41c0
Rollup merge of #140234 - nnethercote:separate-Analysis-and-Results, r=davidtwco
Separate dataflow analysis and results

`Analysis` gets put into `Results` with `EntryStates`, by `iterate_to_fixpoint`. This has two problems:
- `Results` is passed various places where only `Analysis` is needed.
- `EntryStates` is passed around mutably everywhere even though it is immutable.

This commit mostly separates `Analysis` from `Results` and fixes these two problems.

r? `@davidtwco`
2025-05-07 18:19:04 +02:00
Zalathar
77a7ae4e9f coverage: Handle hole spans without dividing spans into buckets
Because we no longer merge non-adjacent spans, there is no need to use buckets
to prevent merging across hole spans.
2025-05-06 20:42:40 +10:00
Zalathar
4d5a1acebf coverage: Only merge adjacent coverage spans
This also removes some manipulation of the function signature span that only
made sense in the context of merging non-adjacent spans.
2025-05-06 20:42:25 +10:00
Guillaume Gomez
ab7623e93c
Rollup merge of #140115 - dianqk:gvn-matchbr, r=oli-obk
mir-opt: execute MatchBranchSimplification after GVN

This can provide more opportunities for MatchBranchSimplification.

Currently, rustc does not optimize the following code into a single statement at mir-opt, and this PR fixes the first case.

```rust
pub fn match1(c: bool, v1: i32, v2: i32) -> i32 {
    if c { v1 - v2 } else { v1 - v2 }
}

pub fn match2(c: bool, v1: i32) -> i32 {
    if c { v1 - 1 } else { v1 - 1 }
}
```

https://rust.godbolt.org/z/Y8xPMjrfM

r? mir-opt
2025-05-05 21:32:30 +02:00
Guillaume Gomez
677a5aca7f
Rollup merge of #140080 - dianqk:one-mirpatch, r=oli-obk
mir-opt: Use one MirPatch in MatchBranchSimplification
2025-05-05 21:32:30 +02:00
bors
243c5a35e1 Auto merge of #140453 - Zoxc:next-disambiguator, r=oli-obk
Remove global `next_disambiguator` state and handle it with a `DisambiguatorState` type

This removes `Definitions.next_disambiguator` as it doesn't guarantee deterministic def paths when `create_def` is called in parallel. Instead a new `DisambiguatorState` type is passed as a mutable reference to `create_def` to help create unique def paths. `create_def` calls with distinct  `DisambiguatorState` instances must ensure that that the def paths are unique without its help.

Anon associated types did rely on this global state for uniqueness and are changed to use (method they're defined in + their position in the method return type) as the `DefPathData` to ensure uniqueness. This also means that the method they're defined in appears in error messages, which is nicer.

`DefPathData::NestedStatic` is added to use for nested data inside statics instead of reusing `DefPathData::AnonConst` to avoid conflicts with those.

cc `@oli-obk`
2025-05-05 11:50:43 +00:00
John Kåre Alsaker
9f8c6d57bf Add comment on creation of SyntheticCoroutineBody 2025-05-04 19:14:35 +02:00
bors
d7df5bdf29 Auto merge of #140464 - oli-obk:successors-mut-perf, r=petrochenkov
Use a closure instead of three chained iterators

Fixes the perf regression from #123948

That PR had chained a third option to the iterator which apparently didn't optimize well
2025-05-03 10:43:38 +00:00
Matthias Krüger
3648f3aa77
Rollup merge of #140458 - azhogin:azhogin/async-drop-fix-dropped-tuple-ice, r=oli-obk
Fix for async drop ice with partly dropped tuple

Fixes https://github.com/rust-lang/rust/issues/140427.
Problem was with block data access with block id from new added blocks in patch.
2025-04-30 22:36:39 +02:00
bors
0fbb922e53 Auto merge of #140023 - cjgillot:arena-try-alloc, r=BoxyUwU
Introduce Arena::try_alloc_from_iter.

`alloc_from_iter` already collects the iterator for reentrancy. So adding an early exit for a fallible iterator integrates naturally into the code. This avoids the other solution to allocate and dump the allocation.
2025-04-29 21:06:15 +00:00
Oli Scherer
9193dfe435 Use a closure instead of three chained iterators 2025-04-29 14:58:21 +00:00
Andrew Zhogin
cce706ec3c Fix for async drop ice with partly dropped tuple 2025-04-29 21:41:15 +07:00
Oli Scherer
820fce61e7 Some style nits 2025-04-29 14:03:06 +00:00
John Kåre Alsaker
e561ec0e03 Remove global next_disambiguator state and handle it with a DisambiguatorState type 2025-04-29 13:22:38 +02:00
bors
4c83e55e2d Auto merge of #137940 - 1c3t3a:alignment-borrows-check, r=saethlin
Extend the alignment check to borrows

The current alignment check does not include checks for creating misaligned references from raw pointers, which is now added in this patch.

When inserting the check we need to be careful with references to field projections (e.g. `&(*ptr).a`), in which case the resulting reference must be aligned according to the field type and not the type of the pointer.

r? `@saethlin`

cc `@RalfJung,` after our discussion in #134424
2025-04-29 05:36:44 +00:00
Bastian Kersting
7082fa27a7 Rework the logic for PointerFinder::visit_place
This makes the implementation of our PointerFinder a bit more
straightforward.
2025-04-28 12:36:47 +00:00
Andrew Zhogin
c366756a85 AsyncDrop implementation using shim codegen of async_drop_in_place::{closure}, scoped async drop added. 2025-04-28 16:23:13 +07:00
Andrew Zhogin
52c1838fa7 dropee_emit_retag function separated in drop glue build 2025-04-28 00:52:30 +07:00
bors
43e62a789c Auto merge of #140288 - Zalathar:new-executor, r=jieyouxu
compiletest: Re-land using the new non-libtest executor by default

This PR re-lands #139998, which had the misfortune of triggering download-rustc in its CI jobs, so we didn't get proper test metrics for comparison with the old implementation. So that was PR was reverted in #140233, with the intention of re-landing it alongside a dummy compiler change to inhibit download-rustc.

---

Original PR description for #139998:
>The new executor was implemented in #139660, but required a manual opt-in. This PR activates the new executor by default, but leaves the old libtest-based executor in place (temporarily) to make reverting easier if something unexpectedly goes horribly wrong.
>
>Currently the new executor can be explicitly disabled by passing the `-N` flag to compiletest (e.g. `./x test ui -- -N`), but eventually that flag will be removed, alongside the removal of the libtest dependency. The flag is mostly there to make manual comparative testing easier if something does go wrong.
>
>As before, there *should* be no user-visible difference between the old executor and the new executor.

---
r? jieyouxu
2025-04-26 22:33:56 +00:00
bors
d3508a8ad0 Auto merge of #140177 - tmandry:compiletest-par, r=jieyouxu
[compiletest] Parallelize test discovery

Certain filesystems are slow to service individual read requests, but can service many in parallel. This change brings down the time to run a single cached test on one of those filesystems from 40s to about 8s.
2025-04-26 02:03:54 +00:00
bors
b4c8b0c3f0 Auto merge of #140298 - matthiaskrgr:rollup-5tc1gvb, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #137683 (Add a tidy check for GCC submodule version)
 - #138968 (Update the index of Result to make the summary more comprehensive)
 - #139572 (docs(std): mention const blocks in const keyword doc page)
 - #140152 (Unify the format of rustc cli flags)
 - #140193 (fix ICE in `#[naked]` attribute validation)
 - #140205 (Tidying up UI tests [2/N])
 - #140284 (remove expect() in `unnecessary_transmutes`)
 - #140290 (rustdoc: fix typo change from equivelent to equivalent)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-04-25 18:51:15 +00:00
Bastian Kersting
a3e7c699bc Extend the alignment check to borrows
The current alignment check does not include checks for creating
misaligned references from raw pointers, which is now added in this
patch.

When inserting the check we need to be careful with references to
field projections (e.g. `&(*ptr).a`), in which case the resulting
reference must be aligned according to the field type and not the
type of the pointer.
2025-04-25 12:16:40 +00:00
bendn
d3a4ebca85
remove expect() in unnecessary_transmutes 2025-04-25 19:07:41 +07:00
Zalathar
1670de40e0 Trivial compiler change to inhibit download-rustc in CI 2025-04-25 20:41:50 +10:00
Matthias Krüger
564e5ccb5c
Rollup merge of #140202 - est31:let_chains_feature_compiler, r=lcnr
Make #![feature(let_chains)] bootstrap conditional in compiler/

Let chains have been stabilized recently in #132833, so we can remove the gating from our uses in the compiler (as the compiler uses edition 2024).
2025-04-25 07:50:25 +02:00
Matthias Krüger
53afa97eb7
Rollup merge of #136083 - bend-n:⃤⃤, r=lcnr
Suggest {to,from}_ne_bytes for transmutations between arrays and integers, etc

implements #136067

Rust has helper methods for many kinds of safe transmutes, for example integer<->bytes. This is a lint against using transmute for these cases.

```rs
fn bytes_at_home(x: [u8; 4]) -> u32 {
   transmute(x)
}

// other examples
transmute::<[u8; 2], u16>();
transmute::<[u8; 8], f64>();
transmute::<u32, [u8; 4]>();
transmute::<char, u32>();
transmute::<u32, char>();
```
It would be handy to suggest `u32::from_ne_bytes(x)`.
This is implemented for `[u8; _]` -> `{float int}`

This also implements the cases:
`fXX` <-> `uXX` = `{from_bits, to_bits}`
`uXX` -> `iXX` via `cast_unsigned` and `cast_signed`
{`char` -> `u32`, `bool` -> `n8`} via `from`
`u32` -> `char` via `from_u32_unchecked` (note: notes `from_u32().unwrap()`) (contested)
`u8` -> `bool` via `==` (debatable)

---
try-job: aarch64-gnu
try-job: test-various
2025-04-24 17:19:42 +02:00
Zalathar
f673c9b056 Trivial compiler change to inhibit download-rustc in CI 2025-04-24 19:44:13 +10:00
Matthias Krüger
a8ebfb256a
Rollup merge of #139261 - RalfJung:msvc-align-mitigation, r=oli-obk
mitigate MSVC alignment issue on x86-32

This implements mitigation for https://github.com/rust-lang/rust/issues/112480 by stopping to emit `align` attributes on loads and function arguments when building for a win32 MSVC target. MSVC is known to not properly align `u64` and similar types, and claiming to LLVM that everything is properly aligned increases the chance that this will cause problems.

Of course, the misalignment is still a bug, but we can't fix that bug, only MSVC can.

Also add an errata note to the platform support page warning users about this known problem.

try-job: `i686-msvc*`
2025-04-24 11:40:35 +02:00
bendn
c8c074288a
Suggest {to,from}_ne_bytes for transmutations between arrays and integers, etc 2025-04-24 13:14:36 +07:00
Nicholas Nethercote
92799b6f89 Separate Analysis and Results.
`Results` contains and `Analysis` and an `EntryStates`. The unfortunate
thing about this is that the analysis needs to be mutable everywhere
(`&mut Analysis`) which forces the `Results` to be mutable everywhere,
even though `EntryStates` is immutable everywhere.

To fix this, this commit renames `Results` as `AnalysisAndResults`,
renames `EntryStates` as `Results`, and separates the analysis and
results as much as possible. (`AnalysisAndResults` doesn't get much use,
it's mostly there to facilitate method chaining of
`iterate_to_fixpoint`.)

`Results` is immutable everywhere, which:
- is a bit clearer on how the data is used,
- avoids an unnecessary clone of entry states in
  `locals_live_across_suspend_points`, and
- moves the results outside the `RefCell` in Formatter.

The commit also reformulates `ResultsHandle` as the generic `CowMut`,
which is simpler than `ResultsHandle` because it doesn't need the
`'tcx` lifetime and the trait bounds. It also which sits nicely
alongside the new use of `Cow` in `ResultsCursor`.
2025-04-24 11:36:07 +10:00
Nicholas Nethercote
4ff55588d3 Pass Analysis to visit_* instead of Results.
Every `Results` contains an `Analysis`, but these methods only need the
`Analysis`. No point passing them more data than they need.
2025-04-24 11:34:06 +10:00
est31
7493e1cdf6 Make #![feature(let_chains)] bootstrap conditional in compiler/ 2025-04-23 16:40:30 +02:00
Chris Denton
b03267fc11
Rollup merge of #140160 - oli-obk:lang-items, r=jieyouxu
Use `is_lang_item` and `as_lang_item` instead of handrolling their logic

Various cleanups and deduplication. Most notably `if is_lang_item(foo, bar) {} else if is_lang_item...` chains are turned into matches. No behaviour changes intended beyond turning ICEs into fatal "lang item not found" errors
2025-04-23 00:43:07 +00:00
Oli Scherer
5d2952100f Use is_lang_item and as_lang_item instead of handrolling their logic 2025-04-22 11:02:37 +00:00
Nicholas Nethercote
521b379705 Remove unnecessary lifetime on ResultsVisitor. 2025-04-22 10:08:05 +10:00
dianqk
5881b7c68b
mir-opt: execute MatchBranchSimplification after GVN
This can provide more opportunities for MatchBranchSimplification.
2025-04-21 21:46:44 +08:00
dianqk
11cfc16a60
mir-opt: Use one MirPatch in MatchBranchSimplification 2025-04-20 20:56:41 +08:00
Chris Denton
98515864d2
Rollup merge of #140024 - cjgillot:continue-jumping, r=compiler-errors
Remove early exits from JumpThreading.

This removes early exits from https://github.com/rust-lang/rust/pull/131203 as I asked during review.

The correctness of the backtracking is `mutated_statement` clearing all relevant conditions. If `process_statement` fails to insert a new condition, for instance by const-eval failure, `mutated_statement`  still removes the obsolete conditions from the state.

r? `@compiler-errors`
2025-04-19 19:30:49 +00:00