Also use Const
in SMIR
instead of just ConstantKind
This commit is contained in:
parent
7f009e54bd
commit
a370f1baa3
3 changed files with 20 additions and 16 deletions
|
@ -1216,22 +1216,26 @@ impl<'tcx> Stable<'tcx> for ty::TraitDef {
|
|||
}
|
||||
|
||||
impl<'tcx> Stable<'tcx> for rustc_middle::mir::ConstantKind<'tcx> {
|
||||
type T = stable_mir::ty::ConstantKind;
|
||||
type T = stable_mir::ty::Const;
|
||||
|
||||
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
|
||||
match *self {
|
||||
ConstantKind::Ty(c) => c.stable(tables).literal,
|
||||
ConstantKind::Unevaluated(unev_const, ty) => {
|
||||
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()),
|
||||
})
|
||||
}
|
||||
ConstantKind::Val(val, ty) => {
|
||||
stable_mir::ty::ConstantKind::Allocated(alloc::new_allocation(ty, val, tables))
|
||||
}
|
||||
ConstantKind::Ty(c) => c.stable(tables),
|
||||
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()),
|
||||
},
|
||||
),
|
||||
},
|
||||
ConstantKind::Val(val, ty) => stable_mir::ty::Const {
|
||||
literal: stable_mir::ty::ConstantKind::Allocated(alloc::new_allocation(
|
||||
ty, val, tables,
|
||||
)),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::rustc_internal::Opaque;
|
||||
use crate::stable_mir::ty::{
|
||||
AdtDef, ClosureDef, Const, ConstantKind, GeneratorDef, GenericArgs, Movability, Region,
|
||||
AdtDef, ClosureDef, Const, GeneratorDef, GenericArgs, Movability, Region,
|
||||
};
|
||||
use crate::stable_mir::{self, ty::Ty, Span};
|
||||
|
||||
|
@ -352,7 +352,7 @@ type UserTypeAnnotationIndex = usize;
|
|||
pub struct Constant {
|
||||
pub span: Span,
|
||||
pub user_ty: Option<UserTypeAnnotationIndex>,
|
||||
pub literal: ConstantKind,
|
||||
pub literal: Const,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
|
|
|
@ -114,7 +114,7 @@ fn test_stable_mir(tcx: TyCtxt<'_>) -> ControlFlow<()> {
|
|||
for block in monomorphic.body().blocks {
|
||||
match &block.terminator {
|
||||
stable_mir::mir::Terminator::Call { func, .. } => match func {
|
||||
stable_mir::mir::Operand::Constant(c) => match &c.literal {
|
||||
stable_mir::mir::Operand::Constant(c) => match &c.literal.literal {
|
||||
stable_mir::ty::ConstantKind::Allocated(alloc) => {
|
||||
assert!(alloc.bytes.is_empty())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue