Commit Graph

265713 Commits

Author SHA1 Message Date
Michael Goulet
c8233a4c6f ProjectionElem and UnOp/BinOp dont need to be PartialOrd/Ord 2024-09-13 14:17:32 -04:00
Matthias Krüger
5343fcdf17
Rollup merge of #130305 - tspiteri:clippy-msrv-for-const_float_bits_conv, r=flip1995
Clippy: consider msrv for const context for const_float_bits_conv

When `const_float_bits_conv` was stabilized for 1.83.0, clippy lints started to be triggered in const context ignoring MSRV. This PR makes the lints trigger in const context only when the MSRV meets 1.83.0.

Fixes https://github.com/rust-lang/rust-clippy/issues/13383.
2024-09-13 18:25:47 +02:00
Matthias Krüger
7d36bfa6c0
Rollup merge of #130301 - RalfJung:clashing_extern_declarations, r=compiler-errors
some fixes for clashing_extern_declarations lint

There were two issues with the clashing_extern_declarations lint:
- It would accept non-`repr(C)` structs as compatible with each other by comparing their fields in declaration order, but the fields could have different memory order (and with `-Zrandomize-layout`, this can really happen).
- It would accept two types as compatible if `compare_layouts` returns `true`, but that function actually just compared the *ABI*, not the fully layout -- and all sized structs with more than 2 fields have the same ABI (`Abi::Aggregate`), so this missed a *lot* of cases.

We don't currently have a clear spec for what we *want* to consider "clashing" and what is fine, so I otherwise kept the original logic. I hope to have a t-lang discussion about this at some point. But meanwhile, these changes seem like clear bugfixes.
2024-09-13 18:25:46 +02:00
Matthias Krüger
b0e323549a
Rollup merge of #130299 - vetleras:add_set_dcx, r=compiler-errors
Add set_dcx to ParseSess

