about summary refs log tree commit diff
path: root/compiler/rustc_mir_transform/src
AgeCommit message (Collapse)AuthorLines
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-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.
2024-01-05Rollup merge of #119538 - nnethercote:cleanup-errors-5, r=compiler-errorsMichael Goulet-12/+12
Cleanup error handlers: round 5 More rustc_errors cleanups. A sequel to https://github.com/rust-lang/rust/pull/119171. r? ````@compiler-errors````
2024-01-05Stabilize THIR unsafeckMatthew Jasper-7/+8
2024-01-05coverage: Make the remaining fields of `CoverageSpan` non-publicZalathar-4/+4
The struct itself is already non-public, so having public fields doesn't achieve anything.
2024-01-05coverage: Split out `SpanFromMir` from `CoverageSpan`Zalathar-24/+51
This draws a clear distinction between the fields/methods that are needed by initial span extraction and preprocessing, and those that are needed by the main "refinement" loop.
2024-01-05coverage: Hoist the splitting of visible macro invocationsZalathar-34/+36
2024-01-05coverage: Hoist the removal of unwanted macro expansion spansZalathar-26/+27
2024-01-05coverage: Overhaul how "visible macros" are determinedZalathar-66/+58
2024-01-05coverage: Avoid early returns from `mir_to_initial_sorted_coverage_spans`Zalathar-15/+14
2024-01-04Migrate memory overlap check from validator to lintTomasz Miąsko-10/+40
The check attempts to identify potential undefined behaviour, rather than whether MIR is well-formed. It belongs in the lint not validator.
2024-01-04Fix validation and linting of injected MIRTomasz Miąsko-3/+9
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-04Visit only reachable blocks in MIR lintTomasz Miąsko-15/+12
No functional changes - all checks have been emitted conditionally on block being rechable already.
2024-01-04Check yield terminator's resume type in borrowckMichael Goulet-0/+1
2024-01-03Rollup merge of #119444 - compiler-errors:closure-or-coroutine, r=oli-obkLeón Orell Valerian Liehr-3/+3
Rename `TyCtxt::is_closure` to `TyCtxt::is_closure_or_coroutine` This function has always been used to test whether the def-id was a closure **or** coroutine: https://github.com/rust-lang/rust/pull/118311/files#diff-69ebec59f7d38331dd1be84ede7957977dcaa39e30ed2869b04aa8c99b2079ccR552 -- the name is just confusing because it disagrees with other fns named `is_closure`, like `Ty::is_closure`. So let's rename it.
2024-01-03Rename some `Diagnostic` setters.Nicholas Nethercote-12/+12
`Diagnostic` has 40 methods that return `&mut Self` and could be considered setters. Four of them have a `set_` prefix. This doesn't seem necessary for a type that implements the builder pattern. This commit removes the `set_` prefixes on those four methods.
2024-01-02Reuse eligible_storage_live memory.Camille GILLOT-7/+10
2023-12-31Inline dominator check.Camille GILLOT-0/+1
2023-12-30is_coroutine -> is_coroutine_or_closureMichael Goulet-3/+3
2023-12-30Auto merge of #119438 - Zalathar:prepare-mappings, r=cjgillotbors-53/+74
coverage: Prepare mappings separately from injecting statements These two tasks historically needed to be interleaved, but after various recent changes (including #116046 and #116917) they can now be fully separated. --- `@rustbot` label +A-code-coverage
2023-12-30coverage: Make `coverage_counters` a local variableZalathar-31/+37
This avoids the awkwardness of having to create it in the pass's constructor, and then mutate it later to actually create the counters.
2023-12-30coverage: Prepare mappings separately from injecting statementsZalathar-29/+44
These two tasks historically needed to be interleaved, but after various recent changes (including #116046 and #116917) they can now be fully separated.
2023-12-30Auto merge of #119377 - tmiasko:after, r=cjgillotbors-6/+0
Don't validate / lint MIR before each pass To avoid redundant work and verbose output in case of failures.
2023-12-30Auto merge of #116012 - cjgillot:gvn-const, r=oli-obkbors-517/+12
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.](https://github.com/rust-lang/rust/commit/2767c4912ea249c2f613a9cedcd6c13ea1237e54)" r? `@oli-obk`
2023-12-29Rollup merge of #119322 - compiler-errors:async-gen-resume-ty, r=cjgillotMatthias Krüger-22/+13
Couple of random coroutine pass simplifications Just aesthetic changes, except for a random `Ty::new_task_context(tcx)` call that was redundant.
2023-12-29coverage: Avoid a possible query stability hazard in `CoverageCounters`Zalathar-3/+6
The iteration order of this hashmap can potentially affect the relative creation order of MIR blocks.
2023-12-29Couple of random coroutine pass simplificationsMichael Goulet-22/+13
2023-12-28Movability doesn't need to be a query anymoreMichael Goulet-17/+12
2023-12-28Remove movability from TyKind::CoroutineMichael Goulet-8/+9
2023-12-28Don't validate / lint MIR before each passTomasz Miąsko-6/+0
To avoid redundant work and verbose output in case of failures.
2023-12-28Fix some commentscuishuang-1/+1
Signed-off-by: cuishuang <imcusg@gmail.com>
2023-12-27coverage: Unexpand spans with `find_ancestor_inside_same_ctxt`Zalathar-22/+6
2023-12-26Auto merge of #119258 - compiler-errors:closure-kind, r=eholkbors-4/+5
Make closures carry their own ClosureKind Right now, we use the "`movability`" field of `hir::Closure` to distinguish a closure and a coroutine. This is paired together with the `CoroutineKind`, which is located not in the `hir::Closure`, but the `hir::Body`. This is strange and redundant. This PR introduces `ClosureKind` with two variants -- `Closure` and `Coroutine`, which is put into `hir::Closure`. The `CoroutineKind` is thus removed from `hir::Body`, and `Option<Movability>` no longer needs to be a stand-in for "is this a closure or a coroutine". r? eholk
2023-12-25Only regular coroutines have movabilityMichael Goulet-4/+5
2023-12-24Replace legacy ConstProp by GVN.Camille GILLOT-516/+11
2023-12-24Enable GVN by default.Camille GILLOT-2/+2
2023-12-24Remove `Session` methods that duplicate `DiagCtxt` methods.Nicholas Nethercote-7/+7
Also add some `dcx` methods to types that wrap `TyCtxt`, for easier access.
2023-12-22Rollup merge of #119198 - compiler-errors:desugaring, r=eholkMichael Goulet-16/+28
Split coroutine desugaring kind from source What a coroutine is desugared from (gen/async gen/async) should be separate from where it comes (fn/block/closure).
2023-12-22Rollup merge of #119077 - tmiasko:lint, r=cjgillotMichael Goulet-2/+133
Separate MIR lints from validation Add a MIR lint pass, enabled with -Zlint-mir, which identifies undefined or likely erroneous behaviour. The initial implementation mostly migrates existing checks of this nature from MIR validator, where they did not belong (those checks have false positives and there is nothing inherently invalid about MIR with undefined behaviour). Fixes #104736 Fixes #104843 Fixes #116079 Fixes #116736 Fixes #118990
2023-12-22Split coroutine desugaring kind from sourceMichael Goulet-16/+28
2023-12-22Auto merge of #119097 - nnethercote:fix-EmissionGuarantee, r=compiler-errorsbors-4/+4
Fix `EmissionGuarantee` There are some problems with the `DiagCtxt` API related to `EmissionGuarantee`. This PR fixes them. r? `@compiler-errors`