Commit Graph

33929 Commits

Author SHA1 Message Date
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
Matthias Krüger
b84d1b8ec9
Rollup merge of #122430 - GuillaumeGomez:link-to-local, r=TaKO8Ki
Generate link to `Local` in `hir::Let` documentation

This PR adds a missing link generation to `Local` type.
2024-03-13 20:01:56 +01:00
Matthias Krüger
96a41ce513
Rollup merge of #122426 - celinval:smir-fix-full, r=oli-obk
Fix StableMIR `WrappingRange::is_full` computation

`WrappingRange::is_full` computation assumed that to be full the range couldn't wrap, which is not necessarily true.

For example, a range of 1..=0 is a valid representation of a full wrapping range.
2024-03-13 20:01:55 +01:00
Matthias Krüger
ff5e1eb8ac
Rollup merge of #122424 - testwill:typos, r=michaelwoerister
fix: typos
2024-03-13 20:01:54 +01:00
bors
3cbb93223f Auto merge of #121668 - erikdesjardins:commonprim, r=scottmcm,oli-obk
Represent `Result<usize, Box<T>>` as ScalarPair(i64, ptr)

This allows types like `Result<usize, std::io::Error>` (and integers of differing sign, e.g. `Result<u64, i64>`) to be passed in a pair of registers instead of through memory, like `Result<u64, u64>` or `Result<Box<T>, Box<U>>` are today.

Fixes #97540.

r? `@ghost`
2024-03-13 15:25:35 +00:00
bors
184c5ab180 Auto merge of #121589 - bvanjoi:fix-98291, r=petrochenkov
delay expand macro bang when there has indeterminate path

Related #98291

I will attempt to clarify the root problem through several examples:

Firstly,

```rs
// rustc code.rs --edition=2018

macro_rules! wrap {
    () => {
        macro_rules! _a {
            () => {
                "Hello world"
            };
        }
    };
}

wrap!();

use _a as a;

fn main() {
    format_args!(_a!());
}
```

The above case will compile successfully because `_a` is defined after the `wrap` expaned, ensuring `_a` can be resolved without any issues.

And,

```rs
// rustc code.rs --edition=2018

macro_rules! wrap {
    () => {
        macro_rules! _a {
            () => {
                "Hello world"
            };
        }
    };
}

wrap!();

use _a as a;

fn main() {
    format_args!("{}", a!());
}
```

The above example will also compile successfully because the `parse_args` in `expand_format_args_impl` will return a value `MacroInput { fmtstr: Expr::Lit::Str, args: [Expr::MacroCall]}`. Since the graph for `args` will be build lately, `a` will eventually be resolved.

However, in the case of:

```rs
// rustc code.rs --edition=2018

macro_rules! wrap {
    () => {
        macro_rules! _a {
            () => {
                "Hello world"
            };
        }
    };
}

wrap!();

use _a as a;

fn main() {
    format_args!(a!());
}
```

The result of `parse_args` is `MacroInput {fmtstr: Expr::Lit::Macro, args: [] }`, we attempt to expand `fmtstr` **eagerly** within `expr_to_spanned_string`. Although we have recorded `(root, _a)` into resolutions, `use _a as a` is an indeterminate import, which will not try to resolve under the conditions of `expander.monotonic = false`.

Therefore, I've altered the strategy for resolving indeterminate imports, ensuring it will also resolve during eager expansion. This could be a significant change to the resolution infra. However, I think it's acceptable if the goal of avoiding resolution under eager expansion is to save time.

r? `@petrochenkov`
2024-03-13 13:20:42 +00:00
Nadrieril
c4236785c7 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.
2024-03-13 14:17:11 +01:00
Nadrieril
f27540697e Rename RustcMatchCheckCtxt -> RustcPatCtxt 2024-03-13 14:07:44 +01:00
Nadrieril
4fc35c46ff Rename TypeCx -> PatCx 2024-03-13 13:56:38 +01:00
Nadrieril
cb15bf6256 Rename ValidityConstraint -> PlaceValidity
The old name came from a time where I wanted to reuse it for
differentiating wildcards from bindings. I don't plan to do this
anymore.
2024-03-13 13:53:18 +01:00
Guillaume Gomez
d919b04e59 Generate link to Local in hir::Let documentation 2024-03-13 11:24:51 +01:00
bors
9ce37dc729 Auto merge of #122240 - RalfJung:miri-addr-reuse, r=oli-obk
miri: add some chance to reuse addresses of previously freed allocations

The hope is that this can help us find ABA issues.

