Commit Graph

285705 Commits

Author SHA1 Message Date
joboet
5abeaa821f
rustc_codegen_llvm: use threadlocal.address intrinsic to access TLS 2025-04-04 21:48:26 +02:00
bors
b8ff7b682e Auto merge of #139213 - bjorn3:cg_clif_test_coretests, r=jieyouxu
Run coretests and alloctests with cg_clif in CI

Part of https://github.com/rust-lang/rustc_codegen_cranelift/issues/1290
2025-04-04 11:59:59 +00:00
bors
a4166dabaa Auto merge of #139354 - matthiaskrgr:rollup-04lgx23, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #138949 (Rename `is_like_osx` to `is_like_darwin`)
 - #139295 (Remove creation of duplicate `AnonPipe`)
 - #139313 (Deduplicate some `rustc_middle` function bodies by calling the `rustc_type_ir` equivalent)
 - #139317 (compiletest: Encapsulate all of the code that touches libtest)
 - #139322 (Add helper function for checking LLD usage to `run-make-support`)
 - #139335 (Pass correct param-env to `error_implies`)
 - #139342 (Add a mailmap entry for myself)
 - #139349 (adt_destructor: sanity-check returned item)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-04-04 08:52:02 +00:00
Matthias Krüger
0a9eae161b
Rollup merge of #139349 - meithecatte:destructor-constness, r=compiler-errors
adt_destructor: sanity-check returned item

Fixes #139278
2025-04-04 08:02:09 +02:00
Matthias Krüger
0c4ac89760
Rollup merge of #139342 - meithecatte:mailmap, r=compiler-errors
Add a mailmap entry for myself
2025-04-04 08:02:09 +02:00
Matthias Krüger
c264f3e4d8
Rollup merge of #139335 - compiler-errors:error-implies, r=oli-obk
Pass correct param-env to `error_implies`

Duplicated comment from the test:

In the error reporting code, when reporting fulfillment errors for goals A and B, we try to see if elaborating A will result in another goal that can equate with B. That would signal that B is "implied by" A, allowing us to skip reporting it, which is beneficial for cutting down on the number of diagnostics we report.

In the new trait solver especially, but even in the old trait solver through things like defining opaque type usages, this `can_equate` call was not properly taking the param-env of the goals, resulting in nested obligations that had empty param-envs. If one of these nested obligations was a `ConstParamHasTy` goal, then we would ICE, since those goals are particularly strict about the param-env they're evaluated in.

This is morally a fix for <https://github.com/rust-lang/rust/issues/139314>, but that repro uses details about how defining usages in the `check_opaque_well_formed` code can spring out of type equality, and will likely stop failing soon coincidentally once we start using `PostBorrowck` mode in that check. Instead, we use lazy normalization to end up generating an alias-eq goal whose nested goals woul trigger the ICE instead, since this is a lot more stable.

Fixes https://github.com/rust-lang/rust/issues/139314

r? ``@oli-obk`` or reassign
2025-04-04 08:02:08 +02:00
Matthias Krüger
2e8bd29de4
Rollup merge of #139322 - Kobzol:run-make-lld-refactor, r=jieyouxu
Add helper function for checking LLD usage to `run-make-support`

Extracted out of https://github.com/rust-lang/rust/pull/138645, should be a simple refactoring.

r? ``@jieyouxu``
2025-04-04 08:02:08 +02:00
Matthias Krüger
9d846764c4
Rollup merge of #139317 - Zalathar:hide-libtest, r=jieyouxu
compiletest: Encapsulate all of the code that touches libtest

Compiletest currently relies on unstable libtest APIs in order to actually execute tests. That's unfortunate, but removing the dependency isn't trivial.

However, we can make a small step towards removing the libtest dependency by encapsulating the libtest interactions into a single dedicated module. That makes it easier to see what parts of libtest are actually used.

---

As a side-effect of moving the `test_opts` function into that dedicated module, this PR also ends up allowing `--fail-fast` to be passed on the command line, instead of requiring an environment variable.

---

