Skip to content

Commit cab9fc9

Browse files
committed
Add stable for Constant in smir
1 parent c9228ae commit cab9fc9

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

Diff for: compiler/rustc_smir/src/rustc_smir/mod.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,19 @@ impl<'tcx> Stable<'tcx> for mir::Operand<'tcx> {
481481
match self {
482482
Copy(place) => stable_mir::mir::Operand::Copy(place.stable(tables)),
483483
Move(place) => stable_mir::mir::Operand::Move(place.stable(tables)),
484-
Constant(c) => stable_mir::mir::Operand::Constant(c.to_string()),
484+
Constant(c) => stable_mir::mir::Operand::Constant(c.stable(tables)),
485+
}
486+
}
487+
}
488+
489+
impl<'tcx> Stable<'tcx> for mir::Constant<'tcx> {
490+
type T = stable_mir::mir::Constant;
491+
492+
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
493+
stable_mir::mir::Constant {
494+
span: self.span.stable(tables),
495+
user_ty: self.user_ty.map(|u| u.as_usize()).or(None),
496+
literal: self.literal.stable(tables),
485497
}
486498
}
487499
}

Diff for: compiler/rustc_smir/src/stable_mir/mir/body.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use crate::rustc_internal::Opaque;
22
use crate::stable_mir::ty::{
3-
AdtDef, ClosureDef, Const, GeneratorDef, GenericArgs, Movability, Region,
3+
AdtDef, ClosureDef, Const, ConstantKind, GeneratorDef, GenericArgs, Movability, Region,
44
};
5-
use crate::stable_mir::{self, ty::Ty};
5+
use crate::stable_mir::{self, ty::Ty, Span};
66

77
#[derive(Clone, Debug)]
88
pub struct Body {
@@ -359,7 +359,7 @@ pub enum AggregateKind {
359359
pub enum Operand {
360360
Copy(Place),
361361
Move(Place),
362-
Constant(String),
362+
Constant(Constant),
363363
}
364364

365365
#[derive(Clone, Debug)]
@@ -383,6 +383,13 @@ pub type VariantIdx = usize;
383383

384384
type UserTypeAnnotationIndex = usize;
385385

386+
#[derive(Clone, Debug)]
387+
pub struct Constant {
388+
pub span: Span,
389+
pub user_ty: Option<UserTypeAnnotationIndex>,
390+
pub literal: ConstantKind,
391+
}
392+
386393
#[derive(Clone, Debug)]
387394
pub struct SwitchTarget {
388395
pub value: u128,

0 commit comments

Comments
 (0)