Skip to content

Commit

Permalink
Make UserTypeProjection projections Opaque
Browse files Browse the repository at this point in the history
Also shifts comments explaining why Stable MIR drops an optional variant
name field, for `Downcast` projection elements, to the `Place::stable`
function.
  • Loading branch information
klinvill committed Nov 15, 2023
1 parent ae1726b commit c036a10
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
7 changes: 6 additions & 1 deletion compiler/rustc_smir/src/rustc_smir/mod.rs
Expand Up @@ -712,6 +712,11 @@ impl<'tcx> Stable<'tcx> for mir::PlaceElem<'tcx> {
to: *to,
from_end: *from_end,
},
// MIR includes an `Option<Symbol>` argument for `Downcast` that is the name of the
// variant, used for printing MIR. However this information should also be accessible
// via a lookup using the `VariantIdx`. The `Option<Symbol>` argument is therefore
// dropped when converting to Stable MIR. A brief justification for this decision can be
// found at https://github.com/rust-lang/rust/pull/117517#issuecomment-1811683486
Downcast(_, idx) => stable_mir::mir::ProjectionElem::Downcast(idx.stable(tables)),
OpaqueCast(ty) => stable_mir::mir::ProjectionElem::OpaqueCast(ty.stable(tables)),
Subtype(ty) => stable_mir::mir::ProjectionElem::Subtype(ty.stable(tables)),
Expand All @@ -723,7 +728,7 @@ 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: format!("{:?}", self.projs) }
UserTypeProjection { base: self.base.as_usize(), projection: opaque(&self.projs) }
}
}

Expand Down
6 changes: 1 addition & 5 deletions compiler/stable_mir/src/mir/body.rs
Expand Up @@ -465,10 +465,6 @@ pub enum ProjectionElem {
},

/// "Downcast" to a variant of an enum or a coroutine.
//
// TODO(klinvill): MIR includes an Option<Symbol> argument that is the name of the variant, used
// for printing MIR. However I don't see it used anywhere. Is such a field needed or can we just
// include the VariantIdx which could be used to recover the field name if needed?
Downcast(VariantIdx),

/// Like an explicit cast from an opaque type to a concrete type, but without
Expand All @@ -488,7 +484,7 @@ pub enum ProjectionElem {
pub struct UserTypeProjection {
pub base: UserTypeAnnotationIndex,

pub projection: String,
pub projection: Opaque,
}

pub type Local = usize;
Expand Down

0 comments on commit c036a10

Please sign in to comment.