Commit Graph

49486 Commits

Author SHA1 Message Date
Jana Dönszelmann
5712d50648 Rollup merge of #144712 - nnethercote:dedup-num-types, r=fmease
Deduplicate `IntTy`/`UintTy`/`FloatTy`.

There are identical definitions in `rustc_type_ir` and `rustc_ast`. This commit removes them and places a single definition in `rustc_ast_ir`. This requires adding `rust_span` as a dependency of `rustc_ast_ir`, but means a bunch of silly conversion functions can be removed.

r? `@fmease`
2025-07-31 17:19:39 +02:00
Jana Dönszelmann
edd2574848 Rollup merge of #144711 - compiler-errors:op-span, r=petrochenkov
Consider operator's span when computing binop expr span

When computing the span of a binop consisting of `lhs` and `rhs`, we previously just took the spans of `lhs.span.to(rhs.span)`. In the case that both `lhs` and `rhs` are both arguments to a macro, this can produce a wildly incorrect span.

To fix this, first compute the span between `lhs` and the binary operator, which will cause `lhs` to possibly be adjusted to a relevant macro metavar, and then compute that span extended to `rhs`, which will cause it to also be adjusted to a relevant macro metavar.

This coincidentally fixes a FIXME in `tests/ui/lint/wide_pointer_comparisons.rs` and suppresses a nonsense suggestion.
2025-07-31 17:19:39 +02:00
Jana Dönszelmann
eec13cd273 Rollup merge of #144702 - compiler-errors:stall-const-arg-has-type, r=lcnr
stall `ConstArgHasType` in `compute_goal_fast_path`

I'm having major deja-vu about this; I thought that already implemented this but 🤷 maybe not.
2025-07-31 17:19:38 +02:00
Jana Dönszelmann
1fe488638b Rollup merge of #144688 - Stypox:better-enter-trace-span, r=RalfJung
Uniform `enter_trace_span!` and add documentation

