Add types to all constants

This commit is contained in:
Oli Scherer 2023-09-04 15:07:17 +00:00
parent a370f1baa3
commit 627fa80bdf
4 changed files with 9 additions and 8 deletions

View File

@ -1136,7 +1136,6 @@ impl<'tcx> Stable<'tcx> for ty::Const<'tcx> {
ty::PlaceholderCt(_) => unimplemented!(), ty::PlaceholderCt(_) => unimplemented!(),
ty::Unevaluated(uv) => { ty::Unevaluated(uv) => {
stable_mir::ty::ConstantKind::Unevaluated(stable_mir::ty::UnevaluatedConst { stable_mir::ty::ConstantKind::Unevaluated(stable_mir::ty::UnevaluatedConst {
ty: tables.intern_ty(self.ty()),
def: tables.const_def(uv.def), def: tables.const_def(uv.def),
args: uv.args.stable(tables), args: uv.args.stable(tables),
promoted: None, promoted: None,
@ -1144,6 +1143,7 @@ impl<'tcx> Stable<'tcx> for ty::Const<'tcx> {
} }
ty::ExprCt(_) => unimplemented!(), ty::ExprCt(_) => unimplemented!(),
}, },
ty: tables.intern_ty(self.ty()),
} }
} }
} }
@ -1224,17 +1224,18 @@ impl<'tcx> Stable<'tcx> for rustc_middle::mir::ConstantKind<'tcx> {
ConstantKind::Unevaluated(unev_const, ty) => stable_mir::ty::Const { ConstantKind::Unevaluated(unev_const, ty) => stable_mir::ty::Const {
literal: stable_mir::ty::ConstantKind::Unevaluated( literal: stable_mir::ty::ConstantKind::Unevaluated(
stable_mir::ty::UnevaluatedConst { stable_mir::ty::UnevaluatedConst {
ty: tables.intern_ty(ty),
def: tables.const_def(unev_const.def), def: tables.const_def(unev_const.def),
args: unev_const.args.stable(tables), args: unev_const.args.stable(tables),
promoted: unev_const.promoted.map(|u| u.as_u32()), promoted: unev_const.promoted.map(|u| u.as_u32()),
}, },
), ),
ty: tables.intern_ty(ty),
}, },
ConstantKind::Val(val, ty) => stable_mir::ty::Const { ConstantKind::Val(val, ty) => stable_mir::ty::Const {
literal: stable_mir::ty::ConstantKind::Allocated(alloc::new_allocation( literal: stable_mir::ty::ConstantKind::Allocated(alloc::new_allocation(
ty, val, tables, ty, val, tables,
)), )),
ty: tables.intern_ty(ty),
}, },
} }
} }

View File

@ -51,6 +51,7 @@ impl Foldable for Const {
super::ty::ConstantKind::Unevaluated(uv) => *uv = uv.fold(folder)?, super::ty::ConstantKind::Unevaluated(uv) => *uv = uv.fold(folder)?,
super::ty::ConstantKind::ParamCt(param) => *param = param.fold(folder)?, super::ty::ConstantKind::ParamCt(param) => *param = param.fold(folder)?,
} }
this.ty = this.ty.fold(folder)?;
ControlFlow::Continue(this) ControlFlow::Continue(this)
} }
} }
@ -69,9 +70,8 @@ impl Foldable for Allocation {
impl Foldable for UnevaluatedConst { impl Foldable for UnevaluatedConst {
fn super_fold<V: Folder>(&self, folder: &mut V) -> ControlFlow<V::Break, Self> { fn super_fold<V: Folder>(&self, folder: &mut V) -> ControlFlow<V::Break, Self> {
let UnevaluatedConst { ty, def, args, promoted } = self; let UnevaluatedConst { def, args, promoted } = self;
ControlFlow::Continue(UnevaluatedConst { ControlFlow::Continue(UnevaluatedConst {
ty: ty.fold(folder)?,
def: def.fold(folder)?, def: def.fold(folder)?,
args: args.fold(folder)?, args: args.fold(folder)?,
promoted: promoted.fold(folder)?, promoted: promoted.fold(folder)?,

View File

@ -19,6 +19,7 @@ impl From<TyKind> for Ty {
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Const { pub struct Const {
pub literal: ConstantKind, pub literal: ConstantKind,
pub ty: Ty,
} }
type Ident = Opaque; type Ident = Opaque;
@ -298,7 +299,6 @@ pub enum ConstantKind {
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct UnevaluatedConst { pub struct UnevaluatedConst {
pub ty: Ty,
pub def: ConstDef, pub def: ConstDef,
pub args: GenericArgs, pub args: GenericArgs,
pub promoted: Option<Promoted>, pub promoted: Option<Promoted>,

View File

@ -47,7 +47,8 @@ impl Visitable for Const {
super::ty::ConstantKind::Allocated(alloc) => alloc.visit(visitor), super::ty::ConstantKind::Allocated(alloc) => alloc.visit(visitor),
super::ty::ConstantKind::Unevaluated(uv) => uv.visit(visitor), super::ty::ConstantKind::Unevaluated(uv) => uv.visit(visitor),
super::ty::ConstantKind::ParamCt(param) => param.visit(visitor), super::ty::ConstantKind::ParamCt(param) => param.visit(visitor),
} }?;
self.ty.visit(visitor)
} }
} }
@ -65,8 +66,7 @@ impl Visitable for Allocation {
impl Visitable for UnevaluatedConst { impl Visitable for UnevaluatedConst {
fn super_visit<V: Visitor>(&self, visitor: &mut V) -> ControlFlow<V::Break> { fn super_visit<V: Visitor>(&self, visitor: &mut V) -> ControlFlow<V::Break> {
let UnevaluatedConst { ty, def, args, promoted } = self; let UnevaluatedConst { def, args, promoted } = self;
ty.visit(visitor)?;
def.visit(visitor)?; def.visit(visitor)?;
args.visit(visitor)?; args.visit(visitor)?;
promoted.visit(visitor) promoted.visit(visitor)