Commit Graph

641 Commits

Author SHA1 Message Date
Oli Scherer
93bc34073e
Rollup merge of #121039 - cjgillot:gvn-adjust, r=compiler-errors
Correctly compute adjustment casts in GVN

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

r? `@oli-obk`
2024-02-14 11:53:41 +01:00
Camille GILLOT
7ec9601a0b Add test. 2024-02-13 17:21:53 +00:00
Matthias Krüger
b785fdb80b
Rollup merge of #120978 - Nadrieril:sane-blocks, r=matthewjasper
match lowering: simplify block creation

Match lowering was doing complicated things with block creation. As far as I can tell it was trying to avoid creating unneeded blocks, but of the three places that start out with `otherwise = &mut None`, two of them called `otherwise.unwrap_or_else(|| self.cfg.start_new_block())` anyway. As far as I can tell the only place where this PR makes a difference is in `lower_match_tree`, which did indeed sometimes avoid creating the unreachable final block + FakeRead. Unless this is important I propose we do the naive thing instead.

I have not checked all the graph isomorphisms by hand, but at a glance the test diff looks sensible.

r? `@matthewjasper`
2024-02-13 17:38:11 +01:00
Nadrieril
faaf81bbbc Start blocks eagerly 2024-02-12 17:37:05 +01:00
Frank King
7660d6bf2c Check representation of unnamed fields 2024-02-12 12:47:31 +08:00
Frank King
0c0df4efe0 Lowering field access for anonymous adts 2024-02-12 12:47:30 +08:00
bors
a166af7729 Auto merge of #120903 - matthiaskrgr:rollup-tmsuzth, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #119213 (simd intrinsics: add simd_shuffle_generic and other missing intrinsics)
 - #120272 (Suppress suggestions in derive macro)
 - #120773 (large_assignments: Allow moves into functions)
 - #120874 (Take empty `where` bounds into account when suggesting predicates)
 - #120882 (interpret/write_discriminant: when encoding niched variant, ensure the stored value matches)
 - #120883 (interpret: rename ReadExternStatic → ExternStatic)
 - #120890 (Adapt `llvm-has-rust-patches` validation to take `llvm-config` into account.)
 - #120895 (don't skip coercions for types with errors)
 - #120896 (Print kind of coroutine closure)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-02-11 17:43:51 +00:00
bors
9aa232ecc7 Auto merge of #120405 - cjgillot:gvn-pointer, r=oli-obk
Fold pointer operations in GVN

This PR proposes 2 combinations of cast operations in MIR GVN:
- a chain of `PtrToPtr` or `MutToConstPointer` casts can be folded together into a single `PtrToPtr` cast;
- we attempt to evaluate more ptr ops when there is no provenance.

In particular, this allows to read from static slices.

