Commit graph

43845 commits

Author SHA1 Message Date
Ben Kimock
1d7cf0ff40 Replace some u64 hashes with Hash64 2025-02-15 13:59:09 -05:00
bors
d8810e3e2d Auto merge of #137030 - matthiaskrgr:rollup-267aumr, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #135778 (account for `c_enum_min_bits` in `multiple-reprs` UI test)
 - #136052 (Correct comment for FreeBSD and DragonFly BSD in unix/thread)
 - #136886 (Remove the common prelude module)
 - #136956 (add vendor directory to .gitignore)
 - #136958 (Fix presentation of purely "additive" replacement suggestion parts)
 - #136967 (Use `slice::fill` in `io::Repeat` implementation)
 - #136976 (alloc boxed: docs: use MaybeUninit::write instead of as_mut_ptr)
 - #137007 (Emit MIR for each bit with on `dont_reset_cast_kind_without_updating_operand`)
 - #137008 (Move code into `rustc_mir_transform`)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-02-14 17:17:45 +00:00
Matthias Krüger
bd094fb573
Rollup merge of #137008 - nnethercote:mv-code-into-rustc_mir_transform, r=oli-obk
Move code into `rustc_mir_transform`

I found two modules in other crates that are better placed in `rustc_mir_transform`, because that's the only crate that uses them.

r? ``@matthewjasper``
2025-02-14 16:23:34 +01:00
Matthias Krüger
49fb61c496
Rollup merge of #136958 - compiler-errors:additive-replacmeent, r=estebank
Fix presentation of purely "additive" replacement suggestion parts

#127541 changes replacement suggestions to use the "diff" view always, which I think is really verbose in cases where a replacement snippet is a "superset" of the snippet that is being replaced.

Consider:

```
LL -     Self::Baz: Clone,
LL +     Self::Baz: Clone, T: std::clone::Clone
```

In this code, we suggest replacing `", "` with `", T: std::clone::Clone"`. This is a consequence of how the snippet is constructed. I believe that since the string that is being replaced is a subset of the replacement string, it's not providing much value to present this as a diff. Users should be able to clearly understand what's being suggested here using the `~` underline view we've been suggesting for some time now.

Given that this affects ~100 tests out of the ~1000 UI tests affected, I expect this to be a pretty meaningful improvement of the fallout of #127541.

---

In the last commit, this PR also "trims" replacement parts so that they are turned into their purely additive subset, if possible. See the diff for what this means.

---

r? estebank
2025-02-14 16:23:32 +01:00
bors
bdc97d1046 Auto merge of #136575 - scottmcm:nsuw-math, r=nikic
Set both `nuw` and `nsw` in slice size calculation

There's an old note in the code to do this, and now that [LLVM-C has an API for it](f0b8ff1251/llvm/include/llvm-c/Core.h (L4403-L4408)), we might as well.  And it's been there since what looks like LLVM 17 de9b6aa341 so doesn't even need to be conditional.

(There's other places, like `RawVecInner` or `Layout`, that might want to do things like this too, but I'll leave those for a future PR.)
2025-02-14 14:21:29 +00:00
bors
d88ffcdb8b Auto merge of #136735 - scottmcm:transmute-nonnull, r=oli-obk
`transmute` should also assume non-null pointers

Previously it only did integer-ABI things, but this way it does data pointers too.  That gives more information in general to the backend, and allows slightly simplifying one of the helpers in slice iterators.
2025-02-14 09:06:17 +00:00
Michael Goulet
6d71251cf9 Trim suggestion parts to the subset that is purely additive 2025-02-14 00:44:10 -08:00
Michael Goulet
f6406dfd4e Consider add-prefix replacements too 2025-02-14 00:27:17 -08:00
Michael Goulet
b480a9214a Use underline suggestions for purely 'additive' replacements 2025-02-14 00:27:13 -08:00
bors
905b1bf1cc Auto merge of #137010 - workingjubilee:rollup-g00c07v, r=workingjubilee
Rollup of 9 pull requests

Successful merges:

 - #135439 (Make `-O` mean `OptLevel::Aggressive`)
 - #136460 (Simplify `rustc_span` `analyze_source_file`)
 - #136904 (add `IntoBounds` trait)
 - #136908 ([AIX] expect `EINVAL` for `pthread_mutex_destroy`)
 - #136924 (Add profiling of bootstrap commands using Chrome events)
 - #136951 (Use the right binder for rebinding `PolyTraitRef`)
 - #136981 (ci: switch loongarch jobs to free runners)
 - #136992 (Update backtrace)
 - #136993 ([cg_llvm] Remove dead error message)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-02-14 06:13:42 +00:00
