Skip to content

Commit 106d686

Browse files
authored
Rollup merge of #114745 - ouz-a:smir_const, r=spastorino
Make Const more useful in smir Since #114587 is merged, we can make use of what we built and make Const more useful by making it not `Opaque` r? `@spastorino`
2 parents 475be26 + d5120d4 commit 106d686

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;
@@ -187,7 +187,11 @@ impl<'tcx> Stable<'tcx> for mir::Rvalue<'tcx> {
187187
use mir::Rvalue::*;
188188
match self {
189189
Use(op) => stable_mir::mir::Rvalue::Use(op.stable(tables)),
190-
Repeat(op, len) => stable_mir::mir::Rvalue::Repeat(op.stable(tables), opaque(len)),
190+
Repeat(op, len) => {
191+
let cnst = ConstantKind::from_const(*len, tables.tcx);
192+
let len = Const { literal: cnst.stable(tables) };
193+
stable_mir::mir::Rvalue::Repeat(op.stable(tables), len)
194+
}
191195
Ref(region, kind, place) => stable_mir::mir::Rvalue::Ref(
192196
opaque(region),
193197
kind.stable(tables),
@@ -372,7 +376,11 @@ impl<'tcx> Stable<'tcx> for ty::TermKind<'tcx> {
372376
use stable_mir::ty::TermKind;
373377
match self {
374378
ty::TermKind::Ty(ty) => TermKind::Type(tables.intern_ty(*ty)),
375-
ty::TermKind::Const(const_) => TermKind::Const(opaque(const_)),
379+
ty::TermKind::Const(cnst) => {
380+
let cnst = ConstantKind::from_const(*cnst, tables.tcx);
381+
let cnst = Const { literal: cnst.stable(tables) };
382+
TermKind::Const(cnst)
383+
}
376384
}
377385
}
378386
}
@@ -829,7 +837,10 @@ impl<'tcx> Stable<'tcx> for ty::GenericArgKind<'tcx> {
829837
match self {
830838
ty::GenericArgKind::Lifetime(region) => GenericArgKind::Lifetime(opaque(region)),
831839
ty::GenericArgKind::Type(ty) => GenericArgKind::Type(tables.intern_ty(*ty)),
832-
ty::GenericArgKind::Const(const_) => GenericArgKind::Const(opaque(&const_)),
840+
ty::GenericArgKind::Const(cnst) => {
841+
let cnst = ConstantKind::from_const(*cnst, tables.tcx);
842+
GenericArgKind::Const(stable_mir::ty::Const { literal: cnst.stable(tables) })
843+
}
833844
}
834845
}
835846
}
@@ -1035,7 +1046,9 @@ impl<'tcx> Stable<'tcx> for Ty<'tcx> {
10351046
}
10361047
ty::Str => TyKind::RigidTy(RigidTy::Str),
10371048
ty::Array(ty, constant) => {
1038-
TyKind::RigidTy(RigidTy::Array(tables.intern_ty(*ty), opaque(constant)))
1049+
let cnst = ConstantKind::from_const(*constant, tables.tcx);
1050+
let cnst = stable_mir::ty::Const { literal: cnst.stable(tables) };
1051+
TyKind::RigidTy(RigidTy::Array(tables.intern_ty(*ty), cnst))
10391052
}
10401053
ty::Slice(ty) => TyKind::RigidTy(RigidTy::Slice(tables.intern_ty(*ty))),
10411054
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)