Unfortunately this needs rustc changes so I can't easily run the regular benchmark suite. I used `src/tools/miri/tests/pass/float_nan.rs` as a substitute:
```
Before:
Benchmark 1: ./x.py run miri --stage 0 --args src/tools/miri/tests/pass/float_nan.rs --args --edition=2021
  Time (mean ± σ):      9.570 s ±  0.013 s    [User: 9.279 s, System: 0.290 s]
  Range (min … max):    9.561 s …  9.579 s    2 runs

After:
Benchmark 1: ./x.py run miri --stage 0 --args src/tools/miri/tests/pass/float_nan.rs --args --edition=2021
  Time (mean ± σ):      9.698 s ±  0.046 s    [User: 9.413 s, System: 0.279 s]
  Range (min … max):    9.666 s …  9.731 s    2 runs
```
That's a ~1.3% slowdown, which seems fine to me. I have seen a lot of noise in this style of benchmarking so I don't quite trust this anyway; we can make further experiments in the Miri repo after this migrated there.

r? `@oli-obk`
2024-03-13 09:22:55 +00:00
bohan
8fcdf54a6b delay expand macro bang when there has indeterminate path 2024-03-13 16:11:16 +08:00
Celina G. Val
e0488c0961 Fix StableMIR is_full computation
`WrappingRange::is_full` computation assumed that to be full the range
couldn't wrap, which is not necessarily true.

For example, a range of 1..=0 is a valid representation of a full
wrapping range.
2024-03-13 00:36:54 -07:00
bors
762d3170f6 Auto merge of #122423 - matthiaskrgr:rollup-qywgl45, r=matthiaskrgr
Rollup of 10 pull requests

Successful merges:

 - #121820 (pattern analysis: Store field indices in `DeconstructedPat` to avoid virtual wildcards)
 - #121908 (match lowering: don't collect test alternatives ahead of time)
 - #122203 (Add `intrinsic_name` to get plain intrinsic name)
 - #122226 (coverage: Remove or migrate all unstable values of `-Cinstrument-coverage`)
 - #122255 (Use `min_exhaustive_patterns` in core & std)
 - #122360 ( Don't Create `ParamCandidate` When Obligation Contains Errors )
 - #122383 (Enable PR tracking review assignment for rust-lang/rust)
 - #122386 (Move `Once` implementations to `sys`)
 - #122400 (Fix ICE in diagnostics for parenthesized type arguments)
 - #122410 (rustdoc: do not preload fonts when browsing locally)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-03-13 07:17:22 +00:00
guoguangwu
ee8efd705b fix: typos
Signed-off-by: guoguangwu <guoguangwug@gmail.com>
2024-03-13 13:57:23 +08:00
Matthias Krüger
1ffa5ded58
Rollup merge of #122400 - wutchzone:122345, r=fmease
Fix ICE in diagnostics for parenthesized type arguments

The second time is the charm 🤞 😁

Fixes #122345

r? fmease
2024-03-13 06:41:24 +01:00
Matthias Krüger
5d131407da
Rollup merge of #122360 - veera-sivarajan:bugfix-121941, r=compiler-errors
Don't Create `ParamCandidate` When Obligation Contains Errors

Fixes #121941

I'm not sure if I understand this correctly but this bug was caused by an error type incorrectly matching against `ParamCandidate`. This was introduced by the changes made in #72621 (figured using cargo-bisect-rustc).

This PR fixes it by skipping `ParamCandidate` generation when an error type is involved. Also, this is similar to #73005 but addresses `ParamCandidate` instead of `ImplCandidate`.
2024-03-13 06:41:23 +01:00
Matthias Krüger
8b9ef3b996
Rollup merge of #122226 - Zalathar:zcoverage-options, r=nnethercote
coverage: Remove or migrate all unstable values of `-Cinstrument-coverage`

(This PR was substantially overhauled from its original version, which migrated all of the existing unstable values intact.)

This PR takes the three nightly-only values that are currently accepted by `-Cinstrument-coverage`, completely removes two of them (`except-unused-functions` and `except-unused-generics`), and migrates the third (`branch`) over to a newly-introduced unstable flag `-Zcoverage-options`.

I have a few motivations for wanting to do this:

- It's unclear whether anyone actually uses the `except-unused-*` values, so this serves as an opportunity to either remove them, or prompt existing users to object to their removal.
- After #117199, the stable values of `-Cinstrument-coverage` treat it as a boolean-valued flag, so having nightly-only extra values feels out-of-place.
  - Nightly-only values also require extra ad-hoc code to make sure they aren't accidentally exposed to stable users.
