Commit Graph

118 Commits

Author SHA1 Message Date
Matthias Krüger
08187c32c7
Rollup merge of #129664 - adetaylor:arbitrary-self-types-pointers-feature-gate, r=wesleywiser
Arbitrary self types v2: pointers feature gate.

The main `arbitrary_self_types` feature gate will shortly be reused for a new version of arbitrary self types which we are amending per [this RFC](https://github.com/rust-lang/rfcs/blob/master/text/3519-arbitrary-self-types-v2.md). The main amendments are:

* _do_ support `self` types which can't safely implement `Deref`
* do _not_ support generic `self` types
* do _not_ support raw pointers as `self` types.

This PR relates to the last of those bullet points: this strips pointer support from the current `arbitrary_self_types` feature. We expect this to cause some amount of breakage for crates using this unstable feature to allow raw pointer self types. If that's the case, we want to know about it, and we want crate authors to know of the upcoming changes.

For now, this can be resolved by adding the new
`arbitrary_self_types_pointers` feature to such crates. If we determine that use of raw pointers as self types is common, then we may maintain that as an unstable feature even if we come to stabilize the rest of the `arbitrary_self_types` support in future. If we don't hear that this PR is causing breakage, then perhaps we don't need it at all, even behind an unstable feature gate.

[Tracking issue](https://github.com/rust-lang/rust/issues/44874)

This is [step 4 of the plan outlined here](https://github.com/rust-lang/rust/issues/44874#issuecomment-2122179688)
2024-09-05 03:47:42 +02:00
Camille GILLOT
f68f66538a Create opaque definitions in resolver. 2024-08-31 20:14:43 +00:00
Adrian Taylor
e77eb042ce Arbitrary self types v2: pointers feature gate.
The main `arbitrary_self_types` feature gate will shortly be reused for
a new version of arbitrary self types which we are amending per [this
RFC](https://github.com/rust-lang/rfcs/blob/master/text/3519-arbitrary-self-types-v2.md).
The main amendments are:

* _do_ support `self` types which can't safely implement `Deref`
* do _not_ support generic `self` types
* do _not_ support raw pointers as `self` types.

This PR relates to the last of those bullet points: this strips pointer
support from the current `arbitrary_self_types` feature.
We expect this to cause some amount of breakage for crates using this
unstable feature to allow raw pointer self types. If that's the case, we
want to know about it, and we want crate authors to know of the upcoming
changes.

For now, this can be resolved by adding the new
`arbitrary_self_types_pointers` feature to such crates. If we determine
that use of raw pointers as self types is common, then we may maintain
that as an unstable feature even if we come to stabilize the rest of the
`arbitrary_self_types` support in future. If we don't hear that this PR
is causing breakage, then perhaps we don't need it at all, even behind
an unstable feature gate.

[Tracking issue](https://github.com/rust-lang/rust/issues/44874)

This is [step 4 of the plan outlined here](https://github.com/rust-lang/rust/issues/44874#issuecomment-2122179688)
2024-08-27 17:32:35 +00:00
Scott McMurray
99cb0c6bc3 Bless *all* the mir-opt tests 2024-08-18 16:07:33 -07:00
Scott McMurray
249a36ffbd Update mir-opt filechecks 2024-08-18 15:52:23 -07:00
Nadrieril
99468bb760 Update tests 2024-08-10 12:07:17 +02:00
Ralf Jung
212417b87f custom MIR: add support for tail calls 2024-08-05 18:23:14 +02:00
Nadrieril
e2fd9aa33e Set up false edges in lower_match_tree 2024-07-29 09:50:07 +02:00
Nadrieril
3e030b38ef Return the otherwise_block instead of passing it as argument
This saves a few blocks and matches the common `unpack!` paradigm.
2024-07-09 22:47:35 +02:00
Nadrieril
8a222ffd6b Don't try to save an extra block
This is preparation for the next commit.
2024-07-09 22:47:35 +02:00
bors
9dcaa7f92c Auto merge of #127028 - Nadrieril:fix-or-pat-expansion, r=matthewjasper
Fix regression in the MIR lowering of or-patterns

In https://github.com/rust-lang/rust/pull/126553 I made a silly indexing mistake and regressed the MIR lowering of or-patterns. This fixes it.

r? `@compiler-errors` because I'd like this to be merged quickly 🙏
2024-07-09 16:33:59 +00:00
Nadrieril
834f043a08 Fix expansion of or-patterns 2024-06-27 11:26:34 +02:00
Nadrieril
5df6f72057 Add test 2024-06-27 11:26:34 +02:00
Nadrieril
7b150a161e Don't use fake wildcards when we can get the failure block directly
This commit too was obtained by repeatedly inlining and simplifying.
2024-06-22 19:05:48 +02:00
Michael Goulet
0fc18e3a17 Remove DebugWithInfcx 2024-06-11 22:13:04 -04:00
Scott McMurray
a4d0fc39ba Add SingleUseConsts mir-opt pass 2024-06-10 00:06:02 -07:00
Oli Scherer
cbee17d502 Revert "Create const block DefIds in typeck instead of ast lowering"
This reverts commit ddc5f9b6c1.
2024-06-07 08:33:58 +00:00
Nicholas Nethercote
c9c80d2c5f rustfmt tests/mir-opt.
The only non-obvious changes:
- `building/storage_live_dead_in_statics.rs` has a `#[rustfmt::skip]`
  attribute to avoid reformating a table of data.
- Two `.mir` files have slight changes involving line numbers.
- In `unusual_item_types.rs` an `EMIT_MIR` annotation is moved to
  outside a function, which is the usual spot, because `tidy` complains
  if such a comment is indented.

The commit also tweaks the comments in `rustfmt.toml`.
2024-06-03 14:17:16 +10:00
Nicholas Nethercote
ac24299636 Reformat mir! macro invocations to use braces.
The `mir!` macro has multiple parts:
- An optional return type annotation.
- A sequence of zero or more local declarations.
- A mandatory starting anonymous basic block, which is brace-delimited.
- A sequence of zero of more additional named basic blocks.

Some `mir!` invocations use braces with a "block" style, like so:
```
mir! {
    let _unit: ();
    {
	let non_copy = S(42);
	let ptr = std::ptr::addr_of_mut!(non_copy);
	// Inside `callee`, the first argument and `*ptr` are basically
	// aliasing places!
	Call(_unit = callee(Move(*ptr), ptr), ReturnTo(after_call), UnwindContinue())
    }
    after_call = {
	Return()
    }
}
```
Some invocations use parens with a "block" style, like so:
```
mir!(
    let x: [i32; 2];
    let one: i32;
    {
	x = [42, 43];
	one = 1;
	x = [one, 2];
	RET = Move(x);
	Return()
    }
)
```
And some invocations uses parens with a "tighter" style, like so:
```
mir!({
    SetDiscriminant(*b, 0);
    Return()
})
```
This last style is generally used for cases where just the mandatory
starting basic block is present. Its braces are placed next to the
parens.

This commit changes all `mir!` invocations to use braces with a "block"
style. Why?

- Consistency is good.

- The contents of the invocation is a block of code, so it's odd to use
  parens. They are more normally used for function-like macros.

- Most importantly, the next commit will enable rustfmt for
  `tests/mir-opt/`. rustfmt is more aggressive about formatting macros
  that use parens than macros that use braces. Without this commit's
  changes, rustfmt would break a couple of `mir!` macro invocations that
  use braces within `tests/mir-opt` by inserting an extraneous comma.
  E.g.:
  ```
  mir!(type RET = (i32, bool);, { // extraneous comma after ';'
      RET.0 = 1;
      RET.1 = true;
      Return()
  })
  ```
  Switching those `mir!` invocations to use braces avoids that problem,
  resulting in this, which is nicer to read as well as being valid
  syntax:
  ```
  mir! {
      type RET = (i32, bool);
      {
	  RET.0 = 1;
	  RET.1 = true;
	  Return()
      }
  }
  ```
2024-06-03 13:24:44 +10:00
Scott McMurray
7150839552 Add custom mir support for PtrMetadata 2024-05-28 09:28:51 -07:00
Oli Scherer
ddc5f9b6c1 Create const block DefIds in typeck instead of ast lowering 2024-05-28 13:38:43 +00:00
Scott McMurray
95c0e5c6a8 Remove Rvalue::CheckedBinaryOp 2024-05-17 20:33:02 -07:00
bors
0f40f14b61 Auto merge of #123332 - Nadrieril:testkind-never, r=matthewjasper
never patterns: lower never patterns to `Unreachable` in MIR

This lowers a `!` pattern to "goto Unreachable". Ideally I'd like to read from the place to make it clear that the UB is coming from an invalid value, but that's tricky so I'm leaving it for later.

r? `@compiler-errors` how do you feel about a lil bit of MIR lowering
2024-05-07 15:14:20 +00:00
Nadrieril
57e8aebb6c Lower never patterns to Unreachable in mir 2024-05-04 16:30:01 +02:00
Nadrieril
92d65a92e2 Add tests 2024-05-04 16:20:47 +02:00
Ross Smyth
6967d1c0fc Stabilize exclusive_range 2024-05-02 19:42:31 -04:00
Gary Guo
cfee72aa24 Fix tests and bless 2024-04-24 13:12:33 +01:00
Nadrieril
50531806ee Add a non-shallow fake borrow 2024-04-20 16:01:35 +02:00
Nadrieril
511bd78863 Rework fake borrow calculation 2024-04-20 16:01:35 +02:00
Maybe Waffle
0bbe362901 Correctly change type when adding adjustments on top of NeverToAny 2024-04-19 11:05:02 +00:00
Maybe Waffle
4d749cad25 Add a test for a == b where a: !, b: !
(this currently produces malformed mir: we call `eq` with first argument not
being a reference)
2024-04-19 11:05:02 +00:00
Oli Scherer
c8dfb59406 bless mir-opt tests 2024-04-08 15:08:06 +00:00
Nadrieril
8021192d34 More precise false edges 2024-04-03 21:02:47 +02:00
Matthew Jasper
a277c901d9 Remove MIR unsafe check
This also remove safety information from MIR.
2024-04-03 08:50:12 +00:00
Jacob Pratt
e9ef8e1efa
Rollup merge of #122935 - RalfJung:with-exposed-provenance, r=Amanieu
rename ptr::from_exposed_addr -> ptr::with_exposed_provenance

As discussed on [Zulip](https://rust-lang.zulipchat.com/#narrow/stream/136281-t-opsem/topic/To.20expose.20or.20not.20to.20expose/near/427757066).

The old name, `from_exposed_addr`, makes little sense as it's not the address that is exposed, it's the provenance. (`ptr.expose_addr()` stays unchanged as we haven't found a better option yet. The intended interpretation is "expose the provenance and return the address".)

The new name nicely matches `ptr::without_provenance`.
2024-04-02 20:37:39 -04:00
Nadrieril
65efa5b3b9 Add FileCheck directives to the new tests. 2024-03-30 18:11:41 +01:00
Nadrieril
75d2e67ed2 Sort Eq candidates in the failure case too 2024-03-30 17:37:15 +01:00
Nadrieril
5ef9ad37ab Add test 2024-03-30 17:37:15 +01:00
Nadrieril
e67f5294df Regroup mir-opt tests of match building 2024-03-30 17:37:15 +01:00
Kevin Reid
3010fa9afb In pretty_print_type(), print async fn futures' paths instead of spans.
This makes `-Zprint-type-sizes`'s output easier to read, because the
name of an `async fn` is more immediately recognizable than its span.

I also deleted the comment "FIXME(eddyb) should use `def_span`." because
it appears to have already been fixed by commit 67727aa7c3.
2024-03-25 08:01:15 -07:00
Ralf Jung
038e7c6c38 rename MIR int2ptr casts to match library name 2024-03-23 13:18:33 +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
Ralf Jung
7d99e80c55 MIR printing: print the path of uneval'd const; refer to promoteds in a consistent way 2024-03-10 14:59:41 +01:00
Nadrieril
8c3688cbb5 Allocate candidate vectors as we sort them 2024-03-02 18:33:19 +01:00
Nadrieril
3d3b321c60 Use an enum instead of manually tracking indices for target_blocks 2024-03-02 18:33:17 +01:00
Zalathar
a7832b14b1 Make the success arms of if lhs || rhs meet up in a separate block
In the previous code, the success block of `lhs` would jump directly to the
success block of `rhs`. However, `rhs_success_block` could already contain
statements that are specific to the RHS, and the direct goto causes them to be
executed in the LHS success path as well.

This patch therefore creates a fresh block that the LHS and RHS success blocks
can both jump to.
2024-02-29 20:24:43 +11:00
许杰友 Jieyou Xu (Joe)
6e48b96692
[AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
Nadrieril
c00b38e9fb Don't bother to save a block 2024-02-17 20:21:57 +01:00
Nadrieril
faaf81bbbc Start blocks eagerly 2024-02-12 17:37:05 +01:00
Michael Goulet
427896dd7e Construct body for by-move coroutine closure output 2024-02-06 02:22:58 +00:00