Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add types to all constants
  • Loading branch information
oli-obk committed Sep 6, 2023
commit 627fa80bdfe0889688e344a7b7dbaf586decd1a6
5 changes: 3 additions & 2 deletions compiler/rustc_smir/src/rustc_smir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1136,14 +1136,14 @@ impl<'tcx> Stable<'tcx> for ty::Const<'tcx> {
ty::PlaceholderCt(_) => unimplemented!(),
ty::Unevaluated(uv) => {
stable_mir::ty::ConstantKind::Unevaluated(stable_mir::ty::UnevaluatedConst {
ty: tables.intern_ty(self.ty()),
def: tables.const_def(uv.def),
args: uv.args.stable(tables),
promoted: None,
})
}
ty::ExprCt(_) => unimplemented!(),
},
ty: tables.intern_ty(self.ty()),
}
}
}
Expand Down Expand Up @@ -1224,17 +1224,18 @@ impl<'tcx> Stable<'tcx> for rustc_middle::mir::ConstantKind<'tcx> {
ConstantKind::Unevaluated(unev_const, ty) => stable_mir::ty::Const {
literal: stable_mir::ty::ConstantKind::Unevaluated(
stable_mir::ty::UnevaluatedConst {
ty: tables.intern_ty(ty),
def: tables.const_def(unev_const.def),
args: unev_const.args.stable(tables),
promoted: unev_const.promoted.map(|u| u.as_u32()),
},
),
ty: tables.intern_ty(ty),
},
ConstantKind::Val(val, ty) => stable_mir::ty::Const {
literal: stable_mir::ty::ConstantKind::Allocated(alloc::new_allocation(
ty, val, tables,
)),
ty: tables.intern_ty(ty),
},
}
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_smir/src/stable_mir/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ impl Foldable for Const {
super::ty::ConstantKind::Unevaluated(uv) => *uv = uv.fold(folder)?,
super::ty::ConstantKind::ParamCt(param) => *param = param.fold(folder)?,
}
this.ty = this.ty.fold(folder)?;
ControlFlow::Continue(this)
}
}
Expand All @@ -69,9 +70,8 @@ impl Foldable for Allocation {

impl Foldable for UnevaluatedConst {
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 {
ty: ty.fold(folder)?,
def: def.fold(folder)?,
args: args.fold(folder)?,
promoted: promoted.fold(folder)?,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_smir/src/stable_mir/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ impl From<TyKind> for Ty {
#[derive(Debug, Clone)]
pub struct Const {
pub literal: ConstantKind,
pub ty: Ty,
}

type Ident = Opaque;
Expand Down Expand Up @@ -298,7 +299,6 @@ pub enum ConstantKind {

#[derive(Clone, Debug)]
pub struct UnevaluatedConst {
pub ty: Ty,
pub def: ConstDef,
pub args: GenericArgs,
pub promoted: Option<Promoted>,
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_smir/src/stable_mir/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ impl Visitable for Const {
super::ty::ConstantKind::Allocated(alloc) => alloc.visit(visitor),
super::ty::ConstantKind::Unevaluated(uv) => uv.visit(visitor),
super::ty::ConstantKind::ParamCt(param) => param.visit(visitor),
}
}?;
self.ty.visit(visitor)
}
}

Expand All @@ -65,8 +66,7 @@ impl Visitable for Allocation {

impl Visitable for UnevaluatedConst {
fn super_visit<V: Visitor>(&self, visitor: &mut V) -> ControlFlow<V::Break> {
let UnevaluatedConst { ty, def, args, promoted } = self;
ty.visit(visitor)?;
let UnevaluatedConst { def, args, promoted } = self;
def.visit(visitor)?;
args.visit(visitor)?;
promoted.visit(visitor)
Expand Down