about summary refs log tree commit diff
path: root/compiler/rustc_mir_transform
AgeCommit message (Collapse)AuthorLines
2023-12-05Auto merge of #118230 - nnethercote:streamline-dataflow-cursors, r=cjgillotbors-7/+7
Streamline MIR dataflow cursors `rustc_mir_dataflow` has two kinds of results (`Results` and `ResultsCloned`) and three kinds of results cursor (`ResultsCursor`, `ResultsClonedCursor`, `ResultsRefCursor`). I found this quite confusing. This PR removes `ResultsCloned`, `ResultsClonedCursor`, and `ResultsRefCursor`, leaving just `Results` and `ResultsCursor`. This makes the relevant code shorter and easier to read, and there is no performance penalty. r? `@cjgillot`
2023-12-04De-genericize some `IntoDiagnostic` impls.Nicholas Nethercote-3/+3
These impls are all needed for just a single `IntoDiagnostic` type, not a family of them. Note that `ErrorGuaranteed` is the default type parameter for `IntoDiagnostic`.
2023-12-03coverage: Skip spans that can't be un-expanded back to the function bodyZalathar-5/+7
When we extract coverage spans from MIR, we try to "un-expand" them back to spans that are inside the function's body span. In cases where that doesn't succeed, the current code just swaps in the entire body span instead. But that tends to result in coverage spans that are completely unrelated to the control flow of the affected code, so it's better to just discard those spans.
2023-12-02Rename `HandlerInner::delay_span_bug` as `HandlerInner::span_delayed_bug`.Nicholas Nethercote-6/+8
Because the corresponding `Level` is `DelayedBug` and `span_delayed_bug` follows the pattern used everywhere else: `span_err`, `span_warning`, etc.
2023-11-29Rollup merge of #118426 - aDotInTheVoid:const-wat, r=compiler-errors,cjgillotMatthias Krüger-1/+6
ConstProp: Correctly remove const if unknown value assigned to it. Closes #118328 The problematic sequence of MIR is: ```rust _1 = const 0_usize; _1 = const _; // This is an associated constant we can't know before monomorphization. _0 = _1; ``` 1. When `ConstProp::visit_assign` happens on `_1 = const 0_usize;`, it records that `0x0usize` is the value for `_1`. 2. Next `visit_assign` happens on `_1 = const _;`. Because the rvalue `.has_param()`, it can't be const evaled. 3. Finaly, `visit_assign` happens on `_0 = _1;`. Here it would think the value of `_1` was `0x0usize` from step 1. The solution is to remove consts when checking the RValue fails, as they may have contained values that should now be invalidated, as that local was overwritten. This should probably be back-ported to beta. Stable is more iffy, as it's gone unidentified since 1.70, so I only think it's worthwhile if there's another reason for a 1.74.1 release anyway.
2023-11-29Rollup merge of #118333 - eduardosm:print-missing-target-features, r=est31Matthias Krüger-54/+113
Print list of missing target features when calling a function with target features outside an unsafe block Fixes https://github.com/rust-lang/rust/issues/108680 Supersedes https://github.com/rust-lang/rust/pull/109710. I used the same wording for the messages, but the implementation is different. r? `@est31`
2023-11-28ConstProp: Remove const when rvalue check fails.Alona Enraght-Moony-1/+6
2023-11-28Fix coroutine validation for mixed panic strategyTomasz Miąsko-12/+4
Validation introduced in #113124 allows UnwindAction::Continue and TerminatorKind::Resume to occur only in functions with ABI that can unwind. The function ABI depends on the panic strategy, which can vary across crates. Usually MIR is built and validated in the same crate. The coroutine drop glue thus far was an exception. As a result validation could fail when mixing different panic strategies. Avoid the problem by executing AbortUnwindingCalls along with the validation.
2023-11-27Address unused tuple struct fields in the compilerJake Goulding-3/+3
2023-11-27Print list of missing target features when calling a function with target ↵Eduardo Sánchez Muñoz-54/+113
features outside an unsafe block
2023-11-27Remove uses of `ResultsClonedCursor`.Nicholas Nethercote-3/+3
By just cloning the entire `Results` in the one place where `ResultsClonedCursor` was used. This is extra allocations but the performance effect is negligible.
2023-11-27Remove one use of `as_results_cursor`.Nicholas Nethercote-4/+4
It's currently used because `requires_storage_results` is used in two locations: once with a cursor, and once later on without a cursor. The non-consuming `as_results_cursor` is used for the first location. But we can instead use the consuming `into_results_cursor` and then use `into_results` to extract the `Results` from the finished-with cursor for use at the second location.
2023-11-26Rollup merge of #118311 - bvanjoi:merge_coroutinue_into_closure, r=petrochenkovGuillaume Gomez-4/+3
merge `DefKind::Coroutine` into `Defkind::Closure` Related to #118188 We no longer need to be concerned about the precise type whether it's `DefKind::Closure` or `DefKind::Coroutine`. Furthermore, thanks for the great work done by `@petrochenkov` on investigating https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/Why.20does.20it.20hang.20when.20querying.20.EF.BB.BF.60opt_def_kind.60.3F r? `@petrochenkov`
2023-11-26merge `DefKind::Coroutine` into `DefKind::Closure`bohan-4/+3
2023-11-26rustc: `hir().local_def_id_to_hir_id()` -> `tcx.local_def_id_to_hir_id()` ↵Vadim Petrochenkov-2/+2
cleanup
2023-11-25Rollup merge of #118158 - nnethercote:reduce-fluent-boilerplate, ↵Michael Goulet-4/+1
r=compiler-errors Reduce fluent boilerplate Best reviewed one commit at a time. r? `@davidtwco`
2023-11-25Rollup merge of #117651 - Zalathar:fold-sums, r=cjgillotMichael Goulet-205/+170
coverage: Simplify building coverage expressions based on sums This is a combination of some interlinked changes to the code that creates coverage counters/expressions for nodes and edges in the coverage graph: - Some preparatory cleanups in `MakeBcbCounters::make_branch_counters` - Use `BcbCounter` (instead of `CovTerm`) when building coverage expressions - This makes it easier to introduce a fold for building sums - Simplify the creation of coverage expressions based on sums, by having `Iterator::fold` do much of the work - Get rid of the awkward `BcbBranch` enum, and replace it with graph edges represented as `(from_bcb, to_bcb)` - This further simplifies the body of the fold
2023-11-26Use `rustc_fluent_macro::fluent_messages!` directly.Nicholas Nethercote-3/+1
Currently we always do this: ``` use rustc_fluent_macro::fluent_messages; ... fluent_messages! { "./example.ftl" } ``` But there is no need, we can just do this everywhere: ``` rustc_fluent_macro::fluent_messages! { "./example.ftl" } ``` which is shorter.
2023-11-26Avoid need for `{D,Subd}iagnosticMessage` imports.Nicholas Nethercote-1/+0
The `fluent_messages!` macro produces uses of `crate::{D,Subd}iagnosticMessage`, which means that every crate using the macro must have this import: ``` use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage}; ``` This commit changes the macro to instead use `rustc_errors::{D,Subd}iagnosticMessage`, which avoids the need for the imports.
2023-11-25Auto merge of #118075 - tmiasko:validate-critical-call-edges, r=cjgillotbors-2/+3
Validate there are no critical call edges in optimized MIR
2023-11-25Auto merge of #118203 - nnethercote:rustc_mir_dataflow, r=cjgillotbors-45/+26
Minor `rustc_mir_dataflow` cleanups r? `@cjgillot`
2023-11-25coverage: Assert that bcb0 starts with bb0 and has no in-edgesZalathar-0/+13
This explains why we don't have to worry about bcb0 having multiple in-edges.
2023-11-25coverage: Eliminate `BcbBranch`Zalathar-104/+69
`BcbBranch` represented an out-edge of a coverage graph node, but would silently refer to a node instead in cases where that node only had one in-edge. Instead we now refer to a graph edge as a `(from_bcb, to_bcb)` pair, or sometimes as just one of those nodes when the other node is implied by the surrounding context. The case of sole in-edges is handled by special code added directly to `get_or_make_edge_counter_operand`.
2023-11-25coverage: Extract `CoverageGraph::bcb_has_multiple_in_edges`Zalathar-9/+16
This was previously a helper method in `MakeBcbCounters`, but putting it in the graph lets us call it from `BcbBranch`, and gives us a more fine-grained borrow.
2023-11-25coverage: Simplify building coverage expressions based on sumsZalathar-71/+54
In some cases we need to prepare a coverage expression that is the sum of an arbitrary number of other terms. This patch simplifies the code paths that build those sums. This causes some churn in the mappings, because the previous code was building its sums in a somewhat idiosyncratic order.
2023-11-25coverage: Use `BcbCounter` to build coverage expressionsZalathar-19/+16
This means that we no longer have to manage the distinction between `BcbCounter` and `CovTerm` when preparing expressions.
2023-11-25coverage: Push down creation of a visited node's counterZalathar-6/+7
Now that this code path unconditionally calls `make_branch_counters`, we might as well make that method responsible for creating the node's counter as well, since it needs the resulting term anyway.
2023-11-25coverage: Push down and inline `bcb_needs_branch_counters`Zalathar-9/+10
This lets us avoid creating two copies of the node's branch list.
2023-11-25coverage: Rename parameter `branching_bcb` to `from_bcb`Zalathar-9/+7
2023-11-23Fix fn_sig_for_fn_abi and the coroutine transform for generatorsbjorn3-1/+31
There were three issues previously: * The self argument was pinned, despite Iterator::next taking an unpinned mutable reference. * A resume argument was passed, despite Iterator::next not having one. * The return value was CoroutineState<Item, ()> rather than Option<Item> While these things just so happened to work with the LLVM backend, cg_clif does much stricter checks when trying to assign a value to a place. In addition it can't handle the mismatch between the amount of arguments specified by the FnAbi and the FnSig.
2023-11-24Remove unused arguments from `on_all_children_bits`.Nicholas Nethercote-34/+17
`on_all_children_bits` has two arguments that are unused: `tcx` and `body`. This was not detected by the compiler because it's a recursive function. This commit removes them, and removes lots of other arguments and fields that are no longer necessary.
2023-11-23Remove an unneeded local variable.Nicholas Nethercote-11/+9
`body` is already a `&Body`.
2023-11-22Replace `no_ord_impl` with `orderable`.Nicholas Nethercote-0/+1
Similar to the previous commit, this replaces `newtype_index`'s opt-out `no_ord_impl` attribute with the opt-in `orderable` attribute.
2023-11-22Replace `custom_encodable` with `encodable`.Nicholas Nethercote-1/+0
By default, `newtype_index!` types get a default `Encodable`/`Decodable` impl. You can opt out of this with `custom_encodable`. Opting out is the opposite to how Rust normally works with autogenerated (derived) impls. This commit inverts the behaviour, replacing `custom_encodable` with `encodable` which opts into the default `Encodable`/`Decodable` impl. Only 23 of the 59 `newtype_index!` occurrences need `encodable`. Even better, there were eight crates with a dependency on `rustc_serialize` just from unused default `Encodable`/`Decodable` impls. This commit removes that dependency from those eight crates.
2023-11-22Auto merge of #117928 - nnethercote:rustc_ast_pretty, r=fee1-deadbors-1/+1
`rustc_ast_pretty` cleanups Some improvements I found while looking at this code. r? `@fee1-dead`
2023-11-22Split critical call edges just before code generationTomasz Miąsko-1/+1
2023-11-22Split critical call edges in coroutine drop shimTomasz Miąsko-1/+2
2023-11-22Update itertools to 0.11.Nicholas Nethercote-1/+1
Because the API for `with_position` improved in 0.11 and I want to use it.
2023-11-21Fix `clippy::needless_borrow` in the compilerNilstrieb-53/+45
`x clippy compiler -Aclippy::all -Wclippy::needless_borrow --fix`. Then I had to remove a few unnecessary parens and muts that were exposed now.
2023-11-20Auto merge of #117783 - tmiasko:inline-ret, r=cjgillotbors-134/+163
Fix insertion of statements to be executed along return edge in inlining Inlining creates additional statements to be executed along the return edge: an assignment to the destination, storage end for temporaries. Previously those statements where inserted directly into a call target, but this is incorrect when the target has other predecessors. Avoid the issue by creating a new dedicated block for those statements. When the block happens to be redundant it will be removed by CFG simplification that follows inlining. Fixes #117355
2023-11-20Fix insertion of statements to be executed along return edge in inliningTomasz Miąsko-14/+44
Inlining creates additional statements to be executed along the return edge: an assignment to the destination, storage end for temporaries. Previously those statements where inserted directly into a call target, but this is incorrect when the target has other predecessors. Avoid the issue by creating a new dedicated block for those statements. When the block happens to be redundant it will be removed by CFG simplification that follows inlining. Fixes #117355
2023-11-19Auto merge of #116828 - compiler-errors:nightlyify-rustc_type_ir, r=jackh726bors-1/+1
Begin to abstract `rustc_type_ir` for rust-analyzer This adds the "nightly" feature which is used by the compiler, and falls back to more simple implementations when that is not active. r? `@lcnr` or `@jackh726`
2023-11-19Use let else to reduce indentationTomasz Miąsko-124/+123
2023-11-18Auto merge of #117525 - GKFX:remove_option_payload_ptr, r=petrochenkovbors-32/+0
Remove option_payload_ptr; redundant to offset_of The `option_payload_ptr` intrinsic is no longer required as `offset_of` supports traversing enums (#114208). This PR removes it in order to dogfood offset_of (as suggested at https://github.com/rust-lang/rust/issues/106655#issuecomment-1790907626). However, it will not build until those changes reach beta (which I think is within the next 8 days?) so I've opened it as a draft.
2023-11-18Begin nightly-ifying rustc_type_irMichael Goulet-1/+1
2023-11-17rename bound region instantiationlcnr-4/+4
- `erase_late_bound_regions` -> `instantiate_bound_regions_with_erased` - `replace_late_bound_regions_X` -> `instantiate_bound_regions_X`
2023-11-16Remove option_payload_ptr; redundant to offset_ofGeorge Bateman-32/+0
2023-11-15Re-format code with new rustfmtMark Rousskov-12/+28
2023-11-14Fix def-use check for call terminatorsTomasz Miąsko-22/+33
2023-11-14Auto merge of #117801 - tmiasko:remove-zsts-fuel, r=cjgillotbors-6/+5
Remove incorrect transformation from RemoveZsts Partial removal of storage statements for a local is incorrect, so a decision to optimize cannot be make independently for each statement. Avoid the issue by performing the transformation completely or not at all.