Commit graph

273162 commits

Author SHA1 Message Date
Michael Goulet
2caada17c0 Properly consider APITs for never type fallback ascription fix 2024-12-12 00:32:18 +00:00
Nicholas Nethercote
40c964510c Remove PErr.
It's just a synonym for `Diag` that adds no value and is only used in a
few places.
2024-12-12 11:31:55 +11:00
bors
1daec069fb Auto merge of #128004 - folkertdev:naked-fn-asm, r=Amanieu
codegen `#[naked]` functions using global asm

tracking issue: https://github.com/rust-lang/rust/issues/90957

Fixes #124375

This implements the approach suggested in the tracking issue: use the existing global assembly infrastructure to emit the body of `#[naked]` functions. The main advantage is that we now have full control over what gets generated, and are no longer dependent on LLVM not sneakily messing with our output (inlining, adding extra instructions, etc).

I discussed this approach with `@Amanieu` and while I think the general direction is correct, there is probably a bunch of stuff that needs to change or move around here. I'll leave some inline comments on things that I'm not sure about.

Combined with https://github.com/rust-lang/rust/pull/127853, if both accepted, I think that resolves all steps from the tracking issue.

r? `@Amanieu`
2024-12-11 21:51:07 +00:00
Ralf Jung
60eca2c575 apply review feedback 2024-12-11 22:18:51 +01:00
Ralf Jung
d6ddc73dae forbid toggling x87 and fpregs on hard-float targets 2024-12-11 22:18:50 +01:00
Ralf Jung
2d887a5c5c generalize 'forbidden feature' concept so that even (un)stable feature can be invalid to toggle
Also rename some things for extra clarity
2024-12-11 22:11:15 +01:00
Eric Huss
1bc58979a2 Stabilize the Rust 2024 prelude 2024-12-11 13:09:57 -08:00
Oli Scherer
98edb8f403 Clarify why a type is rejected for asm! 2024-12-11 20:17:37 +00:00
Oli Scherer
6d3d61f1b0 Evaluate constants in SIMD vec lengths before rejecting them 2024-12-11 20:17:37 +00:00
Michael Goulet
43e2fd5086 Fix ICE when multiple supertrait substitutions need assoc but only one is provided 2024-12-11 19:53:40 +00:00
Michael Goulet
25a7fdf5bc Dont use span as key when collecting missing associated types from dyn 2024-12-11 19:53:27 +00:00
bors
21fe748be1 Auto merge of #134177 - matthiaskrgr:rollup-hgp8q60, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #132975 (De-duplicate and improve definition of core::ffi::c_char)
 - #133598 (Change `GetManyMutError` to match T-libs-api decision)
 - #134148 (add comments in check_expr_field)
 - #134163 (coverage: Rearrange the code for embedding per-function coverage metadata)
 - #134165 (wasm(32|64): update alignment string)
 - #134170 (Subtree update of `rust-analyzer`)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-12-11 19:06:46 +00:00
Matthias Krüger
531e578ee5
Rollup merge of #134170 - lnicola:sync-from-ra, r=lnicola
Subtree update of `rust-analyzer`

r? `@ghost`
2024-12-11 20:00:22 +01:00
Matthias Krüger
eefefbea2f
Rollup merge of #134165 - durin42:wasm-target-string, r=jieyouxu
wasm(32|64): update alignment string

See llvm/llvm-project@c5ab70c508

`@rustbot` label: +llvm-main
2024-12-11 20:00:21 +01:00
Matthias Krüger
13c13ee4ec
Rollup merge of #134163 - Zalathar:covfun, r=SparrowLii,jieyouxu
coverage: Rearrange the code for embedding per-function coverage metadata

This is a series of refactorings to the code that prepares and embeds per-function coverage metadata records (“covfun records”) in the `__llvm_covfun` linker section of the final binary. The `llvm-cov` tool reads this metadata from the binary when preparing a coverage report.

Beyond general cleanup, a big motivation behind these changes is to pave the way for re-landing an updated version of #133418.

---

There should be no change in compiler output, as demonstrated by the absence of (meaningful) changes to coverage tests.

The first patch is just moving code around, so I suggest looking at the other patches to see the actual changes.

---

try-job: x86_64-gnu
try-job: x86_64-msvc
try-job: aarch64-apple
2024-12-11 20:00:18 +01:00
Matthias Krüger
90a42c2519
Rollup merge of #134148 - dev-ardi:cleanup_check_field_expr, r=compiler-errors
add comments in check_expr_field

Nothing special, just a few comments and a couple of small cleanups.
2024-12-11 20:00:15 +01:00
Matthias Krüger
2e60288ce0
Rollup merge of #133598 - ChayimFriedman2:get-many-mut-detailed-err, r=scottmcm
Change `GetManyMutError` to match T-libs-api decision

That is, differentiate between out-of-bounds and overlapping indices, and remove the generic parameter `N`.

I also exported `GetManyMutError` from `alloc` (and `std`), which was apparently forgotten.

Changing the error to carry additional details means LLVM no longer generates separate short-circuiting branches for the checks, instead it generates one branch at the end. I therefore changed the  code to use early returns to make LLVM generate jumps. Benchmark results between the approaches are somewhat mixed, but I chose this approach because it is significantly faster with ranges and also faster with `unwrap()`.

Benchmark (`jumps` refer to short-circuiting, `acc` is not short-circuiting):
```rust
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use my_crate::{get_many_check_valid_acc, get_many_check_valid_jumps, GetManyMutError};

mod externs {
    #[unsafe(no_mangle)]
    fn foo() {}
    #[unsafe(no_mangle)]
    fn bar() {}
    #[unsafe(no_mangle)]
    fn baz() {}
}

unsafe extern "C" {
    safe fn foo();
    safe fn bar();
    safe fn baz();
}

fn bench_method(c: &mut Criterion) {
    c.bench_function("jumps two usize", |b| {
        b.iter(|| get_many_check_valid_jumps(&[black_box(1), black_box(5)], black_box(10)))
    });
    c.bench_function("jumps two usize unwrap", |b| {
        b.iter(|| get_many_check_valid_jumps(&[black_box(1), black_box(5)], black_box(10)).unwrap())
    });
    c.bench_function("jumps two usize ok", |b| {
        b.iter(|| get_many_check_valid_jumps(&[black_box(1), black_box(5)], black_box(10)).ok())
    });
    c.bench_function("jumps three usize", |b| {
        b.iter(|| {
            get_many_check_valid_jumps(&[black_box(1), black_box(5), black_box(7)], black_box(10))
        })
    });
    c.bench_function("jumps three usize match", |b| {
        b.iter(|| {
            match get_many_check_valid_jumps(
                &[black_box(1), black_box(5), black_box(7)],
                black_box(10),
            ) {
                Err(GetManyMutError::IndexOutOfBounds) => foo(),
                Err(GetManyMutError::OverlappingIndices) => bar(),
                Ok(()) => baz(),
            }
        })
    });
    c.bench_function("jumps two Range", |b| {
        b.iter(|| {
            get_many_check_valid_jumps(
                &[black_box(1)..black_box(5), black_box(7)..black_box(8)],
                black_box(10),
            )
        })
    });
    c.bench_function("jumps two RangeInclusive", |b| {
        b.iter(|| {
            get_many_check_valid_jumps(
                &[black_box(1)..=black_box(5), black_box(7)..=black_box(8)],
                black_box(10),
            )
        })
    });

    c.bench_function("acc two usize", |b| {
        b.iter(|| get_many_check_valid_acc(&[black_box(1), black_box(5)], black_box(10)))
    });
    c.bench_function("acc two usize unwrap", |b| {
        b.iter(|| get_many_check_valid_acc(&[black_box(1), black_box(5)], black_box(10)).unwrap())
    });
    c.bench_function("acc two usize ok", |b| {
        b.iter(|| get_many_check_valid_acc(&[black_box(1), black_box(5)], black_box(10)).ok())
    });
    c.bench_function("acc three usize", |b| {
        b.iter(|| {
            get_many_check_valid_acc(&[black_box(1), black_box(5), black_box(7)], black_box(10))
        })
    });
    c.bench_function("acc three usize match", |b| {
        b.iter(|| {
            match get_many_check_valid_jumps(
                &[black_box(1), black_box(5), black_box(7)],
                black_box(10),
            ) {
                Err(GetManyMutError::IndexOutOfBounds) => foo(),
                Err(GetManyMutError::OverlappingIndices) => bar(),
                Ok(()) => baz(),
            }
        })
    });
    c.bench_function("acc two Range", |b| {
        b.iter(|| {
            get_many_check_valid_acc(
                &[black_box(1)..black_box(5), black_box(7)..black_box(8)],
                black_box(10),
            )
        })
    });
    c.bench_function("acc two RangeInclusive", |b| {
        b.iter(|| {
            get_many_check_valid_acc(
                &[black_box(1)..=black_box(5), black_box(7)..=black_box(8)],
                black_box(10),
            )
        })
    });
}

criterion_group!(benches, bench_method);
criterion_main!(benches);
```
Benchmark results:
```none
jumps two usize          time:   [586.44 ps 590.20 ps 594.50 ps]
jumps two usize unwrap   time:   [390.44 ps 393.63 ps 397.44 ps]
jumps two usize ok       time:   [585.52 ps 591.74 ps 599.38 ps]
jumps three usize        time:   [976.51 ps 983.79 ps 991.51 ps]
jumps three usize match  time:   [390.82 ps 393.80 ps 397.07 ps]
jumps two Range          time:   [1.2583 ns 1.2640 ns 1.2695 ns]
jumps two RangeInclusive time:   [1.2673 ns 1.2770 ns 1.2877 ns]
acc two usize            time:   [592.63 ps 596.44 ps 600.52 ps]
acc two usize unwrap     time:   [582.65 ps 587.07 ps 591.90 ps]
acc two usize ok         time:   [581.59 ps 587.82 ps 595.71 ps]
acc three usize          time:   [894.69 ps 901.23 ps 908.24 ps]
acc three usize match    time:   [392.68 ps 395.73 ps 399.17 ps]
acc two Range            time:   [1.5531 ns 1.5617 ns 1.5711 ns]
acc two RangeInclusive   time:   [1.5746 ns 1.5840 ns 1.5939 ns]
```
2024-12-11 20:00:14 +01:00
Matthias Krüger
fe516ef9f4
Rollup merge of #132975 - arichardson:ffi-c-char, r=tgross35
De-duplicate and improve definition of core::ffi::c_char

