Skip to content

Commit 734a0d0

Browse files
committed
Auto merge of rust-lang#115202 - ouz-a:more_smir, r=spastorino
Add stable for Constant in smir Previously rust-lang#114587 we covered much of the groundwork needed to cover Const in smir, so there is no reason keep `Constant` as String. r? `@spastorino`
2 parents 84382dd + cab9fc9 commit 734a0d0

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

compiler/rustc_smir/src/rustc_smir/mod.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,19 @@ impl<'tcx> Stable<'tcx> for mir::Operand<'tcx> {
477477
match self {
478478
Copy(place) => stable_mir::mir::Operand::Copy(place.stable(tables)),
479479
Move(place) => stable_mir::mir::Operand::Move(place.stable(tables)),
480-
Constant(c) => stable_mir::mir::Operand::Constant(c.to_string()),
480+
Constant(c) => stable_mir::mir::Operand::Constant(c.stable(tables)),
481+
}
482+
}
483+
}
484+
485+
impl<'tcx> Stable<'tcx> for mir::Constant<'tcx> {
486+
type T = stable_mir::mir::Constant;
487+
488+
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
489+
stable_mir::mir::Constant {
490+
span: self.span.stable(tables),
491+
user_ty: self.user_ty.map(|u| u.as_usize()).or(None),
492+
literal: self.literal.stable(tables),
481493
}
482494
}
483495
}

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 {
@@ -324,7 +324,7 @@ pub enum AggregateKind {
324324
pub enum Operand {
325325
Copy(Place),
326326
Move(Place),
327-
Constant(String),
327+
Constant(Constant),
328328
}
329329

330330
#[derive(Clone, Debug)]
@@ -348,6 +348,13 @@ pub type VariantIdx = usize;
348348

349349
type UserTypeAnnotationIndex = usize;
350350

351+
#[derive(Clone, Debug)]
352+
pub struct Constant {
353+
pub span: Span,
354+
pub user_ty: Option<UserTypeAnnotationIndex>,
355+
pub literal: ConstantKind,
356+
}
357+
351358
#[derive(Clone, Debug)]
352359
pub struct SwitchTarget {
353360
pub value: u128,

0 commit comments

Comments
 (0)