about summary refs log tree commit diff
path: root/compiler/rustc_mir_transform/src
AgeCommit message (Collapse)AuthorLines
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`
2023-12-21Stricter check for a use of locals without storageTomasz Miąsko-10/+18
2023-12-21Don't require owned data in `MaybeStorageDead`Tomasz Miąsko-1/+2
2023-12-21Lint missing StorageDead when returning from functionsTomasz Miąsko-1/+35
2023-12-21Add pass to identify undefined or erroneous behaviourTomasz Miąsko-1/+89
2023-12-20coverage: Check for `async fn` explicitly, without needing a heuristicZalathar-12/+11
The old code used a heuristic to detect async functions and adjust their coverage spans to produce better output. But there's no need to resort to a heuristic when we can just check whether the current function is actually an `async fn`.
2023-12-20coverage: Pass around `&ExtractedHirInfo` instead of individual fieldsZalathar-29/+16
This reduces the risk of mixing up `fn_source_span` and `body_span`, and makes it easier to pass along additional fields as needed.
2023-12-19Add `level` arg to `into_diagnostic`.Nicholas Nethercote-4/+4
And make all hand-written `IntoDiagnostic` impls generic, by using `DiagnosticBuilder::new(dcx, level, ...)` instead of e.g. `dcx.struct_err(...)`. This means the `create_*` functions are the source of the error level. This change will let us remove `struct_diagnostic`. Note: `#[rustc_lint_diagnostics]` is added to `DiagnosticBuilder::new`, it's necessary to pass diagnostics tests now that it's used in `into_diagnostic` functions.
2023-12-18Auto merge of #119069 - matthiaskrgr:rollup-xxk4m30, r=matthiaskrgrbors-4/+15
Rollup of 5 pull requests Successful merges: - #118852 (coverage: Skip instrumenting a function if no spans were extracted from MIR) - #118905 ([AIX] Fix XCOFF metadata) - #118967 (Add better ICE messages for some undescriptive panics) - #119051 (Replace `FileAllocationInfo` with `FileEndOfFileInfo`) - #119059 (Deny `~const` trait bounds in inherent impl headers) r? `@ghost` `@rustbot` modify labels: rollup
2023-12-18Rollup merge of #118852 - Zalathar:no-spans, r=cjgillotMatthias Krüger-4/+15
coverage: Skip instrumenting a function if no spans were extracted from MIR The immediate symptoms of #118643 were fixed by #118666, but some users reported that their builds now encounter another coverage-related ICE: ``` error: internal compiler error: compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs:98:17: A used function should have had coverage mapping data but did not: (...) ``` I was able to reproduce at least one cause of this error: if no relevant spans could be extracted from a function, but the function contains `CoverageKind::SpanMarker` statements, then codegen still thinks the function is instrumented and complains about the fact that it has no coverage spans. This PR prevents that from happening in two ways: - If we didn't extract any relevant spans from MIR, skip instrumenting the entire function and don't create a `FunctionCoverateInfo` for it. - If coverage codegen sees a `CoverageKind::SpanMarker` statement, skip it early and avoid creating `func_coverage`. --- Fixes #118850.
2023-12-18Rename many `DiagCtxt` and `EarlyDiagCtxt` locals.Nicholas Nethercote-2/+2
2023-12-18Rename many `DiagCtxt` arguments.Nicholas Nethercote-6/+3
2023-12-18Rename `DiagnosticBuilder::handler` as `DiagnosticBuilder::dcx`.Nicholas Nethercote-1/+1
2023-12-18Rename `Handler` as `DiagCtxt`.Nicholas Nethercote-3/+6
2023-12-17Avoid overflow in GVN constant indexing.Camille GILLOT-5/+3
2023-12-15Rollup merge of #119004 - matthiaskrgr:conv, r=compiler-errorsJubilee-1/+1
NFC don't convert types to identical types
2023-12-16Simplify lint decorator derive tooMichael Goulet-17/+3
2023-12-16coverage: Skip instrumenting a function if no spans were extractedZalathar-4/+15
2023-12-15NFC don't convert types to identical typesMatthias Krüger-1/+1
2023-12-15Auto merge of #118966 - matthiaskrgr:rollup-sdvjwy6, r=matthiaskrgrbors-70/+77
Rollup of 3 pull requests Successful merges: - #116888 (Add discussion that concurrent access to the environment is unsafe) - #118888 (Uplift `TypeAndMut` and `ClosureKind` to `rustc_type_ir`) - #118929 (coverage: Tidy up early parts of the instrumentor pass) r? `@ghost` `@rustbot` modify labels: rollup
2023-12-15Rollup merge of #118929 - Zalathar:look-hir, r=cjgillotMatthias Krüger-70/+77
coverage: Tidy up early parts of the instrumentor pass This is extracted from #118237, which needed to be manually rebased anyway. Unlike that PR, this one only affects the coverage instrumentor, and doesn't attempt to move any code into the MIR builder. That can be left to a future version of #118305, which can still benefit from these improvements. So this is now mostly a refactoring of some internal parts of the instrumentor.