about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNicholas Nethercote <n.nethercote@gmail.com>2024-08-30 13:18:45 +1000
committerNicholas Nethercote <n.nethercote@gmail.com>2024-08-30 13:35:41 +1000
commitac7a293336e0f7afd993725e8d91f9ae7859ed89 (patch)
tree0e356cc2b2d712b7aa861c0ec7a8662c9e7d90eb
parent8541b0f1f39eac7d53bd5423289422a82bd19fdd (diff)
downloadrust-ac7a293336e0f7afd993725e8d91f9ae7859ed89.tar.gz
rust-ac7a293336e0f7afd993725e8d91f9ae7859ed89.zip
Avoid repeated interning in `SelfArgVisitor`.
-rw-r--r--compiler/rustc_mir_transform/src/coroutine.rs18
1 files changed, 10 insertions, 8 deletions
diff --git a/compiler/rustc_mir_transform/src/coroutine.rs b/compiler/rustc_mir_transform/src/coroutine.rs
index 6d5597dde67..954e6f25561 100644
--- a/compiler/rustc_mir_transform/src/coroutine.rs
+++ b/compiler/rustc_mir_transform/src/coroutine.rs
@@ -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> {
@@ -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);
 
@@ -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>) {
@@ -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);
 }