Skip to content

Commit

Permalink
Restore movability to SMIR
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Dec 26, 2023
1 parent 8a8826d commit dfe369d
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_smir/src/rustc_internal/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl<'tcx> RustcInternal<'tcx> for RigidTy {
RigidTy::Closure(def, args) => {
rustc_ty::TyKind::Closure(def.0.internal(tables), args.internal(tables))
}
RigidTy::Coroutine(def, args) => {
RigidTy::Coroutine(def, args, _mov) => {
rustc_ty::TyKind::Coroutine(def.0.internal(tables), args.internal(tables))
}
RigidTy::CoroutineWitness(def, args) => {
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_smir/src/rustc_smir/convert/mir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,7 @@ impl<'tcx> Stable<'tcx> for mir::AggregateKind<'tcx> {
stable_mir::mir::AggregateKind::Coroutine(
tables.coroutine_def(*def_id),
generic_arg.stable(tables),
tables.tcx.movability(*def_id).stable(tables),
)
}
}
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_smir/src/rustc_smir/convert/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ impl<'tcx> Stable<'tcx> for ty::TyKind<'tcx> {
ty::Coroutine(def_id, generic_args) => TyKind::RigidTy(RigidTy::Coroutine(
tables.coroutine_def(*def_id),
generic_args.stable(tables),
tables.tcx.movability(*def_id).stable(tables),
)),
ty::Never => TyKind::RigidTy(RigidTy::Never),
ty::Tuple(fields) => {
Expand Down
10 changes: 7 additions & 3 deletions compiler/stable_mir/src/mir/body.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::mir::pretty::{function_body, pretty_statement, pretty_terminator};
use crate::ty::{
AdtDef, ClosureDef, Const, CoroutineDef, GenericArgs, Region, RigidTy, Ty, TyKind, VariantIdx,
AdtDef, ClosureDef, Const, CoroutineDef, GenericArgs, Movability, Region, RigidTy, Ty, TyKind,
VariantIdx,
};
use crate::{Error, Opaque, Span, Symbol};
use std::io;
Expand Down Expand Up @@ -645,7 +646,9 @@ impl Rvalue {
)),
AggregateKind::Adt(def, _, ref args, _, _) => Ok(def.ty_with_args(args)),
AggregateKind::Closure(def, ref args) => Ok(Ty::new_closure(def, args.clone())),
AggregateKind::Coroutine(def, ref args) => Ok(Ty::new_coroutine(def, args.clone())),
AggregateKind::Coroutine(def, ref args, mov) => {
Ok(Ty::new_coroutine(def, args.clone(), mov))
}
},
Rvalue::ShallowInitBox(_, ty) => Ok(Ty::new_box(*ty)),
Rvalue::CopyForDeref(place) => place.ty(locals),
Expand All @@ -659,7 +662,8 @@ pub enum AggregateKind {
Tuple,
Adt(AdtDef, VariantIdx, GenericArgs, Option<UserTypeAnnotationIndex>, Option<FieldIdx>),
Closure(ClosureDef, GenericArgs),
Coroutine(CoroutineDef, GenericArgs),
// FIXME(stable_mir): Movability here is redundant
Coroutine(CoroutineDef, GenericArgs, Movability),
}

#[derive(Clone, Debug, Eq, PartialEq)]
Expand Down
2 changes: 1 addition & 1 deletion compiler/stable_mir/src/mir/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ pub fn pretty_ty(ty: TyKind) -> String {
RigidTy::FnDef(_, _) => format!("{:#?}", rigid_ty),
RigidTy::FnPtr(_) => format!("{:#?}", rigid_ty),
RigidTy::Closure(_, _) => format!("{:#?}", rigid_ty),
RigidTy::Coroutine(_, _) => format!("{:#?}", rigid_ty),
RigidTy::Coroutine(_, _, _) => format!("{:#?}", rigid_ty),
RigidTy::Dynamic(data, region, repr) => {
// FIXME: Fix binder printing, it looks ugly now
pretty.push_str("(");
Expand Down
7 changes: 4 additions & 3 deletions compiler/stable_mir/src/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ impl Ty {
}

/// Create a new coroutine type.
pub fn new_coroutine(def: CoroutineDef, args: GenericArgs) -> Ty {
Ty::from_rigid_kind(RigidTy::Coroutine(def, args))
pub fn new_coroutine(def: CoroutineDef, args: GenericArgs, mov: Movability) -> Ty {
Ty::from_rigid_kind(RigidTy::Coroutine(def, args, mov))
}

/// Create a new box type that represents `Box<T>`, for the given inner type `T`.
Expand Down Expand Up @@ -460,7 +460,8 @@ pub enum RigidTy {
FnDef(FnDef, GenericArgs),
FnPtr(PolyFnSig),
Closure(ClosureDef, GenericArgs),
Coroutine(CoroutineDef, GenericArgs),
// FIXME(stable_mir): Movability here is redundant
Coroutine(CoroutineDef, GenericArgs, Movability),
Dynamic(Vec<Binder<ExistentialPredicate>>, Region, DynKind),
Never,
Tuple(Vec<Ty>),
Expand Down
2 changes: 1 addition & 1 deletion compiler/stable_mir/src/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ impl Visitable for RigidTy {
RigidTy::FnDef(_, args) => args.visit(visitor),
RigidTy::FnPtr(sig) => sig.visit(visitor),
RigidTy::Closure(_, args) => args.visit(visitor),
RigidTy::Coroutine(_, args) => args.visit(visitor),
RigidTy::Coroutine(_, args, _) => args.visit(visitor),
RigidTy::CoroutineWitness(_, args) => args.visit(visitor),
RigidTy::Dynamic(pred, r, _) => {
pred.visit(visitor)?;
Expand Down

0 comments on commit dfe369d

Please sign in to comment.