Skip to content

Commit d44fa8a

Browse files
committed
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 rust-lang/rfcs#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.
1 parent 4ab50a6 commit d44fa8a

File tree

3 files changed

+16
-49
lines changed

3 files changed

+16
-49
lines changed

compiler/rustc_smir/src/rustc_smir/mod.rs

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ impl<'tcx> Stable<'tcx> for mir::Place<'tcx> {
678678
}
679679

680680
impl<'tcx> Stable<'tcx> for mir::PlaceElem<'tcx> {
681-
type T = stable_mir::mir::ProjectionElem<stable_mir::mir::Local, stable_mir::ty::Ty>;
681+
type T = stable_mir::mir::ProjectionElem;
682682
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
683683
use mir::ProjectionElem::*;
684684
match self {
@@ -709,40 +709,8 @@ impl<'tcx> Stable<'tcx> for mir::PlaceElem<'tcx> {
709709
impl<'tcx> Stable<'tcx> for mir::UserTypeProjection {
710710
type T = stable_mir::mir::UserTypeProjection;
711711

712-
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
713-
UserTypeProjection {
714-
base: self.base.as_usize(),
715-
projection: self.projs.iter().map(|e| e.stable(tables)).collect(),
716-
}
717-
}
718-
}
719-
720-
// ProjectionKind is nearly identical to PlaceElem, except its generic arguments are units. We
721-
// therefore don't need to resolve any arguments with the generic types.
722-
impl<'tcx> Stable<'tcx> for mir::ProjectionKind {
723-
type T = stable_mir::mir::ProjectionElem<(), ()>;
724-
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
725-
use mir::ProjectionElem::*;
726-
match self {
727-
Deref => stable_mir::mir::ProjectionElem::Deref,
728-
Field(idx, ty) => stable_mir::mir::ProjectionElem::Field(idx.stable(tables), *ty),
729-
Index(local) => stable_mir::mir::ProjectionElem::Index(*local),
730-
ConstantIndex { offset, min_length, from_end } => {
731-
stable_mir::mir::ProjectionElem::ConstantIndex {
732-
offset: *offset,
733-
min_length: *min_length,
734-
from_end: *from_end,
735-
}
736-
}
737-
Subslice { from, to, from_end } => stable_mir::mir::ProjectionElem::Subslice {
738-
from: *from,
739-
to: *to,
740-
from_end: *from_end,
741-
},
742-
Downcast(_, idx) => stable_mir::mir::ProjectionElem::Downcast(idx.stable(tables)),
743-
OpaqueCast(ty) => stable_mir::mir::ProjectionElem::OpaqueCast(*ty),
744-
Subtype(ty) => stable_mir::mir::ProjectionElem::Subtype(*ty),
745-
}
712+
fn stable(&self, _tables: &mut Tables<'tcx>) -> Self::T {
713+
UserTypeProjection { base: self.base.as_usize(), projection: format!("{:?}", self.projs) }
746714
}
747715
}
748716

compiler/stable_mir/src/mir/body.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -398,22 +398,23 @@ pub enum Operand {
398398
pub struct Place {
399399
pub local: Local,
400400
/// projection out of a place (access a field, deref a pointer, etc)
401-
pub projection: Vec<ProjectionElem<Local, Ty>>,
401+
pub projection: Vec<ProjectionElem>,
402402
}
403403

404-
// TODO(klinvill): in MIR ProjectionElem is parameterized on the second Field argument and the Index
405-
// argument. This is so it can be used for both the rust provided Places (for which the projection
406-
// elements are of type ProjectionElem<Local, Ty>) and user-provided type annotations (for which the
407-
// projection elements are of type ProjectionElem<(), ()>). Should we do the same thing in Stable MIR?
404+
// In MIR ProjectionElem is parameterized on the second Field argument and the Index argument. This
405+
// is so it can be used for both Places (for which the projection elements are of type
406+
// ProjectionElem<Local, Ty>) and user-provided type annotations (for which the projection elements
407+
// are of type ProjectionElem<(), ()>). In SMIR we don't need this generality, so we just use
408+
// ProjectionElem for Places.
408409
#[derive(Clone, Debug)]
409-
pub enum ProjectionElem<V, T> {
410+
pub enum ProjectionElem {
410411
/// Dereference projections (e.g. `*_1`) project to the address referenced by the base place.
411412
Deref,
412413

413414
/// A field projection (e.g., `f` in `_1.f`) project to a field in the base place. The field is
414415
/// referenced by source-order index rather than the name of the field. The fields type is also
415416
/// given.
416-
Field(FieldIdx, T),
417+
Field(FieldIdx, Ty),
417418

418419
/// Index into a slice/array. The value of the index is computed at runtime using the `V`
419420
/// argument.
@@ -429,7 +430,7 @@ pub enum ProjectionElem<V, T> {
429430
///
430431
/// The `x[i]` is turned into a `Deref` followed by an `Index`, not just an `Index`. The same
431432
/// thing is true of the `ConstantIndex` and `Subslice` projections below.
432-
Index(V),
433+
Index(Local),
433434

434435
/// Index into a slice/array given by offsets.
435436
///
@@ -472,24 +473,22 @@ pub enum ProjectionElem<V, T> {
472473

473474
/// Like an explicit cast from an opaque type to a concrete type, but without
474475
/// requiring an intermediate variable.
475-
OpaqueCast(T),
476+
OpaqueCast(Ty),
476477

477478
/// A `Subtype(T)` projection is applied to any `StatementKind::Assign` where
478479
/// type of lvalue doesn't match the type of rvalue, the primary goal is making subtyping
479480
/// explicit during optimizations and codegen.
480481
///
481482
/// This projection doesn't impact the runtime behavior of the program except for potentially changing
482483
/// some type metadata of the interpreter or codegen backend.
483-
Subtype(T),
484+
Subtype(Ty),
484485
}
485486

486487
#[derive(Clone, Debug)]
487488
pub struct UserTypeProjection {
488489
pub base: UserTypeAnnotationIndex,
489490

490-
/// `UserTypeProjection` projections need neither the `V` parameter for `Index` nor the `T` for
491-
/// `Field`.
492-
pub projection: Vec<ProjectionElem<(), ()>>,
491+
pub projection: String,
493492
}
494493

495494
pub type Local = usize;

tests/ui-fulldeps/stable-mir/projections.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ fn main() {
152152
CRATE_NAME.to_string(),
153153
path.to_string(),
154154
];
155-
run!(args, tcx, test_projections(tcx)).unwrap();
155+
run!(args, tcx, test_place_projections(tcx)).unwrap();
156156
}
157157

158158
fn generate_input(path: &str) -> std::io::Result<()> {

0 commit comments

Comments
 (0)