diff --git a/compiler/rustc_smir/src/rustc_smir/mod.rs b/compiler/rustc_smir/src/rustc_smir/mod.rs index 83bacfb8263f8..a4d83debb57bc 100644 --- a/compiler/rustc_smir/src/rustc_smir/mod.rs +++ b/compiler/rustc_smir/src/rustc_smir/mod.rs @@ -691,7 +691,7 @@ impl<'tcx> Stable<'tcx> for mir::Place<'tcx> { } impl<'tcx> Stable<'tcx> for mir::PlaceElem<'tcx> { - type T = stable_mir::mir::ProjectionElem; + type T = stable_mir::mir::ProjectionElem; fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T { use mir::ProjectionElem::*; match self { @@ -722,40 +722,8 @@ impl<'tcx> Stable<'tcx> for mir::PlaceElem<'tcx> { impl<'tcx> Stable<'tcx> for mir::UserTypeProjection { type T = stable_mir::mir::UserTypeProjection; - fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T { - UserTypeProjection { - base: self.base.as_usize(), - projection: self.projs.iter().map(|e| e.stable(tables)).collect(), - } - } -} - -// ProjectionKind is nearly identical to PlaceElem, except its generic arguments are units. We -// therefore don't need to resolve any arguments with the generic types. -impl<'tcx> Stable<'tcx> for mir::ProjectionKind { - type T = stable_mir::mir::ProjectionElem<(), ()>; - fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T { - use mir::ProjectionElem::*; - match self { - Deref => stable_mir::mir::ProjectionElem::Deref, - Field(idx, ty) => stable_mir::mir::ProjectionElem::Field(idx.stable(tables), *ty), - Index(local) => stable_mir::mir::ProjectionElem::Index(*local), - ConstantIndex { offset, min_length, from_end } => { - stable_mir::mir::ProjectionElem::ConstantIndex { - offset: *offset, - min_length: *min_length, - from_end: *from_end, - } - } - Subslice { from, to, from_end } => stable_mir::mir::ProjectionElem::Subslice { - from: *from, - to: *to, - from_end: *from_end, - }, - Downcast(_, idx) => stable_mir::mir::ProjectionElem::Downcast(idx.stable(tables)), - OpaqueCast(ty) => stable_mir::mir::ProjectionElem::OpaqueCast(*ty), - Subtype(ty) => stable_mir::mir::ProjectionElem::Subtype(*ty), - } + fn stable(&self, _tables: &mut Tables<'tcx>) -> Self::T { + UserTypeProjection { base: self.base.as_usize(), projection: format!("{:?}", self.projs) } } } diff --git a/compiler/stable_mir/src/mir/body.rs b/compiler/stable_mir/src/mir/body.rs index 69e83efdf43a3..49b85d665b1b8 100644 --- a/compiler/stable_mir/src/mir/body.rs +++ b/compiler/stable_mir/src/mir/body.rs @@ -398,22 +398,23 @@ pub enum Operand { pub struct Place { pub local: Local, /// projection out of a place (access a field, deref a pointer, etc) - pub projection: Vec>, + pub projection: Vec, } -// TODO(klinvill): in MIR ProjectionElem is parameterized on the second Field argument and the Index -// argument. This is so it can be used for both the rust provided Places (for which the projection -// elements are of type ProjectionElem) and user-provided type annotations (for which the -// projection elements are of type ProjectionElem<(), ()>). Should we do the same thing in Stable MIR? +// In MIR ProjectionElem is parameterized on the second Field argument and the Index argument. This +// is so it can be used for both Places (for which the projection elements are of type +// ProjectionElem) and user-provided type annotations (for which the projection elements +// are of type ProjectionElem<(), ()>). In SMIR we don't need this generality, so we just use +// ProjectionElem for Places. #[derive(Clone, Debug)] -pub enum ProjectionElem { +pub enum ProjectionElem { /// Dereference projections (e.g. `*_1`) project to the address referenced by the base place. Deref, /// A field projection (e.g., `f` in `_1.f`) project to a field in the base place. The field is /// referenced by source-order index rather than the name of the field. The fields type is also /// given. - Field(FieldIdx, T), + Field(FieldIdx, Ty), /// Index into a slice/array. The value of the index is computed at runtime using the `V` /// argument. @@ -429,7 +430,7 @@ pub enum ProjectionElem { /// /// The `x[i]` is turned into a `Deref` followed by an `Index`, not just an `Index`. The same /// thing is true of the `ConstantIndex` and `Subslice` projections below. - Index(V), + Index(Local), /// Index into a slice/array given by offsets. /// @@ -472,7 +473,7 @@ pub enum ProjectionElem { /// Like an explicit cast from an opaque type to a concrete type, but without /// requiring an intermediate variable. - OpaqueCast(T), + OpaqueCast(Ty), /// A `Subtype(T)` projection is applied to any `StatementKind::Assign` where /// type of lvalue doesn't match the type of rvalue, the primary goal is making subtyping @@ -480,16 +481,14 @@ pub enum ProjectionElem { /// /// This projection doesn't impact the runtime behavior of the program except for potentially changing /// some type metadata of the interpreter or codegen backend. - Subtype(T), + Subtype(Ty), } #[derive(Clone, Debug, Eq, PartialEq)] pub struct UserTypeProjection { pub base: UserTypeAnnotationIndex, - /// `UserTypeProjection` projections need neither the `V` parameter for `Index` nor the `T` for - /// `Field`. - pub projection: Vec>, + pub projection: String, } pub type Local = usize; diff --git a/tests/ui-fulldeps/stable-mir/projections.rs b/tests/ui-fulldeps/stable-mir/projections.rs index c3fbf4b6e9129..9c649a2effc75 100644 --- a/tests/ui-fulldeps/stable-mir/projections.rs +++ b/tests/ui-fulldeps/stable-mir/projections.rs @@ -152,7 +152,7 @@ fn main() { CRATE_NAME.to_string(), path.to_string(), ]; - run!(args, tcx, test_projections(tcx)).unwrap(); + run!(args, tcx, test_place_projections(tcx)).unwrap(); } fn generate_input(path: &str) -> std::io::Result<()> {