- The new system allows multiple different settings to be toggled independently, which isn't possible in the current single-value system.
- The new system makes it easier to introduce new behaviour behind an unstable toggle, and then gather nightly-user feedback before possibly making it the default behaviour for all users.
- The new system also gives us a convenient place to put relatively-narrow options that won't ever be the default, but that nightly users might still want access to.
- It's likely that we will eventually want to give stable users more fine-grained control over coverage instrumentation. The new flag serves as a prototype of what that stable UI might eventually look like.

The `branch` option is a placeholder that currently does nothing. It will be used by #122322 to opt into branch coverage instrumentation.

---

I see `-Zcoverage-options` as something that will exist more-or-less indefinitely, though individual sub-options might come and go as appropriate. I think there will always be some demand for nightly-only toggles, so I don't see `-Zcoverage-options` itself ever being stable, though we might eventually stabilize something similar to it.
2024-03-13 06:41:22 +01:00
Matthias Krüger
8d78f8ee0a
Rollup merge of #122203 - adpaco-aws:smir-intrinsic-name, r=celinval
Add `intrinsic_name` to get plain intrinsic name

Add an `intrinsic_name` API to retrieve the plain intrinsic name. The plain name does not include type arguments (as `trimmed_name` does), which is more convenient to match with intrinsic symbols.
2024-03-13 06:41:21 +01:00
Matthias Krüger
e6ba504029
Rollup merge of #121908 - Nadrieril:dynamic-variant-collection, r=matthewjasper
match lowering: don't collect test alternatives ahead of time

I'm very happy with this one. Before this, when sorting candidates into the possible test branches, we manually computed `usize` indices to determine in which branch each candidate goes. To make this work we had a first pass that collected the possible alternatives we'd have to deal with, and a second pass that actually sorts the candidates.

In this PR, I replace `usize` indices with a dedicated enum. This makes `sort_candidates` easier to follow, and we don't need the first pass anymore.

r? ``@matthewjasper``
2024-03-13 06:41:21 +01:00
Matthias Krüger
1b198ba9fe
Rollup merge of #121820 - Nadrieril:idxpat2, r=compiler-errors
pattern analysis: Store field indices in `DeconstructedPat` to avoid virtual wildcards

For a pattern like `Struct { field3: true, .. }`, in pattern analysis we represent it as `Struct { field1: _, field2: _, field3: true, field4: _ }`. This PR makes it so we store `Struct { field3: true, .. }` instead. This means we never have to create fake `_` patterns during lowering.

r? ``@compiler-errors``
2024-03-13 06:41:20 +01:00
bors
5a6c1aa2bc Auto merge of #121421 - saethlin:smarter-mono, r=oli-obk
Avoid lowering code under dead SwitchInt targets

The objective of this PR is to detect and eliminate code which is guarded by an `if false`, even if that `false` is a constant which is not known until monomorphization, or is `intrinsics::debug_assertions()`.

The effect of this is that we generate no LLVM IR the standard library's unsafe preconditions, when they are compiled in a build where they should be immediately optimized out. This mono-time optimization ensures that builds which disable debug assertions do not grow a linkage requirement against `core`, which compiler-builtins currently needs: https://github.com/rust-lang/rust/issues/121552

This revives the codegen side of https://github.com/rust-lang/rust/pull/91222 as planned in https://github.com/rust-lang/rust/issues/120848.
2024-03-13 05:07:26 +00:00
bors
d3555f3d8e Auto merge of #122227 - Zoxc:query-hash-verify, r=michaelwoerister
Verify that query keys result in unique dep nodes

This implements checking that query keys result into unique dep nodes as mentioned in https://github.com/rust-lang/rust/pull/112469.

We could do a perf check to see how expensive this is.

r? `@michaelwoerister`
2024-03-13 02:01:56 +00:00
Zalathar
3407fcc12e coverage: Add -Zcoverage-options for fine control of coverage
This new nightly-only flag can be used to toggle fine-grained flags that
control the details of coverage instrumentation.

Currently the only supported flag value is `branch` (or `no-branch`), which is
a placeholder for upcoming support for branch coverage. Other flag values can
be added in the future, to prototype proposed new behaviour, or to enable
special non-default behaviour.
2024-03-13 11:14:10 +11:00
Zalathar
1f544ce305 coverage: Remove all unstable values of -Cinstrument-coverage 2024-03-13 11:14:09 +11:00
bors
e61dcc7a0a Auto merge of #122220 - saethlin:ppc-can-into-atomicptr, r=oli-obk
Only generate a ptrtoint in AtomicPtr codegen when absolutely necessary

