Skip to content

Commit

Permalink
Avoid repeated interning in SelfArgVisitor.
Browse files Browse the repository at this point in the history
  • Loading branch information
nnethercote committed Aug 30, 2024
1 parent 8541b0f commit ac7a293
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions compiler/rustc_mir_transform/src/coroutine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,14 @@ impl<'tcx> MutVisitor<'tcx> for RenameLocalVisitor<'tcx> {
}

struct SelfArgVisitor<'tcx> {
elem: ProjectionElem<Local, Ty<'tcx>>,
tcx: TyCtxt<'tcx>,
new_base: Place<'tcx>,
}

impl<'tcx> SelfArgVisitor<'tcx> {
fn new(tcx: TyCtxt<'tcx>, elem: ProjectionElem<Local, Ty<'tcx>>) -> Self {
Self { tcx, new_base: Place { local: SELF_ARG, projection: tcx.mk_place_elems(&[elem]) } }
}
}

impl<'tcx> MutVisitor<'tcx> for SelfArgVisitor<'tcx> {
Expand All @@ -130,11 +136,7 @@ impl<'tcx> MutVisitor<'tcx> for SelfArgVisitor<'tcx> {

fn visit_place(&mut self, place: &mut Place<'tcx>, context: PlaceContext, location: Location) {
if place.local == SELF_ARG {
replace_base(
place,
Place { local: SELF_ARG, projection: self.tcx().mk_place_elems(&[self.elem]) },
self.tcx,
);
replace_base(place, self.new_base, self.tcx);
} else {
self.visit_local(&mut place.local, context, location);

Expand Down Expand Up @@ -475,7 +477,7 @@ fn make_coroutine_state_argument_indirect<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Bo
body.local_decls.raw[1].ty = ref_coroutine_ty;

// Add a deref to accesses of the coroutine state
SelfArgVisitor { tcx, elem: ProjectionElem::Deref }.visit_body(body);
SelfArgVisitor::new(tcx, ProjectionElem::Deref).visit_body(body);
}

fn make_coroutine_state_argument_pinned<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
Expand All @@ -490,7 +492,7 @@ fn make_coroutine_state_argument_pinned<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body
body.local_decls.raw[1].ty = pin_ref_coroutine_ty;

// Add the Pin field access to accesses of the coroutine state
SelfArgVisitor { tcx, elem: ProjectionElem::Field(FieldIdx::ZERO, ref_coroutine_ty) }
SelfArgVisitor::new(tcx, ProjectionElem::Field(FieldIdx::ZERO, ref_coroutine_ty))
.visit_body(body);
}

Expand Down

0 comments on commit ac7a293

Please sign in to comment.