Jubilee
e8d0d00798
Rollup merge of #136993 - dpaoliello:cleanllvm4, r=workingjubilee
[cg_llvm] Remove dead error message

Part of #135502

Discovered a dead error message in rustc_codegen_llvm, so removing it.

r? ``@Zalathar``
2025-02-13 21:37:54 -08:00
Jubilee
3957eaa459
Rollup merge of #136951 - compiler-errors:clause-binder, r=lqd
Use the right binder for rebinding `PolyTraitRef`

Fixes #136940

I committed a slightly different test which still demonstrates the issue.
2025-02-13 21:37:52 -08:00
Jubilee
8f4b766885
Rollup merge of #136460 - real-eren:simplify-rustc_span-analyze, r=Noratrieb
Simplify `rustc_span` `analyze_source_file`

Simplifies the logic to what the code *actually* does, which is to just record newlines and multibyte characters. Checking for other ASCII control characters is unnecessary because the generic fallback doesn't do anything for those cases.
Also uses a simpler (and more efficient) means of iterating the set bits of the mask.
2025-02-13 21:37:50 -08:00
Scott McMurray
9ad6839f7a Set both nuw and nsw in slice size calculation
There's an old note in the code to do this, and now that LLVM-C has an API for it, we might as well.
2025-02-13 21:26:48 -08:00
Nicholas Nethercote
28b75a384e Move MirPatch from rustc_middle to rustc_mir_transform.
Because it's only used in `rustc_mir_transform`. (Presumably it is
currently in `rustc_middle` because lots of other MIR-related stuff is,
but that's not a hard requirement.) And because `rustc_middle` is huge
and it's always good to make it smaller.
2025-02-14 16:15:57 +11:00
Nicholas Nethercote
46c72362bc Move drop elaboration infrastructure.
`rustc_mir_dataflow/src/elaborate_drops.rs` contains some infrastructure
used by a few MIR passes: the `elaborate_drop` function, the
`DropElaborator` trait, etc.

`rustc_mir_transform/src/elaborate_drops.rs` (same file name, different
crate) contains the `ElaborateDrops` pass. It relies on a lot of the
infrastructure from `rustc_mir_dataflow/src/elaborate_drops.rs`.

It turns out that the drop infrastructure is only used in
`rustc_mir_transform`, so this commit moves it there. (The only
exception is the small `DropFlagState` type, which is moved to the
existing `rustc_mir_dataflow/src/drop_flag_effects.rs`.) The file is
renamed from `rustc_mir_dataflow/src/elaborate_drops.rs` to
`rustc_mir_transform/src/elaborate_drop.rs` (with no trailing `s`)
because (a) the `elaborate_drop` function is the most important export,
and (b) `rustc_mir_transform/src/elaborate_drops.rs` already exists.

All the infrastructure pieces that used to be `pub` are now
`pub(crate)`, because they are now only used within
`rustc_mir_transform`.
2025-02-14 16:05:34 +11:00
Jubilee
d82ec95083
Rollup merge of #136957 - Zalathar:counters, r=oli-obk
coverage: Eliminate more counters by giving them to unreachable nodes

When preparing a function's coverage counters and metadata during codegen, any part of the original coverage graph that was removed by MIR optimizations can be treated as having an execution count of zero.

Somewhat counter-intuitively, if we give those unreachable nodes a _higher_ priority for receiving physical counters (instead of counter expressions), that ends up reducing the total number of physical counters needed.

This works because if a node is unreachable, we don't actually create a physical counter for it. Instead that node gets a fixed zero counter, and any other node that would have relied on that physical counter in its counter expression can just ignore that term completely.
2025-02-13 17:46:11 -08:00
Jubilee
1b603f959b
Rollup merge of #136928 - lcnr:method-lookup-check-wf, r=compiler-errors
eagerly prove WF when resolving fully qualified paths

fixes https://github.com/rust-lang/trait-system-refactor-initiative/issues/161.

This hopefully shouldn't impact perf. I do think we need to deal with at least part of the fallout here, opening for vibes.

r? ``@compiler-errors``
2025-02-13 17:46:09 -08:00
Jubilee
864eba9fb1
Rollup merge of #136895 - maurer:fix-enum-discr, r=nikic
debuginfo: Set bitwidth appropriately in enum variant tags

