Skip to content

Commit d5120d4

Browse files
committed
Make Const more useful in smir
1 parent abc910b commit d5120d4

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

compiler/rustc_smir/src/rustc_smir/mod.rs

+18-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use crate::rustc_internal::{self, opaque};
1111
use crate::stable_mir::mir::{CopyNonOverlapping, UserTypeProjection, VariantIdx};
1212
use crate::stable_mir::ty::{
13-
allocation_filter, new_allocation, FloatTy, IntTy, Movability, RigidTy, TyKind, UintTy,
13+
allocation_filter, new_allocation, Const, FloatTy, IntTy, Movability, RigidTy, TyKind, UintTy,
1414
};
1515
use crate::stable_mir::{self, Context};
1616
use rustc_hir as hir;
@@ -173,7 +173,11 @@ impl<'tcx> Stable<'tcx> for mir::Rvalue<'tcx> {
173173
use mir::Rvalue::*;
174174
match self {
175175
Use(op) => stable_mir::mir::Rvalue::Use(op.stable(tables)),
176-
Repeat(op, len) => stable_mir::mir::Rvalue::Repeat(op.stable(tables), opaque(len)),
176+
Repeat(op, len) => {
177+
let cnst = ConstantKind::from_const(*len, tables.tcx);
178+
let len = Const { literal: cnst.stable(tables) };
179+
stable_mir::mir::Rvalue::Repeat(op.stable(tables), len)
180+
}
177181
Ref(region, kind, place) => stable_mir::mir::Rvalue::Ref(
178182
opaque(region),
179183
kind.stable(tables),
@@ -358,7 +362,11 @@ impl<'tcx> Stable<'tcx> for ty::TermKind<'tcx> {
358362
use stable_mir::ty::TermKind;
359363
match self {
360364
ty::TermKind::Ty(ty) => TermKind::Type(tables.intern_ty(*ty)),
361-
ty::TermKind::Const(const_) => TermKind::Const(opaque(const_)),
365+
ty::TermKind::Const(cnst) => {
366+
let cnst = ConstantKind::from_const(*cnst, tables.tcx);
367+
let cnst = Const { literal: cnst.stable(tables) };
368+
TermKind::Const(cnst)
369+
}
362370
}
363371
}
364372
}
@@ -815,7 +823,10 @@ impl<'tcx> Stable<'tcx> for ty::GenericArgKind<'tcx> {
815823
match self {
816824
ty::GenericArgKind::Lifetime(region) => GenericArgKind::Lifetime(opaque(region)),
817825
ty::GenericArgKind::Type(ty) => GenericArgKind::Type(tables.intern_ty(*ty)),
818-
ty::GenericArgKind::Const(const_) => GenericArgKind::Const(opaque(&const_)),
826+
ty::GenericArgKind::Const(cnst) => {
827+
let cnst = ConstantKind::from_const(*cnst, tables.tcx);
828+
GenericArgKind::Const(stable_mir::ty::Const { literal: cnst.stable(tables) })
829+
}
819830
}
820831
}
821832
}
@@ -1008,7 +1019,9 @@ impl<'tcx> Stable<'tcx> for Ty<'tcx> {
10081019
}
10091020
ty::Str => TyKind::RigidTy(RigidTy::Str),
10101021
ty::Array(ty, constant) => {
1011-
TyKind::RigidTy(RigidTy::Array(tables.intern_ty(*ty), opaque(constant)))
1022+
let cnst = ConstantKind::from_const(*constant, tables.tcx);
1023+
let cnst = stable_mir::ty::Const { literal: cnst.stable(tables) };
1024+
TyKind::RigidTy(RigidTy::Array(tables.intern_ty(*ty), cnst))
10121025
}
10131026
ty::Slice(ty) => TyKind::RigidTy(RigidTy::Slice(tables.intern_ty(*ty))),
10141027
ty::RawPtr(ty::TypeAndMut { ty, mutbl }) => {

compiler/rustc_smir/src/stable_mir/ty.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ impl Ty {
1515
}
1616
}
1717

18-
pub(crate) type Const = Opaque;
18+
#[derive(Debug, Clone)]
19+
pub struct Const {
20+
pub literal: ConstantKind,
21+
}
22+
1923
type Ident = Opaque;
2024
pub(crate) type Region = Opaque;
2125
type Span = Opaque;

0 commit comments

Comments
 (0)