This special case was added in this PR: https://github.com/rust-lang/rust/pull/77611 in response to this error message:
```
Intrinsic has incorrect argument type!
void ({}*)* `@llvm.ppc.cfence.p0sl_s`
in function rust_oom
LLVM ERROR: Broken function found, compilation aborted!
[RUSTC-TIMING] std test:false 20.161
error: could not compile `std`
```
But when I tried searching for more information about that intrinsic I found this: https://github.com/llvm/llvm-project/issues/55983 which is a report of someone hitting this same error and a fix was landed in LLVM, 2 years after the above Rust PR.
2024-03-13 00:03:50 +00:00
Ben Kimock
81d630453b Avoid lowering code under dead SwitchInt targets 2024-03-12 19:01:04 -04:00
Adrian Palacios
68fc92242f Add intrinsic_name to get plain intrinsic name 2024-03-12 22:03:23 +00:00
Daniel Sedlak
eab1f30c29 Fix ICE in diagnostics for parenthesized type arguments 2024-03-12 21:32:21 +01:00
Veera
96b8225d8d Don't Create ParamCandidate When Obligation Contains Errors
Fixes #121941
2024-03-12 15:27:08 -04:00
bors
6b1e5d9db3 Auto merge of #122389 - workingjubilee:rollup-vbdniap, r=workingjubilee
Rollup of 12 pull requests

Successful merges:

 - #121754 ([bootstrap] Move the `split-debuginfo` setting to the per-target section)
 - #121953 (Add tests for the generated assembly of mask related simd instructions.)
 - #122081 (validate `builder::PATH_REMAP`)
 - #122245 (Detect truncated DepGraph files)
 - #122354 (bootstrap: Don't eagerly format verbose messages)
 - #122355 (rustdoc: fix up old test)
 - #122363 (tests: Add ui/attributes/unix_sigpipe/unix_sigpipe-str-list.rs)
 - #122366 (Fix stack overflow with recursive associated types)
 - #122377 (Fix discriminant_kind copy paste from the pointee trait case)
 - #122378 (Properly rebuild rustbooks)
 - #122380 (Fix typo in lib.rs of proc_macro)
 - #122381 (llvm-wrapper: adapt for LLVM API changes)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-03-12 16:31:43 +00:00
Jubilee
3e9c1d7253
Rollup merge of #122381 - krasimirgg:llvm-19-mar, r=durin42
llvm-wrapper: adapt for LLVM API changes

Adapts rust for 9997e03971.

`@rustbot` label: +llvm-main
r? `@durin42`
2024-03-12 09:04:04 -07:00
Jubilee
bca8c62776
Rollup merge of #122377 - zetanumbers:discriminant_kind_copypaste_fix, r=oli-obk
Fix discriminant_kind copy paste from the pointee trait case

r? `@oli-obk`
2024-03-12 09:04:03 -07:00
Jubilee
0b31375248
Rollup merge of #122366 - oli-obk:opaques_defined_by_overflow, r=lcnr
Fix stack overflow with recursive associated types

fixes #122364
2024-03-12 09:04:02 -07:00
Jubilee
f54350a9ba
Rollup merge of #122245 - saethlin:check-dep-graph-size, r=petrochenkov
Detect truncated DepGraph files

I suspect that the following issues are caused by truncated incr comp files:

* https://github.com/rust-lang/rust/issues/120582
* https://github.com/rust-lang/rust/issues/121499
* https://github.com/rust-lang/rust/issues/122210

We fail with an allocation failure or capacity overflow in this case because we assume that the ending bytes of an DepGraph file are the lengths of arrays. If the file has somehow been truncated then the ending bytes are probably some of our varint encoding, which tries to eliminate zero bytes, so interpreting a random 8 bytes as an array length has a very high chance of producing a byte capacity over `isize::MAX`.

Now theoretically since https://github.com/rust-lang/rust/pull/119510 merged I have fixed the out-of-disk issues and yet in https://github.com/rust-lang/rust/issues/120894#issuecomment-1945126700 I still see some decoding failures that look like out-of-disk ICEs, for example https://crater-reports.s3.amazonaws.com/beta-1.77-1/beta-2024-02-10/gh/scottfones.aoc_2022/log.txt

So this PR should ensure that we get an ICE that clearly identifies if the file in question is truncated.
2024-03-12 09:04:00 -07:00
bors
7de1a1f6db Auto merge of #122218 - Zoxc:no-interleave-panics, r=michaelwoerister
Lock stderr in panic handler