Previously, we unconditionally set the bitwidth to 128-bits, the largest an enum would possibly be. Then, LLVM would cut down the constant by chopping off leading zeroes before emitting the DWARF. LLVM only supported 64-bit enumerators, so this would also have occasionally resulted in truncated data.

LLVM added support for 128-bit enumerators in llvm/llvm-project#125578

That patchset trusts the constant to describe how wide the variant tag is, so the high 64-bits of zeros are considered potentially load-bearing.

As a result, we went from emitting tags that looked like:
DW_AT_discr_value     (0xfe)

(because `dwarf::BestForm` selected `data1`)

to emitting tags that looked like:
DW_AT_discr_value	(<0x10> fe ff ff ff 00 00 00 00 00 00 00 00 00 00 00 00 )

This makes the `DW_AT_discr_value` encode at the bitwidth of the tag, which:
1. Is probably closer to our intentions in terms of describing the data.
2. Doesn't invoke the 128-bit support which may not be supported by all debuggers / downstream tools.
3. Will result in smaller debug information.
2025-02-13 17:46:08 -08:00
Jubilee
d784803115
Rollup merge of #136869 - chenyukang:yukang-fix-133713-let-binding, r=estebank
Fix diagnostic when using = instead of : in let binding

Fixes #133713

r? ``@estebank``
2025-02-13 17:46:08 -08:00
Daniel Paoliello
bfdc96114c [cg_llvm] Remove dead error message 2025-02-13 15:04:39 -08:00
lcnr
81c6d5ec9b eagerly prove WF when resolving fully qualified paths 2025-02-14 00:04:22 +01:00
lcnr
059288ed44 adjust derive_error 2025-02-13 23:49:09 +01:00
lcnr
05bd5ced2d rework pointee handling for the new rigid alias approach 2025-02-13 20:19:11 +00:00
lcnr
de273e459e normalizes-to rework rigid alias handling 2025-02-13 20:19:11 +00:00
clubby789
2966256133 Make -O mean -C opt-level=3 2025-02-13 19:47:55 +00:00
bors
c241e14650 Auto merge of #136593 - lukas-code:ty-value-perf, r=oli-obk
valtree performance tuning

Summary: This PR makes type checking of code with many type-level constants faster.

After https://github.com/rust-lang/rust/pull/136180 was merged, we observed a small perf regression (https://github.com/rust-lang/rust/pull/136318#issuecomment-2635562821). This happened because that PR introduced additional copies in the fast reject code path for consts, which is very hot for certain crates: 6c1d960d88/compiler/rustc_type_ir/src/fast_reject.rs (L486-L487)

This PR improves the performance again by properly interning the valtrees so that copying and comparing them becomes faster. This will become especially useful with `feature(adt_const_params)`, so the fast reject code doesn't have to do a deep compare of the valtrees.

Note that we can't just compare the interned consts themselves in the fast reject, because sometimes `'static` lifetimes in the type are be replaced with inference variables (due to canonicalization) on one side but not the other.

A less invasive alternative that I considered is simply avoiding copies introduced by https://github.com/rust-lang/rust/pull/136180 and comparing the valtrees it in-place (see commit: 9e91e50ac5 / perf results: https://github.com/rust-lang/rust/pull/136593#issuecomment-2642303245), however that was still measurably slower than interning.

There are some minor regressions in secondary benchmarks: These happen due to changes in memory allocations and seem acceptable to me. The crates that make heavy use of valtrees show no significant changes in memory usage.
2025-02-13 15:27:30 +00:00
bors
54cdc751df Auto merge of #136965 - jhpratt:rollup-bsnqvmf, r=jhpratt
Rollup of 8 pull requests

Successful merges:

 - #134999 (Add cygwin target.)
 - #136559 (Resolve named regions when reporting type test failures in NLL)
 - #136660 (Use a trait to enforce field validity for union fields + `unsafe` fields + `unsafe<>` binder types)
 - #136858 (Parallel-compiler-related cleanup)
 - #136881 (cg_llvm: Reduce visibility of all functions in the llvm module)
 - #136888 (Always perform discr read for never pattern in EUV)
 - #136948 (Split out the `extern_system_varargs` feature)
 - #136949 (Fix import in bench for wasm)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-02-13 11:45:11 +00:00
Jacob Pratt
36d37966df
Rollup merge of #136948 - workingjubilee:split-off-extern-system-varargs, r=compiler-errors
Split out the `extern_system_varargs` feature

After the stabilization PR was opened, `extern "system"` functions were added to `extended_varargs_abi_support`. This has a number of questions regarding it that were not discussed and were somewhat surprising. It deserves to be considered as its own feature, separate from `extended_varargs_abi_support`.

Tracking issue:
- https://github.com/rust-lang/rust/issues/136946
2025-02-13 03:53:32 -05:00
Jacob Pratt
6fbca25627
Rollup merge of #136888 - compiler-errors:never-read, r=Nadrieril
Always perform discr read for never pattern in EUV

Always perform a read of `!` discriminants to ensure that it's captured by closures in expr use visitor

Fixes #136852

r? Nadrieril or reassign
2025-02-13 03:53:32 -05:00
Jacob Pratt
f7d5285062
Rollup merge of #136881 - dpaoliello:cleanllvm3, r=Zalathar
cg_llvm: Reduce visibility of all functions in the llvm module

Next part of #135502

This reduces the visibility of all functions in the `llvm` module to `pub(crate)` and marks the `enzyme_ffi` modules with `#![expect(dead_code)]` (as previously discussed: <https://github.com/rust-lang/rust/pull/135502#discussion_r1915608085>).

