Commit Graph

175 Commits

Author SHA1 Message Date
Dylan DPC
7721c7319d
Rollup merge of #110962 - cjgillot:no-hash-drops, r=compiler-errors
Make drop_flags an IndexVec.

Fixes https://github.com/rust-lang/rust/issues/91943
2023-04-29 11:27:56 +05:30
Camille GILLOT
7f26191aed Make drop_flags an IndexVec. 2023-04-28 20:12:45 +00:00
Pietro Albini
a7bb8c7851 handle cfg(bootstrap) 2023-04-28 08:47:55 -07:00
bors
43a78029b4 Auto merge of #110837 - scottmcm:offset-for-add, r=compiler-errors
Use MIR's `Offset` for pointer `add` too

~~Status: draft while waiting for #110822 to land, since this is built atop that.~~
~~r? `@ghost~~`

Canonical Rust code has mostly moved to `add`/`sub` on pointers, which take `usize`, instead of `offset` which takes `isize`.  (And, relatedly, when `sub_ptr` was added it turned out it replaced every single in-tree use of `offset_from`, because `usize` is just so much more useful than `isize` in Rust.)

Unfortunately, `intrinsics::offset` could only accept `*const` and `isize`, so there's a *huge* amount of type conversions back and forth being done.  They're identity conversions in the backend, but still end up producing quite a lot of unhelpful MIR.

This PR changes `intrinsics::offset` to accept `*const` *and* `*mut` along with `isize` *and* `usize`.  Conveniently, the backends and CTFE already handle this, since MIR's `BinOp::Offset` [already supports all four combinations](adaac6b166/compiler/rustc_const_eval/src/transform/validate.rs (L523-L528)).

To demonstrate the difference, I added some `mir-opt/pre-codegen/` tests around slice indexing.  Here's the difference to `[T]::get_mut`, since it uses `<*mut _>::add` internally:
```diff
`@@` -79,30 +70,21 `@@` fn slice_get_mut_usize(_1: &mut [u32], _2: usize) -> Option<&mut u32> {
         StorageLive(_12);                // scope 3 at $SRC_DIR/core/src/slice/index.rs:LL:COL
         StorageLive(_9);                 // scope 6 at $SRC_DIR/core/src/slice/index.rs:LL:COL
         _9 = _8 as *mut u32 (PtrToPtr);  // scope 11 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
-        StorageLive(_13);                // scope 13 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
-        _13 = _2 as isize (IntToInt);    // scope 13 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
-        StorageLive(_14);                // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
-        StorageLive(_15);                // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
-        _15 = _9 as *const u32 (Pointer(MutToConstPointer)); // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
-        _14 = Offset(move _15, _13);     // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
-        StorageDead(_15);                // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
-        _7 = move _14 as *mut u32 (PtrToPtr); // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
-        StorageDead(_14);                // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
-        StorageDead(_13);                // scope 13 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
+        _7 = Offset(_9, _2);             // scope 13 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
         StorageDead(_9);                 // scope 6 at $SRC_DIR/core/src/slice/index.rs:LL:COL
         StorageDead(_12);                // scope 3 at $SRC_DIR/core/src/slice/index.rs:LL:COL
         StorageDead(_11);                // scope 3 at $SRC_DIR/core/src/slice/index.rs:LL:COL
```
1c1c8e442a (diff-a841b6a4538657add3f39bc895744331453d0625e7aace128b1f604f0b63c8fdR80)
2023-04-28 09:26:59 +00:00
Scott McMurray
e1da77c76d Also use mir::Offset for pointer add 2023-04-27 22:44:42 -07:00
Matthias Krüger
cf911ac757
Rollup merge of #110766 - m-ou-se:fmt-rt, r=jyn514
More core::fmt::rt cleanup.

- Removes the `V1` suffix from the `Argument` and `Flag` types.

- Moves more of the format_args lang items into the `core::fmt::rt` module. (The only remaining lang item in `core::fmt` is `Arguments` itself, which is a public type.)

Part of https://github.com/rust-lang/rust/issues/99012