After [this](https://github.com/rust-lang/rust/pull/126623) PR was merged, it is no longer possible to inject one's own `Emitter` in the way [described in the Compiler Development Guide](https://rustc-dev-guide.rust-lang.org/rustc-driver-getting-diagnostics.html). The reason is that the `dcx` field in `ParseSess` is no longer public, so it is not possible to update the `dcx` field with a `DiagCtxt` that contains one's own `Emitter` in the `psess_created` callback in `rustc_interface::Config`. The only way I have found to insert my own `DiagCtxt` is by creating an entirely new `ParseSess` and replacing the old one. This is not a good solution as the original `ParseSess` contains fields I would like to keep. (In my case the problem is that I lose the `cfg` and `check-cfg` fields of the original.)

The solution proposed in this PR is to add a `set_dcx` method to `ParseSess`. Per my limited understanding of the rustc codebase this should be fine as `set_dcx` requires a mutable reference to `ParseSess`, which is as far as I know only available in the `psess_created` callback (outside of `rustc_interface::run_compiler`).

If this PR is accepted, I will create a new PR to update the aforementioned example in the Compiler Development Guide.
2024-09-13 18:25:46 +02:00
Matthias Krüger
c5e0f9ae42
Rollup merge of #130297 - nnethercote:dataflow-cleanups, r=cjgillot
Dataflow cleanups

r? `@cjgillot`
2024-09-13 18:25:45 +02:00
Matthias Krüger
778f6fba2b
Rollup merge of #130266 - heiher:loong-medium-cmodel, r=compiler-errors
target: default to the medium code model on LoongArch targets

The Rust LoongArch targets have been using the default LLVM code model so far, which is "small" in LLVM-speak and "normal" in LoongArch-speak. As described in the "Code Model" section of LoongArch ELF psABI spec v20231219 [1], one can only make function calls as far as ±128MiB with the "normal" code model; this is insufficient for very large software containing Rust components that needs to be linked into the big text section, such as Chromium.

Because:

* we do not want to ask users to recompile std if they are to build such software,
* objects compiled with larger code models can be linked with those with smaller code models without problems, and
* the "medium" code model is comparable to the "small"/"normal" one performance-wise (same data access pattern; each function call becomes 2-insn long and indirect, but this may be relaxed back into the direct 1-insn form in a future LLVM version), but is able to perform function calls within ±128GiB,

it is better to just switch the targets to the "medium" code model, which is also "medium" in LLVM-speak.

Relands [2]:  #120661

[1]: https://github.com/loongson/la-abi-specs/blob/v2.30/laelf.adoc#code-models
[2]: https://github.com/rust-lang/rust/issues/121289#issuecomment-2333687396
2024-09-13 18:25:45 +02:00
Matthias Krüger
24da940631
Rollup merge of #129320 - jder:issue-128848, r=compiler-errors
Fix crash when labeling arguments for call_once and friends

When calling a method on Fn* traits explicitly, argument diagnostics should point at the called method (eg Fn::call_once), not the underlying callee.

This PR makes 3 main changes:

* It uses TupleArguments to detect if the user called a Fn* method directly (`my_fn.call_once(…)`) or implicitly (`my_fn(…)`). If it was explicit, argument diagnostics should point at the call_once method, not the underlying callable.
* The previous state was causing confusion between the two arguments lists (which could be different lengths), causing an out-of-bounds slice indexing in #128848. I added a length assert to capture the requirement in case this regresses or happens in another case.
* Unfortunately, this assert tripped when the required arguments information was not available (`self.get_hir_params_with_generics` was returning an empty Vec), so I've updated that to return None when that information is not available. (cc `@strottos` if you have any comments, since you added this function in #121595) Sorry this causes a bunch of indentation changes, recommend reviewing [ignoring whitespace](https://github.com/rust-lang/rust/pull/129320/files?w=1).)

This is my first rustc PR, so please call out if you'd like this split into more commits (or PRs), style nits, etc. I will add a few comments/questions inline. Thank you!

Fixes #128848
2024-09-13 18:25:44 +02:00
onur-ozkan
f03bfb871b avoid updating LLVM submodule during bootstrap unit tests
Signed-off-by: onur-ozkan <work@onurozkan.dev>
2024-09-13 18:54:53 +03:00
Guillaume Gomez
e7fa03ba5e Remove gcc changes for dist build 2024-09-13 17:14:40 +02:00
bors
0307e401c2 Auto merge of #130215 - RalfJung:interpret-simd, r=compiler-errors
interpret: simplify SIMD type handling

This is possible as a follow-up to https://github.com/rust-lang/rust/pull/129403
2024-09-13 13:55:22 +00:00
Jesse Rusak
57de75050a When calling a method on Fn* traits explicitly, argument diagnostics should
point at the called method (eg Fn::call_once), not the underlying callee.

Fixes 128848
2024-09-13 09:33:51 -04:00
Ralf Jung
e2bc16c101 interpret: simplify SIMD type handling 2024-09-13 15:26:08 +02:00
Trevor Spiteri
581f1924e3 handle transmutes in const context if msrvs::CONST_FLOAT_BITS_CONV 2024-09-13 13:57:41 +02:00
Trevor Spiteri
d195f80639 Revert "stabilize const_float_bits_conv" for src/tools/clippy/clippy_lints
This reverts the part of commit 19908ff7a3 in
subdirectory src/tools/clippy/clippy_lints.
2024-09-13 13:56:41 +02:00
bors
473ae00839 Auto merge of #130303 - Zalathar:rollup-8vsqdox, r=Zalathar
Rollup of 3 pull requests

Successful merges:

 - #130245 (make basic allocation functions track_caller in Miri for nicer backtraces)
 - #130261 (skip target sanity check when it's a `local-rebuild`)
 - #130287 (rustdoc: rename `issue-\d+.rs` tests to have meaningful names (part 9))

r? `@ghost`
`@rustbot` modify labels: rollup
2024-09-13 11:27:53 +00:00
Ralf Jung
f362a59c3e some fixes for clashing_extern_declarations lint 2024-09-13 11:51:17 +02:00
Stuart Cook
1c23c8ba0c
Rollup merge of #130287 - notriddle:notriddle/issue-d, r=jieyouxu
rustdoc: rename `issue-\d+.rs` tests to have meaningful names (part 9)

Follow up

* https://github.com/rust-lang/rust/pull/116214
* https://github.com/rust-lang/rust/pull/116432
* https://github.com/rust-lang/rust/pull/116824
* https://github.com/rust-lang/rust/pull/118105
* https://github.com/rust-lang/rust/pull/119561
* https://github.com/rust-lang/rust/pull/123574
* https://github.com/rust-lang/rust/pull/125382
* https://github.com/rust-lang/rust/pull/127671

As always, it's easier to review the commits one at a time. Don't use the Files Changed tab. It's confusing.
2024-09-13 19:38:01 +10:00
Stuart Cook
26bda05938
Rollup merge of #130261 - onur-ozkan:#130242, r=Kobzol
skip target sanity check when it's a `local-rebuild`

Running the stage0 target sanity check on the newly built compiler can result in errors and incorrect assumptions.

Resolves #130242
2024-09-13 19:38:00 +10:00
Stuart Cook
368718961c
Rollup merge of #130245 - RalfJung:miri-alloc-backtrace, r=Amanieu
make basic allocation functions track_caller in Miri for nicer backtraces

This matches what we did with basic pointer and atomic operations.
2024-09-13 19:37:59 +10:00
onur-ozkan
af33be54d5 add llvm-bitcode-linker and llvm-tools bins to ci-rustc's sysroot
Signed-off-by: onur-ozkan <work@onurozkan.dev>
2024-09-13 12:23:08 +03:00
Vetle Rasmussen
bde1f4dd57 Add set_dcx to ParseSess 2024-09-13 11:15:19 +02:00
bors
5e842953cc Auto merge of #130052 - khuey:clear-dilocation-after-const-emission, r=michaelwoerister
Don't leave debug locations for constants sitting on the builder indefinitely

Because constants are currently emitted *before* the prologue, leaving the debug location on the IRBuilder spills onto other instructions in the prologue and messes up both line numbers as well as the point LLVM chooses to be the prologue end.

Example LLVM IR (irrelevant IR elided):
Before:
```
define internal { i64, i64 } `@_ZN3tmp3Foo18var_return_opt_try17he02116165b0fc08cE(ptr` align 8 %self) !dbg !347 { start:
  %self.dbg.spill = alloca [8 x i8], align 8
  %_0 = alloca [16 x i8], align 8
  %residual.dbg.spill = alloca [0 x i8], align 1
    #dbg_declare(ptr %residual.dbg.spill, !353, !DIExpression(), !357)
  store ptr %self, ptr %self.dbg.spill, align 8, !dbg !357
    #dbg_declare(ptr %self.dbg.spill, !350, !DIExpression(), !358)
```
After:
```
define internal { i64, i64 } `@_ZN3tmp3Foo18var_return_opt_try17h00b17d08874ddd90E(ptr` align 8 %self) !dbg !347 { start:
  %self.dbg.spill = alloca [8 x i8], align 8
  %_0 = alloca [16 x i8], align 8
  %residual.dbg.spill = alloca [0 x i8], align 1
    #dbg_declare(ptr %residual.dbg.spill, !353, !DIExpression(), !357)
  store ptr %self, ptr %self.dbg.spill, align 8
    #dbg_declare(ptr %self.dbg.spill, !350, !DIExpression(), !358)
```
Note in particular how !357 from %residual.dbg.spill's dbg_declare no longer falls through onto the store to %self.dbg.spill. This fixes argument values at entry when the constant is a ZST (e.g. `<Option as Try>::Residual`). This fixes #130003 (but note that it does *not* fix issues with argument values and non-ZST constants, which emit their own stores that have debug info on them, like #128945).

r? `@michaelwoerister`
2024-09-13 08:57:41 +00:00
Nicholas Nethercote
359b6589ac Remove sess from CheckLoopVisitor. 2024-09-13 17:52:44 +10:00
bors
d0985bb524 Auto merge of #130292 - ehuss:revert-130040, r=onur-ozkan
Revert  #130040 - unify llvm-bitcode-linker, wasm-component-ld and llvm-tools logics

This is a revert of #130040 to fix #130291 which is preventing installing nightly with the llvm-tools component due to a conflict with the `bin/llc` file which exists in both the rustc and llvm-tools components.
2024-09-13 06:33:05 +00:00
Nicholas Nethercote
bb943f93ff Rename FlowState as Domain.
Because that's what it is; no point having a different name for it.
2024-09-13 16:27:24 +10:00
Nicholas Nethercote
8d32578fe1 Rename and reorder lots of lifetimes.
- Replace non-standard names like 's, 'p, 'rg, 'ck, 'parent, 'this, and
  'me with vanilla 'a. These are cases where the original name isn't
  really any more informative than 'a.
- Replace names like 'cx, 'mir, and 'body with vanilla 'a when the lifetime
  applies to multiple fields and so the original lifetime name isn't
  really accurate.
- Put 'tcx last in lifetime lists, and 'a before 'b.
2024-09-13 15:46:20 +10:00
Nicholas Nethercote
606b9cb406 Rename some lifetimes.
Giving them more typical names.
2024-09-13 15:36:55 +10:00
Nicholas Nethercote
072bf482c9 Remove unnecessary lifetime from RunCompiler.
This does change the external interface, but not in a way that will
cause any breakage because external users don't mention the lifetimes.
2024-09-13 15:36:55 +10:00
Nicholas Nethercote
7b613ed8d2 Remove unnecessary lifetimes from rustc_expand. 2024-09-13 15:33:21 +10:00
Nicholas Nethercote
65863c5e75 Remove unnecessary lifetimes from Arena. 2024-09-13 15:33:19 +10:00
Nicholas Nethercote
0b59bba6ec Remove unnecessary lifetime from CheckLoopVisitor. 2024-09-13 15:29:57 +10:00
Nicholas Nethercote
5138399885 Remove unnecessary lifetime from BuiltinTypeAliasBounds. 2024-09-13 15:27:19 +10:00
Nicholas Nethercote
c1121f8590 Remove unnecessary lifetime from FeaturePreviouslyDeclared. 2024-09-13 15:27:19 +10:00
bors
a5efa01895 Auto merge of #107251 - dingxiangfei2009:let-chain-rescope, r=jieyouxu
Rescope temp lifetime in if-let into IfElse with migration lint

Tracking issue #124085

This PR shortens the temporary lifetime to cover only the pattern matching and consequent branch of a `if let`.

At the expression location, means that the lifetime is shortened from previously the deepest enclosing block or statement in Edition 2021. This warrants an Edition change.

Coming with the Edition change, this patch also implements an edition lint to warn about the change and a safe rewrite suggestion to preserve the 2021 semantics in most cases.

Related to #103108.
Related crater runs: https://github.com/rust-lang/rust/pull/129466.
2024-09-13 03:47:30 +00:00
Eric Huss
df8e6c343c Revert "Auto merge of #130040 - onur-ozkan:llvm-tools-with-ci-rustc, r=Kobzol"
This reverts commit adaff5368b, reversing
changes made to 2e8db5e9e3.
2024-09-12 20:18:56 -07:00
bors
d3a8524e80 Auto merge of #129137 - camelid:lazy-def-macro-const, r=BoxyUwU
Fix anon const def-creation when macros are involved

Fixes #128016.

Ever since #125915, some `ast::AnonConst`s turn into `hir::ConstArgKind::Path`s,
which don't have associated `DefId`s. To deal with the fact that we don't have
resolution information in `DefCollector`, we decided to implement a process
where if the anon const *appeared* to be trivial (i.e., `N` or `{ N }`), we
would avoid creating a def for it in `DefCollector`. If later, in AST lowering,
we realized it turned out to be a unit struct literal, or we were lowering it
to something that didn't use `hir::ConstArg`, we'd create its def there.

However, let's say we have a macro `m!()` that expands to a reference to a free
constant `FOO`. If we use `m!()` in the body of an anon const (e.g., `Foo<{ m!() }>`),
then in def collection, it appears to be a nontrivial anon const and we create
a def. But the macro expands to something that looks like a trivial const arg,
but is not, so in AST lowering we "fix" the mistake we assumed def collection
made and create a def for it. This causes a duplicate definition ICE.

The long-term fix for this is to delay the creation of defs for all expression-like
nodes until AST lowering (see #128844 for an incomplete attempt at this). This
would avoid issues like this one that are caused by hacky workarounds. However,
doing this uncovers a pre-existing bug with opaque types that is quite involved
to fix (see #129023).

In the meantime, this PR fixes the bug by delaying def creation for anon consts
whose bodies are macro invocations until after we expand the macro and know
what is inside it. This is accomplished by adding information to create the
anon const's def to the data in `Resolver.invocation_parents`.

r? `@BoxyUwU`
2024-09-13 01:10:51 +00:00
Nicholas Nethercote
55c9f96265 Remove unnecessary Clone/Copy derives from analyses.
No analysis needs `Copy`, and `MaybeBorrowedLocals` is the only analysis
that needs `Clone`. In `locals_live_across_suspend_points` it gets
cloned so it can be used within a `MaybeRequiresStorage`.
2024-09-13 09:58:30 +10:00
Félix Saparelli
0b2235d732
Stabilize entry_insert 2024-09-13 11:45:44 +12:00
Nicholas Nethercote
d0be42d9f0 Remove unnecessary lifetime from UnsafeInferVarsVisitor. 2024-09-13 09:36:00 +10:00
bors
adaff5368b Auto merge of #130040 - onur-ozkan:llvm-tools-with-ci-rustc, r=Kobzol
unify `llvm-bitcode-linker`, `wasm-component-ld` and llvm-tools logics

To use the precompiled `ci-rustc` in CI, we need to install `llvm-bitcode-linker` and LLVM tools into ci-rustc's sysroot. Without them some CI pipelines may fail, as shown [here](https://github.com/rust-lang/rust/pull/122709#issuecomment-2334365988).

Blocker for https://github.com/rust-lang/rust/pull/122709
2024-09-12 20:51:46 +00:00
Michael Howell
48c7e444b1 rustdoc: re-bless stderrs after renaming the test case 2024-09-12 13:48:51 -07:00
Michael Howell
061cbae7c9 rustdoc: rename issue-\d+.rs tests to have meaningful names 2024-09-12 13:47:51 -07:00
Michael Howell
9454a89ef0 Add URL and crate_name to test cases 2024-09-12 13:38:24 -07:00
Ding Xiang Fei
b4b2b356d9
simplify the suggestion notes 2024-09-13 02:43:49 +08:00
bors
2e8db5e9e3 Auto merge of #130281 - matthiaskrgr:rollup-1b2ibs8, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #130101 (some const cleanup: remove unnecessary attributes, add const-hack indications)
 - #130208 (Introduce `'ra` lifetime name.)
 - #130263 (coverage: Simplify creation of sum counters)
 - #130273 (more eagerly discard constraints on overflow)
 - #130276 (Add test for nalgebra hang in coherence)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-09-12 18:27:55 +00:00
Noah Lev
e0bd01167e Re-enable ConstArgKind::Path lowering by default
...and remove the `const_arg_path` feature gate as a result. It was only
a stopgap measure to fix the regression that the new lowering introduced
(which should now be fixed by this PR).
2024-09-12 13:56:01 -04:00
Noah Lev
8b75004bca Fix anon const def-creation when macros are involved
Ever since #125915, some `ast::AnonConst`s turn into `hir::ConstArgKind::Path`s,
which don't have associated `DefId`s. To deal with the fact that we don't have
resolution information in `DefCollector`, we decided to implement a process
where if the anon const *appeared* to be trivial (i.e., `N` or `{ N }`), we
would avoid creating a def for it in `DefCollector`. If later, in AST lowering,
we realized it turned out to be a unit struct literal, or we were lowering it
to something that didn't use `hir::ConstArg`, we'd create its def there.

However, let's say we have a macro `m!()` that expands to a reference to a free
constant `FOO`. If we use `m!()` in the body of an anon const (e.g., `Foo<{ m!() }>`),
then in def collection, it appears to be a nontrivial anon const and we create
a def. But the macro expands to something that looks like a trivial const arg,
but is not, so in AST lowering we "fix" the mistake we assumed def collection
made and create a def for it. This causes a duplicate definition ICE.

The ideal long-term fix for this is a bit unclear. One option is to delay def
creation for all expression-like nodes until AST lowering (see #128844 for an
incomplete attempt at this). This would avoid issues like this one that are
caused by hacky workarounds. However, this approach has some downsides as well,
and the best approach is yet to be determined.

In the meantime, this PR fixes the bug by delaying def creation for anon consts
whose bodies are macro invocations until after we expand the macro and know
what is inside it. This is accomplished by adding information to create the
anon const's def to the data in `Resolver.invocation_parents`.
2024-09-12 13:48:30 -04:00
Matthias Krüger
ed1602e480
Rollup merge of #130276 - compiler-errors:nalgebra-hang, r=lcnr
Add test for nalgebra hang in coherence

r? lcnr
2024-09-12 19:03:43 +02:00
Matthias Krüger
cb1d80d1e5
Rollup merge of #130273 - lcnr:overflow-no-constraints, r=compiler-errors
more eagerly discard constraints on overflow

We always discard the results of overflowing goals inside of the trait solver. We previously did so when instantiating the response in `evaluate_goal`. Canonicalizing results only to later discard them is also  inefficient 🤷

It's simpler and nicer to debug to eagerly discard constraints inside of the query itself.

r? ``@compiler-errors``
2024-09-12 19:03:43 +02:00
Matthias Krüger
7cae463bda
Rollup merge of #130263 - Zalathar:sums, r=compiler-errors
coverage: Simplify creation of sum counters

A small and self-contained improvement, extracted from some larger changes that I'm still working on.

Ultimately I want to avoid creating these sum counter-expressions in some cases (in favour of just adding physical counters directly to the nodes we care about), so a good incremental move towards that is splitting the “gather edge counters” step out from the ”build a sum of those counters” step.

Creating an extra intermediate vector should have negligible cost (and coverage isn't exercised by the benchmark suite anyway). The removed logging is redundant with the `#[instrument(..)]` logging we already have on the underlying method calls.
2024-09-12 19:03:42 +02:00