about summary refs log tree commit diff
diff options
context:
space:
mode:
authorKirby Linvill <kjlinvill@gmail.com>2023-11-09 20:34:30 -0700
committerKirby Linvill <kjlinvill@gmail.com>2023-11-09 20:56:40 -0700
commit2e70d95cdba8ea185c5d695c410744590785e4ac (patch)
treeafe656ec56e99a2cb3d93ebb431991c5a09165f6
parent30d6733eb3dd4c393c517056fd3cc276b288b57f (diff)
downloadrust-2e70d95cdba8ea185c5d695c410744590785e4ac.tar.gz
rust-2e70d95cdba8ea185c5d695c410744590785e4ac.zip
Remove rich UserTypeProjection projections in SMIR
It's not clear to me (klinvill) that UserTypeProjections are produced
anymore with the removal of type ascriptions as per
https://github.com/rust-lang/rfcs/pull/3307. Furthermore, it's not clear
to me which variants of ProjectionElem could appear in such projections.
For these reasons, I'm reverting projections in UserTypeProjections to
simple strings until I can get more clarity on UserTypeProjections.
-rw-r--r--compiler/rustc_smir/src/rustc_smir/mod.rs38
-rw-r--r--compiler/stable_mir/src/mir/body.rs25
-rw-r--r--tests/ui-fulldeps/stable-mir/projections.rs2
3 files changed, 16 insertions, 49 deletions
diff --git a/compiler/rustc_smir/src/rustc_smir/mod.rs b/compiler/rustc_smir/src/rustc_smir/mod.rs
index 83bacfb8263..a4d83debb57 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<stable_mir::mir::Local, stable_mir::ty::Ty>;
+    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 69e83efdf43..49b85d665b1 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<ProjectionElem<Local, Ty>>,
+    pub projection: Vec<ProjectionElem>,
 }
 
-// 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<Local, Ty>) 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<Local, Ty>) 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<V, T> {
+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<V, T> {
     ///
     /// 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<V, T> {
 
     /// 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<V, T> {
     ///
     /// 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<ProjectionElem<(), ()>>,
+    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 c3fbf4b6e91..9c649a2effc 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<()> {