Skip to content

Commit 2e70d95

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 30d6733 commit 2e70d95

File tree

3 files changed

+16
-49
lines changed

3 files changed

+16
-49
lines changed

compiler/rustc_smir/src/rustc_smir/mod.rs

+3-35
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ impl<'tcx> Stable<'tcx> for mir::Place<'tcx> {
691691
}
692692

693693
impl<'tcx> Stable<'tcx> for mir::PlaceElem<'tcx> {
694-
type T = stable_mir::mir::ProjectionElem<stable_mir::mir::Local, stable_mir::ty::Ty>;
694+
type T = stable_mir::mir::ProjectionElem;
695695
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
696696
use mir::ProjectionElem::*;
697697
match self {
@@ -722,40 +722,8 @@ impl<'tcx> Stable<'tcx> for mir::PlaceElem<'tcx> {
722722
impl<'tcx> Stable<'tcx> for mir::UserTypeProjection {
723723
type T = stable_mir::mir::UserTypeProjection;
724724

725-
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
726-
UserTypeProjection {
727-
base: self.base.as_usize(),
728-
projection: self.projs.iter().map(|e| e.stable(tables)).collect(),
729-
}
730-
}
731-
}
732-
733-
// ProjectionKind is nearly identical to PlaceElem, except its generic arguments are units. We
734-
// therefore don't need to resolve any arguments with the generic types.
735-
impl<'tcx> Stable<'tcx> for mir::ProjectionKind {
736-
type T = stable_mir::mir::ProjectionElem<(), ()>;
737-
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
738-
use mir::ProjectionElem::*;
739-
match self {
740-
Deref => stable_mir::mir::ProjectionElem::Deref,
741-
Field(idx, ty) => stable_mir::mir::ProjectionElem::Field(idx.stable(tables), *ty),
742-
Index(local) => stable_mir::mir::ProjectionElem::Index(*local),
743-
ConstantIndex { offset, min_length, from_end } => {
744-
stable_mir::mir::ProjectionElem::ConstantIndex {
745-
offset: *offset,
746-
min_length: *min_length,
747-
from_end: *from_end,
748-
}
749-
}
750-
Subslice { from, to, from_end } => stable_mir::mir::ProjectionElem::Subslice {
751-
from: *from,
752-
to: *to,
753-
from_end: *from_end,
754-
},
755-
Downcast(_, idx) => stable_mir::mir::ProjectionElem::Downcast(idx.stable(tables)),
756-
OpaqueCast(ty) => stable_mir::mir::ProjectionElem::OpaqueCast(*ty),
757-
Subtype(ty) => stable_mir::mir::ProjectionElem::Subtype(*ty),
758-
}
725+
fn stable(&self, _tables: &mut Tables<'tcx>) -> Self::T {
726+
UserTypeProjection { base: self.base.as_usize(), projection: format!("{:?}", self.projs) }
759727
}
760728
}
761729

compiler/stable_mir/src/mir/body.rs

+12-13
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, Eq, PartialEq)]
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

+1-1
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)