r? ``@Zalathar``
2025-02-13 03:53:31 -05:00
Jacob Pratt
1f669fdc7d
Rollup merge of #136858 - safinaskar:parallel-cleanup-2025-02-11-07-54, r=SparrowLii
Parallel-compiler-related cleanup

Parallel-compiler-related cleanup

I carefully split changes into commits. Commit messages are self-explanatory. Squashing is not recommended.

cc "Parallel Rustc Front-end" https://github.com/rust-lang/rust/issues/113349

r? SparrowLii

``@rustbot`` label: +WG-compiler-parallel
2025-02-13 03:53:31 -05:00
Jacob Pratt
4ea261018a
Rollup merge of #136660 - compiler-errors:BikeshedGuaranteedNoDrop, r=lcnr
Use a trait to enforce field validity for union fields + `unsafe` fields + `unsafe<>` binder types

This PR introduces a new, internal-only trait called `BikeshedGuaranteedNoDrop`[^1] to faithfully model the field check that used to be implemented manually by `allowed_union_or_unsafe_field`.

942db6782f/compiler/rustc_hir_analysis/src/check/check.rs (L84-L115)

Copying over the doc comment from the trait:

```rust
/// Marker trait for the types that are allowed in union fields, unsafe fields,
/// and unsafe binder types.
///
/// Implemented for:
/// * `&T`, `&mut T` for all `T`,
/// * `ManuallyDrop<T>` for all `T`,
/// * tuples and arrays whose elements implement `BikeshedGuaranteedNoDrop`,
/// * or otherwise, all types that are `Copy`.
///
/// Notably, this doesn't include all trivially-destructible types for semver
/// reasons.
///
/// Bikeshed name for now.
```

As far as I am aware, there's no new behavior being guaranteed by this trait, since it operates the same as the manually implemented check. We could easily rip out this trait and go back to using the manually implemented check for union fields, however using a trait means that this code can be shared by WF for `unsafe<>` binders too. See the last commit.

The only diagnostic changes are that this now fires false-negatives for fields that are ill-formed. I don't consider that to be much of a problem though.

r? oli-obk

[^1]: Please let's not bikeshed this name lol. There's no good name for `ValidForUnsafeFieldsUnsafeBindersAndUnionFields`.
2025-02-13 03:53:30 -05:00
Jacob Pratt
4e6605fb0d
Rollup merge of #136559 - compiler-errors:resolve-regions-for-type-test-failure, r=BoxyUwU
Resolve named regions when reporting type test failures in NLL

Just a improvement tweak to an error message that I broke out of a bigger PR that I had to close lol
2025-02-13 03:53:29 -05:00
Jacob Pratt
6f671ad6c3
Rollup merge of #134999 - Berrysoft:dev/new-cygwin-target, r=chenyukang,workingjubilee
Add cygwin target.

This PR simply adds cygwin target together with msys2 target, based on ````@ookiineko```` 's (the account has been deleted) [work](https://github.com/ookiineko-cygport/rust) on cygwin target. My full work is here: https://github.com/rust-lang/rust/compare/master...Berrysoft:rust:dev/cygwin

