Commit Graph

921 Commits

Author SHA1 Message Date
bors
9d795a6e6e Auto merge of #111082 - saethlin:box-assertkind, r=saethlin
Box AssertKind

r? `@nnethercote` this feels like your kind of thing

I want to add a new variant to `AssertKind` that needs 3 operands, and that ends up breaking a bunch of size assertions. So... what if we go the opposite direction first; shrinking `AssertKind` by boxing it?
2023-05-02 14:02:29 +00:00
bors
5133e15459 Auto merge of #109521 - tmiasko:const-prop-validation, r=wesleywiser
Don't validate constants in const propagation

Validation is neither necessary nor desirable.

The constant validation is already omitted at mir-opt-level >= 3, so there there are not changes in MIR test output (the propagation of invalid constants is covered by an existing test in tests/mir-opt/const_prop/invalid_constant.rs).
2023-05-02 03:42:37 +00:00
Ben Kimock
f08f903fa9 Box AssertKind 2023-05-01 23:12:41 -04:00
bors
d6ddee637b Auto merge of #111066 - matthiaskrgr:rollup-4k6rj23, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #109540 (std docs: edit `PathBuf::set_file_name` example)
 - #110093 (Add 64-bit `time_t` support on 32-bit glibc Linux to `set_times`)
 - #110987 (update wasi_clock_time_api ref.)
 - #111038 (Leave promoteds untainted by errors when borrowck fails)
 - #111042 (Add `#[no_coverage]` to the test harness's `fn main`)
 - #111057 (Make sure the implementation of TcpStream::as_raw_fd is fully inlined)
 - #111065 (Explicitly document how Send and Sync relate to references)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-05-01 20:35:53 +00:00
Scott McMurray
5292d48b85 Codegen fewer instructions in mem::replace 2023-04-30 22:33:04 -07:00
Tomasz Miąsko
c678acd3a2 Leave promoteds untainted by errors when borrowck fails
Previously, when borrowck failed it would taint all promoteds within the MIR
body. An attempt to evaluated the promoteds would subsequently fail with
spurious "note: erroneous constant used". For example:

```console
...
note: erroneous constant used
 --> tests/ui/borrowck/tainted-promoteds.rs:7:9
  |
7 |     a = &0 * &1 * &2 * &3;
  |         ^^

note: erroneous constant used
 --> tests/ui/borrowck/tainted-promoteds.rs:7:14
  |
7 |     a = &0 * &1 * &2 * &3;
  |              ^^

note: erroneous constant used
 --> tests/ui/borrowck/tainted-promoteds.rs:7:19
  |
7 |     a = &0 * &1 * &2 * &3;
  |                   ^^

note: erroneous constant used
 --> tests/ui/borrowck/tainted-promoteds.rs:7:24
  |
7 |     a = &0 * &1 * &2 * &3;
  |                        ^^
```

Borrowck failure doesn't indicate that there is anything wrong with
promoteds. Leave them untainted.
2023-04-30 23:57:47 +02:00
Matthias Krüger
791d33c5eb
Rollup merge of #110973 - bindsdev:packed-struct-ref-diagnostic-note, r=compiler-errors
improve error notes for packed struct reference diagnostic

Addresses #110199
2023-04-30 01:14:58 +02:00
bindsdev
107d480892 improve error notes for packed struct reference diagnostic 2023-04-28 20:28:56 -05:00
Camille GILLOT
7f26191aed Make drop_flags an IndexVec. 2023-04-28 20:12:45 +00:00
bors
6ce22733b9 Auto merge of #110882 - BoxyUwU:rename-some-ty-flags, r=compiler-errors
rename `NEEDS_SUBST` and `NEEDS_INFER`

implements rust-lang/compiler-team#617
2023-04-27 09:55:37 +00:00
Boxy
842419712a rename needs_subst to has_param 2023-04-27 08:35:19 +01:00
bors
8b8110e146 Auto merge of #110728 - cjgillot:no-false-optes, r=oli-obk
Do not bother optimizing impossible functions.

