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> {
|
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 {
|
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
|
||||||
match *self {
|
match *self {
|
||||||
ConstantKind::Ty(c) => c.stable(tables).literal,
|
ConstantKind::Ty(c) => c.stable(tables),
|
||||||
ConstantKind::Unevaluated(unev_const, ty) => {
|
ConstantKind::Unevaluated(unev_const, ty) => stable_mir::ty::Const {
|
||||||
stable_mir::ty::ConstantKind::Unevaluated(stable_mir::ty::UnevaluatedConst {
|
literal: stable_mir::ty::ConstantKind::Unevaluated(
|
||||||
|
stable_mir::ty::UnevaluatedConst {
|
||||||
ty: tables.intern_ty(ty),
|
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()),
|
||||||
})
|
},
|
||||||
}
|
),
|
||||||
ConstantKind::Val(val, ty) => {
|
},
|
||||||
stable_mir::ty::ConstantKind::Allocated(alloc::new_allocation(ty, val, tables))
|
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::rustc_internal::Opaque;
|
||||||
use crate::stable_mir::ty::{
|
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};
|
use crate::stable_mir::{self, ty::Ty, Span};
|
||||||
|
|
||||||
|
@ -352,7 +352,7 @@ type UserTypeAnnotationIndex = usize;
|
||||||
pub struct Constant {
|
pub struct Constant {
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
pub user_ty: Option<UserTypeAnnotationIndex>,
|
pub user_ty: Option<UserTypeAnnotationIndex>,
|
||||||
pub literal: ConstantKind,
|
pub literal: Const,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
|
|
|
@ -114,7 +114,7 @@ fn test_stable_mir(tcx: TyCtxt<'_>) -> ControlFlow<()> {
|
||||||
for block in monomorphic.body().blocks {
|
for block in monomorphic.body().blocks {
|
||||||
match &block.terminator {
|
match &block.terminator {
|
||||||
stable_mir::mir::Terminator::Call { func, .. } => match func {
|
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) => {
|
stable_mir::ty::ConstantKind::Allocated(alloc) => {
|
||||||
assert!(alloc.bytes.is_empty())
|
assert!(alloc.bytes.is_empty())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue