Commit graph

32454 commits

Author SHA1 Message Date
bors
7d145ebffa Auto merge of #133223 - zachs18:uniquerc-impls, r=Noratrieb
`UniqueRc` trait impls

UniqueRc tracking Issue: #112566

Stable traits: (i.e. impls behind only the `unique_rc_arc` feature gate)

* Support the same formatting as `Rc`:
  * `fmt::Debug` and `fmt::Display` delegate to the pointee.
  * `fmt::Pointer` prints the address of the pointee.
* Add explicit `!Send` and `!Sync` impls, to mirror `Rc`.
* Borrowing traits: `Borrow`, `BorrowMut`, `AsRef`, `AsMut`
  * `Rc` does not implement `BorrowMut` and `AsMut`, but `UniqueRc` can.
* Unconditional `Unpin`, like other heap-allocated types.
* Comparison traits `(Partial)Ord` and `(Partial)Eq` delegate to the pointees.
  * `PartialEq for UniqueRc` does not do `Rc`'s specialization shortcut for pointer equality when `T: Eq`, since by definition two `UniqueRc`s cannot share an allocation.
* `Hash` delegates to the pointee.
* `AsRawFd`, `AsFd`, `AsHandle`, `AsSocket` delegate to the pointee like `Rc`.
  * Sidenote: The bounds on `T` for the existing `Pointer<T>` impls for specifically `AsRawFd` and `AsSocket` do not allow `T: ?Sized`. For the added `UniqueRc` impls I allowed `T: ?Sized` for all four traits, but I did not change the existing (stable) impls.

Unstable traits:
* `DispatchFromDyn`, allows using `UniqueRc<Self>` as a method receiver under `feature(arbitrary_self_types)`.
* Existing `PinCoerceUnsized for UniqueRc` is generalized to allow non-`Global` allocators, like `Rc`.
* `DerefPure`, allows using `UniqueRc` in deref-patterns under `feature(deref_patterns)`, like `Rc`.

For documentation, `Rc` only has documentation on the comparison traits' methods, so I copied/adapted the documentation for those, and left the rest without impl-specific docs.

~~Edit: Marked as draft while I figure out `UnwindSafe`.~~
Edit: Ignoring `UnwindSafe` for this PR
2024-12-15 08:26:19 +00:00
bors
db94f76b49 Auto merge of #133734 - scottmcm:lower-indexing-to-ptrmetadata, r=davidtwco,RalfJung
Bounds-check with PtrMetadata instead of Len in MIR

Rather than emitting `Len(*_n)` in array index bounds checks, emit `PtrMetadata(copy _n)` instead -- with some asterisks for arrays and `&mut` that need it to be done slightly differently.

We're getting pretty close to removing `Len` entirely, actually.  I think just one more PR after this (for slice drop shims).

r? mir
2024-12-14 22:43:39 +00:00
bors
ecf35e081a Auto merge of #133099 - RalfJung:forbidden-hardfloat-features, r=workingjubilee
forbid toggling x87 and fpregs on hard-float targets

Part of https://github.com/rust-lang/rust/issues/116344, follow-up to https://github.com/rust-lang/rust/pull/129884:

The `x87`  target feature on x86 and the `fpregs` target feature on ARM must not be disabled on a hardfloat target, as that would change the float ABI. However, *enabling* `fpregs` on ARM is [explicitly requested](https://github.com/rust-lang/rust/issues/130988) as it seems to be useful. Therefore, we need to refine the distinction of "forbidden" target features and "allowed" target features: all (un)stable target features can determine on a per-target basis whether they should be allowed to be toggled or not. `fpregs` then checks whether the current target has the `soft-float` feature, and if yes, `fpregs` is permitted -- otherwise, it is not. (Same for `x87` on x86).

Also fixes https://github.com/rust-lang/rust/issues/132351. Since `fpregs` and `x87` can be enabled on some builds and disabled on others, it would make sense that one can query it via `cfg`. Therefore, I made them behave in `cfg` like any other unstable target feature.

The first commit prepares the infrastructure, but does not change behavior. The second commit then wires up `fpregs` and `x87` with that new infrastructure.

r? `@workingjubilee`
2024-12-13 19:43:00 +00:00
bors
c6288abd92 Auto merge of #134122 - oli-obk:push-zqnyznxtpnll, r=petrochenkov
Move impl constness into impl trait header

This PR is kind of the opposite of the rejected https://github.com/rust-lang/rust/pull/134114

Instead of moving more things into the `constness` query, we want to keep them where their corresponding hir nodes are lowered. So I gave this a spin for impls, which have an obvious place to be (the impl trait header). And surprisingly it's also a perf improvement (likely just slightly better query & cache usage).

The issue was that removing anything from the `constness` query makes it just return `NotConst`, which is wrong. So I had to change it to `bug!` out if used wrongly, and only then remove the impl blocks from the `constness` query. I think this change is good in general, because it makes using `constness` more robust (as can be seen by how few sites that had to be changed, so it was almost solely used specifically for the purpose of asking for functions' constness). The main thing where this change was not great was in clippy, which was using the `constness` query as a general DefId -> constness map. I added a `DefKind` filter in front of that. If it becomes a more common pattern we can always move that helper into rustc.
2024-12-13 16:17:34 +00:00
bors
0dc2c87e48 Auto merge of #134047 - saethlin:inline-fmt-rt, r=m-ou-se
Switch inline(always) in core/src/fmt/rt.rs to plain inline

I have a vague memory of these being instantiated a lot. Let's ask perf.

Looks like this is an improvement!
2024-12-13 12:04:04 +00:00
bors
7ef657f73d Auto merge of #133899 - scottmcm:strip-mir-debuginfo, r=oli-obk
We don't need `NonNull::as_ptr` debuginfo

In order to stop pessimizing the use of local variables in core, skip debug info for MIR temporaries in tiny (single-BB) functions.

For functions as simple as this -- `Pin::new`, etc -- nobody every actually wants debuginfo for them in the first place.  They're more like intrinsics than real functions, and stepping over them is good.
2024-12-13 08:32:20 +00:00
bors
4839571ddc Auto merge of #132961 - adetaylor:arbitrary-self-types-the-big-bit, r=compiler-errors,wesleywiser
Arbitrary self types v2: main compiler changes

This is the main PR in a series of PRs related to Arbitrary Self Types v2, tracked in #44874. Specifically this is step 7 of the plan [described here](https://github.com/rust-lang/rust/issues/44874#issuecomment-2122179688), for [RFC 3519](https://github.com/rust-lang/rfcs/pull/3519).

Overall this PR:
* Switches from the `Deref` trait to the new `Receiver` trait when the unstable `arbitrary_self_types` feature is enabled (the simple bit)
* Introduces new algorithms to spot "shadowing"; that is, the case where a newly-added method in an outer smart pointer might end up overriding a pre-existing method in the pointee (the complex bit). Most of this bit was explored in [this earlier perf-testing PR](https://github.com/rust-lang/rust/pull/127812#issuecomment-2236911900).
* Lots of tests

This should not break compatibility for:
* Stable users, where it should have no effect
* Users of the existing `arbitrary_self_types` feature (because we implement `Receiver` for `T: Deref`) _unless_ those folks have added methods which may shadow methods in inner types, which we no longer want to allow

Subsequent PRs will add better diagnostics.

It's probably easiest to review this commit-by-commit.

r? `@wesleywiser`
2024-12-12 21:40:39 +00:00
bors
d5708aad45 Auto merge of #132789 - matthiaskrgr:debug_tests, r=jieyouxu
add some debug-assertion crash tests

r? ghost

try-job: x86_64-gnu
2024-12-12 16:08:06 +00:00
bors
e4c861005c Auto merge of #134199 - RalfJung:gitmerge, r=oli-obk
Revert "Stop git from merging generated files"

This reverts https://github.com/rust-lang/rust/pull/133851. "-merge" makes git not even do merges if they are entirely conflict-free, which is not the behavior we want. We sometimes have conflict-free merges in generated files and it's much better if git can handle them automatically.

r? `@oli-obk`
Cc `@jieyouxu` `@Urgau`
2024-12-12 12:02:38 +00:00
bors
67dcb7a3c3 Auto merge of #129181 - beetrees:asm-spans, r=pnkfelix,compiler-errors
Pass end position of span through inline ASM cookie

Before this PR, only the start position of the span was passed though the inline ASM cookie to diagnostics. LLVM 19 has full support for 64-bit inline ASM cookies; this PR uses that to pass the end position of the span in the upper 32 bits, meaning inline ASM diagnostics now point at the entire line the error occurred on, not just the first character of it.
2024-12-12 02:34:06 +00:00
bors
ead998e6de 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
bors
8e244991f9 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
48f34bb639
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
d41a896908
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
Lukas Wirth
e7a4c99ce3
Merge pull request #18663 from Veykril/push-syoklzkntykn
fix: Swallow rustfmt parsing panics
2024-12-11 10:06:28 +00:00
Laurențiu Nicola
b248e53859
Merge pull request #18662 from lnicola/sync-from-rust
internal: Sync from downstream
2024-12-11 10:05:39 +00:00
Lukas Wirth
8963e9736b fix: Swallow rustfmt parsing panics 2024-12-11 10:52:04 +01:00
Laurențiu Nicola
c1433e9742 Bump rustc crates 2024-12-11 11:50:19 +02:00
Laurențiu Nicola
30262281eb Merge from rust-lang/rust 2024-12-11 11:49:08 +02:00
Laurențiu Nicola
b19be7dcfe Preparing for merge from rust-lang/rust 2024-12-11 11:48:46 +02:00
Lukas Wirth
41f3319173
Merge pull request #18458 from Giga-Bowser/master
feat: Add diagnostic fix to remove unnecessary wrapper in type mismatch
2024-12-11 07:09:15 +00:00
Lukas Wirth
087cb629be
Merge pull request #18653 from SomeoneToIgnore/hash-completions
Hash completion items to properly match them during /resolve
2024-12-11 07:08:33 +00:00
Lukas Wirth
002fcea441
Merge pull request #18657 from Giga-Bowser/generate-enum-variant
minor: Migrate `generate_enum_variant` to `SyntaxEditor`
2024-12-11 07:07:22 +00:00
Lukas Wirth
b0c82c974d
Merge pull request #18656 from roife/fix-issue-18639
feat: preserve order of parameters in extract_functions
2024-12-11 07:00:17 +00:00
roife
78fb0e47ca feat: preserve order of parameters in extract_functions 2024-12-11 02:26:58 +08:00
Giga Bowser
547f75a2ce minor: Migrate generate_enum_variant to SyntaxEditor 2024-12-10 13:11:33 -05:00
Giga Bowser
21b376583a minor: Add ty_infer constructor to SyntaxFactory 2024-12-10 12:33:32 -05:00
Giga Bowser
d7d68310c0 minor: Add whitespace constructor to SyntaxFactory 2024-12-10 12:25:13 -05:00
Giga Bowser
c70bf568bb minor: Add item_enum constructor to SyntaxFactory
I recursively added all constructors it depends on. I also changed the old `make::` constructors to support more of the grammar.
2024-12-10 11:12:44 -05:00
Kirill Bulatov
4169926b3f Address the feedback from pascalkuthe
* Use Base64 to minify the hash representation in the JSON data
* Do hash checks only for items with similar labels
2024-12-10 13:01:23 +02:00
Kirill Bulatov
2529e9e1e1 Address the feedback from Veykril
* Exclude documentation field from hashing
* Do less cloning during initial completion list generation
2024-12-10 12:33:30 +02:00
bors
4c05bc75bb Auto merge of #133902 - Kobzol:ci-dist-arm-runner, r=MarcoIeni
CI: move `dist-arm-linux` to an ARM runner

First, I want to test whether we could actually move this to a free runner, vs moving to the 8-core ARM runner.

Fixes: https://github.com/rust-lang/infra-team/issues/181

r? `@MarcoIeni`

try-job: dist-arm-linux
2024-12-10 07:44:46 +00:00
Laurențiu Nicola
7b4b83ba91
Merge pull request #18649 from roife/fix-issue-18648
minor: enhance name suggestion for `Arc<T>` and `Rc<T>`
2024-12-10 07:05:36 +00:00
Laurențiu Nicola
54879d9ae4
Merge pull request #18650 from yuki0iq/fix-typo
crates/r-a: Fix typo in debug message
2024-12-10 05:08:21 +00:00
Giga Bowser
68b85ce66f minor: Migrate remove_unnecessary_wrapper to SyntaxEditor 2024-12-09 21:16:31 -05:00
Giga Bowser
59cd717602 fix: Handle the final statement in SyntaxFactory::block_expr properly
This caused a bug that was rather tricky to hunt down!
2024-12-09 21:15:15 -05:00
Giga Bowser
d881208d1b Add diagnostic fix to remove unnecessary wrapper in type mismatch
I also reorganized the tests in a more logical order, and removed the redundant `test_` prefix from their names.
2024-12-09 21:15:15 -05:00
Kirill Bulatov
d8d35dbfcc Clippy fixes 2024-12-10 01:04:02 +02:00
Kirill Bulatov
89c2aaed8c Avoid hashing completion-related ranges as those may change during /resolve query 2024-12-10 00:45:57 +02:00
Yuki Sireneva
dff827741d
crates/r-a: Fix typo in debug message 2024-12-10 00:13:17 +03:00
Kirill Bulatov
b59b2fb469 Unite more bool hashing 2024-12-09 22:38:55 +02:00
Kirill Bulatov
5906bda975 Stop excluding Helix from the general resolve path 2024-12-09 22:26:00 +02:00
Kirill Bulatov
d348ffb480 Always compute the hash when r-a wants the imports to be resolved 2024-12-09 22:26:00 +02:00
Kirill Bulatov
62d97d9ba7 Draft completion hashing 2024-12-09 22:26:00 +02:00
roife
9c03cbb499 minor: enhance name suggestion for Arc<T> and Rc<T> 2024-12-10 02:47:52 +08:00
Lukas Wirth
99a6ecd41e
Merge pull request #18647 from Veykril/push-nsrrmmnzzoym
internal: Disable pipe on typing handler
2024-12-09 15:06:29 +00:00
Lukas Wirth
f021ec3b96 Disable pipe on typing handler 2024-12-09 15:52:04 +01:00
Lukas Wirth
067b4a32dd
Merge pull request #18645 from Veykril/push-yruoyrvrsntw
fix: Non-exhaustive structs may be empty
2024-12-09 13:26:47 +00:00
Lukas Wirth
55a7ee8065 fix: Non-exhaustive structs may be empty 2024-12-09 14:12:22 +01:00
Lukas Wirth
d8248714dc
Merge pull request #18644 from Veykril/push-nolvpzqvoqwx
Remove patch sysroot cfg-if hack
2024-12-09 10:58:27 +00:00