about summary refs log tree commit diff
path: root/compiler/rustc_mir_transform/src
AgeCommit message (Collapse)AuthorLines
2024-01-25Rollup merge of #120330 - ↵Matthias Krüger-1/+6
compiler-errors:no-coroutine-info-in-coroutine-drop-body, r=nnethercote Remove coroutine info when building coroutine drop body Coroutine drop shims are not themselves coroutines, so erase the "`coroutine`" field from the body so that helper fns like `yield_ty` and `coroutine_kind` properly return `None` for the drop shim.
2024-01-25Remove unused featuresclubby789-2/+0
2024-01-25Rollup merge of #120292 - Zalathar:dismantle, r=oli-obkMatthias Krüger-212/+178
coverage: Dismantle `Instrumentor` and flatten span refinement This is a combination of two refactorings that are unrelated, but would otherwise have a merge conflict. No functional changes, other than a small tweak to debug logging as part of rearranging some functions. Ignoring whitespace is highly recommended, since most of the modified lines have just been reindented. --- The first change is to dismantle `Instrumentor` into ordinary functions. This is one of those cases where encapsulating several values into a struct ultimately hurts more than it helps. With everything stored as local variables in one main function, and passed explicitly into helper functions, it's easier to see what is used where, and make changes as necessary. --- The second change is to flatten the functions for extracting/refining coverage spans. Consolidating this code into flatter functions reduces the amount of pointer-chasing required to read and modify it.
2024-01-25Remove coroutine info when building coroutine drop bodyMichael Goulet-1/+6
2024-01-25Auto merge of #119627 - oli-obk:const_prop_lint_n̵o̵n̵sense, r=cjgillotbors-366/+362
Remove all ConstPropNonsense We track all locals and projections on them ourselves within the const propagator and only use the InterpCx to actually do some low level operations or read from constants (via `OpTy` we get for said constants). This helps moving the const prop lint out from the normal pipeline and running it just based on borrowck information. This in turn allows us to make progress on https://github.com/rust-lang/rust/pull/108730#issuecomment-1875557745 there are various follow up cleanups that can be done after this PR (e.g. not matching on Rvalue twice and doing binop checks twice), but lets try landing this one first. r? `@RalfJung`
2024-01-24Rollup merge of #120185 - Zalathar:auto-derived, r=wesleywiserLeón Orell Valerian Liehr-0/+11
coverage: Don't instrument `#[automatically_derived]` functions This PR makes the coverage instrumentor detect and skip functions that have [`#[automatically_derived]`](https://doc.rust-lang.org/reference/attributes/derive.html#the-automatically_derived-attribute) on their enclosing impl block. Most notably, this means that methods generated by built-in derives (e.g. `Clone`, `Debug`, `PartialEq`) are now ignored by coverage instrumentation, and won't appear as executed or not-executed in coverage reports. This is a noticeable change in user-visible behaviour, but overall I think it's a net improvement. For example, we've had a few user requests for this sort of change (e.g. #105055, https://github.com/rust-lang/rust/issues/84605#issuecomment-1902069040), and I believe it's the behaviour that most users will expect/prefer by default. It's possible to imagine situations where users would want to instrument these derived implementations, but I think it's OK to treat that as an opportunity to consider adding more fine-grained option flags to control the details of coverage instrumentation, while leaving this new behaviour as the default. (Also note that while `-Cinstrument-coverage` is a stable feature, the exact details of coverage instrumentation are allowed to change. So we *can* make this change; the main question is whether we *should*.) Fixes #105055.
2024-01-24Rollup merge of #119460 - Zalathar:improper-region, r=wesleywiserLeón Orell Valerian Liehr-1/+34
coverage: Never emit improperly-ordered coverage regions If we emit a coverage region that is improperly ordered (end < start), `llvm-cov` will fail with `coveragemap_error::malformed`, which is inconvenient for users and also very hard to debug. Ideally we would fix the root causes of these situations, but they tend to occur in very obscure edge-case scenarios (often involving nested macros), and we don't always have a good MCVE to work from. So it makes sense to also have a catch-all check that will prevent improperly-ordered regions from ever being emitted. --- This is mainly aimed at resolving #119453. We don't have a specific way to reproduce it, which is why I haven't been able to add a test case in this PR. But based on the information provided in that issue, this change seems likely to avoid the error in `llvm-cov`. `````@rustbot````` label +A-code-coverage
2024-01-24coverage: Flatten the functions for extracting/refining coverage spansZalathar-74/+53
Consolidating this code into flatter functions reduces the amount of pointer-chasing required to read and modify it.
2024-01-24coverage: Dismantle `Instrumentor` into ordinary functionsZalathar-139/+126
2024-01-23Auto merge of #120283 - fmease:rollup-rk0f6r5, r=fmeasebors-15/+2
Rollup of 9 pull requests Successful merges: - #112806 (Small code improvements in `collect_intra_doc_links.rs`) - #119766 (Split tait and impl trait in assoc items logic) - #120139 (Do not normalize closure signature when building `FnOnce` shim) - #120160 (Manually implement derived `NonZero` traits.) - #120171 (Fix assume and assert in jump threading) - #120183 (Add `#[coverage(off)]` to closures introduced by `#[test]` and `#[bench]`) - #120195 (add several resolution test cases) - #120259 (Split Diagnostics for Uncommon Codepoints: Add List to Display Characters Involved) - #120261 (Provide structured suggestion to use trait objects in some cases of `if` arm type divergence) r? `@ghost` `@rustbot` modify labels: rollup
2024-01-23Rollup merge of #120171 - cjgillot:jump-threading-assume-assert, r=tmiaskoLeón Orell Valerian Liehr-15/+2
Fix assume and assert in jump threading r? ``@tmiasko``
2024-01-23Move condition enabling the pass to `is_enabled`Tomasz Miąsko-6/+2
The practical motivation is to omit the pass from -Zdump-mir=all when disabled.
2024-01-23No need to check min_lengthOli Scherer-1/+1
2024-01-23Switch to using `ImmTy` instead of `OpTy`, as we don't use the `MPlace` ↵Oli Scherer-21/+16
variant at all
2024-01-23Inline Index conversion into `project` methodOli Scherer-21/+14
2024-01-23Remove unnecessary optional layout being passed alongOli Scherer-48/+26
2024-01-23Implement ConstantIndex handling and use that instead using our own ↵Oli Scherer-26/+15
ProjectionElem variant
2024-01-23Remove ConstPropMachine and re-use the DummyMachine insteadOli Scherer-141/+4
2024-01-23Avoid some packing/unpacking of the AssertLint enumOli Scherer-49/+41
2024-01-23const prop nonsense eliminatedOli Scherer-1/+6
2024-01-23We're not really using the `ConstPropMachine` anymoreOli Scherer-46/+20
2024-01-23Const prop doesn't need a stack anymoreOli Scherer-44/+22
2024-01-23Remove location threadingOli Scherer-49/+40
2024-01-23Stop using `eval_rvalue_into_place` in const propOli Scherer-156/+200
2024-01-23partially inline `eval_rvalue_into_place` for const prop lintOli Scherer-6/+185
2024-01-23Allow passing a layout to the `eval_*` methodsOli Scherer-11/+26
2024-01-23Auto merge of #116152 - cjgillot:unchunck, r=nnethercotebors-2/+2
Only use dense bitsets in dataflow analyses When a dataflow state has the size close to the number of locals, we should prefer a dense bitset, like we already store locals in a dense vector. Other occurrences of `ChunkedBitSet` need to be justified by the size of the dataflow state.
2024-01-23Do not thread through Assert terminator.Camille GILLOT-15/+2
2024-01-22Remove uses of HybridBitSet.Camille GILLOT-2/+2
2024-01-23Rename `TyCtxt::emit_spanned_lint` as `TyCtxt::emit_node_span_lint`.Nicholas Nethercote-8/+8
2024-01-22Use debug_assert instead of expanded equivalentWesley Wiser-4/+2
2024-01-22Auto merge of #120161 - cjgillot:static-pass-name, r=tmiaskobors-2/+16
Make MIR pass name a compile-time constant. Post-processing a compile-time string at runtime is a bit silly. This PR makes CTFE do it all.
2024-01-22coverage: Don't instrument `#[automatically_derived]` functionsZalathar-0/+11
2024-01-21Make MIR pass name a compile-time constant.Camille GILLOT-2/+16
2024-01-18Extract process_assign.Camille GILLOT-89/+79
2024-01-18Extract process_constant.Camille GILLOT-34/+44
2024-01-18Use an interpreter in jump threading.Camille GILLOT-27/+75
2024-01-17Rollup merge of #115291 - cjgillot:dest-prop-save, r=JakobDegenMatthias Krüger-44/+37
Save liveness results for DestinationPropagation `DestinationPropagation` needs to verify that merge candidates do not conflict with each other. This is done by verifying that a local is not live when its counterpart is written to. To get the liveness information, the pass runs `MaybeLiveLocals` dataflow analysis repeatedly, once for each propagation round. This is quite costly, and the main driver for the perf impact on `ucd` and `diesel`. (See https://github.com/rust-lang/rust/pull/115105#issuecomment-1689205908) In order to mitigate this cost, this PR proposes to save the result of the analysis into a `SparseIntervalMatrix`, and mirror merges of locals into that matrix: `liveness(destination) := liveness(destination) union liveness(source)`. <details> <summary>Proof</summary> We denote by `'` all the quantities of the transformed program. Let $\varphi$ be a mapping of locals, which maps `source` to `destination`, and is identity otherwise. The exact liveness set after a statement is $out'(statement)$, and the proposed liveness set is $\varphi(out(statement))$. Consider a statement. Suppose that the output state verifies $out' \subset phi(out)$. We want to prove that $in' \subset \varphi(in)$ where $in = (out - kill) \cup gen$, and conclude by induction. We have 2 cases: either that statement is kept with locals renumbered by $\varphi$, or it is a tautological assignment and it removed. 1. If the statement is kept: the gen-set and the kill-set of $statement' = \varphi(statement)$ are $gen' = \varphi(gen)$ and $kill' = \varphi(kill)$ exactly. From soundness requirement 3, $\varphi(in)$ is disjoint from $\varphi(kill)$. This implies that $\varphi(out - kill)$ is disjoint from $\varphi(kill)$, and so $\varphi(out - kill) = \varphi(out) - \varphi(kill)$. Then $\varphi(in) = (\varphi(out) - \varphi(kill)) \cup \varphi(gen) = (\varphi(out) - kill') \cup gen'$. We can conclude that $out' \subset \varphi(out) \implies in' \subset \varphi(in)$. 2. If the statement is removed. As $\varphi(statement)$ is a tautological assignment, we know that $\varphi(gen) = \varphi(kill) = \\{ destination \\}$, while $gen' = kill' = \emptyset$. So $\varphi(in) = \varphi(out) \cup \\{ destination \\}$. Then $in' = out' \subset out \subset \varphi(in)$. By recursion, we can conclude by that $in' \subset \varphi(in)$ everywhere. </details> This approximate liveness results is only suboptimal if there are locals that fully disappear from the CFG due to an assignment cycle. These cases are quite unlikely, so we do not bother with them. This change allows to reduce the perf impact of DestinationPropagation by half on diesel and ucd (https://github.com/rust-lang/rust/pull/115105#issuecomment-1694701904). cc ````@JakobDegen````
2024-01-17Auto merge of #119670 - cjgillot:gvn-arithmetic, r=oli-obkbors-6/+175
Fold arithmetic identities in GVN Extracted from https://github.com/rust-lang/rust/pull/111344 This PR implements a few arithmetic folds for unary and binary operations. This should take care of the missed optimizations introduced by https://github.com/rust-lang/rust/pull/116012.
2024-01-17Auto merge of #119922 - nnethercote:fix-Diag-code-is_lint, r=oli-obkbors-1/+1
Rework how diagnostic lints are stored. `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. r? `@oli-obk`
2024-01-16Expand match over binops.Camille GILLOT-15/+18
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.