Skip to content

Add stable for Constant in smir #115202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -481,7 +481,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 @@ -359,7 +359,7 @@ pub enum AggregateKind {
pub enum Operand {
Copy(Place),
Move(Place),
Constant(String),
Constant(Constant),
}

#[derive(Clone, Debug)]
Expand All @@ -383,6 +383,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