Instead of having a list of unsigned char targets for each OS, follow the logic Clang uses and instead set the value based on architecture with a special case for Darwin and Windows operating systems. This makes it easier to support new operating systems targeting Arm/AArch64 without having to modify this config statement for each new OS. The new list does not quite match Clang since I noticed a few bugs in the Clang implementation (https://github.com/llvm/llvm-project/issues/115957).

Fixes https://github.com/rust-lang/rust/issues/129945
Closes https://github.com/rust-lang/rust/pull/131319
2024-12-11 20:00:12 +01:00
Zachary S
6a8bc4bc6b Remove consteval note from <*mut T>::align_offset docs. 2024-12-11 12:56:12 -06:00
onur-ozkan
12684456d3 remove Kind check for symbol_intern_string_literal
Signed-off-by: onur-ozkan <work@onurozkan.dev>
2024-12-11 20:39:05 +03:00
onur-ozkan
f11edf7611 allow symbol_intern_string_literal lint in test modules
Signed-off-by: onur-ozkan <work@onurozkan.dev>
2024-12-11 20:38:55 +03:00
Oli Scherer
c04b52ae9e Add regression tests 2024-12-11 16:41:27 +00:00
bors
1f3bf231e1 Auto merge of #134164 - jhpratt:rollup-s7z0vcc, r=jhpratt
Rollup of 8 pull requests

Successful merges:

 - #134079 (Add a note saying that `{u8,i8}::from_{be,le,ne}_bytes` is meaningless)
 - #134105 (Validate self in host predicates correctly)
 - #134136 (Exercise const trait interaction with default fields)
 - #134139 ([AIX] keep profile-rt symbol alive)
 - #134141 (Remove more traces of anonymous ADTs)
 - #134142 (Rudimentary heuristic to insert parentheses when needed for RPIT overcaptures lint)
 - #134158 (Rename `projection_def_id` to `item_def_id`)
 - #134160 (Add vacation entry for myself in triagebot.toml)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-12-11 15:31:52 +00:00
Orion Gonzalez
014363e89e Don't emit "field expressions may not have generic arguments" if it's a method call without () 2024-12-11 16:23:04 +01:00
Orion Gonzalez
55806e5655 document check_expr_field 2024-12-11 13:48:50 +01:00
Adrian Taylor
337af8a370 Arbitrary self types v2: generics test.
There's some discussion on the RFC about whether generic receivers should be
allowed, but in the end the conclusion was that they should be blocked
(at least for some definition of 'generic'). This blocking landed in
an earlier PR; this commit adds additional tests to ensure the
interaction with the rest of the Arbitrary Self Types v2 feature is as
expected. This test may be a little duplicative but it seems better
to land it than not.
2024-12-11 11:59:13 +00:00
Adrian Taylor
a269b31231 Arbitrary self types v2: detect shadowing problems.
This builds on the previous commits by actually adding checks for cases
where a new method shadows an older method.
2024-12-11 11:59:13 +00:00
Adrian Taylor
48e1df87e1 Arbitrary self types v2: deshadow quicker
A previous commit added a search for certain types of "shadowing"
situation where one method (in an outer smart pointer type, typically)
might hide or shadow the method in the pointee.

Performance investigation showed that the naïve approach is too slow -
this commit speeds it up, while being functionally the same.

This still does not actually cause the deshadowing check to emit any
errors; that comes in a subsequent commit which is where all the tests
live.
2024-12-11 11:59:12 +00:00
Adrian Taylor
2707f5578d Arbitrary self types v2: deshadowing probe
This is the first part of a series of commits which impact the
"deshadowing detection" in the arbitrary self types v2 RFC.

This commit should not have any functional changes, but may impact
performance. Subsequent commits add back the performance, and add error
checking to this new code such that it has a functional effect.

Rust prioritizes method candidates in this order:
1. By value;
2. By reference;
3. By mutable reference;
4. By const ptr.
5. By reborrowed pin.

Previously, if a suitable candidate was found in one of these earlier
categories, Rust wouldn't even move onto probing the other categories.

As part of the arbitrary self types work, we're going to need to change
that - even if we choose a method from one of the earlier categories, we
will sometimes need to probe later categories to search for methods that
we may be shadowing.

This commit adds those extra searches for shadowing, but it does not yet
produce an error when such shadowing problems are found. That will come
in a subsequent commit, by filling out the 'check_for_shadowing'
method.

This commit contains a naive approach to detecting these shadowing
problems, which shows what we've functionally looking to do. However,
it's too slow. The performance of this approach was explored in this
PR:
https://github.com/rust-lang/rust/pull/127812#issuecomment-2236911900
Subsequent commits will improve the speed of the search.
2024-12-11 11:59:12 +00:00
Adrian Taylor
7f7c964e47 Arbitrary self types v2: pick diags to stack.
This commit makes no (intentional) functional change.

Previously, the picking process maintained two lists of extra
information useful for diagnostics:

* any unstable candidates which might have been picked
* any unsatisfied predicates

Previously, these were dealt with quite differently - the former list
was passed around as a function parameter; the latter lived in a RefCell
in the ProbeCtxt.

With this change we increase consistency by keeping them together in a
new PickDiagHints structure, passed as a parameter, with no need for
interior mutability.

The lifecycle of each of these lists remains fairly complex, so it's
explained with new comments in pick_core.

A further cleanup here would be to package the widely-used tuple
  (ty::Predicate<'tcx>,
   Option<ty::Predicate<'tcx>>,
   Option<ObligationCause<'tcx>>)
into a named struct for UnsatisfiedPredicate. This seems worth doing but
it turns out that this tuple is used in dozens of places, so if we're
going to do this we should do it as a separate PR to avoid constant
rebase trouble.
2024-12-11 11:59:12 +00:00
Adrian Taylor
e75660dad3 Arbitrary self types v2: use Receiver trait
In this new version of Arbitrary Self Types, we no longer use the Deref trait
exclusively when working out which self types are valid. Instead, we follow a
chain of Receiver traits. This enables methods to be called on smart pointer
types which fundamentally cannot support Deref (for instance because they are
wrappers for pointers that don't follow Rust's aliasing rules).

This includes:
* Changes to tests appropriately
* New tests for:
  * The basics of the feature
  * Ensuring lifetime elision works properly
  * Generic Receivers
  * A copy of the method subst test enhanced with Receiver

This is really the heart of the 'arbitrary self types v2' feature, and
is the most critical commit in the current PR.

Subsequent commits are focused on:
* Detecting "shadowing" problems, where a smart pointer type can hide
  methods in the pointee.
* Diagnostics and cleanup.

Naming: in this commit, the "Autoderef" type is modified so that it no
longer solely focuses on the "Deref" trait, but can now consider the
"Receiver" trait instead. Should it be renamed, to something like
"TraitFollower"? This was considered, but rejected, because
* even in the Receiver case, it still considers built-in derefs
* the name Autoderef is short and snappy.
2024-12-11 11:59:12 +00:00
Oli Scherer
c0e0d8f874 Require the constness query to only be invoked on things that can have constness 2024-12-11 11:07:02 +00:00
Oli Scherer
3d0bf68625 Make a helper private 2024-12-11 11:07:02 +00:00
Augie Fackler
48b883287a wasm(32|64): update alignment string
See llvm/llvm-project@c5ab70c508

@rustbot label: +llvm-main
2024-12-11 05:52:59 -05:00
Zalathar
3f3a9bf7f5 coverage: Store intermediate region tables in CovfunRecord
This defers the call to `llvm_cov::write_function_mappings_to_buffer` until
just before its enclosing global variable is created.
2024-12-11 21:35:45 +11:00
Zalathar
512f3fdebe coverage: Only generate a CGU's covmap record if it has covfun records 2024-12-11 21:35:44 +11:00
Zalathar
9e6b7c17c8 coverage: Adjust a codegen test to ignore the order of covmap/covfun globals 2024-12-11 21:34:48 +11:00
Lukas Wirth
a18e38e6e2
Merge pull request #18663 from Veykril/push-syoklzkntykn
fix: Swallow rustfmt parsing panics
2024-12-11 10:06:28 +00:00
Laurențiu Nicola
81720881ae
Merge pull request #18662 from lnicola/sync-from-rust
internal: Sync from downstream
2024-12-11 10:05:39 +00:00
Lukas Wirth
e6fbb5c8e6 fix: Swallow rustfmt parsing panics 2024-12-11 10:52:04 +01:00
Laurențiu Nicola
884f57f9fc Bump rustc crates 2024-12-11 11:50:19 +02:00
Laurențiu Nicola
5db2aa865c Merge from rust-lang/rust 2024-12-11 11:49:08 +02:00
Laurențiu Nicola
1649eb6dd7 Preparing for merge from rust-lang/rust 2024-12-11 11:48:46 +02:00
WANG Rui
78f3946ffd ABI checks: add support for loongarch
LoongArch psABI[^1] specifies that LSX vector types are passed via general-purpose
registers, while LASX vector types are passed indirectly through the stack.

This patch addresses the following warnings:

```
warning: this function call uses a SIMD vector type that is not currently supported with the chosen ABI
    --> .../library/core/src/../../stdarch/crates/core_arch/src/loongarch64/lsx/generated.rs:3695:5
     |
3695 |     __lsx_vreplgr2vr_b(a)
     |     ^^^^^^^^^^^^^^^^^^^^^ function called here
     |
     = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
     = note: for more information, see issue #116558 <https://github.com/rust-lang/rust/issues/116558>
     = note: `#[warn(abi_unsupported_vector_types)]` on by default
```

[^1]: https://github.com/loongson/la-abi-specs/blob/release/lapcs.adoc
2024-12-11 17:34:44 +08:00
Jacob Pratt
c384b28148
Rollup merge of #134160 - celinval:chores-vacation, r=jieyouxu
Add vacation entry for myself in triagebot.toml

It's that wonderful time of the year. 😃
2024-12-11 03:30:45 -05:00
Jacob Pratt
c4e27d67a7
Rollup merge of #134158 - compiler-errors:item-def-id, r=jackh726
Rename `projection_def_id` to `item_def_id`

Renames `projection_def_id` to `item_def_id`, since `item_def_id` is what we call the analogous method for ~~`AliasTerm`/`AliasTy`~~ `PolyExistentialProjection`. I keep forgetting that this one is not called `item_def_id`.
2024-12-11 03:30:44 -05:00
Jacob Pratt
f1030765f3
Rollup merge of #134142 - compiler-errors:paren-sug, r=jieyouxu
Rudimentary heuristic to insert parentheses when needed for RPIT overcaptures lint

We don't have basically any preexisting machinery to detect when parentheses are needed for *types*. AFAICT, all of the diagnostics we have for opaques just... fail when they suggest `+ 'a` when that's ambiguous.

Fixes #132853
2024-12-11 03:30:44 -05:00
Jacob Pratt
16b64938c2
Rollup merge of #134141 - compiler-errors:anon-adt, r=lqd
Remove more traces of anonymous ADTs

Anonymous ADTs were removed in #131045, but I forgot to remove this.
2024-12-11 03:30:43 -05:00
Jacob Pratt
2891a92e90
Rollup merge of #134139 - mustartt:pgo-linker-flag, r=saethlin
[AIX] keep profile-rt symbol alive

Clang passes `-u __llvm_profile_runtime` on AIX. https://reviews.llvm.org/D136192
We want to preserve the symbol in the case there are no instrumented object files.
2024-12-11 03:30:42 -05:00
Jacob Pratt
fe7fc76835
Rollup merge of #134136 - estebank:const-trait-default-field-test, r=jieyouxu
Exercise const trait interaction with default fields

Add a test case for using the result of a fn call of an associated function of a `const` trait in a struct default field.

```rust
struct X;
trait Trait {
    fn value() -> Self;
}
impl const Trait for X {
    fn value() -> Self { X }
}
struct S<T: const Trait> {
    a: T = T::value(),
}
```
2024-12-11 03:30:42 -05:00