Misc improvements to coroutine transform code#156672
Conversation
|
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
|
r? @tiif rustbot has assigned @tiif. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
0c96073 to
757cfe5
Compare
This comment has been minimized.
This comment has been minimized.
| writeln!(w, "{INDENT}{INDENT}variant_fields = {{")?; | ||
| for (variant, fields) in variant_fields.iter_enumerated() { | ||
| let variant_name = ty::CoroutineArgs::variant_name(variant); | ||
| let header = format!("{INDENT}{INDENT}{INDENT}{variant_name:9}({variant:?}): {fields:?},"); |
There was a problem hiding this comment.
I am trying to figure out what is the reason of having {variant_name:9}, does the variant name have at most 9 characters?
There was a problem hiding this comment.
Mainly: because impl Debug for CoroutineLayout uses that.
Variant names are Unresumed (9), Returned (8), Poisoned (8) and Suspend followed by a number.
| if let Some(name) = name | ||
| && let source_info = layout.field_tys[field].source_info | ||
| && source_info.scope == parent | ||
| { |
There was a problem hiding this comment.
| if let Some(name) = name | |
| && let source_info = layout.field_tys[field].source_info | |
| && source_info.scope == parent | |
| { | |
| let source_info = layout.field_tys[field].source_info; | |
| if let Some(name) = name | |
| && source_info.scope == parent | |
| { |
It might be clearer to separate source_info from the condition statement?
| | TerminatorKind::Unreachable | ||
| | TerminatorKind::CoroutineDrop | ||
| | TerminatorKind::FalseEdge { .. } | ||
| | TerminatorKind::FalseUnwind { .. } => {} |
There was a problem hiding this comment.
In this PR, can_unwind will return true if there is a TerminatorKind::FalseUnwind, but previously it will not. Will this introduce any kind of behavioural change?
There was a problem hiding this comment.
FalseUnwind cannot happen at this stage of compilation.
| @@ -1173,40 +1173,8 @@ fn can_unwind<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>) -> bool { | |||
| } | |||
|
|
|||
| // Unwinds can only start at certain terminators. | |||
There was a problem hiding this comment.
| // Unwinds can only start at certain terminators. |
| body.basic_blocks.iter().any(|block| block.terminator().unwind().is_some()) | ||
| // If we didn't find an unwinding terminator, the function cannot unwind. |
There was a problem hiding this comment.
| body.basic_blocks.iter().any(|block| block.terminator().unwind().is_some()) | |
| // If we didn't find an unwinding terminator, the function cannot unwind. | |
| // If we didn't find an unwinding terminator, the function cannot unwind. | |
| body.basic_blocks.iter().any(|block| block.terminator().unwind().is_some()) |
|
r? @oli-obk |
This comment has been minimized.
This comment has been minimized.
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
…uwer Rollup of 12 pull requests Successful merges: - #154591 (Remove `will_cache_on_disk_for_key_fn`) - #156672 (Misc improvements to coroutine transform code) - #157027 (HIR ty lowering: Move some things into submodules) - #157051 (Allow two object files for a single CGU in CompiledModule) - #157100 (Some more per owner things) - #153497 (Use `trait_object_dummy_self` more & heavily fix+update related docs) - #155638 (Fix tupled closure signature in `AsyncFn` arg mismatch diagnostic) - #156826 (style: Clarify nullary call and `()` no-break rule applies past max width) - #157004 (Remove unused functions in `value_analysis.rs`) - #157032 (Fixed more &x ->&mut x suggestions) - #157033 (Note irrefutable while let in loop type errors) - #157139 (compiler: `ops::RangeInclusive` → `range::RangeInclusive`) Failed merges: - #156875 (Correct and document semantics of `yield` terminator)
Rollup merge of #156672 - cjgillot:coroutine-qol, r=oli-obk Misc improvements to coroutine transform code Several quality-of-life improvements: A dedicated mir-opt directory for coroutines, there are very few tests right now, but more should come. A dedicated pretty-printer for coroutine layout. In particular, it does not rely on `Ty as Debug` which has unstable output. This is important for async fns which capture opaque types, in particular other async fns. A drive-by simplification. Last, I change how the coroutine entry block is inserted. The current implementation shifts everything by 1. I prefer swapping with the current entry, which makes debugging and MIR diffing much easier.
Several quality-of-life improvements:
A dedicated mir-opt directory for coroutines, there are very few tests right now, but more should come.
A dedicated pretty-printer for coroutine layout. In particular, it does not rely on
Ty as Debugwhich has unstable output. This is important for async fns which capture opaque types, in particular other async fns.A drive-by simplification.
Last, I change how the coroutine entry block is inserted. The current implementation shifts everything by 1. I prefer swapping with the current entry, which makes debugging and MIR diffing much easier.