Commit Graph

810 Commits

Author SHA1 Message Date
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
Camille GILLOT
22ed51e136 Do not read a scalar on a non-scalar layout. 2024-01-16 22:32:48 +00:00
Camille GILLOT
3c48243b6f Simplify Len. 2024-01-16 22:20:54 +00:00
Camille GILLOT
5fc23ad8e6 Simplify unary operations. 2024-01-16 22:20:54 +00:00
Camille GILLOT
666030c51b Simplify binary ops. 2024-01-16 22:20:53 +00:00
LegionMammal978
bc3fb5245a Rename pointer field on Pin
The internal, unstable field of `Pin` can conflict with fields from the
inner type accessed via the `Deref` impl. Rename it from `pointer` to
`__pointer`, to make it less likely to conflict with anything else.
2024-01-16 14:58:42 -05:00
bors
bf2637f4e8 Auto merge of #119954 - scottmcm:option-unwrap-failed, r=WaffleLapkin
Split out `option::unwrap_failed` like we have `result::unwrap_failed`

...and like `option::expect_failed`
2024-01-16 15:32:39 +00:00
bors
fa0dc208d0 Auto merge of #119672 - cjgillot:dse-sandwich, r=oli-obk
Sandwich MIR optimizations between DSE.

This PR reorders MIR optimization passes in an attempt to increase their efficiency.

- Stop running CopyProp before GVN, it's useless as GVN will do the same thing anyway. Instead, we perform CopyProp at the end of the pipeline, to ensure we do not emit copy/move chains.
- Run DSE before GVN, as it increases the probability to have single-assignment locals.
- Run DSE after the final CopyProp to turn copies into moves.

r? `@ghost`
2024-01-16 11:34:16 +00:00
bors
f9c2421a2a Auto merge of #119439 - cjgillot:gvn-faster, r=oli-obk
Avoid some redundant work in GVN

The first 2 commits are about reducing the perf effect.

Third commit avoids doing redundant work: is a local is SSA, it already has been simplified, and the resulting value is in `self.locals`. No need to call any code on it.

The last commit avoids removing some storage statements.

r? wg-mir-opt
2024-01-16 05:17:49 +00:00
sfzhu93
5747eceef8 add FIXME for default_boxed_slice.rs 2024-01-14 22:35:00 -08:00
Scott McMurray
23483664a2 Split out option::unwrap_failed like we have result::unwrap_failed
...and like `option::expect_failed`
2024-01-14 12:45:01 -08:00
sfzhu93
cd77d59f97 update enum.rs for code review 2024-01-12 20:50:28 -08:00
sfzhu93
1c886d794c resolve code reviews 2024-01-11 23:36:09 -08:00
sfzhu93
d63f10b7ad resolve code reviews 2024-01-11 23:22:33 -08:00
Matthias Krüger
8294356a5d
Rollup merge of #119842 - Zalathar:kind, r=oli-obk
coverage: Add enums to accommodate other kinds of coverage mappings

Extracted from  #118305.

LLVM supports several different kinds of coverage mapping regions, but currently we only ever emit ordinary “code” regions.  This PR performs the plumbing required to add other kinds of regions as enum variants, but does not add any specific variants other than `Code`.

The main motivation for this change is branch coverage, but it will also allow separate experimentation with gap regions and skipped regions, which might help in producing more accurate and useful coverage reports.

---

``@rustbot`` label +A-code-coverage
2024-01-11 19:42:51 +01:00
Camille GILLOT
bc35ee41fa Do not run simplify_locals inside DSE.
The full pass is run short after.
2024-01-11 09:58:22 +00:00
Camille GILLOT
0aedd6e86f Sandwich MIR optimizations between DSE. 2024-01-11 09:58:19 +00:00
Zalathar
124fff0777 coverage: Add enums to accommodate other kinds of coverage mappings 2024-01-11 16:43:12 +11:00
bors
3a6bf351a3 Auto merge of #119677 - cjgillot:early-cfg-opt, r=oli-obk
Reorder early post-inlining passes.

`RemoveZsts`, `RemoveUnneededDrops` and `UninhabitedEnumBranching` only depend on types, so they should be executed together early after MIR inlining introduces those types.

This does not change the end-result, but this makes the pipeline a bit more consistent.
2024-01-11 04:09:07 +00:00
Guillaume Gomez
9b905417f5
Rollup merge of #119699 - cjgillot:simplify-unreachable, r=oli-obk
Merge dead bb pruning and unreachable bb deduplication.

Both routines share the same basic structure: iterate on all bbs to identify work, and then renumber bbs.

We can do both at once.
2024-01-09 13:23:18 +01:00
sfzhu93
7135168d08 Add FileCheck for enum.rs 2024-01-08 21:58:01 -08:00
sfzhu93
1adda9a170 Add FileCheck to terminator.rs and tuple.rs 2024-01-08 20:21:23 -08:00
sfzhu93
732f6a1303 Add FileCheck to struct.rs 2024-01-08 20:21:06 -08:00
sfzhu93
d765e3ae1f Add FileCheck to slice_len.rs 2024-01-08 20:20:53 -08:00
sfzhu93
3ab1d5d450 Add FileCheck to 3 tests: self_assign_add, self_assign, and sibling_ptr 2024-01-08 20:20:27 -08:00
sfzhu93
e9152e2b6c Add FileCheck to 3 tests: ref_without_sb, repeat, repr_transparent 2024-01-08 20:19:59 -08:00
sfzhu93
9452d7ed1a Add FileCheck to 3 tests: large_array_index, mult_by_zero, and offset_of 2024-01-08 20:18:59 -08:00
sfzhu93
24aefa0e5d Add FileCheck for if.rs, inherit_overflow.rs, issue_81605.rs 2024-01-08 17:01:13 -08:00
sfzhu93
33e5d851a9 Add FileCheck for enum.rs 2024-01-07 22:03:42 -08:00
sfzhu93
e05c779ee3 Add FileCheck for checked.rs and default_boxed_slice.rs. 2024-01-07 21:16:55 -08:00
sfzhu93
1eaeaaf08b Add FileCheck for array_index.rs, boolean_identities.rs and cast.rs 2024-01-07 21:16:22 -08:00
bors
75c68cfd2b Auto merge of #119675 - cjgillot:set-no-discriminant, r=tmiasko
Skip threading over no-op SetDiscriminant.

