Commit Graph

34014 Commits

Author SHA1 Message Date
Matthias Krüger
1f4aff7d2b
Rollup merge of #122487 - GuillaumeGomez:rename-stmtkind-local, r=oli-obk
Rename `StmtKind::Local` variant into `StmtKind::Let`

It comes from this [discussion](https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Improve.20naming.20of.20.60ExprKind.3A.3ALet.60.3F).

Starting point was:

> I often end up looking at [ExprKind::Let](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/enum.ExprKind.html#variant.Let) instead of Local because of the name. I think renaming it (both the `ExprKind` variant and the Let struct) to `LetPattern` or LetPat could improve the situation as I'm not sure I'm not the only one encountering this issue.

And then it evolved into:

> It's already `Expr::Let` instead of `StmtKind::Local`. Counterproposal: rename `StmtKind::Local` to `StmtKind::Let`.

The goal here is to clear this confusion.

r? `@oli-obk`
2024-03-14 20:00:21 +01:00
Matthias Krüger
b200108bc5
Rollup merge of #122373 - surechen:fix_121331, r=petrochenkov
Fix the conflict problem between the diagnostics fixes of lint `unnecessary_qualification`  and  `unused_imports`

fixes #121331

For an `item` that triggers lint unnecessary_qualification, if the `use item` which imports this item is also trigger unused import, fixing the two lints at the same time may lead to the problem that the `item` cannot be found.
This PR will avoid reporting lint unnecessary_qualification when conflict occurs.

r? ``@petrochenkov``
2024-03-14 20:00:20 +01:00
Matthias Krüger
54a5a49af0
Rollup merge of #122322 - Zalathar:branch, r=oli-obk
coverage: Initial support for branch coverage instrumentation

(This is a review-ready version of the changes that were drafted in #118305.)

This PR adds support for branch coverage instrumentation, gated behind the unstable flag value `-Zcoverage-options=branch`. (Coverage instrumentation must also be enabled with `-Cinstrument-coverage`.)

During THIR-to-MIR lowering (MIR building), if branch coverage is enabled, we collect additional information about branch conditions and their corresponding then/else blocks. We inject special marker statements into those blocks, so that the `InstrumentCoverage` MIR pass can reliably identify them even after the initially-built MIR has been simplified and renumbered.

The rest of the changes are mostly just plumbing needed to gather up the information that was collected during MIR building, and include it in the coverage metadata that we embed in the final binary.

Note that `llvm-cov show` doesn't print branch coverage information in its source views by default; that needs to be explicitly enabled with `--show-branches=count` or similar.

---

The current implementation doesn't have any support for instrumenting `if let` or let-chains. I think it's still useful without that, and adding it would be non-trivial, so I'm happy to leave that for future work.
2024-03-14 20:00:19 +01:00
Matthias Krüger
722514f466
Rollup merge of #122212 - erikdesjardins:byval-align2, r=wesleywiser
Copy byval argument to alloca if alignment is insufficient

Fixes #122211

"Ignore whitespace" recommended.
2024-03-14 20:00:18 +01:00
Matthias Krüger
4dff106433
Rollup merge of #121764 - Zoxc:incr-sess-no-source, r=oli-obk
Make incremental sessions identity no longer depend on the crate names provided by source code

This makes incremental sessions identity no longer depend on the crate names provided by source code, implementing
https://github.com/rust-lang/compiler-team/issues/726.

r? ````@oli-obk````
2024-03-14 20:00:18 +01:00
Matthias Krüger
68ca795286
Rollup merge of #117118 - bzEq:aix-linker, r=wesleywiser
[AIX] Remove AixLinker's debuginfo() implementation

AIX ld's `-s` option doesn't perfectly fit` debuginfo()`'s semantics and may unexpectedly remove metadata in shared libraries. Remove the implementation of `AixLinker` and suggest user to use `strip` utility instead.
2024-03-14 20:00:17 +01:00
bors
30f74ff0dc Auto merge of #122497 - matthiaskrgr:rollup-pg9ux4r, r=matthiaskrgr
Rollup of 10 pull requests

Successful merges:

 - #119029 (Avoid closing invalid handles)
 - #122238 (Document some builtin impls in the next solver)
 - #122247 (rustdoc-search: depth limit `T<U>` -> `U` unboxing)
 - #122287 (add test ensuring simd codegen checks don't run when a static assertion failed)
 - #122368 (chore: remove repetitive words)
 - #122397 (Various cleanups around the const eval query providers)
 - #122406 (Fix WF for `AsyncFnKindHelper` in new trait solver)
 - #122477 (Change some attribute to only_local)
 - #122482 (Ungate the `UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES` lint)
 - #122490 (Update build instructions for OpenHarmony)

Failed merges:

 - #122471 (preserve span when evaluating mir::ConstOperand)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-03-14 16:36:02 +00:00
Matthias Krüger
c0fd2db49a
Rollup merge of #122482 - weiznich:fix/122446, r=compiler-errors
Ungate the `UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES` lint

This was missed during stablisation of the `#[diagnostic]` attribute namespace.

Fixes #122446
2024-03-14 15:44:36 +01:00
Matthias Krüger
8303c6ae48
Rollup merge of #122477 - surechen:change_attribute_only_local_20240314, r=lcnr
Change some attribute to only_local

Modified according to https://github.com/rust-lang/compiler-team/issues/505.

r? `@lcnr`
2024-03-14 15:44:36 +01:00
Matthias Krüger
54b73006c6
Rollup merge of #122406 - compiler-errors:next-solver-asynckind-wf, r=lcnr
Fix WF for `AsyncFnKindHelper` in new trait solver

`to_opt_closure_kind` ICEs when it sees placeholders... so don't do that

no test b/c I'm too lazy to write a no-core test for this, but I could be convinced otherwise

r? lcnr
2024-03-14 15:44:35 +01:00
Matthias Krüger
b4dffc9926
Rollup merge of #122397 - oli-obk:machine-read-hook2, r=RalfJung
Various cleanups around the const eval query providers

r? `@RalfJung`

after this, working on running validation before interning starts with swapping the order of two lines of code
2024-03-14 15:44:34 +01:00
Matthias Krüger
1dce191441
Rollup merge of #122368 - pavedroad:master, r=oli-obk
chore: remove repetitive words
2024-03-14 15:44:34 +01:00
Matthias Krüger
6a4dd19ade
Rollup merge of #122287 - RalfJung:simd-static-assert, r=pnkfelix
add test ensuring simd codegen checks don't run when a static assertion failed

stdarch relies on this to ensure that SIMD indices are in bounds.

I would love to know why this works, but I can't figure out where codegen decides to not codegen a function if a required-const does not evaluate. `@oli-obk` `@bjorn3` do you have any idea?
2024-03-14 15:44:33 +01:00
Matthias Krüger
7997ef4eba
Rollup merge of #122238 - fee1-dead-contrib:builtin-impl-next-solver-dox, r=lcnr
Document some builtin impls in the next solver

This does not cover all builtin impls, but ones that I were able to go over within a cycle.

r? `@lcnr`

Let me know if the place isn't correct for these, or if you'd like me to change how the impls are presented ^^
2024-03-14 15:44:32 +01:00
bors
fe61575228 Auto merge of #120943 - petrochenkov:somehir3, r=oli-obk
Create some minimal HIR for associated opaque types

`LocalDefId`s for opaque types in traits and impls are created after AST -> HIR lowering, so they don't have corresponding HIR and return their various properties through fed queries.

In this PR I also feed some core HIR-related queries for these `LocalDefId`s (which happen to be HIR owners).
As a result all `LocalDefId`s now have corresponding `HirId`s and HIR nodes, and "optional" methods like `opt_local_def_id_to_hir_id` and `opt_hir_node_by_def_id` can be removed.

Follow up to https://github.com/rust-lang/rust/pull/120206.
2024-03-14 14:28:58 +00:00
Oli Scherer
a316c21dc8 Rename some things around validation error reporting to signal that it is in fact about validation failures 2024-03-14 12:21:35 +00:00
Oli Scherer
16046c77aa Move the entire success path into eval_body_using_ecx 2024-03-14 12:21:29 +00:00
Oli Scherer
2e6c4900b6 Move validation into eval_body_using_ecx 2024-03-14 12:21:23 +00:00
Oli Scherer
cc7e0b2200 Share the InterpCx creation between static and const evaluation 2024-03-14 12:21:18 +00:00
Oli Scherer
02a0ac8058 Remove an argument that can be computed cheaply 2024-03-14 12:21:12 +00:00
Oli Scherer
d3b7b558aa Directly pass in the stack instead of computing it from a machine 2024-03-14 12:21:06 +00:00
Oli Scherer
d2d2bd2736 Move generate_stacktrace_from_stack away from InterpCx to avoid having to know the Machine type 2024-03-14 12:20:58 +00:00
Deadbeef
69d781abef move impl documentation to their actual locations 2024-03-14 20:18:04 +08:00
Guillaume Gomez
a4e0e50a3f Rename hir::StmtKind::Local into hir::StmtKind::Let 2024-03-14 12:42:04 +01:00
Guillaume Gomez
ca9f0630a9 Rename ast::StmtKind::Local into ast::StmtKind::Let 2024-03-14 12:42:04 +01:00
Oli Scherer
6b936b6c08 Move InterpCx into eval_in_interpreter 2024-03-14 11:40:42 +00:00
Oli Scherer
8b8efd157b Move error handling into const_validate_mplace 2024-03-14 11:40:36 +00:00
Oli Scherer
93888cd0a4 Move only usage of take_static_root_alloc to its definition and inline it 2024-03-14 11:40:30 +00:00
Oli Scherer
d6c999754c Generalize eval_in_interpreter with a helper trait 2024-03-14 11:40:23 +00:00
Oli Scherer
71f1943cbf Fix accidental re-addition of removed code in a previous PR 2024-03-14 11:39:27 +00:00
Matthias Krüger
0286591d59
Rollup merge of #122416 - Zalathar:levels, r=petrochenkov
Various style improvements to `rustc_lint::levels`

While reading this file, I noticed a few opportunities to make things a little nicer:

- Replace some nested if-let with let-chains
- Tweak a match pattern to allow shorthand struct syntax
- Fuse an `is_empty` check with getting the last element
- Merge some common code that emits `MalformedAttribute` and continues
- Format `"{tool}::{name}"` in a way that's consistent with other match arms
- Replace if-let-else-panic with let-else
- Use early-exit to flatten a method body

Some of these changes cause indentation churn, so ignoring whitespace is recommended.
2024-03-14 11:09:59 +01:00
Matthias Krüger
bd53d1eee3
Rollup merge of #122405 - celinval:smir-new-const, r=oli-obk
Add methods to create StableMIR constant

I've been experimenting with transforming the StableMIR to instrument the code with potential UB checks.

The modified body will only be used by our analysis tool, however, constants in StableMIR must be backed by rustc constants. Thus, I'm adding a few functions to build constants, such as building string and other primitives.

One question I have is whether we should create a global allocation instead for strings.

r? ``````@oli-obk``````
2024-03-14 11:09:58 +01:00
Matthias Krüger
7a744af83e
Rollup merge of #121899 - shepmaster:dead-code-docs, r=wesleywiser
Document how removing a type's field can be bad and what to do instead

Related to #119645
2024-03-14 11:09:57 +01:00
Matthias Krüger
fce6e752ab
Rollup merge of #120699 - nnethercote:rm-useless-TRACK_DIAGNOSTIC-calls, r=oli-obk
Document `TRACK_DIAGNOSTIC` calls.

r? ```````@cjgillot```````
2024-03-14 11:09:57 +01:00
Georg Semmler
25411113c1
Ungate the UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES lint
This was missed during stablisation of the `#[diagnostic]` attribute
namespace.

Fixes #122446
2024-03-14 10:49:28 +01:00
surechen
5dd44f43c7 change some attribute to only_local 2024-03-14 17:12:39 +08:00
bors
cb580ff677 Auto merge of #122243 - RalfJung:local-place-sanity-check, r=oli-obk
interpret: ensure that Place is never used for a different frame

We store the address where the stack frame stores its `locals`. The idea is that even if we pop and push, or switch to a different thread with a larger number of frames, then the `locals` address will most likely change so we'll notice that problem. This is made possible by some recent changes by `@WaffleLapkin,` where we no longer use `Place` across things that change the number of stack frames.

I made these debug assertions for now, just to make sure this can't cost us any perf.

The first commit is unrelated but it's a one-line comment change so it didn't warrant a separate PR...

r? `@oli-obk`
2024-03-14 07:28:07 +00:00
Zalathar
060c7ce7e9 coverage: -Zcoverage-options=branch is no longer a placeholder 2024-03-14 17:19:06 +11:00
Zalathar
31d0b50178 coverage: Include recorded branch info in coverage instrumentation 2024-03-14 17:19:02 +11:00
Zalathar
c1bec0ce6b coverage: Record branch information during MIR building 2024-03-14 16:31:44 +11:00
Zalathar
f9cdaeb6fd coverage: Data structures for recording branch info during MIR building 2024-03-14 16:27:42 +11:00
bors
6f3eb1ce3d Auto merge of #122454 - matthiaskrgr:rollup-xbmufdc, r=matthiaskrgr
Rollup of 11 pull requests

Successful merges:

 - #122422 (compiletest: Allow `only-unix` in test headers)
 - #122424 (fix: typos)
 - #122425 (Increase timeout for new bors bot)
 - #122426 (Fix StableMIR `WrappingRange::is_full` computation)
 - #122429 (Add Exploit Mitigations PG to triagebot.toml)
 - #122430 (Generate link to `Local` in `hir::Let` documentation)
 - #122434 (pattern analysis: rename a few types)
 - #122437 (pattern analysis: remove `MaybeInfiniteInt::JustAfterMax`)
 - #122438 (Safe Transmute: Require that source referent is smaller than destination)
 - #122442 (extend docs of -Zprint-mono-items)
 - #122449 (Delay a bug for stranded opaques)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-03-14 04:54:37 +00:00
bors
5ac0b2d021 Auto merge of #122347 - oli-obk:track_errors13, r=compiler-errors
Revert "Auto merge of #122140 - oli-obk:track_errors13, r=davidtwco"

This reverts commit 65cd843ae0, reversing changes made to d255c6a57c.

reverts https://github.com/rust-lang/rust/pull/122140

It was a large regression in wall time due to trashing CPU caches
2024-03-14 02:54:10 +00:00
surechen
1a81a941ad fixes #121331 2024-03-14 09:54:42 +08:00
bors
c7fed9f854 Auto merge of #122204 - pnkfelix:downgrade-const-eval-dnagling-ptr-in-final-to-future-incompat-lint, r=wesleywiser
Downgrade const eval dangling ptr in final to future incompat lint

Short term band-aid for issue #121610, downgrading the prior hard error to a future-incompat lint (tracked in issue #122153).

Note we should not mark #121610 as resolved until after this (or something analogous) is beta backported.
2024-03-14 00:06:26 +00:00
Matthias Krüger
c52ce4eabb
Rollup merge of #122449 - compiler-errors:stranded-opaque, r=oli-obk
Delay a bug for stranded opaques

r? oli-obk

Fixes #122445
2024-03-13 20:01:58 +01:00
Matthias Krüger
8d2f79c3f1
Rollup merge of #122442 - RalfJung:print-mono-items, r=compiler-errors
extend docs of -Zprint-mono-items

Currently the values one can set this to are not documented anywhere.

I think ideally this flag wouldn't overwrite the collector's behavior, a "print" flag should just print what happens but not change what happens. But our codegen-units tests rely on being able to collect all items without the other side-effects of `-C link-dead-code` and I can't tell whether that reliance is incidental or crucial, so I'm not touching this and just documenting the (messy) status quo.
2024-03-13 20:01:58 +01:00
Matthias Krüger
89c3fa92d4
Rollup merge of #122438 - jswrenn:check-referent-size, r=compiler-errors
Safe Transmute: Require that source referent is smaller than destination

`BikeshedIntrinsicFrom` currently models transmute-via-union; i.e., it attempts to provide a `where` bound for this function:
```rust
pub unsafe fn transmute_via_union<Src, Dst>(src: Src) -> Dst {
    use core::mem::*;

    #[repr(C)]
    union Transmute<T, U> {
        src: ManuallyDrop<T>,
        dst: ManuallyDrop<U>,
    }

    let transmute = Transmute { src: ManuallyDrop::new(src) };

    // SAFETY: The caller must guarantee that the transmutation is safe.
    let dst = transmute.dst;

    ManuallyDrop::into_inner(dst)
}
```
A quirk of this model is that it admits padding extensions in value-to-value transmutation: The destination type can be bigger than the source type, so long as the excess consists of uninitialized bytes. However, this isn't permissible for reference-to-reference transmutations (introduced in #110662) — extra referent bytes cannot come from thin air.

This PR patches our analysis for reference-to-reference transmutations to require that the destination referent is no larger than the source referent.

r? `@compiler-errors`
2024-03-13 20:01:58 +01:00
Matthias Krüger
5c2aa6dc6f
Rollup merge of #122437 - Nadrieril:no-after-max, r=compiler-errors
pattern analysis: remove `MaybeInfiniteInt::JustAfterMax`

It was inherited from before half-open ranges, but it doesn't pull its weight anymore. We lose a tiny bit of diagnostic precision as can be seen in the test. I'm generally in favor of half-open ranges over explicit `x..=MAX` ranges anyway.
2024-03-13 20:01:57 +01:00
Matthias Krüger
b3376bb92f
Rollup merge of #122434 - Nadrieril:renames, r=compiler-errors
pattern analysis: rename a few types

A few long overdue renames. `ValidityConstraint` was supposed to serve double purpose but I don't need that anymore. I don't know what I was thinking with `TypeCx` I think I was trying to be clever. That's fixed now 😄

r? ``@compiler-errors``
2024-03-13 20:01:57 +01:00