about summary refs log tree commit diff
path: root/compiler/rustc_mir_transform/src
AgeCommit message (Collapse)AuthorLines
2023-10-16coverage: Call `prev`/`curr` less in other placesZalathar-11/+17
This reduces clutter, and makes it easier to notice regions where mutations definitely don't occur.
2023-10-16coverage: Call `prev`/`curr` less in `to_refined_spans`Zalathar-22/+20
This makes it easier to see that the non-initial cases assume that `prev` and `curr` are set, and all operate on the same prev/curr references.
2023-10-16coverage: Remove redundant field `prev_expn_span`Zalathar-7/+2
This span can always be retrieved from `prev`, so there is no need to store it separately.
2023-10-16coverage: Flatten guard logic in `maybe_flush_pending_dups`Zalathar-15/+16
2023-10-16coverage: Flatten guard logic in `maybe_push_macro_name_span`Zalathar-20/+17
2023-10-16coverage: Simplify `push_refined_span`Zalathar-12/+8
It turns out that all of the `len` manipulation here was just reimplementing `last_mut`.
2023-10-16coverage: Use `DUMMY_SP` instead of creating a dummy span manuallyZalathar-4/+4
This patch also sorts the constructor fields into declaration order.
2023-10-16coverage: Rename `hold_pending_dups_unless_dominated` to `update_pending_dups`Zalathar-2/+2
2023-10-16coverage: Rename `check_pending_dups` to `maybe_flush_pending_dups`Zalathar-2/+2
This method's main responsibility is to flush the pending dups into refined spans, if appropriate.
2023-10-16coverage: Rename `check_invoked_macro_name_span` to `maybe_push_macro_name_span`Zalathar-5/+7
2023-10-15Auto merge of #116688 - compiler-errors:rustfmt-up, r=WaffleLapkin,Nilstriebbors-78/+139
Format all the let-chains in compiler crates Since rust-lang/rustfmt#5910 has landed, soon we will have support for formatting let-chains (as soon as rustfmt syncs and beta gets bumped). This PR applies the changes [from master rustfmt to rust-lang/rust eagerly](https://rust-lang.zulipchat.com/#narrow/stream/122651-general/topic/out.20formatting.20of.20prs/near/374997516), so that the next beta bump does not have to deal with a 200+ file diff and can remain concerned with other things like `cfg(bootstrap)` -- #113637 was a pain to land, for example, because of let-else. I will also add this commit to the ignore list after it has landed. The commands that were run -- I'm not great at bash-foo, but this applies rustfmt to every compiler crate, and then reverts the two crates that should probably be formatted out-of-tree. ``` ~/rustfmt $ ls -1d ~/rust/compiler/* | xargs -I@ cargo run --bin rustfmt -- `@/src/lib.rs` --config-path ~/rust --edition=2021 # format all of the compiler crates ~/rust $ git checkout HEAD -- compiler/rustc_codegen_{gcc,cranelift} # revert changes to cg-gcc and cg-clif ``` cc `@rust-lang/rustfmt` r? `@WaffleLapkin` or `@Nilstrieb` who said they may be able to review this purely mechanical PR :> cc `@Mark-Simulacrum` and `@petrochenkov,` who had some thoughts on the order of operations with big formatting changes in https://github.com/rust-lang/rust/pull/95262#issue-1178993801. I think the situation has changed since then, given that let-chains support exists on master rustfmt now, and I'm fairly confident that this formatting PR should land even if *bootstrap* rustfmt doesn't yet format let-chains in order to lessen the burden of the next beta bump.
2023-10-14Auto merge of #115524 - RalfJung:misalign, r=wesleywiserbors-32/+6
const-eval: make misalignment a hard error It's been a future-incompat error (showing up in cargo's reports) since https://github.com/rust-lang/rust/pull/104616, Rust 1.68, released in March. That should be long enough. The question for the lang team is simply -- should we move ahead with this, making const-eval alignment failures a hard error? (It turns out some of them accidentally already were hard errors since #104616. But not all so this is still a breaking change. Crater found no regression.)
2023-10-13Format all the let chains in compilerMichael Goulet-78/+139
2023-10-12coverage: Simplify adding BCB successors to the traversal worklistsZalathar-38/+39
2023-10-12coverage: Don't store loop backedges in the traversal contextZalathar-7/+10
As long as we store the loop header BCB, we can look up its incoming loop backedges as needed.
2023-10-12coverage: Store a graph reference in the graph traversal structZalathar-17/+16
Having to keep passing in a graph reference was a holdover from when the graph was partly mutated during traversal. As of #114354 that is no longer necessary, so we can simplify the traversal code by storing a graph reference as a field in `TraverseCoverageGraphWithLoops`.
2023-10-12coverage: Use a `VecDeque` for loop traversal worklistsZalathar-31/+18
The previous code was storing the worklist in a vector, and then selectively adding items to the start or end of the vector. That's a perfect use-case for a double-ended queue. This change also reveals that the existing code was a bit confused about which end of the worklist is the front or back. For now, items are always removed from the front of the queue (instead of the back), and code that adds items to the queue has been flipped, to preserve the existing behaviour.
2023-10-12coverage: Rename `next_bcb` to just `bcb`Zalathar-9/+10
This is the only BCB that `TraverseCoverageGraphWithLoops::next` works with, so calling it `next_bcb` just makes the code less clear.
2023-10-12coverage: Simplify the detection of reloop edges to be given expressionsZalathar-82/+57
2023-10-11Rollup merge of #116315 - cjgillot:cpl-clean, r=petrochenkovMatthias Krüger-50/+11
Do not check for impossible predicates in const-prop lint. The enclosing query already checks for them, and replaces the body with a single `unreachable` if they are indeed impossible.
2023-10-10Auto merge of #113915 - cjgillot:ssa-call, r=tmiaskobors-43/+71
Also consider call and yield as MIR SSA. The SSA analysis on MIR only considered `Assign` statements as defining a SSA local. This PR adds assignments as part of a `Call` or `Yield` terminator in that category. This mainly allows to perform CopyProp on a call return place. The only subtlety is in the dominance property: the assignment is only complete at the beginning of the target block.
2023-10-10Rollup merge of #116595 - RalfJung:mir-enable-passes, r=oli-obkMatthias Krüger-1/+5
-Zmir-enable-passes: document that this may enable unsound passes also add some comments explaining why MIR opts are marked as unsound
2023-10-10Rollup merge of #116589 - Zalathar:successors, r=oli-obkMatthias Krüger-80/+38
coverage: Unbox and simplify `bcb_filtered_successors` This is a small cleanup in the coverage instrumentor's graph-building code. --- This function already has access to the MIR body, so instead of taking a reference to a terminator, it's simpler and easier to pass in a basic block index. There is no need to box the returned iterator if we instead add appropriate lifetime captures, and make `short_circuit_preorder` generic over the type of iterator it expects. We can also greatly simplify the function's implementation by observing that the only difference between its two cases is whether we take all of a BB's successors, or just the first one. --- `@rustbot` label +A-code-coverage
2023-10-10add some comments explaining why MIR opts are marked as unsoundRalf Jung-1/+5
2023-10-10coverage: Unbox and simplify `bcb_filtered_successors`Zalathar-28/+24
This function already has access to the MIR body, so instead of taking a reference to a terminator, it's simpler and easier to pass in a basic block index. There is no need to box the returned iterator if we instead add appropriate lifetime captures, since `short_circuit_preorder` is now generic over the type of iterator it expects. We can also greatly simplify the function's implementation by observing that the only difference between its two cases is whether we take all of a BB's successors, or just the first one.
2023-10-10coverage: Replace `ShortCircuitPreorder` with a single functionZalathar-55/+17
Instead of defining a named struct, we can use `std::iter::from_fn` and store intermediate state in a closure.
2023-10-10coverage: Remove enum `CoverageStatement`Zalathar-46/+17
This enum was mainly needed to track the precise origin of a span in MIR, for debug printing purposes. Since the old debug code was removed in #115962, we can replace it with just the span itself.
2023-10-10coverage: Disconnect span extraction from `CoverageSpansGenerator`Zalathar-87/+85
By performal initial span extraction in a separate free function, we can remove some accidental complexity from the main generator code.
2023-10-10coverage: Move initial MIR span extraction into a submoduleZalathar-185/+194
2023-10-09Rollup merge of #116549 - DaniPopes:miropts-let-chains, r=oli-obkMatthias Krüger-86/+43
Simplify some mir passes by using let chains
2023-10-09Auto merge of #116533 - cjgillot:skip-trivial-mir, r=oli-obkbors-0/+9
Do not run optimizations on trivial MIR. Fixes https://github.com/rust-lang/rust/issues/116513 The bug was introduced in https://github.com/rust-lang/rust/pull/110728, which put the check too early in the query chain. cc `@oli-obk` `@ouz-a`
2023-10-09Simplify some mir passes by using let chainsDaniPopes-86/+43
2023-10-08Also consider call and yield as MIR SSA.Camille GILLOT-43/+71
2023-10-08Auto merge of #116454 - tmiasko:small-dominators, r=cjgillotbors-64/+30
Generalize small dominators optimization * Use small dominators optimization from 640ede7b0a1840415cb6ec881c2210302bfeba18 more generally. * Merge `DefLocation` and `LocationExtended` since they serve the same purpose.
2023-10-08Do not run optimizations on trivial MIR.Camille GILLOT-0/+9
2023-10-06Preserve DebugInfo in DeadStoreElimination.Camille GILLOT-7/+15
2023-10-05Replace LocationExtended with DefLocation in SsaLocalsTomasz Miąsko-27/+11
2023-10-05Remove small dominators optimization from SsaLocalsTomasz Miąsko-41/+23
The optimization is now part of the general implementation.
2023-10-05move subtyper change reveal_allouz-a-3/+9
2023-10-04Remove mir::LocalDecl::internal.Camille GILLOT-11/+7
2023-10-03Auto merge of #115301 - Zalathar:regions-vec, r=davidtwcobors-112/+115
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-03coverage: Remove `next_id` methods from counter/expression IDsZalathar-2/+2
When these methods were originally written, I wasn't aware that `newtype_index!` already supports addition with ordinary numbers, without needing to unwrap and re-wrap.
2023-10-03coverage: Remove code for making expression copies of BCB countersZalathar-14/+2
Now that coverage statements can have multiple code regions attached to them, this code is never used.
2023-10-03coverage: Store each BCB's code regions in one coverage statementZalathar-21/+28
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-03coverage: Let each coverage statement hold a vector of code regionsZalathar-18/+17
This makes it possible for a `StatementKind::Coverage` to hold more than one code region, but that capability is not yet used.
2023-10-03coverage: Update comments/logs that referred to `CoverageSpan`Zalathar-20/+20
The concrete type `CoverageSpan` is no longer used outside of the `spans` module. This is a separate patch to avoid noise in the preceding patch that actually encapsulates coverage spans.
2023-10-03coverage: Encapsulate coverage spansZalathar-54/+63
By encapsulating the coverage spans in a struct, we can change the internal representation without disturbing existing call sites. This will be useful for grouping coverage spans by BCB. This patch includes some changes that were originally in #115912, which avoid the need for a particular test to deal with coverage spans at all. (Comments/logs referring to `CoverageSpan` are updated in a subsequent patch.)
2023-10-02have better explanation for `relate_types`ouz-a-7/+14
2023-10-02change is_subtype to relate_typesouz-a-3/+21
2023-10-02Add docs, remove code, change subtyper codeouz-a-9/+12