This is not yet sufficient to see through slice operations that use `PtrComponents` (because that's a union), but still a step forward.

r? `@ghost`
2024-02-11 04:24:40 +00:00
Matthias Krüger
870435b50b
Rollup merge of #120896 - compiler-errors:coro-closure-kind, r=oli-obk
Print kind of coroutine closure

Make sure that we print "async closure" when we have an async closure, rather than calling it generically a ["coroutine-closure"](https://github.com/rust-lang/rust/pull/120361).

Fixes #120886

r? oli-obk
2024-02-11 01:37:57 +01:00
Michael Goulet
86ddb53cab Print kind of coroutine closure 2024-02-10 23:18:01 +00:00
Camille GILLOT
014b29eecf Remove ConstGoto and SeparateConstSwitch. 2024-02-09 21:13:53 +00:00
Camille GILLOT
e132cac3c4 Enable by default. 2024-02-09 21:13:51 +00:00
Camille GILLOT
a2a9125d6a Add test for ptr ops with same provenance. 2024-02-09 21:06:24 +00:00
Camille GILLOT
d50f26e409 Const-prop pointers. 2024-02-09 21:06:23 +00:00
Camille GILLOT
5a6f14c4f4 Split gvn wide ptr tests. 2024-02-09 21:01:57 +00:00
Camille GILLOT
28df0a62f6 Compute binary ops between pointers in GVN. 2024-02-09 21:01:57 +00:00
Camille GILLOT
304b4ad8b9 Compute unsizing casts in GVN. 2024-02-09 21:01:57 +00:00
Camille GILLOT
1f544ca0cc Fold consecutive PtrToPtr casts. 2024-02-09 21:01:56 +00:00
Ben Kimock
611c3cb561 Bless/fix tests 2024-02-08 19:56:30 -05:00
Matthias Krüger
65aa9eae73
Rollup merge of #120688 - cjgillot:gvn-partial-move, r=oli-obk
GVN: also turn moves into copies with projections

Fixes https://github.com/rust-lang/rust/issues/120613
2024-02-08 09:06:34 +01:00
Matthias Krüger
7fb36f2d3b
Rollup merge of #120214 - Nadrieril:fix-120210, r=pnkfelix
match lowering: consistently lower bindings deepest-first

Currently when lowering match expressions to MIR, we do a funny little dance with the order of bindings. I attempt to explain it in the third commit: we handle refutable (i.e. needing a test) patterns differently than irrefutable ones. This leads to inconsistencies, as reported in https://github.com/rust-lang/rust/issues/120210. The reason we need a dance at all is for situations like:

```rust
fn foo1(x: NonCopyStruct) {
    let y @ NonCopyStruct { copy_field: z } = x;
    // the above should turn into
    let z = x.copy_field;
    let y = x;
}
```

Here the `y ```````@```````` binding will move out of `x`, so we need to copy the field first.

I believe that the inconsistency came about when we fixed https://github.com/rust-lang/rust/issues/69971, and didn't notice that the fix didn't extend to refutable patterns. My guess then is that ordering bindings by "deepest-first, otherwise source order" is a sound choice. This PR implements that (at least I hope, match lowering is hard to follow 🥲).

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

r? ```````@oli-obk``````` since you merged the original fix to https://github.com/rust-lang/rust/issues/69971
cc ```````@matthewjasper```````
2024-02-08 09:06:33 +01:00
Guillaume Boisseau
65c09546ac
Rollup merge of #120455 - JarlEvanson:sroa-miri-tests, r=cjgillot
Add FileCheck annotations to MIR-opt SROA tests

Part of #116971, adds FileCheck annotations to SROA MIR-opt tests in `tests/mir-opt/sroa` and a few uncategorized files.

r? cjgillot
2024-02-07 18:24:42 +01:00
Ben Kimock
3c7a8b9d71 Fixup async_closure_shims mir-opt test 2024-02-06 23:40:58 -05:00
Ben Kimock
2116ed723d Tweak a few mir-opt tests instead of using -Clink-dead-code 2024-02-06 23:36:05 -05:00
Ben Kimock
4451bf4d67 Use a better set of targets for blessing mir-opt tests 2024-02-06 23:36:05 -05:00
Michael Goulet
ca44416023 Fix drop shim for AsyncFnOnce closure, AsyncFnMut shim for AsyncFn closure 2024-02-06 02:22:58 +00:00
Michael Goulet
427896dd7e Construct body for by-move coroutine closure output 2024-02-06 02:22:58 +00:00
Camille GILLOT
6fbd761644 Also turn moves into copies even if through projections. 2024-02-05 23:31:54 +00:00
Camille GILLOT
c151ed4764 Add test. 2024-02-05 23:26:37 +00:00
Matthias Krüger
2b259577aa
Rollup merge of #119759 - sfzhu93:master, r=cjgillot
Add FileCheck annotations to dataflow-const-prop tests

part of #116971.

A few shadowing variable names are changed, so that it is easier to match the variable names in MIR using FileCheck syntax.

Also, there's a FIXME in [enum.rs](https://github.com/rust-lang/rust/pull/119759/files#diff-7621f55327838e489a95ac99ae1e6126b37c57aff582594e6bee9d7e7e56fc58) because the MIR looks suspicious to me. It has been explained in the comments.

r? cjgillot
2024-02-04 19:42:09 +01:00
Jarl Evanson
bae4f177b8
Enable structs SROA MIR-opt test 2024-02-04 12:04:39 -06:00
Guillaume Gomez
6e046fef29
Rollup merge of #120424 - RalfJung:raw-ptr-meta, r=Nilstrieb
raw pointer metadata API: data address -> data pointer

A pointer consists of [more than just an address](https://github.com/rust-lang/rfcs/pull/3559), so let's not equate "pointer" and "address" in these docs.
2024-01-30 11:19:16 +01:00
Ralf Jung
b4e1c569fe raw pointer metadata API: data address -> data pointer 2024-01-29 07:56:38 +01:00
sfzhu93
699b59c01d update terminator.rs 2024-01-28 22:44:32 -08:00
Jarl Evanson
103159809a
Enable lifetimes SROA MIR-opt test 2024-01-28 16:04:07 -06:00
Jarl Evanson
d1edc9d0db
Enable simplify MIR-opt test 2024-01-28 13:50:20 -06:00
Jarl Evanson
f38489e957
Enable remove_storage_markers MIR-opt test 2024-01-28 13:47:52 -06:00
Markus Reiter
021739c840
Update tests. 2024-01-27 16:38:57 +01:00
Matthias Krüger
346397d081
Rollup merge of #119562 - LegionMammal978:rename-pin-pointer, r=Amanieu,dtolnay
Rename `pointer` field on `Pin`

A few days ago, I was helping another user create a self-referential type using `PhantomPinned`. However, I noticed an odd behavior when I tried to access one of the type's fields via `Pin`'s `Deref` impl:

```rust
use std::{marker::PhantomPinned, ptr};

struct Pinned {
    data: i32,
    pointer: *const i32,
    _pin: PhantomPinned,
}

fn main() {
    let mut b = Box::pin(Pinned {
        data: 42,
        pointer: ptr::null(),
        _pin: PhantomPinned,
    });
    {
        let pinned = unsafe { b.as_mut().get_unchecked_mut() };
        pinned.pointer = &pinned.data;
    }
    println!("{}", unsafe { *b.pointer });
}
```

```rust
error[E0658]: use of unstable library feature 'unsafe_pin_internals'
  --> <source>:19:30
   |
19 |     println!("{}", unsafe { *b.pointer });
   |                              ^^^^^^^^^

error[E0277]: `Pinned` doesn't implement `std::fmt::Display`
  --> <source>:19:20
   |
19 |     println!("{}", unsafe { *b.pointer });
   |                    ^^^^^^^^^^^^^^^^^^^^^ `Pinned` cannot be formatted with the default formatter
   |
   = help: the trait `std::fmt::Display` is not implemented for `Pinned`
   = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
   = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
```

Since the user named their field `pointer`, it conflicts with the `pointer` field on `Pin`, which is public but unstable since Rust 1.60.0 with #93176. On versions from 1.33.0 to 1.59.0, where the field on `Pin` is private, this program compiles and prints `42` as expected.

To avoid this confusing behavior, this PR renames `pointer` to `__pointer`, so that it's less likely to conflict with a `pointer` field on the underlying type, as accessed through the `Deref` impl. This is technically a breaking change for anyone who names their field `__pointer` on the inner type; if this is undesirable, it could be renamed to something more longwinded. It's also a nightly breaking change for any external users of `unsafe_pin_internals`.
2024-01-26 23:15:49 +01:00
Ralf Jung
64cd13ff3b add test for GVN issue; cleanup in dataflow_const_prop 2024-01-26 10:40:29 +01:00
Michael Goulet
3004e8c44b Remove coroutine info when building coroutine drop body 2024-01-25 03:26:29 +00:00
Nadrieril
09d4613f20 Put new bindings first in refutable cases too 2024-01-25 02:56:02 +01:00
sfzhu93
65b10839d6 update enum.rs 2024-01-22 17:34:49 -08:00
Camille GILLOT
d7a7be4049 Add test for jump-threading assume. 2024-01-23 00:00:22 +00:00
Camille GILLOT
161c674ef0 Add Assume custom MIR. 2024-01-22 23:55:10 +00:00
Nadrieril
203cc6930e
Rollup merge of #119461 - cjgillot:jump-threading-interp, r=tmiasko
Use an interpreter in MIR jump threading

This allows to understand assignments of aggregate constants. This case appears more frequently with GVN promoting aggregates to constants.
2024-01-21 06:38:36 +01:00
sfzhu93
7ad307dc9d finish a pattern in enum.rs 2024-01-20 08:22:07 -08:00
sfzhu93
edba94907d update misuse of check-label 2024-01-20 08:09:14 -08:00
George Bateman
803b810eac
Remove feature(offset_of) from tests 2024-01-19 20:38:51 +00:00
Camille GILLOT
be9668d398 Use an interpreter in jump threading. 2024-01-18 22:53:07 +00:00