1. The latest changes to `enter_trace_span!` were ported from Miri (see https://github.com/rust-lang/miri/pull/4452#discussion_r2204958019), so now both the `rustc_const_eval` and the Miri macro accept the same syntax. Furthermore, the Miri macro was changed to just call rustc_const_eval`'s, to avoid duplication.
2. I made the `layout_of` (& friends) calls use that new syntax, e.g. `enter_trace_span!(layouting::layout_of, ...)`
3. I made sure the macro specifies all types/traits/macros it refers to using `$crate::`, so the macro works anywhere independently of which types/traits/macros are imported in the context it is used in.
4. I added documentation, examples and tips to the macro's doc. To make the rustdoc compile I had to add some hidden lines (`#`), but now it acts as a compilation test which will avoid reintroducing issue 3. in the future. I will also create a documentation file with everything one needs to know about tracing at a later point, but I figured adding some of that info directly on the tracing macro makes it more discoverable.
5. In `stack.rs` I made it so that the `"frame"` span has a field named "frame" (instead of "message") with the data about the frame. This field used to be called "message" (tracing's default) since it was previously formatted using `"{}", instance`, and now I replaced it with `frame = %instance`.
2025-07-31 17:19:37 +02:00
Stypox
bb08a4dfc7 Make Miri's enter_trace_span! call const_eval's 2025-07-31 15:42:29 +02:00
lcnr
26c03e206a dont assemble shadowed impl candidates 2025-07-31 15:35:21 +02:00
Scott Schafer
935fdb6980 fix: Match width of ascii and unicode secondary file start 2025-07-31 07:26:39 -06:00
Jana Dönszelmann
e1d3ad89c7 remove rustc_attr_data_structures 2025-07-31 14:19:27 +02:00
bors
3fb1b53a9d Auto merge of #144731 - samueltardieu:rollup-36y30k2, r=samueltardieu
Rollup of 4 pull requests

Successful merges:

 - rust-lang/rust#136840 (Fix linker-plugin-lto only doing thin lto)
 - rust-lang/rust#144053 (Remove install Rust script from CI)
 - rust-lang/rust#144297 (Make `libtest::ERROR_EXIT_CODE` const public to not redefine it in rustdoc)
 - rust-lang/rust#144721 (`std_detect`: Linux 6.16 support for RISC-V)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-07-31 12:04:04 +00:00
Samuel Tardieu
d8c09c10e5 Rollup merge of #136840 - Flakebi:linker-plugin-lto-fat, r=dianqk
Fix linker-plugin-lto only doing thin lto

When rust provides LLVM bitcode files to lld and the bitcode contains
function summaries as used for thin lto, lld defaults to using thin lto.
This prevents some optimizations that are only applied for fat lto.

We solve this by not creating function summaries when fat lto is
enabled. The bitcode for the module is just directly written out.

An alternative solution would be to set the `ThinLTO=0` module flag to
signal lld to do fat lto.
The code in clang that sets this flag is here:
560149b5e3/clang/lib/CodeGen/BackendUtil.cpp (L1150)
The code in LLVM that queries the flag and defaults to thin lto if not
set is here:
e258bca950/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp (L4441-L4446)

try-job: x86_64-gnu-debug
try-job: aarch64-gnu-debug
2025-07-31 13:12:45 +02:00
Nicholas Nethercote
066a973312 Overhaul Constraint.
This commit changes it to store a `Region` instead of a `RegionVid` for the `Var` cases:
- We avoid having to call `Region::new_var` to re-create `Region`s from
  `RegionVid`s in a few places, avoiding the interning process, giving a
  small perf win. (At the cost of the type allowing some invalid
  combinations of values.)
- All the cases now store two `Region`s, so the commit also separates
  the `ConstraintKind` (a new type) from the `sub` and `sup` arguments
  in `Constraint`.
2025-07-31 20:04:51 +10:00
Nicholas Nethercote
75a1f47750 Avoid vacuous Constraint::{VarSubVar,RegSubReg} constraints.
If the two regions are the same, we can skip it. This is a small perf win.
2025-07-31 20:04:51 +10:00
Nicholas Nethercote
704f2ca172 Tidy up Cargo.toml files.
- Add some missing `tidy-alphabetical-*` markers.
- Remove some unnecessary blank lines.
2025-07-31 19:58:04 +10:00
Nicholas Nethercote
1901dde97b Deduplicate IntTy/UintTy/FloatTy.
There are identical definitions in `rustc_type_ir` and `rustc_ast`. This
commit removes them and places a single definition in `rustc_ast_ir`.
This requires adding `rust_span` as a dependency of `rustc_ast_ir`, but
means a bunch of silly conversion functions can be removed.

The one annoying wrinkle is that the old version had differences in
their `Debug` impls, e.g. one printed `u32` while the other printed
`U32`. Some compiler error messages rely on the former (yuk), and some
clippy output depends on the latter. So the commit also changes clippy
to not rely on `Debug` and just implement what it needs itself.
2025-07-31 19:56:11 +10:00
Nicholas Nethercote
64be8bb599 Check consts in ValidateBoundVars.
Alongside the existing type and region checking.
2025-07-31 19:54:58 +10:00
Nicholas Nethercote
507dec4dc3 Make const bound handling more like types/regions.
Currently there is `Ty` and `BoundTy`, and `Region` and `BoundRegion`,
and `Const` and... `BoundVar`. An annoying inconsistency.

This commit repurposes the existing `BoundConst`, which was barely used,
so it's the partner to `Const`. Unlike `BoundTy`/`BoundRegion` it lacks
a `kind` field but it's still nice to have because it makes the const
code more similar to the ty/region code everywhere.

The commit also removes `impl From<BoundVar> for BoundTy`, which has a
single use and doesn't seem worth it.

These changes fix the "FIXME: We really should have a separate
`BoundConst` for consts".
2025-07-31 19:29:40 +10:00
Nicholas Nethercote
94cc5bb962 Streamline const folding/visiting.
Type folders can only modify a few "types of interest": `Binder`, `Ty`,
`Predicate`, `Clauses`, `Region`, `Const`. Likewise for type visitors,
but they can also visit errors (via `ErrorGuaranteed`).

Currently the impls of `try_super_fold_with`, `super_fold_with`, and
`super_visit_with` do more than they need to -- they fold/visit values
that cannot contain any types of interest.

This commit removes those unnecessary fold/visit operations, which makes
these impls more similar to the impls for `Ty`. It also removes the
now-unnecessary derived impls for the no-longer-visited types.
2025-07-31 19:29:40 +10:00
bors
64ca23b623 Auto merge of #144723 - Zalathar:rollup-f9e0rfo, r=Zalathar
Rollup of 3 pull requests

Successful merges:

 - rust-lang/rust#144657 (fix: Only "close the window" when its the last annotated file)
 - rust-lang/rust#144665 (Re-block SRoA on SIMD types)
 - rust-lang/rust#144713 (`rustc_middle::ty` cleanups)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-07-31 08:54:41 +00:00
Stuart Cook
017586c93a Rollup merge of #144713 - nnethercote:rustc_middle-ty-cleanups, r=lcnr
`rustc_middle::ty` cleanups

r? `@davidtwco`
2025-07-31 18:52:11 +10:00
Stuart Cook
8cca6bce4e Rollup merge of #144665 - scottmcm:restore-sroa-simd-check, r=compiler-errors
Re-block SRoA on SIMD types

Fixes rust-lang/rust#144621
2025-07-31 18:52:10 +10:00
Stuart Cook
880113eff9 Rollup merge of #144657 - Muscraft:fix-unicode-close-window, r=fee1-dead
fix: Only "close the window" when its the last annotated file

While comparing the Unicode theme output of `rustc` and `annotate-snippets`, I found that `rustc` would ["close the window"](686bc1c5f9/compiler/rustc_errors/src/emitter.rs (L1025-L1027)) (draw a `╰╴`), even though there were other annotated files that followed the current one. This PR makes it so the emitter will only "close the window" on the last annotated file.

Before:
```
error[E0624]: method `method` is private
   ╭▸ $DIR/close_window.rs:9:7
   │
LL │     s.method();
   ╰╴      ━━━━━━ private method
   │
   ⸬ $DIR/auxiliary/close_window.rs:3:5
   │
LL │     fn method(&self) {}
   ╰╴    ──────────────── private method defined here
```

After:
```
error[E0624]: method `method` is private
   ╭▸ $DIR/close_window.rs:9:7
   │
LL │     s.method();
   │       ━━━━━━ private method
   │
   ⸬ $DIR/auxiliary/close_window.rs:3:5
   │
LL │     fn method(&self) {}
   ╰╴    ──────────────── private method defined here
```
2025-07-31 18:52:10 +10:00
Flakebi
7a127fba65 Fix linker-plugin-lto only doing thin lto
When rust provides LLVM bitcode files to lld and the bitcode contains
function summaries as used for thin lto, lld defaults to using thin lto.
This prevents some optimizations that are only applied for fat lto.

We solve this by not creating function summaries when fat lto is
enabled. The bitcode for the module is just directly written out.

An alternative solution would be to set the `ThinLTO=0` module flag to
signal lld to do fat lto.
The code in clang that sets this flag is here:
560149b5e3/clang/lib/CodeGen/BackendUtil.cpp (L1150)
The code in LLVM that queries the flag and defaults to thin lto if not
set is here:
e258bca950/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp (L4441-L4446)
2025-07-31 10:38:34 +02:00
Scott Schafer
761c4e308c fix: Only "close the window" when its the last annotated file 2025-07-31 00:25:09 -06:00
xizheyin
7b667e7811 Extend is_case_difference to handle digit-letter confusables
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-07-31 13:55:59 +08:00
Stuart Cook
9c6a618a7b Rollup merge of #144717 - nnethercote:mv-rustc_middle-parameterized, r=compiler-errors
Move `rustc_middle::parameterized`

It doesn't need to be in `rustc_middle`.

r? `@compiler-errors`
2025-07-31 15:42:02 +10:00
Stuart Cook
45169cbf38 Rollup merge of #144685 - jdonszelmann:lang-items-once, r=wafflelapkin
Only extract lang items once in codegen_fn_attrs

This one should be obvious. These two extraction points used to be far apart but now that they're refactored to be close it was rather obvious we're just doing double work....

r? ``@WaffleLapkin``

Buils on rust-lang/rust#144655
2025-07-31 15:42:01 +10:00
Stuart Cook
5c123c25e3 Rollup merge of #144663 - Zalathar:empty-span, r=petrochenkov
coverage: Re-land "Enlarge empty spans during MIR instrumentation"

This allows us to assume that coverage spans will only be discarded during codegen in very unusual situations.

---

This seemingly-simple change has a rather messy history:
- rust-lang/rust#140847
- rust-lang/rust#141650
- rust-lang/rust#144298
- rust-lang/rust#144480

Since then, a number of related changes have landed that should make it reasonable to try again:
- rust-lang/rust#144530
- rust-lang/rust#144560
- rust-lang/rust#144616

In particular, we have multiple fixes/mitigations, and a confirmed regression test for the original bug that is not triggered by re-landing the changes in this PR.
2025-07-31 15:42:00 +10:00
Stuart Cook
8628b78f24 Rollup merge of #144232 - xacrimon:explicit-tail-call, r=WaffleLapkin
Implement support for `become` and explicit tail call codegen for the LLVM backend

This PR implements codegen of explicit tail calls via `become` in `rustc_codegen_ssa` and support within the LLVM backend. Completes a task on (https://github.com/rust-lang/rust/issues/112788). This PR implements all the necessary bits to make explicit tail calls usable, other backends have received stubs for now and will ICE if you use `become` on them. I suspect there is some bikeshedding to be done on how we should go about implementing this for other backends, but it should be relatively straightforward for GCC after this is merged.

During development I also put together a POC bytecode VM based on tail call dispatch to test these changes out and analyze the codegen to make sure it generates expected assembly. That is available [here](https://github.com/xacrimon/tcvm).
2025-07-31 15:42:00 +10:00
Stuart Cook
f478bec907 Rollup merge of #143672 - beepster4096:box_drop_flags_again, r=oli-obk
Fix Box allocator drop elaboration

New version of rust-lang/rust#131146.

Clearing Box's drop flag after running its destructor can cause it to skip dropping its allocator, so just don't. Its cleared by the drop ladder code afterwards already.

Unlike the last PR this also handles other types with destructors properly, in the event that we can have open drops on them in the future (by partial initialization or DerefMove or something).

Finally, I also added tests for the interaction with async drop here but I discovered rust-lang/rust#143658, so one of the tests has a `knownbug` annotation. Not sure if it should be in this PR at all though.

Fixes rust-lang/rust#131082

r? wesleywiser - prev. reviewer
2025-07-31 15:41:59 +10:00
Nicholas Nethercote
7aec38b6d9 Fix up size asserts.
- Put them in the module that defines the type.
- Add some `WithCachedTypeInfo<T>` asserts for consistency.
2025-07-31 15:17:21 +10:00
Nicholas Nethercote
cf95e45ec6 Move InferVarInfo out of rustc_middle.
It's only used in `rustc_hir_typeck`.
2025-07-31 15:17:20 +10:00
Nicholas Nethercote
0b3c980c24 Remove TyCtxt::get_attrs_unchecked.
It's identical to `TyCtxt::get_all_attrs` except it takes `DefId`
instead of `impl Into<DefIf>`.
2025-07-31 15:17:20 +10:00
Nicholas Nethercote
a949c47f0d Remove ParamEnvAnd::into_parts.
The fields are public, so this doesn't need a method, normal
deconstruction and/or field access is good enough.
2025-07-31 15:17:20 +10:00
Nicholas Nethercote
c4e3cc0228 Move TermVid out of rustc_middle.
It's only used in `rustc_infer`.
2025-07-31 15:17:08 +10:00
Nicholas Nethercote
66fd421208 Move rustc_middle::parameterized to rustc_metadata.
It's only used there.
2025-07-31 15:14:34 +10:00
Nicholas Nethercote
0a3eb2f88e Remove unused ParameterizedOverTcx impls. 2025-07-31 15:04:22 +10:00
Michael Goulet
51cd9b564f Consider operator's span when computing binop expr span 2025-07-31 02:28:11 +00:00
Nicholas Nethercote
b44eb11bdf Move ParamTerm out of rustc_middle.
It's only used in `rustc_hir_typeck`.
2025-07-31 11:50:45 +10:00
Nicholas Nethercote
3a1f2d5cc2 Move an EarlyParamRegion impl block.
Next to all the other `EarlyParamRegion` pieces.
2025-07-31 11:50:43 +10:00
Nicholas Nethercote
790ab94798 Move ImplHeader out of rustc_middle.
It's not used in `rustc_middle`, and `rustc_trait_selection` is a better
place for it.
2025-07-31 11:50:36 +10:00
Nicholas Nethercote
e83c8cb26c Move ResolverOutputs out of rustc_middle.
It's not used in `rustc_middle`, and `rustc_resolve` is a better place
for it.
2025-07-31 11:50:23 +10:00
Nicholas Nethercote
2bf10de494 Remove unused impl_decodable_via_ref! entries. 2025-07-31 11:48:53 +10:00
bors
32e7a4b92b Auto merge of #144405 - lcnr:hir-typeck-uniquify, r=BoxyUwU
uniquify root goals during HIR typeck

We need to rely on region identity to deal with hangs such as https://github.com/rust-lang/trait-system-refactor-initiative/issues/210 and to keep the current behavior of `fn try_merge_responses`.

This is a problem as borrowck starts by replacing each *occurrence* of a region with a unique inference variable. This frequently splits a single region during HIR typeck into multiple distinct regions. As we assume goals to always succeed during borrowck, relying on two occurances of a region being identical during HIR typeck causes ICE. See the now fixed examples in https://github.com/rust-lang/trait-system-refactor-initiative/issues/27 and rust-lang/rust#139409.

We've previously tried to avoid this issue by always *uniquifying* regions when canonicalizing goals. This prevents caching subtrees during canonicalization which resulted in hangs for very large types. People rely on such types in practice, which caused us to revert our attempt to reinstate `#[type_length_limit]` in https://github.com/rust-lang/rust/pull/127670. The complete list of changes here:
- rust-lang/rust#107981
- rust-lang/rust#110180
- rust-lang/rust#114117
- rust-lang/rust#130821

After more consideration, all occurrences of such large types need to happen outside of typeck/borrowck. We know this as we already walk over all types in the MIR body when replacing their regions with nll vars.

This PR therefore enables us to rely on region identity inside of the trait solver by exclusively **uniquifying root goals during HIR typeck**. These are the only goals we assume to hold during borrowck. This is insufficient as type inference variables may "hide" regions we later uniquify. Because of this, we now stash proven goals which depend on inference variables in HIR typeck and reprove them after writeback. This closes https://github.com/rust-lang/trait-system-refactor-initiative/issues/127.

This was originally part of rust-lang/rust#144258 but I've moved it into a separate PR. While I believe we need to rely on region identity to fix the performance issues in some way, I don't know whether rust-lang/rust#144258 is the best approach to actually do so. Regardless of how we deal with the hangs however, this change is necessary and desirable regardless.

r? `@compiler-errors` or `@BoxyUwU`
2025-07-31 00:32:55 +00:00
Stypox
e1f674cfa9 Use specific name for "frame" span field
Otherwise the field would be named "message" by default
2025-07-31 00:40:00 +02:00
Stypox
3b5fec08f1 Use new enter_trace_span! syntax for layout_of & friends 2025-07-31 00:40:00 +02:00
Stypox
8e786169e8 Uniform enter_trace_span! and add documentation
The macro was uniformed between rustc_const_eval and miri
2025-07-31 00:40:00 +02:00
bors
606dcc0d2e Auto merge of #116316 - cjgillot:incr-privacy, r=petrochenkov
Remove eval_always from check_private_in_public.

This PR attempts to avoid re-computing `check_private_in_public` query. First by marking the query as non-`eval_always`, and by reducing the amount of accesses to HIR as much as possible.

Latest perf https://github.com/rust-lang/rust/pull/116316#issuecomment-3094672105 shows that we manage it. The cost is extra dep-graph bookkeeping.
2025-07-30 21:29:47 +00:00
Michael Goulet
170ccbf434 expand WF obligations when checking method calls 2025-07-30 20:57:00 +00:00
Michael Goulet
585eac88c8 stall ConstArgHasType in compute_goal_fast_path 2025-07-30 20:30:17 +00:00
Nurzhan Sakén
3ff3a1ee00 Stabilize strict_overflow_ops 2025-07-30 23:39:35 +04:00