Fixes https://github.com/rust-lang/rust/issues/119674
2024-01-07 15:34:05 +00:00
Camille GILLOT
4071572cb4 Merge dead bb pruning and unreachable bb deduplication. 2024-01-07 15:12:10 +00:00
Camille GILLOT
7e39100586 Avoid recording no-op replacements. 2024-01-07 13:54:05 +00:00
Camille GILLOT
4ee01faaf0 Do not re-simplify SSA locals. 2024-01-07 13:54:05 +00:00
Camille GILLOT
a8c4d43cb1 Reorder early post-inlining passes. 2024-01-07 01:42:57 +00:00
bors
78c988fe3e Auto merge of #119035 - saethlin:remove-linker-requirement, r=onur-ozkan
Run Miri and mir-opt tests without a target linker

Normally, we need a linker for the target to build the standard library. That's only because `std` declares crate-type lib and dylib; building the dylib is what creates a need for the linker.

But for mir-opt tests (and for Miri) we do not need to build a `libstd.so`. So with this PR, when we build the standard library for mir-opt tests, instead of `cargo build` we run `cargo rustc --crate-type=lib` which overrides the configured crate types in `std`'s manifest.

I've also swapped in what seems to me a better hack than `BOOTSTRAP_SKIP_TARGET_SANITY` to prevent cross-interpreting with Miri from checking for a target linker and expanded it to mir-opt tests too. Whether it's actually better is up to a reviewer.
2024-01-07 00:32:24 +00:00
Camille GILLOT
41eb9a49af Skip threading over no-op SetDiscriminant. 2024-01-07 00:28:20 +00:00
Ben Kimock
735a6a4212 Run Miri and mir-opt tests without a target linker 2024-01-06 14:17:33 -05:00
Martin Nordholts
95eb5bcb67 rustc_mir_transform: Make DestinationPropagation stable for queries
By using FxIndexMap instead of FxHashMap, so that the order of visiting
of locals is deterministic.

We also need to bless
copy_propagation_arg.foo.DestinationPropagation.panic*.diff. Do not
review the diff of the diff. Instead look at the diff file before and
after this commit. Both before and after this commit, 3 statements are
replaced with nop. It's just that due to change in ordering, different
statements are replaced. But the net result is the same.
2024-01-05 20:55:32 +01:00
Michael Goulet
3a983ad3b0
Rollup merge of #119577 - tmiasko:lint, r=oli-obk
Migrate memory overlap check from validator to lint

The check attempts to identify potential undefined behaviour, rather
than whether MIR is well-formed. It belongs in the lint not validator.

Follow up to changes from #119077.
2024-01-05 10:57:22 -05:00
Michael Goulet
e74a0cdfed
Rollup merge of #119566 - Zalathar:remove-spanview, r=Swatinem,Nilstrieb
Remove `-Zdump-mir-spanview`

The `-Zdump-mir-spanview` flag was added back in #76074, as a development/debugging aid for the initial work on what would eventually become `-Cinstrument-coverage`. It causes the compiler to emit an HTML file containing a function's source code, with various spans highlighted based on the contents of MIR.

When the suggestion was made to [triage and remove unnecessary `-Z` flags (Zulip)](https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/.60-Z.60.20option.20triage), I noted that this flag could potentially be worth removing, but I wanted to keep it around to see whether I found it useful for my own coverage work.

But when I actually tried to use it, I ran into various issues (e.g. it crashes on `tests/coverage/closure.rs`). If I can't trust it to work properly without a full overhaul, then instead of diving down a rabbit hole of trying to fix arcane span-handling bugs, it seems better to just remove this obscure old code entirely.

---

````@rustbot```` label +A-code-coverage
2024-01-05 10:57:21 -05:00
Tomasz Miąsko
df116ec246 Migrate memory overlap check from validator to lint
The check attempts to identify potential undefined behaviour, rather
than whether MIR is well-formed. It belongs in the lint not validator.
2024-01-04 23:32:22 +01:00
Tomasz Miąsko
a084e063e6 Fix validation and linting of injected MIR
Reevaluate `body.should_skip()` after updating the MIR phase to ensure
that injected MIR is processed correctly.

Update a few custom MIR tests that were ill-formed for the injected
phase.
2024-01-04 23:06:42 +01:00
Matthias Krüger
a919d97aaa
Rollup merge of #119325 - RalfJung:custom-mir, r=compiler-errors
custom mir: make it clear what the return block is

Custom MIR recently got support for specifying the "unwind action", so now there's two things coming after the actual call part of `Call` terminators. That's not very self-explaining so I propose we change the syntax to imitate keyword arguments:
```
Call(popped = Vec::pop(v), ReturnTo(drop), UnwindContinue())
```

Also fix some outdated docs and add some docs to `Call` and `Drop`.
2024-01-04 15:33:58 +01:00
Zalathar
af3205421f Remove -Zdump-mir-spanview 2024-01-04 13:43:27 +11:00
Nilstrieb
ffafcd8819 Update to bitflags 2 in the compiler
This involves lots of breaking changes. There are two big changes that
force changes. The first is that the bitflag types now don't
automatically implement normal derive traits, so we need to derive them
manually.

Additionally, bitflags now have a hidden inner type by default, which
breaks our custom derives. The bitflags docs recommend using the impl
form in these cases, which I did.
2023-12-30 18:17:28 +01:00
bors
8d76d07666 Auto merge of #116012 - cjgillot:gvn-const, r=oli-obk
Implement constant propagation on top of MIR SSA analysis

This implements the idea I proposed in https://github.com/rust-lang/rust/pull/110719#issuecomment-1718324700

Based on https://github.com/rust-lang/rust/pull/109597

The value numbering "GVN" pass formulates each rvalue that appears in MIR with an abstract form (the `Value` enum), and assigns an integer `VnIndex` to each. This abstract form can be used to deduplicate values, reusing an earlier local that holds the same value instead of recomputing. This part is proposed in #109597.

From this abstract representation, we can perform more involved simplifications, for example in https://github.com/rust-lang/rust/pull/111344.

