Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] mir-opt for generators/futures: copy propagate upvar into locals #108590

Next Next commit
refactoring: move replace_base utility function to root of rustc_mi…
…r_transform crate.

incorporated review feedback: simplify replace_base via Place::project_deeper
  • Loading branch information
pnkfelix committed Aug 17, 2023
commit 6277dbb4ce250473b01b4e4b0d986e5256d2318b
9 changes: 1 addition & 8 deletions compiler/rustc_mir_transform/src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,7 @@ impl<'tcx> MutVisitor<'tcx> for PinArgVisitor<'tcx> {
}
}

fn replace_base<'tcx>(place: &mut Place<'tcx>, new_base: Place<'tcx>, tcx: TyCtxt<'tcx>) {
place.local = new_base.local;

let mut new_projection = new_base.projection.to_vec();
new_projection.append(&mut place.projection.to_vec());

place.projection = tcx.mk_place_elems(&new_projection);
}
use crate::replace_base;

const SELF_ARG: Local = Local::from_u32(1);

Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_mir_transform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -626,3 +626,7 @@ fn promoted_mir(tcx: TyCtxt<'_>, def: LocalDefId) -> &IndexVec<Promoted, Body<'_

tcx.arena.alloc(promoted)
}

fn replace_base<'tcx>(place: &mut Place<'tcx>, new_base: Place<'tcx>, tcx: TyCtxt<'tcx>) {
pnkfelix marked this conversation as resolved.
Show resolved Hide resolved
*place = new_base.project_deeper(&place.projection[..], tcx)
}