Skip to content

Commit d517a1c

Browse files
committed
Add SMIR visitor for Places and projections
1 parent 998aa38 commit d517a1c

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

compiler/stable_mir/src/mir/body.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ pub struct Place {
406406
// ProjectionElem<Local, Ty>) and user-provided type annotations (for which the projection elements
407407
// are of type ProjectionElem<(), ()>). In SMIR we don't need this generality, so we just use
408408
// ProjectionElem for Places.
409-
#[derive(Clone, Debug)]
409+
#[derive(Clone, Debug, Eq, PartialEq)]
410410
pub enum ProjectionElem {
411411
/// Dereference projections (e.g. `*_1`) project to the address referenced by the base place.
412412
Deref,

compiler/stable_mir/src/mir/visit.rs

+32-1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,15 @@ pub trait MirVisitor {
7676
self.super_place(place, ptx, location)
7777
}
7878

79+
fn visit_projection_elem(
80+
&mut self,
81+
elem: &ProjectionElem,
82+
ptx: PlaceContext,
83+
location: Location,
84+
) {
85+
self.super_projection_elem(elem, ptx, location);
86+
}
87+
7988
fn visit_local(&mut self, local: &Local, ptx: PlaceContext, location: Location) {
8089
let _ = (local, ptx, location);
8190
}
@@ -264,7 +273,29 @@ pub trait MirVisitor {
264273
fn super_place(&mut self, place: &Place, ptx: PlaceContext, location: Location) {
265274
let _ = location;
266275
let _ = ptx;
267-
visit_opaque(&Opaque(place.projection.clone()));
276+
self.visit_local(&place.local, ptx, location);
277+
278+
for elem in &place.projection {
279+
self.visit_projection_elem(elem, ptx, location);
280+
}
281+
}
282+
283+
fn super_projection_elem(
284+
&mut self,
285+
elem: &ProjectionElem,
286+
ptx: PlaceContext,
287+
location: Location,
288+
) {
289+
match elem {
290+
ProjectionElem::Deref => {}
291+
ProjectionElem::Field(_idx, ty) => self.visit_ty(ty, location),
292+
ProjectionElem::Index(local) => self.visit_local(local, ptx, location),
293+
ProjectionElem::ConstantIndex { offset: _, min_length: _, from_end: _ } => {}
294+
ProjectionElem::Subslice { from: _, to: _, from_end: _ } => {}
295+
ProjectionElem::Downcast(_idx) => {}
296+
ProjectionElem::OpaqueCast(ty) => self.visit_ty(ty, location),
297+
ProjectionElem::Subtype(ty) => self.visit_ty(ty, location),
298+
}
268299
}
269300

270301
fn super_rvalue(&mut self, rvalue: &Rvalue, location: Location) {

0 commit comments

Comments
 (0)