Auto merge of #115202 - ouz-a:more_smir, r=spastorino

Add stable for Constant in smir

Previously https://github.com/rust-lang/rust/pull/114587 we covered much of the groundwork needed to cover Const in smir, so there is no reason keep `Constant` as String.

r? `@spastorino`
This commit is contained in:
bors 2023-08-25 20:35:39 +00:00
commit 734a0d0aa0
2 changed files with 23 additions and 4 deletions

View File

@ -477,7 +477,19 @@ fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
match self { match self {
Copy(place) => stable_mir::mir::Operand::Copy(place.stable(tables)), Copy(place) => stable_mir::mir::Operand::Copy(place.stable(tables)),
Move(place) => stable_mir::mir::Operand::Move(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),
} }
} }
} }

View File

@ -1,8 +1,8 @@
use crate::rustc_internal::Opaque; use crate::rustc_internal::Opaque;
use crate::stable_mir::ty::{ 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)] #[derive(Clone, Debug)]
pub struct Body { pub struct Body {
@ -324,7 +324,7 @@ pub enum AggregateKind {
pub enum Operand { pub enum Operand {
Copy(Place), Copy(Place),
Move(Place), Move(Place),
Constant(String), Constant(Constant),
} }
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
@ -348,6 +348,13 @@ pub struct UserTypeProjection {
type UserTypeAnnotationIndex = usize; type UserTypeAnnotationIndex = usize;
#[derive(Clone, Debug)]
pub struct Constant {
pub span: Span,
pub user_ty: Option<UserTypeAnnotationIndex>,
pub literal: ConstantKind,
}
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct SwitchTarget { pub struct SwitchTarget {
pub value: u128, pub value: u128,