With the abstract representation `Value`, we can also attempt to evaluate each to a constant using the interpreter. This builds a `VnIndex -> OpTy` map. From this map, we can opportunistically replace an operand or a rvalue with a constant if their value has an associated `OpTy`.

The most relevant commit is [Evaluated computed values to constants.](2767c4912e)"

r? `@oli-obk`
2023-12-30 03:45:58 +00:00
Michael Goulet
fcb42b42d6 Remove movability from TyKind::Coroutine 2023-12-28 16:35:01 +00:00
Ralf Jung
0f9baa8a31 custom mir: make it clear what the return block is 2023-12-26 20:15:26 +01:00
bors
2fe50cd72c Auto merge of #119129 - jyn514:verbose, r=compiler-errors,estebank
rework `-Zverbose`

implements the changes described in https://github.com/rust-lang/compiler-team/issues/706

the first commit is only a name change from `-Zverbose` to `-Zverbose-internals` and does not change behavior. the second commit changes diagnostics.

possible follow up work:
- `ty::pretty` could print more info with `--verbose` than it does currently. `-Z verbose-internals` shows too much info in a way that's not helpful to users. michael had ideas about this i didn't fully understand: https://rust-lang.zulipchat.com/#narrow/stream/233931-t-compiler.2Fmajor-changes/topic/uplift.20some.20-Zverbose.20calls.20and.20rename.20to.E2.80.A6.20compiler-team.23706/near/408984200
- `--verbose` should imply `-Z write-long-types-to-disk=no`. the code in `ty_string_with_limit` should take `--verbose` into account (apparently this affects `Ty::sort_string`, i'm not familiar with this code). writing a file to disk should suggest passing `--verbose`.

r? `@compiler-errors` cc `@estebank`
2023-12-26 12:27:29 +00:00
jyn
cb6d033316 don't elide shared parts of types in diagnostics when --verbose is passed
this also changes some parts of lifetime printing, which previously were not gated behind `-Z verbose`
2023-12-24 16:47:18 -05:00
Camille GILLOT
2837727471 Replace legacy ConstProp by GVN. 2023-12-24 20:08:57 +00:00
Camille GILLOT
a03c972816 Enable GVN by default. 2023-12-24 20:08:57 +00:00
Tomasz Miąsko
ba430a36c0 Enable -Zlint-mir by default for mir-opt tests 2023-12-21 00:00:00 +00:00
bors
f704f3b93b Auto merge of #119112 - Nadrieril:remove-target_blocks-hack, r=matthewjasper
match lowering: Remove the `make_target_blocks` hack

This hack was introduced 4 years ago in [`a1d0266` (#60730)](a1d0266878) to improve LLVM optimization time, specifically noticed in the `encoding` benchmark. Measurements today indicate it is no longer needed.

r? `@matthewjasper`
2023-12-19 21:15:31 +00:00
jyn
b5d8361909 rename to verbose-internals 2023-12-19 13:35:37 -05:00
Nadrieril
31bad13f82 Remove the make_target_blocks hack
It was introduced 4 years ago in a1d0266878 to improve LLVM
optimization time. Measurements today indicate it is no longer needed.
2023-12-19 11:37:39 +01:00
Camille GILLOT
8022057ebb Avoid overflow in GVN constant indexing. 2023-12-17 19:50:38 +00:00
Tomasz Miąsko
ef1831a21f End locals' live range before suspending coroutine
State transforms retains storage statements for locals that are not
stored inside a coroutine. It ensures those locals are live when
resuming by inserting StorageLive as appropriate. It forgot to end the
storage of those locals when suspending, which is fixed here.

While the end of live range is implicit when executing return, it is
nevertheless useful for inliner which would otherwise extend the live
range beyond return.
2023-12-11 23:11:20 +01:00
bors
c71c246876 Auto merge of #118550 - cjgillot:filecheck-const-prop, r=Mark-Simulacrum
Add FileCheck annotations to const_prop tests

Unblocks https://github.com/rust-lang/rust/pull/116012
Advances https://github.com/rust-lang/rust/issues/116971
2023-12-10 03:00:58 +00:00
Ralf Jung
29c95e98e3 also print 'immutable' flag 2023-12-07 17:46:36 +01:00
Camille GILLOT
30a95b7c0a FileCheck while_let_loops. 2023-12-02 21:10:04 +00:00
Camille GILLOT
c00068e49f FileCheck tuple_literal_propagation. 2023-12-02 21:08:55 +00:00
Camille GILLOT
87522d0007 FileCheck return_place. 2023-12-02 21:08:12 +00:00
Camille GILLOT
a12027e128 FileCheck switch_int. 2023-12-02 21:06:48 +00:00
Camille GILLOT
19767eb7a6 FileCheck slice_len. 2023-12-02 21:06:38 +00:00
Camille GILLOT
3e90c1b434 FileCheck scalar_literal_propagation. 2023-12-02 21:02:42 +00:00
Camille GILLOT
f3743aec51 FileCheck repeat. 2023-12-02 21:01:48 +00:00
Camille GILLOT
343ef6a9cb FileCheck reify_fn_ptr. 2023-12-02 21:00:59 +00:00
Camille GILLOT
6baec3ccc2 FileCheck ref_deref. 2023-12-02 20:58:45 +00:00
Camille GILLOT
c8c9207e4c FileCheck read_immutable_static. 2023-12-02 20:56:26 +00:00
Camille GILLOT
45dd5d6bf3 FileCheck mutable_variable_unprop_assign. 2023-12-02 20:54:56 +00:00
Camille GILLOT
6a8eea8f5b FileCheck mutable_variable_aggregate_partial_read. 2023-12-02 20:51:23 +00:00
Camille GILLOT
d91bb5074e FileCheck mutable_variable_no_prop. 2023-12-02 20:50:00 +00:00
Camille GILLOT
3e169abc1b FileCheck mutable_variable_aggregate_mut_ref. 2023-12-02 20:49:50 +00:00
Camille GILLOT
03c5ad1549 FileCheck mutable_variable_aggregate. 2023-12-02 20:49:38 +00:00
Camille GILLOT
ea9f968333 FileCheck mutable_variable. 2023-12-02 20:49:28 +00:00
Camille GILLOT
902a3e2e75 FileCheck mult_by_zero. 2023-12-02 20:39:26 +00:00
Camille GILLOT
8e9b912c4c FileCheck issue_67019. 2023-12-02 20:38:07 +00:00
Camille GILLOT
ce9b1e23a5 FileCheck issue_66971. 2023-12-02 20:37:05 +00:00
Camille GILLOT
218d8ccf43 FileCheck inherit_overflow. 2023-12-02 20:31:27 +00:00
Camille GILLOT
6086dd6766 FileCheck indirect. 2023-12-02 20:29:47 +00:00
Camille GILLOT
bf5d114da8 FileCheck discriminant. 2023-12-02 20:28:33 +00:00
Camille GILLOT
043d29b58a FileCheck and rename const_prop_fails_gracefully. 2023-12-02 20:23:16 +00:00
Camille GILLOT
7f328d2a44 FileCheck checked_add. 2023-12-02 20:18:58 +00:00
Camille GILLOT
e6a1b77cd1 FileCheck cast. 2023-12-02 20:18:47 +00:00
Camille GILLOT
b8f2f63931 FileCheck boxes. 2023-12-02 20:18:21 +00:00
Camille GILLOT
3fc03948a8 FileCheck boolean_identities. 2023-12-02 20:18:14 +00:00
Camille GILLOT
e8e35c8127 FileCheck bad_op_unsafe_oob_for_slices. 2023-12-02 20:18:02 +00:00
Camille GILLOT
97f03cb898 FileCheck bad_op_mod_by_zero. 2023-12-02 20:17:49 +00:00
Camille GILLOT
0d5bc872a9 FileCheck bad_op_div_by_zero. 2023-12-02 20:17:37 +00:00
Camille GILLOT
9f01d9d1b6 FileCheck array_index. 2023-12-02 20:17:20 +00:00
Camille GILLOT
6564bac532 FileCheck aggregate. 2023-12-02 20:17:04 +00:00
Camille GILLOT
378abbc604 FileCheck address_of_pair. 2023-12-02 20:16:49 +00:00
bors
3f1e30a0a5 Auto merge of #118077 - calebzulawski:sync-portable-simd-2023-11-19, r=workingjubilee
Portable SIMD subtree update

Syncs nightly to the latest changes from rust-lang/portable-simd

r? `@rust-lang/libs`
2023-12-02 18:04:01 +00:00
Matthias Krüger
434232f7b2
Rollup merge of #118426 - aDotInTheVoid:const-wat, r=compiler-errors,cjgillot
ConstProp: Correctly remove const if unknown value assigned to it.

Closes #118328

The problematic sequence of MIR is:

```rust
          _1 = const 0_usize;
          _1 = const _; // This is an associated constant we can't know before monomorphization.
          _0 = _1;
```

1. When `ConstProp::visit_assign` happens on `_1 = const 0_usize;`, it records that `0x0usize` is the value for `_1`.
2. Next `visit_assign` happens on `_1 = const _;`. Because the rvalue `.has_param()`, it can't be const evaled.
3. Finaly, `visit_assign` happens on `_0 = _1;`. Here it would think the value of `_1` was `0x0usize` from step 1.

The solution is to remove consts when checking the RValue fails, as they may have contained values that should now be invalidated, as that local was overwritten.

This should probably be back-ported to beta. Stable is more iffy, as it's gone unidentified since 1.70, so I only think it's worthwhile if there's another reason for a 1.74.1 release anyway.
2023-11-29 12:34:50 +01:00
bors
b1e56deada Auto merge of #114841 - bvanjoi:fix-114814, r=cuviper
add track_caller for arith ops

Fixes #114814

`#[track_caller]` is works, r? `@scottmcm`
2023-11-29 00:47:25 +00:00
Alona Enraght-Moony
6e956c0a38 Rename and add another test 2023-11-28 23:17:28 +00:00
Alona Enraght-Moony
9121a41450 ConstProp: Remove const when rvalue check fails. 2023-11-28 22:15:11 +00:00
Alona Enraght-Moony
b1a6cf4a0e Precommit test for https://github.com/rust-lang/rust/issues/118328. 2023-11-28 15:12:46 +00:00
Caleb Zulawski
4d9607869a Update std::simd usage and test outputs 2023-11-26 09:02:25 -05:00
Gary Guo
2c03f21d1f Bless MIR tests 2023-11-26 00:14:18 +00:00
bohan
fc87d6e23d add track_caller for arith ops 2023-11-24 00:54:06 +08:00
Tomasz Miąsko
1be1c2ebcf Fix insertion of statements to be executed along return edge in inlining
Inlining creates additional statements to be executed along the return
edge: an assignment to the destination, storage end for temporaries.

Previously those statements where inserted directly into a call target,
but this is incorrect when the target has other predecessors.

Avoid the issue by creating a new dedicated block for those statements.
When the block happens to be redundant it will be removed by CFG
simplification that follows inlining.

Fixes #117355
2023-11-20 09:27:30 +01:00
George Bateman
661df4fd55
Remove option_payload_ptr; redundant to offset_of 2023-11-16 22:56:25 +00:00
bors
5526682702 Auto merge of #117330 - tmiasko:custom-mir-cleanup-blocks, r=cjgillot
Custom MIR: Support cleanup blocks

Cleanup blocks are declared with `bb (cleanup) = { ... }`.

`Call` and `Drop` terminators take an additional argument describing the unwind action, which is one of the following:

* `UnwindContinue()`
* `UnwindUnreachable()`
* `UnwindTerminate(reason)`, where reason is `ReasonAbi` or `ReasonInCleanup`
* `UnwindCleanup(block)`

Also support unwind resume and unwind terminate terminators:

* `UnwindResume()`
* `UnwindTerminate(reason)`
2023-11-14 08:53:25 +00:00
Tomasz Miąsko
78da577650 Custom MIR: Support cleanup blocks
Cleanup blocks are declared with `bb (cleanup) = { ... }`.

`Call` and `Drop` terminators take an additional argument describing the
unwind action, which is one of the following:

* `UnwindContinue()`
* `UnwindUnreachable()`
* `UnwindTerminate(reason)`, where reason is `ReasonAbi` or `ReasonInCleanup`
* `UnwindCleanup(block)`

Also support unwind resume and unwind terminate terminators:

* `UnwindResume()`
* `UnwindTerminate(reason)`
2023-11-14 08:23:58 +01:00
Michael Goulet
7994b5849c Compute layout with spans for better cycle errors in coroutines 2023-11-13 02:22:25 +00:00
lcnr
92267c9794 update mir-opt tests 2023-11-08 22:55:29 +01:00
bors
992943dbae Auto merge of #117537 - GKFX:offset-of-enum-feature, r=cjgillot
Feature gate enums in offset_of

As requested at https://github.com/rust-lang/rust/issues/106655#issuecomment-1790815262, put enums in offset_of behind their own feature gate.

`@rustbot` label F-offset_of
2023-11-05 13:44:59 +00:00
bors
8acf40bd54 Auto merge of #117469 - cjgillot:filecheck-mir, r=Mark-Simulacrum
Add FileCheck annotations to a few MIR opt tests

const_debuginfo did not specify which passes were running.
const_prop_miscompile is renamed and moved to const_prop directory.
while_storage was broken.
2023-11-05 07:54:12 +00:00
George Bateman
7c09b99ebb
Feature gate enums in offset_of 2023-11-03 13:16:47 +00:00
bors
722b3eeb72 Auto merge of #117498 - matthiaskrgr:rollup-z7mg4ck, r=matthiaskrgr
Rollup of 4 pull requests

Successful merges:

 - #117298 (Recover from missing param list in function definitions)
 - #117373 (Avoid the path trimming ICE lint in error reporting)
 - #117441 (Do not assert in op_to_const.)
 - #117488 (Update minifier-rs version to 0.3.0)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-11-01 22:37:24 +00:00
bors
75b064d269 Auto merge of #117029 - rmehri01:mir_opt_filecheck_inline_tests, r=cjgillot
Add FileCheck annotations to MIR-opt inlining tests

Part of #116971, adds FileCheck annotations to MIR-opt tests in `tests/mir-opt/inline`.

I left out a few (such as `inline_cycle`) where it mentioned that the particular outcome of inlining isn't important, just that the inliner doesn't get stuck in an infinite loop.

r? cjgillot
2023-11-01 20:37:38 +00:00
Camille GILLOT
0f8f77fcc2 Rebase fallout. 2023-11-01 16:55:18 +00:00
Camille GILLOT
a2e151ca4b Make ui into mir-opt test. 2023-11-01 16:49:18 +00:00
Ryan Mehri
5f75326d74 fix spans for inline_couroutine panic-abort 2023-11-01 07:58:19 -07:00
bors
146dafa262 Auto merge of #114208 - GKFX:offset_of_enum, r=wesleywiser
Support enum variants in offset_of!

This MR implements support for navigating through enum variants in `offset_of!`, placing the enum variant name in the second argument to `offset_of!`. The RFC placed it in the first argument, but I think it interacts better with nested field access in the second, as you can then write things like

```rust
offset_of!(Type, field.Variant.field)
```

Alternatively, a syntactic distinction could be made between variants and fields (e.g. `field::Variant.field`) but I'm not convinced this would be helpful.

[RFC 3308 # Enum Support](https://rust-lang.github.io/rfcs/3308-offset_of.html#enum-support-offset_ofsomeenumstructvariant-field_on_variant)
Tracking Issue #106655.
2023-11-01 14:17:56 +00:00
Matthias Krüger
260e07b0cb
Rollup merge of #115626 - clarfonthey:unchecked-math, r=thomcc
Clean up unchecked_math, separate out unchecked_shifts

Tracking issue: #85122

Changes:

1. Remove `const_inherent_unchecked_arith` flag and make const-stability flags the same as the method feature flags. Given the number of other unsafe const fns already stabilised, it makes sense to just stabilise these in const context when they're stabilised.
2. Move `unchecked_shl` and `unchecked_shr` into a separate `unchecked_shifts` flag, since the semantics for them are unclear and they'll likely be stabilised separately as a result.
3. Add an `unchecked_neg` method exclusively to signed integers, under the `unchecked_neg` flag. This is because it's a new API and probably needs some time to marinate before it's stabilised, and while it *would* make sense to have a similar version for unsigned integers since `checked_neg` also exists for those there is absolutely no case where that would be a good idea, IMQHO.

The longer-term goal here is to prepare the `unchecked_math` methods for an FCP and stabilisation since they've existed for a while, their semantics are clear, and people seem in favour of stabilising them.
2023-11-01 11:29:41 +01:00
George Bateman
9d6ce61376
Update MIR tests for offset_of 2023-10-31 23:26:02 +00:00
George Bateman
e936416a8d
Support enum variants in offset_of! 2023-10-31 23:25:54 +00:00
Camille GILLOT
ac4d0965bb FileCheck const_prop_miscompile. 2023-10-31 22:56:02 +00:00
Camille GILLOT
e65ec7d8f1 FileCheck const_debuginfo. 2023-10-31 22:55:59 +00:00
Camille GILLOT
3d454707ab FileCheck while_storage. 2023-10-31 22:55:14 +00:00
Ryan Mehri
2fcb4d92b0 change inline_retag to after.mir 2023-10-31 11:58:20 -07:00
Camille GILLOT
ae2e21114b FileCheck uninhabited_enum_branching. 2023-10-31 11:44:23 +00:00
Camille GILLOT
cb918904fe Only emit != assumptions if the otherwise target is reachable. 2023-10-31 11:44:23 +00:00
Camille GILLOT
096196d5b0 Refactor UninhabitedEnumBranching to mark targets unreachable. 2023-10-31 11:44:23 +00:00
Camille GILLOT
0b13e636f5 Simplify assume of a constant. 2023-10-31 11:44:23 +00:00
Camille GILLOT
c748ac1f11 Replace SwitchInt to unreachable by an assumption. 2023-10-31 11:44:23 +00:00
Camille GILLOT
ed27cb0f49 Reorder passes. 2023-10-31 11:44:23 +00:00
bors
83c9732e0c Auto merge of #116270 - cjgillot:gvn-aggregate, r=oli-obk,RalfJung
See through aggregates in GVN

This PR is extracted from https://github.com/rust-lang/rust/pull/111344

The first 2 commit are cleanups to avoid repeated work. I propose to stop removing useless assignments as part of this pass, and let a later `SimplifyLocals` do it. This makes tests easier to read (among others).

The next 3 commits add a constant folding mechanism to the GVN pass, presented in https://github.com/rust-lang/rust/pull/116012. ~This pass is designed to only use global allocations, to avoid any risk of accidental modification of the stored state.~

The following commits implement opportunistic simplifications, in particular:
- projections of aggregates: `MyStruct { x: a }.x` gets replaced by `a`, works with enums too;
- projections of arrays: `[a, b][0]` becomes `a`;
- projections of repeat expressions: `[a; N][x]` becomes `a`;
- transform arrays of equal operands into a repeat rvalue.

Fixes https://github.com/rust-lang/miri/issues/3090

r? `@oli-obk`
2023-10-29 14:50:53 +00:00
bors
59bb9505bc Auto merge of #103208 - cjgillot:match-fake-read, r=oli-obk,RalfJung
Allow partially moved values in match

This PR attempts to unify the behaviour between `let _ = PLACE`, `let _: TY = PLACE;` and `match PLACE { _ => {} }`.
The logical conclusion is that the `match` version should not check for uninitialised places nor check that borrows are still live.

The `match PLACE {}` case is handled by keeping a `FakeRead` in the unreachable fallback case to verify that `PLACE` has a legal value.

Schematically, `match PLACE { arms }` in surface rust becomes in MIR:
```rust
PlaceMention(PLACE)
match PLACE {
  // Decision tree for the explicit arms
  arms,
  // An extra fallback arm
  _ => {
    FakeRead(ForMatchedPlace, PLACE);
    unreachable
  }
}
```

`match *borrow { _ => {} }` continues to check that `*borrow` is live, but does not read the value.
`match *borrow {}` both checks that `*borrow` is live, and fake-reads the value.

Continuation of ~https://github.com/rust-lang/rust/pull/102256~ ~https://github.com/rust-lang/rust/pull/104844~

Fixes https://github.com/rust-lang/rust/issues/99180 https://github.com/rust-lang/rust/issues/53114
2023-10-27 18:51:43 +00:00
bors
6f65201659 Auto merge of #113262 - Nilstrieb:rawr-casting, r=lcnr
Never consider raw pointer casts to be trival

HIR typeck tries to figure out which casts are trivial by doing them as
coercions and seeing whether this works. Since HIR typeck is oblivious
of lifetimes, this doesn't work for pointer casts that only change the
lifetime of the pointee, which are, as borrowck will tell you, not
trivial.

This change makes it so that raw pointer casts are never considered
trivial.

This also incidentally fixes the "trivial cast" lint false positive on
the same code. Unfortunately, "trivial cast" lints are now never emitted
on raw pointer casts, even if they truly are trivial. This could be
fixed by also doing the lint in borrowck for raw pointers specifically.

fixes #113257
2023-10-26 12:54:19 +00:00
Ryan Mehri
1ec10ec77f address review comments 2023-10-25 15:25:38 -07:00
Ryan Mehri
6ab66c3f37 FileCheck unwrap_unchecked 2023-10-25 15:25:38 -07:00
Ryan Mehri
3faf05b6e7 FileCheck unsized_argument 2023-10-25 15:25:38 -07:00
Ryan Mehri
6e047c07a6 FileCheck unchecked_shifts 2023-10-25 15:25:38 -07:00
Ryan Mehri
5cf65eb16a FileCheck issue_78442 2023-10-25 15:25:38 -07:00
Ryan Mehri
bb695977de FileCheck inline_scopes_parenting 2023-10-25 15:25:38 -07:00
Ryan Mehri
773dc62756 FileCheck inline_as_ref_as_mut 2023-10-25 15:25:38 -07:00
Ryan Mehri
1b9cb5d59b FileCheck inline_trait_method 2023-10-25 15:25:38 -07:00
Ryan Mehri
f7acf17945 FileCheck inline_trait_method_2 2023-10-25 15:25:38 -07:00
Ryan Mehri
25325667f2 FileCheck inline_specialization 2023-10-25 15:25:38 -07:00
Ryan Mehri
21a4c39cb8 FileCheck inline_retag 2023-10-25 15:25:38 -07:00
Ryan Mehri
3202d4e357 FileCheck inline_options 2023-10-25 15:25:38 -07:00
Ryan Mehri
de8255194a FileCheck inline_into_box_place 2023-10-25 15:25:38 -07:00
Ryan Mehri
19c36a96df FileCheck inline_instruction_set 2023-10-25 15:25:38 -07:00
Ryan Mehri
20e7caa737 FileCheck inline_coroutine 2023-10-25 15:25:38 -07:00
Ryan Mehri
d8f33ef93d FileCheck inline_diverging 2023-10-25 15:25:38 -07:00
Ryan Mehri
7ee05d24b5 FileCheck inline_closure 2023-10-25 15:22:01 -07:00
Ryan Mehri
5caee416a5 FileCheck inline_closure_captures 2023-10-25 15:22:01 -07:00
Ryan Mehri
9d61e6a4e4 FileCheck inline_closure_borrows_arg 2023-10-25 15:22:01 -07:00
Ryan Mehri
de56d2d9b2 FileCheck inline_box_fn 2023-10-25 15:22:01 -07:00
Ryan Mehri
22679cd36d FileCheck inline_any_operand 2023-10-25 15:22:01 -07:00
Ryan Mehri
f005d2325a FileCheck exponential_runtime 2023-10-25 15:22:01 -07:00
Ryan Mehri
76faae9cdc FileCheck dyn_trait 2023-10-25 15:22:01 -07:00
Ryan Mehri
9b3f5e1527 FileCheck dont_ice_on_generic_rust_call 2023-10-25 15:22:01 -07:00
Ryan Mehri
2f9aa7da9f FileCheck cycle 2023-10-25 15:22:01 -07:00
Ryan Mehri
2d0a34bb78 FileCheck caller_with_trivial_bound 2023-10-25 15:22:01 -07:00
Ryan Mehri
62fe807e3c FileCheck asm_unwind 2023-10-25 15:22:01 -07:00
Nilstrieb
b6657a8ad4 Never consider raw pointer casts to be trival
HIR typeck tries to figure out which casts are trivial by doing them as
coercions and seeing whether this works. Since HIR typeck is oblivious
of lifetimes, this doesn't work for pointer casts that only change the
lifetime of the pointee, which are, as borrowck will tell you, not
trivial.

This change makes it so that raw pointer casts are never considered
trivial.

This also incidentally fixes the "trivial cast" lint false positive on
the same code. Unfortunately, "trivial cast" lints are now never emitted
on raw pointer casts, even if they truly are trivial. This could be
fixed by also doing the lint in borrowck for raw pointers specifically.
2023-10-25 23:15:18 +02:00
Camille GILLOT
d80eb3a498 Verify that the alloc_id is Memory. 2023-10-25 17:59:30 +00:00
Matthias Krüger
a1ab16792b
Rollup merge of #117141 - tmiasko:inline-target-features, r=oli-obk
Require target features to match exactly during inlining

In general it is not correct to inline a callee with a target features
that are subset of the callee. Require target features to match exactly
during inlining.

The exact match could be potentially relaxed, but this would require
identifying specific feature that are allowed to differ, those that need
to match, and those that can be present in caller but not in callee.

This resolves MIR part of #116573. For other concerns with respect to
the previous implementation also see areInlineCompatible in LLVM.
2023-10-25 19:51:14 +02:00
Camille GILLOT
c4cc9ca060 Do not merge fn pointer casts. 2023-10-25 06:47:04 +00:00
Camille GILLOT
ac0228da59 FileCheck gvn. 2023-10-25 06:46:48 +00:00
Camille GILLOT
5e78b9cdb3 Disambiguate non-deterministic constants. 2023-10-25 06:46:48 +00:00
Camille GILLOT
dbf9ea30dd Transform large arrays into Repeat expressions when possible. 2023-10-25 06:46:48 +00:00
Camille GILLOT
80a5e8522d Extract simplify_aggregate. 2023-10-25 06:46:47 +00:00
Camille GILLOT
f110f22060 Simplify repeat expressions. 2023-10-25 06:46:47 +00:00
Camille GILLOT
48d2157a89 Simplify aggregate projections. 2023-10-25 06:46:47 +00:00
Camille GILLOT
692e528647 Simplify projections in GVN. 2023-10-25 06:46:47 +00:00
Camille GILLOT
38c86b0798 Evaluate computed values to constants. 2023-10-25 06:46:47 +00:00
Camille GILLOT
d28405972f Do not remove unused definitions inside GVN. 2023-10-25 06:46:45 +00:00
bors
df871fbf05 Auto merge of #115796 - cjgillot:const-prop-rvalue, r=oli-obk
Generate aggregate constants in DataflowConstProp.
2023-10-24 21:47:53 +00:00
Tomasz Miąsko
011b260cc8 Require target features to match exactly during inlining
In general it is not correct to inline a callee with a target features
that are subset of the callee. Require target features to match exactly
during inlining.

The exact match could be potentially relaxed, but this would require
identifying specific feature that are allowed to differ, those that need
to match, and those that can be present in caller but not in callee.

This resolves MIR part of #116573. For other concerns with respect to
the previous implementation also see areInlineCompatible in LLVM.
2023-10-24 22:49:15 +02:00
Tomasz Miąsko
b3cfd5bb04 Precommit target features compatibility test 2023-10-24 22:44:59 +02:00
Tomasz Miąsko
ff7bf792ce Migrate inline_compatibility.rs test to FileCheck 2023-10-24 22:19:44 +02:00
Camille GILLOT
ec28dc7aa7 Use PlaceMention for match scrutinees. 2023-10-24 15:30:17 +00:00
Camille GILLOT
9c85dfa1d7 Tweak test to avoid platform dependency. 2023-10-24 15:16:57 +00:00
bors
cd674d6179 Auto merge of #116300 - cjgillot:split-move, r=petrochenkov
Separate move path tracking between borrowck and drop elaboration.

The primary goal of this PR is to skip creating a `MovePathIndex` for path that do not need dropping in drop elaboration.

The 2 first commits are cleanups.

The next 2 commits displace `move` errors from move-path builder to borrowck. Move-path builder keeps the same logic, but does not carry error information any more.

The remaining commits allow to filter `MovePathIndex` creation according to types. This is used in drop elaboration, to avoid computing dataflow for paths that do not need dropping.
2023-10-24 00:25:32 +00:00
Camille GILLOT
8c1b039d48 Use a ConstValue instead. 2023-10-21 16:26:05 +00:00
Camille GILLOT
31d101093c Generate ValTrees in DataflowConstProp. 2023-10-21 16:20:46 +00:00
Camille GILLOT
c9c0c0cbca Do not create move paths that do not need dropping. 2023-10-21 10:32:59 +00:00
Camille GILLOT
a845bac6ba FileCheck annotations. 2023-10-21 07:08:53 +00:00
Camille GILLOT
8fb99afb02 Correct loop_headers logic. 2023-10-21 07:08:53 +00:00
Camille GILLOT
6abd8f119e Rebase fallout. 2023-10-21 07:08:48 +00:00
Camille GILLOT
df9e5ee038 Handle more terminators. 2023-10-21 07:01:24 +00:00
Camille GILLOT
0d0a536777 Do not thread through loop headers. 2023-10-21 06:59:37 +00:00
Camille GILLOT
751a079413 Implement JumpThreading pass. 2023-10-21 06:58:38 +00:00
Oli Scherer
e96ce20b34 s/generator/coroutine/ 2023-10-20 21:14:01 +00:00
Oli Scherer
60956837cf s/Generator/Coroutine/ 2023-10-20 21:10:38 +00:00
Camille GILLOT
328192bff4 FileCheck transmute. 2023-10-19 15:51:54 +00:00
Camille GILLOT
69d9369f0c FileCheck inline_shims. 2023-10-19 15:51:54 +00:00
Camille GILLOT
13683554ed FileCheck issue_106141. 2023-10-19 15:51:54 +00:00
Camille GILLOT
c679b208d2 Mention skip in README. 2023-10-19 15:51:54 +00:00
Camille GILLOT
d24e44a07e FileCheck lower_slice_len. 2023-10-19 15:51:54 +00:00
Camille GILLOT
ad057d4397 FileCheck lower_array_len. 2023-10-19 15:51:54 +00:00
Camille GILLOT
4bae847969 FileCheck lower_intrinsics. 2023-10-19 15:51:54 +00:00
Camille GILLOT
d8cffda66a FileCheck casts. 2023-10-19 15:51:54 +00:00
Camille GILLOT
68c409f8f6 FileCheck combine_transmutes. 2023-10-19 15:51:54 +00:00
Camille GILLOT
386fff34f7 FileCheck duplicate_switch_targets. 2023-10-19 15:51:54 +00:00
Camille GILLOT
f856247cc9 FileCheck intrinsic_asserts. 2023-10-19 15:51:54 +00:00
Camille GILLOT
ddc328c2f1 FileCheck combine_clone_of_primitives. 2023-10-19 15:51:54 +00:00
Camille GILLOT
5453a4f056 FileCheck bool_compare. 2023-10-19 15:51:53 +00:00
Camille GILLOT
f0690d5232 FileCheck combine_array_len. 2023-10-19 15:51:53 +00:00
Camille GILLOT
d6f4bd5a8d Add README. 2023-10-19 15:51:53 +00:00
Camille GILLOT
38bf660771 FileCheck box_expr.rs
This check is made `needs-unwind`, as the panic=abort case is a strictly
simpler version.
2023-10-19 15:51:53 +00:00
Camille GILLOT
f65eb1f752 FileCheck basic_assignment.rs. 2023-10-19 15:51:53 +00:00
Camille GILLOT
00a7958e79 FileCheck asm_unwind_panic_abort.rs 2023-10-19 15:51:53 +00:00
Camille GILLOT
47fa01d2b8 FileCheck array_index_is_temporary.rs 2023-10-19 15:51:53 +00:00
Camille GILLOT
8daf14f046 Run filecheck on reference_prop.rs 2023-10-19 15:51:53 +00:00
Camille GILLOT
4ff03cd1a4 Allow to run filecheck in mir-opt tests. 2023-10-19 15:51:52 +00:00
Matthias Krüger
096943a534
Rollup merge of #116896 - cjgillot:single-inline, r=oli-obk
Only check in a single place if a pass is enabled.

Fixes https://github.com/rust-lang/rust/issues/116294
2023-10-19 14:38:26 +02:00
Camille GILLOT
c1c5a1d69a Only check in a single place if a pass is enabled. 2023-10-18 16:59:23 +00:00
Zalathar
13b2d604ec coverage: Store expression data in function coverage info
Even though expression details are now stored in the info structure, we still
need to inject `ExpressionUsed` statements into MIR, because if one is missing
during codegen then we know that it was optimized out and we can remap all of
its associated code regions to zero.
2023-10-18 23:44:34 +11:00
Zalathar
6da319f635 coverage: Store all of a function's mappings in function coverage info
Previously, mappings were attached to individual coverage statements in MIR.
That necessitated special handling in MIR optimizations to avoid deleting those
statements, since otherwise codegen would be unable to reassemble the original
list of mappings.

With this change, a function's list of mappings is now attached to its MIR
body, and survives intact even if individual statements are deleted by
optimizations.
2023-10-18 23:42:39 +11:00
Ben Kimock
33b0e4be06 Automatically enable cross-crate inlining for small functions 2023-10-17 19:53:51 -04:00
Camille GILLOT
1f90d857d7 Stop trying to preserve pretty-printing. 2023-10-16 19:15:28 +00:00
Camille GILLOT
0eb958a89b Rebless. 2023-10-16 18:36:47 +00:00
Camille GILLOT
02424e4bc5 Normalize alloc-id in tests. 2023-10-16 16:29:35 +00:00
ltdk
91405ab74a Clean up unchecked_math, separate out unchecked_shifts 2023-10-13 02:17:08 -04:00
Camille GILLOT
37f080edbc Also consider call and yield as MIR SSA. 2023-10-08 16:05:26 +00:00
Camille GILLOT
27d6a57e58 Preserve DebugInfo in DeadStoreElimination. 2023-10-06 15:46:11 +00:00
ouz-a
3088c4b046 move subtyper change reveal_all 2023-10-05 18:56:30 +03:00
Camille GILLOT
e63d19c4dd Remove mir::LocalDecl::internal. 2023-10-04 17:55:15 +00:00
bors
36aab8df0a Auto merge of #115301 - Zalathar:regions-vec, r=davidtwco
coverage: Allow each coverage statement to have multiple code regions

The original implementation of coverage instrumentation was built around the assumption that a coverage counter/expression would be associated with *up to one* code region. When it was discovered that *multiple* regions would sometimes need to share a counter, a workaround was found: for the remaining regions, the instrumentor would create a fresh expression that adds zero  to the existing counter/expression.

That got the job done, but resulted in some awkward code, and produces unnecessarily complicated coverage maps in the final binary.

---

This PR removes that tension by changing `StatementKind::Coverage`'s code region field from `Option<CodeRegion>` to `Vec<CodeRegion>`.

The changes on the codegen side are fairly straightforward. As long as each `CoverageKind::Counter` only injects one `llvm.instrprof.increment`, the rest of coverage codegen is happy to handle multiple regions mapped to the same counter/expression, with only minor option-to-vec adjustments.

On the instrumentor/mir-transform side, we can get rid of the code that creates extra (x + 0) expressions. Instead we gather all of the code regions associated with a single BCB, and inject them all into one coverage statement.

---

There are several patches here but they can be divided in to three phases:
- Preparatory work
- Actually switching over to multiple regions per coverage statement
- Cleaning up

So viewing the patches individually may be easier.
2023-10-03 18:36:21 +00:00
Zalathar
86a66c8171 coverage: Store each BCB's code regions in one coverage statement
If a BCB has more than one code region, those extra regions can now all be
stored in the same coverage statement, instead of being stored in additional
statements.
2023-10-03 13:03:39 +11:00
Zalathar
ee9d00f6b8 coverage: Let each coverage statement hold a vector of code regions
This makes it possible for a `StatementKind::Coverage` to hold more than one
code region, but that capability is not yet used.
2023-10-03 13:03:39 +11:00
ouz-a
5d753abb30 have better explanation for relate_types 2023-10-02 23:39:45 +03:00
ouz-a
6f0c5ee2d4 change is_subtype to relate_types 2023-10-02 23:39:45 +03:00