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.
This commit is contained in:
parent
30d6733eb3
commit
2e70d95cdb
@ -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) }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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<()> {
|
||||
|
Loading…
x
Reference in New Issue
Block a user