Commit Graph

555 Commits

Author SHA1 Message Date
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
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