Follow-up to https://github.com/rust-lang/rust/pull/110616
2023-04-28 07:34:02 +02:00
Matthias Krüger
563eb04c5d
Rollup merge of #110864 - compiler-errors:into-future-stable, r=jackh726
`IntoFuture::into_future` is no longer unstable

We don't need to gate the `IntoFuture::into_future` call in `.await` lowering anymore.

``@bors`` rollup
2023-04-27 15:10:55 +02:00
Michael Goulet
c18e7b765f IntoFuture::into_future is no longer unstable 2023-04-26 22:44:18 +00:00
Scott McMurray
8bcfc0e597 Add some MIR pre-codegen tests for slice indexing 2023-04-26 14:43:36 -07:00
bors
9c044d77a3 Auto merge of #110822 - scottmcm:lower-offset-to-mir, r=compiler-errors
Lower `intrinsics::offset` to `mir::BinOp::Offset`

They're [semantically the same](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/enum.Rvalue.html#variant.BinaryOp), so this means the backends don't need to handle the intrinsic and means fewer MIR basic blocks in pointer arithmetic code.
2023-04-26 15:52:33 +00:00
Scott McMurray
05a665f21a Lower intrinsics::offset to mir::BinOp::Offset
They're semantically the same, so this means the backends don't need to handle the intrinsic and means fewer MIR basic blocks in pointer arithmetic code.
2023-04-25 19:23:45 -07:00
Michael Goulet
bb99cdc7cd vars are ? 2023-04-25 19:53:09 +00:00
bors
253b727f46 Auto merge of #110713 - cjgillot:track-mir-opt, r=scottmcm
Add mir-opt tests to track MIR quality.

cc `@scottmcm` `@saethlin`

If you have other ideas, please say so.
2023-04-24 17:01:02 +00:00
Mara Bos
9cc5949f9f Update tests. 2023-04-24 16:16:14 +02:00
Camille GILLOT
332b7f51d6 Add mir-opt tests to track MIR quality. 2023-04-23 17:10:53 +00:00
bors
915aa06700 Auto merge of #110705 - saethlin:ignore-locals-cost, r=cjgillot
Remove the size of locals heuristic in MIR inlining

This heuristic doesn't necessarily correlate to complexity of the MIR Body. In particular, a lot of straight-line code in MIR tends to never reuse a local, even though any optimizer would effectively reuse the storage or just put everything in registers. So it doesn't even necessarily make sense that this would be a stack size heuristic.

So... what happens if we just delete the heuristic? The benchmark suite improves significantly. Less heuristics better?

r? `@cjgillot`
2023-04-23 15:41:45 +00:00
bors
3462f79e94 Auto merge of #108118 - oli-obk:lazy_typeck, r=cjgillot
Run various queries from other queries instead of explicitly in phases

These are just legacy leftovers from when rustc didn't have a query system. While there are more cleanups of this sort that can be done here, I want to land them in smaller steps.

This phased order of query invocations was already a lie, as any query that looks at types (e.g. the wf checks run before) can invoke e.g. const eval which invokes borrowck, which invokes typeck, ...
2023-04-23 13:34:31 +00:00
Ben Kimock
173845ce0e Remove the size of locals heuristic in MIR inlining 2023-04-22 19:17:11 -04:00
Wesley Wiser
4e8b642646 Turn on ConstDebugInfo pass. 2023-04-22 23:41:48 +02:00
bors
80a2ec49a4 Auto merge of #106934 - DrMeepster:offset_of, r=WaffleLapkin
Add offset_of! macro (RFC 3308)

Implements https://github.com/rust-lang/rfcs/pull/3308 (tracking issue #106655) by adding the built in macro `core::mem::offset_of`. Two of the future possibilities are also implemented:

* Nested field accesses (without array indexing)
* DST support (for `Sized` fields)

I wrote this a few months ago, before the RFC merged. Now that it's merged, I decided to rebase and finish it.

