Skip to content

Commit d7cb118

Browse files
committed
Merge DerefArgVisitor and PinArgVisitor.
They are almost identical, differing only in the `ProjectionElem` they insert. This commit merges them into a new type `SelfArgVisitor`.
1 parent 5331280 commit d7cb118

1 file changed

Lines changed: 7 additions & 47 deletions

File tree

‎compiler/rustc_mir_transform/src/coroutine.rs‎

Lines changed: 7 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,12 @@ impl<'tcx> MutVisitor<'tcx> for RenameLocalVisitor<'tcx> {
112112
}
113113
}
114114

115-
structDerefArgVisitor<'tcx>{
115+
structSelfArgVisitor<'tcx>{
116+
elem:ProjectionElem<Local,Ty<'tcx>>,
116117
tcx:TyCtxt<'tcx>,
117118
}
118119

119-
impl<'tcx>MutVisitor<'tcx>forDerefArgVisitor<'tcx>{
120+
impl<'tcx>MutVisitor<'tcx>forSelfArgVisitor<'tcx>{
120121
fntcx(&self) -> TyCtxt<'tcx>{
121122
self.tcx
122123
}
@@ -129,49 +130,7 @@ impl<'tcx> MutVisitor<'tcx> for DerefArgVisitor<'tcx> {
129130
if place.local == SELF_ARG{
130131
replace_base(
131132
place,
132-
Place{
133-
local:SELF_ARG,
134-
projection:self.tcx().mk_place_elems(&[ProjectionElem::Deref]),
135-
},
136-
self.tcx,
137-
);
138-
}else{
139-
self.visit_local(&mut place.local, context, location);
140-
141-
for elem in place.projection.iter(){
142-
ifletPlaceElem::Index(local) = elem {
143-
assert_ne!(local,SELF_ARG);
144-
}
145-
}
146-
}
147-
}
148-
}
149-
150-
structPinArgVisitor<'tcx>{
151-
ref_coroutine_ty:Ty<'tcx>,
152-
tcx:TyCtxt<'tcx>,
153-
}
154-
155-
impl<'tcx>MutVisitor<'tcx>forPinArgVisitor<'tcx>{
156-
fntcx(&self) -> TyCtxt<'tcx>{
157-
self.tcx
158-
}
159-
160-
fnvisit_local(&mutself,local:&mutLocal, _:PlaceContext, _:Location){
161-
assert_ne!(*local,SELF_ARG);
162-
}
163-
164-
fnvisit_place(&mutself,place:&mutPlace<'tcx>,context:PlaceContext,location:Location){
165-
if place.local == SELF_ARG{
166-
replace_base(
167-
place,
168-
Place{
169-
local:SELF_ARG,
170-
projection:self.tcx().mk_place_elems(&[ProjectionElem::Field(
171-
FieldIdx::ZERO,
172-
self.ref_coroutine_ty,
173-
)]),
174-
},
133+
Place{local:SELF_ARG,projection:self.tcx().mk_place_elems(&[self.elem])},
175134
self.tcx,
176135
);
177136
}else{
@@ -568,7 +527,7 @@ fn make_coroutine_state_argument_indirect<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Bo
568527
body.local_decls.raw[1].ty = ref_coroutine_ty;
569528

570529
// Add a deref to accesses of the coroutine state
571-
DerefArgVisitor{ tcx }.visit_body(body);
530+
SelfArgVisitor{ tcx,elem:ProjectionElem::Deref}.visit_body(body);
572531
}
573532

574533
fnmake_coroutine_state_argument_pinned<'tcx>(tcx:TyCtxt<'tcx>,body:&mutBody<'tcx>){
@@ -583,7 +542,8 @@ fn make_coroutine_state_argument_pinned<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body
583542
body.local_decls.raw[1].ty = pin_ref_coroutine_ty;
584543

585544
// Add the Pin field access to accesses of the coroutine state
586-
PinArgVisitor{ ref_coroutine_ty, tcx }.visit_body(body);
545+
SelfArgVisitor{ tcx,elem:ProjectionElem::Field(FieldIdx::ZERO, ref_coroutine_ty)}
546+
.visit_body(body);
587547
}
588548

589549
/// Allocates a new local and replaces all references of `local` with it. Returns the new local.

0 commit comments

Comments
 (0)