This is currently checked by `ConstProp`, but I see no reason to restrict it to ConstProp only.
2023-04-27 04:29:49 +00:00
Tomasz Miąsko
4adb8fbda0 Remove workaround for CastKind::Transmute from const prop
Since constants are no longer validated before propagation the
workaround is obsolete. Remove it.
2023-04-27 00:33:52 +02:00
Tomasz Miąsko
6a8fcdc597 Don't validate constants before propagation
Validation is neither necessary nor desirable.

The validation is already omitted at mir-opt-level >= 3, so there there
are not changes in MIR test output (the propagation of invalid constants
is covered by an existing test in tests/mir-opt/const_prop/invalid_constant.rs).
2023-04-27 00:32:03 +02: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
bors
8763965a2c Auto merge of #97368 - tmandry:coverage-underflow, r=jyn514
coverage: Don't underflow column number

I noticed this when running coverage on a debug build of rustc. There
may be other places that do this but I'm just fixing the one I hit.

r? `@wesleywiser` `@richkadel`
2023-04-26 12:03:13 +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
Matthias Krüger
297b222066
Rollup merge of #110556 - kylematsuda:earlybinder-explicit-item-bounds, r=compiler-errors
Switch to `EarlyBinder` for `explicit_item_bounds`

Part of the work to finish https://github.com/rust-lang/rust/issues/105779.

This PR adds `EarlyBinder` to the return type of the `explicit_item_bounds` query and removes `bound_explicit_item_bounds`.