There is still (at least) one other aspect of the libtest dependency that this PR does not address, namely the fact that we rely on libtest's output capture (via unstable std APIs) to capture the output that we print during individual tests. I hope to do something about that at some point.

r? jieyouxu
2025-04-04 08:02:07 +02:00
Matthias Krüger
96ab10c087
Rollup merge of #139313 - oli-obk:push-uzvmpxqyvrzp, r=compiler-errors
Deduplicate some `rustc_middle` function bodies by calling the `rustc_type_ir` equivalent

Maybe in the future we can use method delegation, but I'd rather avoid that for now (I don't even know if it can do that already)
2025-04-04 08:02:06 +02:00
Matthias Krüger
f701a5cc38
Rollup merge of #139295 - JakeWharton:jw.duplicate-anon-pipe.2025-04-02, r=joboet
Remove creation of duplicate `AnonPipe`

The `File` is unwrapped to a `Handle` into an `AnonPipe`, and then that `AnonPipe` was unwrapped to a `Handle` into another `AnonPipe`. The second operation is entirely redundant.
2025-04-04 08:02:06 +02:00
Matthias Krüger
66e61c78e7
Rollup merge of #138949 - madsmtm:rename-to-darwin, r=WaffleLapkin
Rename `is_like_osx` to `is_like_darwin`