cc `@thomcc` (RFC author)
2023-04-22 00:10:44 +00:00
Oli Scherer
334423263a Run check_match and check_liveness when MIR is built instead of having an explicit phase for them 2023-04-21 22:32:38 +00:00
bors
4a03f14b09 Auto merge of #110569 - saethlin:mir-pass-cooperation, r=cjgillot
Deduplicate unreachable blocks, for real this time

In https://github.com/rust-lang/rust/pull/106428 (in particular 41eda69516) we noticed that inlining `unreachable_unchecked` can produce duplicate unreachable blocks. So we improved two MIR optimizations: `SimplifyCfg` was given a simplify to deduplicate unreachable blocks, then `InstCombine` was given a combiner to deduplicate switch targets that point at the same block. The problem is that change doesn't actually work.

Our current pass order is
```
SimplifyCfg (does nothing relevant to this situation)
Inline (produces multiple unreachable blocks)
InstCombine (doesn't do anything here, oops)
SimplifyCfg (produces the duplicate SwitchTargets that InstCombine is looking for)
```

So in here, I have factored out the specific function from `InstCombine` and placed it inside the simplify that produces the case it is looking for. This should ensure that it runs in the scenario it was designed for.

Fixes https://github.com/rust-lang/rust/issues/110551
r? `@cjgillot`
2023-04-21 15:08:02 +00:00
DrMeepster
b95852b93c test improvements 2023-04-21 02:14:03 -07:00
DrMeepster
511e457c4b offset_of 2023-04-21 02:14:02 -07:00
Ben Kimock
8ec49ad19a Run combine_duplicate_switch_targets after the simplification that produces them 2023-04-20 20:40:01 -04:00
Camille GILLOT
ddf8ebef32 Bless mir-opt. 2023-04-20 18:03:32 +00:00
Ben Kimock
b658050846 Demonstrate the bug 2023-04-19 22:56:48 -04:00
bors
3a5c8e91f0 Auto merge of #110393 - fee1-dead-contrib:rm-const-traits, r=oli-obk
Rm const traits in libcore

See [zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/146212-t-compiler.2Fconst-eval/topic/.60const.20Trait.60.20removal.20or.20rework)

* [x] Bless ui tests
* [ ] Re constify some unstable functions with workarounds if they are needed
2023-04-19 13:03:40 +00:00
Deadbeef
dd025c3b56 fix codegen difference 2023-04-17 09:27:07 +00:00
Deadbeef
99851c48cf bless mir-opt 2023-04-17 01:19:29 +00:00
Eric Huss
a4e851cf62 Add some reasons why tests are ignored. 2023-04-15 16:11:42 -07:00
Camille GILLOT
483525eed3 Remove obsolete test. 2023-04-15 07:46:47 +00:00
Matthias Krüger
e85ecbbcdc
Rollup merge of #110233 - nbdd0121:intrinsic, r=tmiasko
Make rust-intrinsic ABI unwindable

Fix #104451, fix https://github.com/rust-lang/miri/issues/2839

r? `@RalfJung`
2023-04-13 21:58:37 +02:00
Gary Guo
b07a470d1a Add regression test 2023-04-13 12:35:12 +01:00
Gary Guo
5c9b371a2f Bless tests 2023-04-12 14:05:05 +01:00
Andy Wang
cecb901e68
Add Offset binary op to custom mir 2023-04-11 16:23:35 +02:00
Tomasz Miąsko
7ddc245b14 ./x.py test --bless 2023-04-07 00:00:00 +00:00
bors
da14081468 Auto merge of #102906 - nbdd0121:mir, r=wesleywiser,tmiasko
Refactor unwind in MIR

This makes unwinding from current `Option<BasicBlock>` into
```rust
enum UnwindAction {
	Continue,
	Cleanup(BasicBlock),
	Unreachable,
	Terminate,
}
```

cc `@JakobDegen` `@RalfJung` `@Amanieu`
2023-04-07 10:31:14 +00:00
bors
0534655d9b Auto merge of #108504 - cjgillot:thir-pattern, r=compiler-errors,Nilstrieb
Check pattern refutability on THIR

The current `check_match` query is based on HIR, but partially re-lowers HIR into THIR.
This PR proposed to use the results of the `thir_body` query to check matches, instead of re-building THIR.