Fixes https://github.com/rust-lang/rust/issues/119789.
2024-03-12 14:01:38 +00:00
Krasimir Georgiev
0a2ddcd46b llvm-wrapper: adapt for LLVM API changes
Adapts rust for 9997e03971.
2024-03-12 12:39:25 +00:00
Daria Sukhonina
5336a02d28 Fix discriminant_kind copy paste from the pointee trait case 2024-03-12 14:37:22 +03:00
bors
3b85d2c7fc Auto merge of #121644 - oli-obk:unique_static_innards2, r=RalfJung,nnethercote
Ensure nested allocations in statics neither get deduplicated nor duplicated

This PR generates new `DefId`s for nested allocations in static items and feeds all the right queries to make the compiler believe these are regular `static` items. I chose this design, because all other designs are fragile and make the compiler horribly complex for such a niche use case.

At present this wrecks incremental compilation performance *in case nested allocations exist* (because any query creating a `DefId` will be recomputed and never loaded from the cache). This will be resolved later in https://github.com/rust-lang/rust/pull/115613 . All other statics are unaffected by this change and will not have performance regressions (heh, famous last words)

This PR contains various smaller refactorings that can be pulled out into separate PRs. It is best reviewed commit-by-commit. The last commit is where the actual magic happens.

r? `@RalfJung` on the const interner and engine changes

fixes https://github.com/rust-lang/rust/issues/79738
2024-03-12 10:29:15 +00:00
Oli Scherer
e2773733f3 Some comment nits 2024-03-12 08:51:20 +00:00
bors
5b7343b966 Auto merge of #122170 - alexcrichton:rename-wasi-threads, r=petrochenkov
Rename `wasm32-wasi-preview1-threads` to `wasm32-wasip1-threads`

This commit renames the current `wasm32-wasi-preview1-threads` target to `wasm32-wasip1-threads`. The need for this rename is a bit unfortunate as the previous name was chosen in an attempt to be future-compatible with other WASI targets. Originally this target was proposed to be `wasm32-wasi-threads`, and that's what was originally implemented in wasi-sdk as well. After discussion though and with the plans for the upcoming component-model target (now named `wasm32-wasip2`) the "preview1" naming was chosen for the threads-based target. The WASI subgroup later decided that it was time to drop the "preview" terminology and recommends "pX" instead, hence previous PRs to add `wasm32-wasip2` and rename `wasm32-wasi` to `wasm32-wasip1`.

So, with all that history, the "proper name" for this target is different than its current name, so one way or another a rename is required. This PR proposes renaming this target cold-turkey, unlike `wasm32-wasi` which is having a long transition period to change its name. The threads-based target is predicted to see only a fraction of the traffic of `wasm32-wasi` due to the unstable nature of the WASI threads proposal itself.

While I was here I updated the in-tree documentation in the target spec file itself as most of the documentation was copied from the original WASI target and wasn't as applicable to this target.

Also, as an aside, I can at least try to apologize for all the naming confusion here, but this is hopefully the last WASI-related rename.
2024-03-12 08:30:46 +00:00
bors
b0170b693e Auto merge of #122365 - matthiaskrgr:rollup-4i350h6, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #115141 (Update Windows platform support)
 - #121865 (Add FileCheck annotations to MIR-opt unnamed-fields tests)
 - #122000 (Fix 32-bit overflows in LLVM composite constants)
 - #122194 (Enable creating backtraces via -Ztreat-err-as-bug when stashing errors)
 - #122319 (Don't ICE when non-self part of trait goal is constrained in new solver)
 - #122339 (Update books)
 - #122342 (Update /NODEFAUTLIB comment for msvc)
 - #122343 (Remove some unnecessary `allow(incomplete_features)` in the test suite)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-03-12 06:29:06 +00:00
Oli Scherer
783490da70 Fix stack overflow with recursive associated types 2024-03-12 06:03:43 +00:00
Oli Scherer
bbedde835e Exhaustively match on the mutability and nestedness 2024-03-12 05:53:47 +00:00
Oli Scherer
bbbf06d5e9 Manual rustfmt 2024-03-12 05:53:46 +00:00
Oli Scherer
926bfe5078 s/mt/mutability/ 2024-03-12 05:53:46 +00:00
Oli Scherer
d3514a036d Ensure nested allocations in statics do not get deduplicated 2024-03-12 05:53:46 +00:00
Oli Scherer
92414ab25d Make some functions private that are only ever used in the same module 2024-03-12 05:53:46 +00:00