Replace `is_like_osx` with `is_like_darwin`, which more closely describes reality (OS X is the pre-2016 name for macOS, and is by now quite outdated; Darwin is the overall name for the OS underlying Apple's macOS, iOS, etc.).

``@rustbot`` label O-apple
r? compiler
2025-04-04 08:02:05 +02:00
bors
f174fd716a Auto merge of #139287 - compiler-errors:folder-experiment-1, r=lqd
Folder experiment: Monomorphize region resolver

**NOTE:** This is one of a series of perf experiments that I've come up with while sick in bed. I'm assigning them to lqd b/c you're a good reviewer and you'll hopefully be awake when these experiments finish, lol.

r? lqd

This is actually two tweaks to the `RegionFolder`, monomorphizing its callback and accounting for flags to avoid folding unnecessarily.
2025-04-04 05:41:45 +00:00
Maja Kądziołka
a14e8f687c
adt_destructor: sanity-check returned item
Fixes #139278
2025-04-04 05:18:48 +02:00
bors
9e14530c7c Auto merge of #120706 - Bryanskiy:leak, r=lcnr
Initial support for auto traits with default bounds

This PR is part of ["MCP: Low level components for async drop"](https://github.com/rust-lang/compiler-team/issues/727)
Tracking issue: #138781
Summary: https://github.com/rust-lang/rust/pull/120706#issuecomment-1934006762

### Intro

Sometimes we want to use type system to express specific behavior and provide safety guarantees. This behavior can be specified by various "marker" traits. For example, we use `Send` and `Sync` to keep track of which types are thread safe. As the language develops, there are more problems that could be solved by adding new marker traits:

- to forbid types with an async destructor to be dropped in a synchronous context a trait like `SyncDrop` could be used [Async destructors, async genericity and completion futures](https://sabrinajewson.org/blog/async-drop).
- to support [scoped tasks](https://without.boats/blog/the-scoped-task-trilemma/) or in a more general sense to provide a [destruction guarantee](https://zetanumbers.github.io/book/myosotis.html) there is a desire among some users to see a `Leak` (or `Forget`) trait.
- Withoutboats in his [post](https://without.boats/blog/changing-the-rules-of-rust/) reflected on the use of `Move` trait instead of a `Pin`.

All the traits proposed above are supposed to be auto traits implemented for most types, and usually implemented automatically by compiler.

For backward compatibility these traits have to be added implicitly to all bound lists in old code (see below). Adding new default bounds involves many difficulties: many standard library interfaces may need to opt out of those default bounds, and therefore be infected with confusing `?Trait` syntax, migration to a new edition may contain backward compatibility holes, supporting new traits in the compiler can be quite difficult and so forth. Anyway, it's hard to evaluate the complexity until we try the system on a practice.

In this PR we introduce new optional lang items for traits that are added to all bound lists by default, similarly to existing `Sized`. The examples of such traits could be `Leak`, `Move`, `SyncDrop` or something else, it doesn't matter much right now (further I will call them `DefaultAutoTrait`'s). We want to land this change into rustc under an option, so it becomes available in bootstrap compiler. Then we'll be able to do standard library experiments with the aforementioned traits without adding hundreds of `#[cfg(not(bootstrap))]`s. Based on the experiments, we can come up with some scheme for the next edition, in which such bounds are added in a more targeted way, and not just everywhere.

Most of the implementation is basically a refactoring that replaces hardcoded uses of `Sized` with iterating over a list of traits including both `Sized` and the new traits when `-Zexperimental-default-bounds` is enabled (or just `Sized` as before, if the option is not enabled).

### Default bounds for old editions

All existing types, including generic parameters, are considered `Leak`/`Move`/`SyncDrop` and can be forgotten, moved or destroyed in generic contexts without specifying any bounds. New types that cannot be, for example, forgotten and do not implement `Leak` can be added at some point, and they should not be usable in such generic contexts in existing code.

To both maintain this property and keep backward compatibility with existing code, the new traits should be added as default bounds _everywhere_ in previous editions. Besides the implicit `Sized` bound contexts that includes supertrait lists and trait lists in trait objects (`dyn Trait1 + ... + TraitN`). Compiler should also generate implicit `DefaultAutoTrait` implementations for foreign types (`extern { type Foo; }`) because they are also currently usable in generic contexts without any bounds.

#### Supertraits

Adding the new traits as supertraits to all existing traits is potentially necessary, because, for example, using a `Self` param in a trait's associated item may be a breaking change otherwise:

```rust
trait Foo: Sized {
    fn new() -> Option<Self>; // ERROR: `Option` requires `DefaultAutoTrait`, but `Self` is not `DefaultAutoTrait`
}

// desugared `Option`
enum Option<T: DefaultAutoTrait + Sized> {
    Some(T),
    None,
}
```

However, default supertraits can significantly affect compiler performance. For example, if we know that `T: Trait`, the compiler would deduce that `T: DefaultAutoTrait`. It also implies proving `F: DefaultAutoTrait` for each field `F` of type `T` until an explicit impl is be provided.

If the standard library is not modified, then even traits like `Copy` or `Send` would get these supertraits.

In this PR for optimization purposes instead of adding default supertraits, bounds are added to the associated items:

```rust
// Default bounds are generated in the following way:
trait Trait {
   fn foo(&self) where Self: DefaultAutoTrait {}
}

// instead of this:
trait Trait: DefaultAutoTrait {
   fn foo(&self) {}
}
```

It is not always possible to do this optimization because of backward compatibility:

```rust
pub trait Trait<Rhs = Self> {}
pub trait Trait1 : Trait {} // ERROR: `Rhs` requires `DefaultAutoTrait`, but `Self` is not `DefaultAutoTrait`
```

or

```rust
trait Trait {
   type Type where Self: Sized;
}
trait Trait2<T> : Trait<Type = T> {} // ERROR: `???` requires `DefaultAutoTrait`, but `Self` is not `DefaultAutoTrait`
```

Therefore, `DefaultAutoTrait`'s are still being added to supertraits if the `Self` params or type bindings were found in the trait header.

#### Trait objects

Trait objects requires explicit `+ Trait` bound to implement corresponding trait which is not backward compatible:

```rust
fn use_trait_object(x: Box<dyn Trait>) {
   foo(x) // ERROR: `foo` requires `DefaultAutoTrait`, but `dyn Trait` is not `DefaultAutoTrait`
}

// implicit T: DefaultAutoTrait here
fn foo<T>(_: T) {}
```

So, for a trait object `dyn Trait` we should add an implicit bound `dyn Trait + DefaultAutoTrait` to make it usable, and allow relaxing it with a question mark syntax `dyn Trait + ?DefaultAutoTrait` when it's not necessary.

#### Foreign types

If compiler doesn't generate auto trait implementations for a foreign type, then it's a breaking change if the default bounds are added everywhere else:

```rust
// implicit T: DefaultAutoTrait here
fn foo<T: ?Sized>(_: &T) {}

extern "C" {
    type ExternTy;
}

fn forward_extern_ty(x: &ExternTy) {
    foo(x); // ERROR: `foo` requires `DefaultAutoTrait`, but `ExternTy` is not `DefaultAutoTrait`
}
```

We'll have to enable implicit `DefaultAutoTrait` implementations for foreign types at least for previous editions:

```rust
// implicit T: DefaultAutoTrait here
fn foo<T: ?Sized>(_: &T) {}

extern "C" {
    type ExternTy;
}

impl DefaultAutoTrait for ExternTy {} // implicit impl

fn forward_extern_ty(x: &ExternTy) {
    foo(x); // OK
}
```

### Unresolved questions

New default bounds affect all existing Rust code complicating an already complex type system.

- Proving an auto trait predicate requires recursively traversing the type and proving the predicate for it's fields. This leads to a significant performance regression. Measurements for the stage 2 compiler build show up to 3x regression.
    - We hope that fast path optimizations for well known traits could mitigate such regressions at least partially.
- New default bounds trigger some compiler bugs in both old and new trait solver.
- With new default bounds we encounter some trait solver cycle errors that break existing code.
    - We hope that these cases are bugs that can be addressed in the new trait solver.

Also migration to a new edition could be quite ugly and enormous, but that's actually what we want to solve. For other issues there's a chance that they could be solved by a new solver.
2025-04-04 01:35:52 +00:00
Maja Kądziołka
ad1fb1e208
Add a mailmap entry for myself 2025-04-04 01:34:35 +02:00
bors
4fd8c04da0 Auto merge of #139336 - matthiaskrgr:rollup-zsi8pgf, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #138017 (Tighten up assignment operator representations.)
 - #138462 (Dedup `&mut *` reborrow suggestion in loops)
 - #138610 (impl !PartialOrd for HirId)
 - #138767 (Allow boolean literals in `check-cfg`)
 - #139068 (io: Avoid marking some bytes as uninit)
 - #139255 (Remove unused variables generated in merged doctests)
 - #139270 (Add a mailmap entry for myself)
 - #139303 (Put Noratrieb on vacation)
 - #139312 (add Marco Ieni to mailmap)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-04-03 22:26:29 +00:00
Matthias Krüger
4cf6c21f3a
Rollup merge of #139312 - marcoieni:marco-mailmap, r=Kobzol
add Marco Ieni to mailmap
2025-04-03 21:18:33 +02:00
Matthias Krüger
42aef0c1ab
Rollup merge of #139303 - Noratrieb:Noratrieb-patch-3, r=Noratrieb
Put Noratrieb on vacation

My review queue has gotten a bit out of hand. I'll work on reviewing those PRs before taking up new ones.
2025-04-03 21:18:33 +02:00
Matthias Krüger
ec9aa8c36b
Rollup merge of #139270 - RossSmyth:mailmap, r=Noratrieb
Add a mailmap entry for myself

Turns out I have not been at all consistent. Oops.
2025-04-03 21:18:32 +02:00
Matthias Krüger
ed6efe6723
Rollup merge of #139255 - GuillaumeGomez:unused-var-merged-doctest, r=fmease
Remove unused variables generated in merged doctests

The variable is unused so no need to keep it around.

cc `@notriddle`
r? `@camelid`
2025-04-03 21:18:31 +02:00
Matthias Krüger
ff8f2eff3a
Rollup merge of #139068 - a1phyr:less_uninit, r=joboet
io: Avoid marking some bytes as uninit

These bytes were marked as uninit, which would cause them to be initialized multiple times even though it was not necessary.
2025-04-03 21:18:31 +02:00
Matthias Krüger
9d733eca06
Rollup merge of #138767 - clubby789:check-cfg-bool, r=Urgau
Allow boolean literals in `check-cfg`

https://github.com/rust-lang/rust/pull/138632#issuecomment-2738114495
This makes it consistent with `--cfg`

We could alternatively add a forward-compatible lint against `--cfg true/false`
r? `@Urgau`
2025-04-03 21:18:30 +02:00
Matthias Krüger
48a3919884
Rollup merge of #138610 - oli-obk:no-sort-hir-ids, r=compiler-errors
impl !PartialOrd for HirId

revive of https://github.com/rust-lang/rust/pull/92233

Another checkbox of https://github.com/rust-lang/rust/issues/90317, another small step in making incremental less likely to die in horrible ways
2025-04-03 21:18:30 +02:00
Matthias Krüger
731ce84d19
Rollup merge of #138462 - ShE3py:mut-borrow-in-loop, r=oli-obk
Dedup `&mut *` reborrow suggestion in loops

#73534 added a reborrow suggestion in loops; #127579 generalized this to generic parameters, making the suggestion triggers twice:
```rs
use std::io::Read;

fn decode_scalar(_reader: impl Read) {}
fn decode_array(reader: &mut impl Read) {
    for _ in 0.. {
        decode_scalar(reader);
    }
}
```
```
error[E0382]: use of moved value: `reader`
 --> src/lib.rs:6:23
  |
4 | fn decode_array(reader: &mut impl Read) {
  |                 ------ move occurs because `reader` has type `&mut impl Read`, which does not implement the `Copy` trait
5 |     for _ in 0.. {
  |     ------------ inside of this loop
6 |         decode_scalar(reader);
  |                       ^^^^^^ value moved here, in previous iteration of loop
  |
help: consider creating a fresh reborrow of `reader` here
  |
6 |         decode_scalar(&mut *reader);
  |                       ++++++
help: consider creating a fresh reborrow of `reader` here
  |
6 |         decode_scalar(&mut *reader);
  |                       ++++++
```
This PR removes the suggestion in loops, as it requires generic parameters anyway (i.e., the reborrow is automatic if there is no generic params).

`@rustbot` label +A-borrow-checker +A-diagnostics +A-suggestion-diagnostics +D-papercut
2025-04-03 21:18:29 +02:00
Matthias Krüger
e5c7451a10
Rollup merge of #138017 - nnethercote:tighten-assignment-op, r=spastorino
Tighten up assignment operator representations.

This is step 3 of [MCP 831](https://github.com/rust-lang/compiler-team/issues/831).

r? `@spastorino`
2025-04-03 21:18:28 +02:00
bors
00095b3da4 Auto merge of #132527 - DianQK:gvn-stmt-iter, r=oli-obk
gvn: Invalid dereferences for all non-local mutations

Fixes #132353.

This PR removes the computation value by traversing SSA locals through `for_each_assignment_mut`.

Because the `for_each_assignment_mut` traversal skips statements which have side effects, such as dereference assignments, the computation may be unsound. Instead of `for_each_assignment_mut`, we compute values by traversing in reverse postorder.

Because we compute and use the symbolic representation of values on the fly, I invalidate all old values when encountering a dereference assignment. The current approach does not prevent the optimization of a clone to a copy.

In the future, we may add an alias model, or dominance information for dereference assignments, or SSA form to help GVN.

r? cjgillot

cc `@jieyouxu` #132356
cc `@RalfJung` #133474
2025-04-03 19:17:33 +00:00
Michael Goulet
64b58dd13b Pass correct param-env to error_implies 2025-04-03 18:55:53 +00:00
Oli Scherer
6189594c0a Deduplicate some rustc_middle function bodies by calling the rustc_type_ir equivalent 2025-04-03 15:44:37 +00:00
bors
82eb03ec62 Auto merge of #139301 - matthiaskrgr:rollup-sa6ali8, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #139080 (Experimental feature gate for `super let`)
 - #139145 (slice: Remove some uses of unsafe in first/last chunk methods)
 - #139149 (unstable book: document import_trait_associated_functions)
 - #139273 (Apply requested API changes to `cell_update`)
 - #139282 (rustdoc: make settings checkboxes always square)
 - #139283 (Rustc dev guide subtree update)
 - #139294 (Fix the `f16`/`f128` feature gates on integer literals)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-04-03 15:31:20 +00:00
bjorn3
fde54c2c03 Fix testing with randomized layouts enabled 2025-04-03 15:30:01 +00:00
dianqk
7d44887374
Invalid dereferences for all non-local mutations 2025-04-03 21:59:49 +08:00
dianqk
4e05d858ad
Only preserving derefs for trivial terminators like SwitchInt and Goto 2025-04-03 21:59:49 +08:00
dianqk
ac7dd7a1b3
Remove unsound-mir-opts for simplify_aggregate_to_copy 2025-04-03 21:59:43 +08:00
Jakub Beránek
9ec11c246d
Move link-self-contained-consistency test to a more reasonable location 2025-04-03 15:41:38 +02:00
Jakub Beránek
6af96f873a
Add a helper function for checking if LLD was used to run-make-support 2025-04-03 15:40:23 +02:00
Zalathar
ecf9e204c9 compiletest: Encapsulate all of the code that touches libtest 2025-04-03 23:15:09 +11:00
bjorn3
13970949d1 Run coretests and alloctests with cg_clif in CI 2025-04-03 12:07:14 +00:00
bors
946aea0b3d Auto merge of #139137 - petrochenkov:errwhere2, r=jieyouxu
compiletest: Require `//~` annotations even if `error-pattern` is specified

This is continuation of #138865 with some help from #139100.

`error-pattern` annotations that duplicate the newly added `//~` annotations are removed, other `error-pattern`s are not touched yet.

In exceptional cases `//@ compile-flags: --error-format=human` can be used to opt out of these checks.
In this PR I only had to use the opt out 3 times:
- `tests/ui/parser/utf16-{be,le}-without-bom.rs` - there are too many errors that are nearly identical (modulo location), because an error is reported on every second symbol
- `tests/ui-fulldeps/missing-rustc-driver-error.rs` - the errors list various rustc crate dependencies and may unexpectedly invalidate on random rustc changes
2025-04-03 12:05:32 +00:00
Bryanskiy
581c5fbc40 Initial support for auto traits with default bounds 2025-04-03 14:59:39 +03:00
Zalathar
3e762b1897 compiletest: Allow --fail-fast as a command-line option 2025-04-03 22:06:29 +11:00
MarcoIeni
b310e8cd8f
add Marco Ieni to mailmap 2025-04-03 12:36:39 +02:00
clubby789
3df2acd31b Allow boolean literals in check-cfg 2025-04-03 09:54:23 +00:00
Oli Scherer
57c4ab7ff5 impl !PartialOrd for HirId 2025-04-03 09:22:21 +00:00
Oli Scherer
5a4e7eb040 impl !PartialOrd for UpvarMigrationInfo 2025-04-03 09:22:21 +00:00
Oli Scherer
0795b3de9b Upvars HirIds always have the same owner, thus just use an ItemLocalId 2025-04-03 09:22:21 +00:00
Oli Scherer
805f389da5 Remove LintExpectationId from Level variants 2025-04-03 09:22:21 +00:00
Oli Scherer
c51816ee59 Make LevelAndSource a struct 2025-04-03 09:17:55 +00:00
Oli Scherer
f3eaf1624c Split ExpectationLintId off Level 2025-04-03 09:17:55 +00:00
bors
e0883a2a6c Auto merge of #137738 - Daniel-Aaron-Bloom:const_slice_make_iter, r=dtolnay
Make slice iterator constructors unstably const

See [tracking issue](https://github.com/rust-lang/rust/issues/137737) for justification.

try-job: aarch64-apple
try-job: x86_64-gnu
2025-04-03 08:57:46 +00:00
bjorn3
fadea8e0ba Unset RUSTC_WRAPPER in cg_clif's build system 2025-04-03 08:53:15 +00:00