Skip to content

Commit

Permalink
Auto merge of rust-lang#115202 - ouz-a:more_smir, r=spastorino
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
bors committed Aug 25, 2023
2 parents 84382dd + cab9fc9 commit 734a0d0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
14 changes: 13 additions & 1 deletion compiler/rustc_smir/src/rustc_smir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,19 @@ impl<'tcx> Stable<'tcx> for mir::Operand<'tcx> {
match self {
Copy(place) => stable_mir::mir::Operand::Copy(place.stable(tables)),
Move(place) => stable_mir::mir::Operand::Move(place.stable(tables)),
Constant(c) => stable_mir::mir::Operand::Constant(c.to_string()),
Constant(c) => stable_mir::mir::Operand::Constant(c.stable(tables)),
}
}
}

impl<'tcx> Stable<'tcx> for mir::Constant<'tcx> {
type T = stable_mir::mir::Constant;

fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
stable_mir::mir::Constant {
span: self.span.stable(tables),
user_ty: self.user_ty.map(|u| u.as_usize()).or(None),
literal: self.literal.stable(tables),
}
}
}
Expand Down
13 changes: 10 additions & 3 deletions compiler/rustc_smir/src/stable_mir/mir/body.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::rustc_internal::Opaque;
use crate::stable_mir::ty::{
AdtDef, ClosureDef, Const, GeneratorDef, GenericArgs, Movability, Region,
AdtDef, ClosureDef, Const, ConstantKind, GeneratorDef, GenericArgs, Movability, Region,
};
use crate::stable_mir::{self, ty::Ty};
use crate::stable_mir::{self, ty::Ty, Span};

#[derive(Clone, Debug)]
pub struct Body {
Expand Down Expand Up @@ -324,7 +324,7 @@ pub enum AggregateKind {
pub enum Operand {
Copy(Place),
Move(Place),
Constant(String),
Constant(Constant),
}

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

type UserTypeAnnotationIndex = usize;

#[derive(Clone, Debug)]
pub struct Constant {
pub span: Span,
pub user_ty: Option<UserTypeAnnotationIndex>,
pub literal: ConstantKind,
}

#[derive(Clone, Debug)]
pub struct SwitchTarget {
pub value: u128,
Expand Down

0 comments on commit 734a0d0

Please sign in to comment.