about summary refs log tree commit diff
path: root/compiler/rustc_mir_transform
AgeCommit message (Collapse)AuthorLines
2024-01-16Explain side-effects from simplify_operand.Camille GILLOT-0/+4
2024-01-16Do not read a scalar on a non-scalar layout.Camille GILLOT-2/+7
2024-01-16Simplify Len.Camille GILLOT-4/+34
2024-01-16Simplify unary operations.Camille GILLOT-0/+20
2024-01-16Simplify binary ops.Camille GILLOT-2/+109
2024-01-16Auto merge of #116520 - Enselic:large-copy-into-fn, r=oli-obkbors-46/+50
large_assignments: Lint on specific large args passed to functions Requires lowering function call arg spans down to MIR, which is done in the second commit. Part of #83518 Also see * https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/arg.20Spans.20for.20TerminatorKind.3A.3ACall.3F * https://rust-lang.zulipchat.com/#narrow/stream/122651-general/topic/move_size_limit.20lint r? `@oli-obk` (E-mentor)
2024-01-16Auto merge of #119672 - cjgillot:dse-sandwich, r=oli-obkbors-7/+16
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-16Auto merge of #119439 - cjgillot:gvn-faster, r=oli-obkbors-27/+46
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-15compiler: Lower fn call arg spans down to MIRMartin Nordholts-46/+50
To enable improved accuracy of diagnostics in upcoming commits.
2024-01-14Rework how diagnostic lints are stored.Nicholas Nethercote-1/+1
`Diagnostic::code` has the type `DiagnosticId`, which has `Error` and `Lint` variants. Plus `Diagnostic::is_lint` is a bool, which should be redundant w.r.t. `Diagnostic::code`. Seems simple. Except it's possible for a lint to have an error code, in which case its `code` field is recorded as `Error`, and `is_lint` is required to indicate that it's a lint. This is what happens with `derive(LintDiagnostic)` lints. Which means those lints don't have a lint name or a `has_future_breakage` field because those are stored in the `DiagnosticId::Lint`. It's all a bit messy and confused and seems unintentional. This commit: - removes `DiagnosticId`; - changes `Diagnostic::code` to `Option<String>`, which means both errors and lints can straightforwardly have an error code; - changes `Diagnostic::is_lint` to `Option<IsLint>`, where `IsLint` is a new type containing a lint name and a `has_future_breakage` bool, so all lints can have those, error code or not.
2024-01-14coverage: Simplify computing successors in the BCB graphZalathar-14/+7
2024-01-14coverage: Move helper `add_basic_coverage_block` into a local closureZalathar-22/+18
This also switches from `split_off(0)` to `std::mem::take` when emptying the accumulated list of blocks, because `split_off(0)` handles capacity in a way that is unintuitive when used in a loop.
2024-01-14coverage: Simplify the loop that combines blocks into BCBsZalathar-57/+33
The old loop had two separate places where it would flush the acumulated list of straight-line blocks into a new BCB. One occurred at the start of the loop body when the current block couldn't be chained into, and the other occurred at the end of the loop body when the current block couldn't be chained from. The latter check can be hoisted to the start of the loop body by making it examine the previous block (which has added itself to the list) instead of the current block. With that done, we can combine the two separate flushes into one flush with two possible trigger conditions.
2024-01-14coverage: Indicate whether a block's successors allow BCB chainingZalathar-28/+63
2024-01-14coverage: Determine a block's successors from just the terminatorZalathar-14/+11
Filtering out unreachable successors is only needed by the main graph traversal loop, so we can move the filtering step into that loop instead, eliminating the need to pass the MIR body into `bcb_filtered_successors`.
2024-01-11Rollup merge of #119842 - Zalathar:kind, r=oli-obkMatthias Krüger-32/+49
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-11Do not run simplify_locals inside DSE.Camille GILLOT-2/+0
The full pass is run short after.
2024-01-11Sandwich MIR optimizations between DSE.Camille GILLOT-5/+16
2024-01-11coverage: Add enums to accommodate other kinds of coverage mappingsZalathar-7/+20
2024-01-11coverage: Store extracted spans as a flat list of mappingsZalathar-27/+27
This is less elegant in some ways, since we no longer visit a BCB's spans as a batch, but will make it much easier to add support for other kinds of coverage mapping regions (e.g. branch regions or gap regions).
2024-01-11coverage: Extract helper function `term_for_bcb`Zalathar-4/+8
2024-01-11Auto merge of #119677 - cjgillot:early-cfg-opt, r=oli-obkbors-6/+17
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-10coverage: Discard code regions that might cause fatal errors in `llvm-cov`Zalathar-1/+36
2024-01-09Rollup merge of #119699 - cjgillot:simplify-unreachable, r=oli-obkGuillaume Gomez-65/+46
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-09Rollup merge of #119668 - cjgillot:transform-promote, r=oli-obkGuillaume Gomez-1/+954
Simplify implementation of MIR promotion Non-functional changes. Best read ignoring whitespace.
2024-01-09Rollup merge of #119033 - Zalathar:unicode, r=davidtwcoMatthias Krüger-20/+71
coverage: `llvm-cov` expects column numbers to be bytes, not code points Normally the compiler emits column numbers as a 1-based number of Unicode code points. But when we embed coverage mappings for `-Cinstrument-coverage`, those mappings will ultimately be read by the `llvm-cov` tool. That tool assumes that column numbers are 1-based numbers of *bytes*, and relies on that assumption when slicing up source code to apply highlighting (in HTML reports, and in text-based reports with colour). For the very common case of all-ASCII source code, bytes and code points are the same, so the difference isn't noticeable. But for code that contains non-ASCII characters, emitting column numbers as code points will result in `llvm-cov` slicing strings in the wrong places, producing mangled output or fatal errors. (See https://github.com/taiki-e/cargo-llvm-cov/issues/275 as an example of what can go wrong.)
2024-01-08Make match exhaustive.Camille GILLOT-1/+1
2024-01-08Simplify code flow.Camille GILLOT-222/+157
2024-01-08Move promote_consts back to rustc_mir_transform.Camille GILLOT-1/+1019
2024-01-08coverage: `llvm-cov` expects column numbers to be bytes, not code pointsZalathar-14/+59
2024-01-08coverage: Allow `make_code_region` to failZalathar-6/+12
2024-01-08Remove `DiagnosticBuilderState`.Nicholas Nethercote-2/+1
Currently it's used for two dynamic checks: - When a diagnostic is emitted, has it been emitted before? - When a diagnostic is dropped, has it been emitted/cancelled? The first check is no longer need, because `emit` is consuming, so it's impossible to emit a `DiagnosticBuilder` twice. The second check is still needed. This commit replaces `DiagnosticBuilderState` with a simpler `Option<Box<Diagnostic>>`, which is enough for the second check: functions like `emit` and `cancel` can take the `Diagnostic` and then `drop` can check that the `Diagnostic` was taken. The `DiagCtxt` reference from `DiagnosticBuilderState` is now stored as its own field, removing the need for the `dcx` method. As well as making the code shorter and simpler, the commit removes: - One (deprecated) `ErrorGuaranteed::unchecked_claim_error_was_emitted` call. - Two `FIXME(eddyb)` comments that are no longer relevant. - The use of a dummy `Diagnostic` in `into_diagnostic`. Nice!
2024-01-07Do not recompute liveness for DestinationPropagation.Camille GILLOT-44/+37
2024-01-07Auto merge of #119675 - cjgillot:set-no-discriminant, r=tmiaskobors-2/+20
Skip threading over no-op SetDiscriminant. Fixes https://github.com/rust-lang/rust/issues/119674
2024-01-07Merge dead bb pruning and unreachable bb deduplication.Camille GILLOT-65/+46
2024-01-07Avoid recording no-op replacements.Camille GILLOT-5/+8
2024-01-07Do not re-simplify SSA locals.Camille GILLOT-14/+23
2024-01-07Cache feature unsized locals + use smallvec.Camille GILLOT-3/+7
2024-01-07Make rev_locals a vec.Camille GILLOT-7/+10
2024-01-07Reorder early post-inlining passes.Camille GILLOT-6/+17
2024-01-07Skip threading over no-op SetDiscriminant.Camille GILLOT-2/+20
2024-01-06rustc_mir_transform: Enforce `rustc::potential_query_instability` lintMartin Nordholts-1/+4
Stop allowing `rustc::potential_query_instability` on all of rustc_mir_transform and instead allow it on a case-by-case basis if it is safe to do so. In this particular crate, all instances were safe to allow.
2024-01-06Rollup merge of #119591 - Enselic:DestinationPropagation-stable, r=cjgillotMatthias Krüger-16/+14
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 files 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. In other words, compare this diff (before fix): * https://github.com/rust-lang/rust/blob/090d5eac722000906cc00d991f2bf052b0e388c3/tests/mir-opt/dest-prop/copy_propagation_arg.foo.DestinationPropagation.panic-unwind.diff With this diff (after fix): * https://github.com/rust-lang/rust/blob/f603babd63a607e155609dc0277806e559626ea0/tests/mir-opt/dest-prop/copy_propagation_arg.foo.DestinationPropagation.panic-unwind.diff and you can see that both before and after the fix, we replace 3 statements with `nop`s. I find it _slightly_ surprising that the test this PR affects did not previously fail spuriously due to the indeterminism of `FxHashMap`, but I guess in can be explained with the predictability of small `FxHashMap`s with `usize` (`Local`) keys, or something along those lines. This should fix [this](https://github.com/rust-lang/rust/pull/119252#discussion_r1436101791) comment, but I wanted to make a separate PR for this fix for a simpler development and review process. Part of https://github.com/rust-lang/rust/issues/84447 which is E-help-wanted. r? `@cjgillot` who is reviewer for the highly related PR https://github.com/rust-lang/rust/pull/119252.
2024-01-06Auto merge of #119499 - cjgillot:dtm-opt, r=nnethercotebors-7/+10
Two small bitset optimisations
2024-01-06Auto merge of #119648 - compiler-errors:rollup-42inxd8, r=compiler-errorsbors-154/+175
Rollup of 9 pull requests Successful merges: - #119208 (coverage: Hoist some complex code out of the main span refinement loop) - #119216 (Use diagnostic namespace in stdlib) - #119414 (bootstrap: Move -Clto= setting from Rustc::run to rustc_cargo) - #119420 (Handle ForeignItem as TAIT scope.) - #119468 (rustdoc-search: tighter encoding for f index) - #119628 (remove duplicate test) - #119638 (fix cyle error when suggesting to use associated function instead of constructor) - #119640 (library: Fix warnings in rtstartup) - #119642 (library: Fix a symlink test failing on Windows) r? `@ghost` `@rustbot` modify labels: rollup
2024-01-05Rollup merge of #119208 - Zalathar:hoist, r=WaffleLapkin,SwatinemMichael Goulet-154/+175
coverage: Hoist some complex code out of the main span refinement loop The span refinement loop in `spans.rs` takes the spans that have been extracted from MIR, and modifies them to produce more helpful output in coverage reports. It is also one of the most complicated pieces of code in the coverage instrumentor. It has an abundance of moving pieces that make it difficult to understand, and most attempts to modify it end up accidentally changing its behaviour in unacceptable ways. This PR nevertheless tries to make a dent in it by hoisting two pieces of special-case logic out of the main loop, and into separate preprocessing passes. Coverage tests show that the resulting mappings are *almost* identical, with all known differences being unimportant. This should hopefully unlock further simplifications to the refinement loop, since it now has fewer edge cases to worry about.
2024-01-06Auto merge of #119459 - cjgillot:inline-mir-utils, r=compiler-errorsbors-0/+1
Inline a few utility functions around MIR Most of them are small enough to benefit from inlining.
2024-01-05rustc_mir_transform: Make DestinationPropagation stable for queriesMartin Nordholts-16/+14
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-05Rollup merge of #119563 - compiler-errors:coroutine-resume, r=oli-obkMatthias Krüger-0/+1
Check yield terminator's resume type in borrowck In borrowck, we didn't check that the lifetimes of the `TerminatorKind::Yield`'s `resume_place` were actually compatible with the coroutine's signature. That means that the lifetimes were totally going unchecked. Whoops! This PR implements this checking. Fixes #119564 r? types
2024-01-05Rollup merge of #119577 - tmiasko:lint, r=oli-obkMichael Goulet-24/+57
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.