r? `@compiler-errors` (hope it's okay to request you, since you reviewed #110299 and #110498 😃)
2023-04-25 21:06:32 +02:00
Camille GILLOT
0ee32fb3c7 Move unstatisfaction check earlier. 2023-04-25 17:11:46 +00:00
Camille GILLOT
0f857791ad Fully clear the body. 2023-04-24 18:53:47 +00:00
Yuki Okushi
4d3ab3da4e
Rollup merge of #110685 - cjgillot:clean-dcp, r=oli-obk
Some cleanups to DataflowConstProp

Mostly moving code around and short-circuiting useless cases.
2023-04-25 02:33:30 +09:00
Maybe Waffle
e496fbec92 Split {Idx, IndexVec, IndexSlice} into their own modules 2023-04-24 13:53:35 +00:00
Matthias Krüger
2ce9b574a4
Rollup merge of #110714 - cjgillot:reveal-consts, r=oli-obk
Normalize types and consts in MIR opts.

Some passes were using a non-RevealAll param_env, which is needlessly restrictive in mir-opts.

As a drive-by, we normalize all constants, since just normalizing their types is not enough.
2023-04-24 07:53:25 +02:00
Matthias Krüger
3ecae2932c
Rollup merge of #110706 - scottmcm:transmute_unchecked, r=oli-obk
Add `intrinsics::transmute_unchecked`

This takes a whole 3 lines in `compiler/` since it lowers to `CastKind::Transmute` in MIR *exactly* the same as the existing `intrinsics::transmute` does, it just doesn't have the fancy checking in `hir_typeck`.

Added to enable experimenting with the request in <https://github.com/rust-lang/rust/pull/106281#issuecomment-1496648190> and because the portable-simd folks might be interested for dependently-sized array-vector conversions.

It also simplifies a couple places in `core`.

See also https://github.com/rust-lang/rust/pull/108442#issuecomment-1474777273, where `CastKind::Transmute` was added having exactly these semantics before the lang meeting (which I wasn't in) independently expressed interest.
2023-04-24 07:53:25 +02:00
Camille GILLOT
15e5072147 Do not bother optimizing impossible functions. 2023-04-23 16:35:49 +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
Camille GILLOT
4fe51365d7 Use param_env_reveal_all_normalized in MIR opts. 2023-04-23 10:04:41 +00:00
Camille GILLOT
7efcf67a3b Also reveal constants before MIR opts. 2023-04-23 10:04:41 +00:00
Scott McMurray
1de2257c3f Add intrinsics::transmute_unchecked
This takes a whole 3 lines in `compiler/` since it lowers to `CastKind::Transmute` in MIR *exactly* the same as the existing `intrinsics::transmute` does, it just doesn't have the fancy checking in `hir_typeck`.

Added to enable experimenting with the request in <https://github.com/rust-lang/rust/pull/106281#issuecomment-1496648190> and because the portable-simd folks might be interested for dependently-sized array-vector conversions.

It also simplifies a couple places in `core`.
2023-04-22 17:22:03 -07: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
Camille GILLOT
dd78b997b5 Reduce rightward drift. 2023-04-22 12:30:37 +00:00
Camille GILLOT
dd452ae70e Simplify logic. 2023-04-22 12:30:36 +00:00
Camille GILLOT
629cdb42d3 Move eval_discriminant. 2023-04-22 12:30:36 +00:00
Camille GILLOT
0e68cbd45d Remove useless special case. 2023-04-22 12:30:36 +00:00
bors
21fab435da Auto merge of #104844 - cjgillot:mention-eval-place, r=jackh726,RalfJung
Evaluate place expression in `PlaceMention`

https://github.com/rust-lang/rust/pull/102256 introduces a `PlaceMention(place)` MIR statement which keep trace of `let _ = place` statements from surface rust, but without semantics.

This PR proposes to change the behaviour of `let _ =` patterns with respect to the borrow-checker to verify that the bound place is live.

Specifically, consider this code:
```rust
let _ = {
    let a = 5;
    &a
};
```

This passes borrowck without error on stable. Meanwhile, replacing `_` by `_: _` or `_p` errors with "error[E0597]: `a` does not live long enough", [see playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=c448d25a7c205dc95a0967fe96bccce8).

This PR *does not* change how `_` patterns behave with respect to initializedness: it remains ok to bind a moved-from place to `_`.

The relevant test is `tests/ui/borrowck/let_underscore_temporary.rs`. Crater check found no regression.

For consistency, this PR changes miri to evaluate the place found in `PlaceMention`, and report eventual dangling pointers found within it.

r? `@RalfJung`
2023-04-22 09:54:21 +00:00
bors
3128fd8ddf Auto merge of #110666 - JohnTitor:rollup-3pwilte, r=JohnTitor
Rollup of 7 pull requests

Successful merges:

 - #109949 (rustdoc: migrate `document_type_layout` to askama)
 - #110622 (Stable hash tag (discriminant) of `GenericArg`)
 - #110635 (More `IS_ZST` in `library`)
 - #110640 (compiler/rustc_target: Raise m68k-linux-gnu baseline to 68020)
 - #110657 (nit: consistent naming for SimplifyConstCondition)
 - #110659 (rustdoc: clean up JS)
 - #110660 (Print ty placeholders pretty)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-04-22 05:35:08 +00: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
1ce80e210d Allow LocalDefId as the argument to def_path_str 2023-04-21 22:27:20 +00:00
miguelraz
6f29a3c980 nit: consistent naming for SimplifyConstCondition 2023-04-21 15:45:25 -06:00
Camille GILLOT
2870d269f5 Actually keep PlaceMention if requested. 2023-04-21 21:34:59 +00:00
Kyle Matsuda
5a69b5d0f9 Changes from review 2023-04-21 09:57:37 -06: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
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
Kyle Matsuda
e54854f6a9 add subst_identity_iter and subst_identity_iter_copied methods on EarlyBinder; use this to simplify some EarlyBinder noise around explicit_item_bounds calls 2023-04-20 12:36:50 -06:00
Kyle Matsuda
f3b279fcc5 add EarlyBinder to output of explicit_item_bounds; replace bound_explicit_item_bounds usages; remove bound_explicit_item_bounds query 2023-04-20 12:36:50 -06:00
Kyle Matsuda
0892a7380b change usages of explicit_item_bounds to bound_explicit_item_bounds 2023-04-20 12:36:50 -06:00
Camille GILLOT
b275d2c30b Remove WithOptconstParam. 2023-04-20 17:48:32 +00:00