Fix coroutine MIR saved local remapping#158655
Conversation
|
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
|
r? @TaKO8Ki rustbot has assigned @TaKO8Ki. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
r? cjgillot who probably has more context |
f809a69 to
fd23727
Compare
|
@rustbot ready |
| fn visit_body(&mut self, body: &mut Body<'tcx>) { | ||
| self.super_body(body); | ||
| } | ||
|
|
There was a problem hiding this comment.
This is not useful any more
| + | ||
| + bb33: { | ||
| + StorageLive(_6); | ||
| + _6 = async_drop_in_place::<[AsyncInt; 2]>(copy (_21.0: &mut [AsyncInt; 2])) -> [return: bb32, unwind: bb16]; |
There was a problem hiding this comment.
The indexing does not appear in this file. Should we output the mir for StateTransform of async_drop_in_place::<[AsyncInt; 2]>?
| PlaceElem::Field(field, ty) => { | ||
| let mut new_ty = ty; | ||
| self.visit_ty(&mut new_ty, TyContext::Location(location)); | ||
| if ty != new_ty { Some(PlaceElem::Field(field, new_ty)) } else { None } | ||
| } | ||
| PlaceElem::OpaqueCast(ty) => { | ||
| let mut new_ty = ty; | ||
| self.visit_ty(&mut new_ty, TyContext::Location(location)); | ||
| if ty != new_ty { Some(PlaceElem::OpaqueCast(new_ty)) } else { None } | ||
| } | ||
| PlaceElem::UnwrapUnsafeBinder(ty) => { | ||
| let mut new_ty = ty; | ||
| self.visit_ty(&mut new_ty, TyContext::Location(location)); | ||
| if ty != new_ty { Some(PlaceElem::UnwrapUnsafeBinder(new_ty)) } else { None } | ||
| } | ||
| PlaceElem::Deref |
There was a problem hiding this comment.
| PlaceElem::Field(field, ty) => { | |
| let mut new_ty = ty; | |
| self.visit_ty(&mut new_ty, TyContext::Location(location)); | |
| if ty != new_ty { Some(PlaceElem::Field(field, new_ty)) } else { None } | |
| } | |
| PlaceElem::OpaqueCast(ty) => { | |
| let mut new_ty = ty; | |
| self.visit_ty(&mut new_ty, TyContext::Location(location)); | |
| if ty != new_ty { Some(PlaceElem::OpaqueCast(new_ty)) } else { None } | |
| } | |
| PlaceElem::UnwrapUnsafeBinder(ty) => { | |
| let mut new_ty = ty; | |
| self.visit_ty(&mut new_ty, TyContext::Location(location)); | |
| if ty != new_ty { Some(PlaceElem::UnwrapUnsafeBinder(new_ty)) } else { None } | |
| } | |
| PlaceElem::Deref | |
| PlaceElem::Field(..) | |
| | PlaceElem::OpaqueCast(..) | |
| | PlaceElem::UnwrapUnsafeBinder(..) | |
| | PlaceElem::Deref |
| None | ||
| } else { | ||
| let mut new_local = local; | ||
| self.visit_local( | ||
| &mut new_local, | ||
| PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy), | ||
| location, | ||
| ); | ||
| if new_local == local { None } else { Some(PlaceElem::Index(new_local)) } | ||
| } |
There was a problem hiding this comment.
| None | |
| } else { | |
| let mut new_local = local; | |
| self.visit_local( | |
| &mut new_local, | |
| PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy), | |
| location, | |
| ); | |
| if new_local == local { None } else { Some(PlaceElem::Index(new_local)) } | |
| } | |
| } | |
| None |
| ) -> Option<PlaceElem<'tcx>> { | ||
| match elem { | ||
| PlaceElem::Index(local) => { | ||
| if let Some(&Some((ty, variant, idx))) = self.remap.get(local) { |
There was a problem hiding this comment.
Do you mind adding a comment to explain what happens?
| | StatementKind::Intrinsic(..) | ||
| | StatementKind::BackwardIncompatibleDropHint { .. } | ||
| | StatementKind::StorageLive(..) => {} | ||
| } |
There was a problem hiding this comment.
A bit sad that we are duplicating code, but if #157943 lands, we will be able to use replace this file with its precise liveness analysis
Signed-off-by: Xiangfei Ding <dingxiangfei2009@protonmail.ch>
Storage is still required even if the local is moved out and immediately moved in again. Signed-off-by: Xiangfei Ding <dingxiangfei2009@protonmail.ch>
fd23727 to
aa485b2
Compare
|
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. |
|
The job Click to see the possible cause of the failure (guessed by this bot) |
The unsound analysis was found while I was working on the
async-dropcode. Apparently the counter variable in the array drop glue is not correctly identified as a saved local.Also we did not patch up indices in
ProjectionElem::Indexwhen they are saved locals.The reproduction is in the older commit with the expected output.