I have succeeded in building a new rustc for cygwin target, and eventually distributed a new version of [fish-shell](https://github.com/Berrysoft/fish-shell/releases) (rewritten by Rust) for MSYS2.

I will open a new PR to fix std if this PR is accepted.
2025-02-13 03:53:28 -05:00
Scott McMurray
0cc14b688d transmute should also assume non-null pointers
Previously it only did integer-ABI things, but this way it does data pointers too.  That gives more information in general to the backend, and allows slightly simplifying one of the helpers in slice iterators.
2025-02-12 23:01:27 -08:00
Michael Goulet
72b4df3772 Implement lint for definition site item shadowing too 2025-02-13 05:45:53 +00:00
Michael Goulet
18a3cc5c2c Rework collapse method to work correctly with more complex supertrait graphs 2025-02-13 05:45:53 +00:00
Michael Goulet
f8c51d3002 Implement shadowing lint 2025-02-13 05:45:53 +00:00
Michael Goulet
0c85044a5d Implement RFC 3624 supertrait_item_shadowing 2025-02-13 05:45:53 +00:00
Jubilee Young
4bb0c3da2c Split out the extern_system_varargs feature
After the stabilization PR was opened, `extern "system"` functions were
added to `extended_varargs_abi_support`. This has a number of questions
regarding it that were not discussed and were somewhat surprising.
It deserves to be considered as its own feature, separate from
`extended_varargs_abi_support`.
2025-02-12 19:57:45 -08:00
Michael Goulet
d0564fda65 Use BikeshedGuaranteedNotDrop in unsafe binder type WF too 2025-02-13 03:45:07 +00:00
Michael Goulet
516afd557c Implement and use BikeshedGuaranteedNoDrop for union/unsafe field validity 2025-02-13 03:45:04 +00:00
Zalathar
ab786d3b98 coverage: Eliminate more counters by giving them to unreachable nodes
When preparing a function's coverage counters and metadata during codegen, any
part of the original coverage graph that was removed by MIR optimizations can
be treated as having an execution count of zero.

Somewhat counter-intuitively, if we give those unreachable nodes a _higher_
priority for receiving physical counters (instead of counter expressions), that
ends up reducing the total number of physical counters needed.

This works because if a node is unreachable, we don't actually create a
physical counter for it. Instead that node gets a fixed zero counter, and any
other node that would have relied on that physical counter in its counter
expression can just ignore that term completely.
2025-02-13 13:45:53 +11:00
bors
9fcc9cf4a2 Auto merge of #136954 - jhpratt:rollup-koefsot, r=jhpratt
Rollup of 12 pull requests

Successful merges:

 - #134090 (Stabilize target_feature_11)
 - #135025 (Cast allocas to default address space)
 - #135841 (Reject `?Trait` bounds in various places where we unconditionally warned since 1.0)
 - #136217 (Mark condition/carry bit as clobbered in C-SKY inline assembly)
 - #136699 (std: replace the `FromInner` implementation for addresses with private conversion functions)
 - #136806 (Fix cycle when debug-printing opaque types from RPITIT)
 - #136807 (compiler: internally merge `PtxKernel` into `GpuKernel`)
 - #136818 (Implement `read*_exact` for `std:io::repeat`)
 - #136927 (Correctly escape hashtags when running `invalid_rust_codeblocks` lint)
 - #136937 (Update books)
 - #136945 (Add diagnostic item for `std::io::BufRead`)
 - #136947 (Reinstate nnethercote in the review rotation.)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-02-13 02:13:24 +00:00
Daniel Paoliello
e7cef26a3d cg_llvm: Reduce visibility of all functions in the llvm module 2025-02-13 12:36:25 +11:00
Zalathar
659e20fa75 Remove LLVMGetModuleContext
This was unused after the removal of `-Zprofile` in #131829.
2025-02-13 12:36:09 +11:00
Michael Goulet
d1b35f9fcc Improved named region errors 2025-02-13 01:36:01 +00:00
Jacob Pratt
9a26bb1892
Rollup merge of #136945 - samueltardieu:push-rsqlyknnvyqm, r=fmease
Add diagnostic item for `std::io::BufRead`

This will be used in Clippy to detect unbuffered calls to `Read::bytes()`.
2025-02-12 20:10:03 -05:00
Jacob Pratt
33c186baf7
Rollup merge of #136807 - workingjubilee:merge-gpus-to-get-the-arcradeongeforce, r=bjorn3
compiler: internally merge `PtxKernel` into `GpuKernel`

r? ``@bjorn3`` for review
2025-02-12 20:10:00 -05:00