Most of the diagnostic changes are spans getting shorter, or commas/semicolons not getting removed.

This PR degrades the diagnostic for confusing constants in patterns (`let A = foo()` where `A` resolves to a `const A` somewhere): it does not point ot the definition of `const A` any more.
2023-04-06 12:42:01 +00:00
Gary Guo
04126398c2 Ignore many tests on wasm32 2023-04-06 10:08:07 +01:00
Gary Guo
2a9d710d99 Bless tests 2023-04-06 09:34:17 +01:00
Thom Chiovoloni
0db1f54f89 Bless tests 2023-04-05 15:59:29 +00:00
Michael Goulet
786fc90855 Tweak debug outputs to make debugging new solver easier 2023-04-05 03:18:29 +00:00
Camille GILLOT
4d8ed585f2 Bless mir-opt. 2023-04-03 15:59:21 +00:00
bors
22a7a19f93 Auto merge of #98112 - saethlin:mir-alignment-checks, r=oli-obk
Insert alignment checks for pointer dereferences when debug assertions are enabled

Closes https://github.com/rust-lang/rust/issues/54915

- [x] Jake tells me this sounds like a place to use `MirPatch`, but I can't figure out how to insert a new basic block with a new terminator in the middle of an existing basic block, using `MirPatch`. (if nobody else backs up this point I'm checking this as "not actually a good idea" because the code looks pretty clean to me after rearranging it a bit)
- [x] Using `CastKind::PointerExposeAddress` is definitely wrong, we don't want to expose. Calling a function to get the pointer address seems quite excessive. ~I'll see if I can add a new `CastKind`.~ `CastKind::Transmute` to the rescue!
- [x] Implement a more helpful panic message like slice bounds checking.

r? `@oli-obk`
2023-03-31 08:50:35 +00:00
Dylan DPC
a3eb2f0f22
Rollup merge of #109664 - m-ou-se:format-args-placeholder-span, r=oli-obk
Use span of placeholders in format_args!() expansion.

`format_args!("{}", x)` expands to something that contains `Argument::new_display(&x)`. That entire expression was generated with the span of `x`.

After this PR, `&x` uses the span of `x`, but the `new_display` call uses the span of the `{}` placeholder within the format string. If an implicitly captured argument was used like in `format_args!("{x}")`, both use the span of the `{x}` placeholder.

This fixes https://github.com/rust-lang/rust/issues/109576, and also allows for more improvements to similar diagnostics in the future, since the usage of `x` can now be traced to the exact `{}` placeholder that required it to be `Display` (or `Debug` etc.)
2023-03-29 14:07:28 +05:30
Scott McMurray
f20af8d43d Simplify transmutes in MIR InstCombine
Thanks to the combination of #108246 and #108442 it could already remove identity transmutes.

With this PR, it can also simplify them to `IntToInt` casts, `Discriminant` reads, or `Field` projections.
2023-03-28 18:18:10 -07:00
Mara Bos
769886cc35 Bless mir-opt tests.
(Only the lifetime spans changed.)
2023-03-27 14:57:02 +02:00
bors
2420bd34ba Auto merge of #106428 - saethlin:inline-diverging-functions, r=cjgillot
Permit the MIR inliner to inline diverging functions

This heuristic prevents inlining of `hint::unreachable_unchecked`, which in turn makes `Option/Result::unwrap_unchecked` a bad inlining candidate. I looked through the changes to `core`, `alloc`, `std`, and `hashbrown` by hand and they all seem reasonable. Let's see how this looks in perf...

---

Based on rustc-perf it looks like this regresses ctfe-stress, and the cachegrind diff indicates that this regression is in `InterpCx::statement`. I don't know how to do any deeper analysis because that function is _enormous_ in the try toolchain, which has no debuginfo in it. And a local build produces significantly different codegen for that function, even with LTO.
2023-03-26 05:55:32 +00:00
Ben Kimock
b932751984 Ignore the unwrap_unchecked test on wasm32-unknown-unknown 2023-03-25 19:33:19 -04:00