about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2023-08-14 21:57:51 +0200
committerGitHub <noreply@github.com>2023-08-14 21:57:51 +0200
commit106d686e9859fbeb17662dc40cda4525e2e87498 (patch)
tree26289fd72ddca2218bac52758460d216cd7c7a1c
parent475be26d99b8e3898c482e0ac42ab7bce3d511bf (diff)
parentd5120d4a4618f7cf7d04d28741f88ba3dcb69aee (diff)
downloadrust-106d686e9859fbeb17662dc40cda4525e2e87498.tar.gz
rust-106d686e9859fbeb17662dc40cda4525e2e87498.zip
Rollup merge of #114745 - ouz-a:smir_const, r=spastorino
Make Const more useful in smir

Since https://github.com/rust-lang/rust/pull/114587 is merged, we can make use of what we built and make Const more useful by making it not `Opaque`

r? `@spastorino`
-rw-r--r--compiler/rustc_smir/src/rustc_smir/mod.rs23
-rw-r--r--compiler/rustc_smir/src/stable_mir/ty.rs6
2 files changed, 23 insertions, 6 deletions
diff --git a/compiler/rustc_smir/src/rustc_smir/mod.rs b/compiler/rustc_smir/src/rustc_smir/mod.rs
index bc12422e7d7..06b37008ebe 100644
--- a/compiler/rustc_smir/src/rustc_smir/mod.rs
+++ b/compiler/rustc_smir/src/rustc_smir/mod.rs
@@ -10,7 +10,7 @@
 use crate::rustc_internal::{self, opaque};
 use crate::stable_mir::mir::{CopyNonOverlapping, UserTypeProjection, VariantIdx};
 use crate::stable_mir::ty::{
-    allocation_filter, new_allocation, FloatTy, IntTy, Movability, RigidTy, TyKind, UintTy,
+    allocation_filter, new_allocation, Const, FloatTy, IntTy, Movability, RigidTy, TyKind, UintTy,
 };
 use crate::stable_mir::{self, Context};
 use rustc_hir as hir;
@@ -187,7 +187,11 @@ impl<'tcx> Stable<'tcx> for mir::Rvalue<'tcx> {
         use mir::Rvalue::*;
         match self {
             Use(op) => stable_mir::mir::Rvalue::Use(op.stable(tables)),
-            Repeat(op, len) => stable_mir::mir::Rvalue::Repeat(op.stable(tables), opaque(len)),
+            Repeat(op, len) => {
+                let cnst = ConstantKind::from_const(*len, tables.tcx);
+                let len = Const { literal: cnst.stable(tables) };
+                stable_mir::mir::Rvalue::Repeat(op.stable(tables), len)
+            }
             Ref(region, kind, place) => stable_mir::mir::Rvalue::Ref(
                 opaque(region),
                 kind.stable(tables),
@@ -372,7 +376,11 @@ impl<'tcx> Stable<'tcx> for ty::TermKind<'tcx> {
         use stable_mir::ty::TermKind;
         match self {
             ty::TermKind::Ty(ty) => TermKind::Type(tables.intern_ty(*ty)),
-            ty::TermKind::Const(const_) => TermKind::Const(opaque(const_)),
+            ty::TermKind::Const(cnst) => {
+                let cnst = ConstantKind::from_const(*cnst, tables.tcx);
+                let cnst = Const { literal: cnst.stable(tables) };
+                TermKind::Const(cnst)
+            }
         }
     }
 }
@@ -829,7 +837,10 @@ impl<'tcx> Stable<'tcx> for ty::GenericArgKind<'tcx> {
         match self {
             ty::GenericArgKind::Lifetime(region) => GenericArgKind::Lifetime(opaque(region)),
             ty::GenericArgKind::Type(ty) => GenericArgKind::Type(tables.intern_ty(*ty)),
-            ty::GenericArgKind::Const(const_) => GenericArgKind::Const(opaque(&const_)),
+            ty::GenericArgKind::Const(cnst) => {
+                let cnst = ConstantKind::from_const(*cnst, tables.tcx);
+                GenericArgKind::Const(stable_mir::ty::Const { literal: cnst.stable(tables) })
+            }
         }
     }
 }
@@ -1035,7 +1046,9 @@ impl<'tcx> Stable<'tcx> for Ty<'tcx> {
             }
             ty::Str => TyKind::RigidTy(RigidTy::Str),
             ty::Array(ty, constant) => {
-                TyKind::RigidTy(RigidTy::Array(tables.intern_ty(*ty), opaque(constant)))
+                let cnst = ConstantKind::from_const(*constant, tables.tcx);
+                let cnst = stable_mir::ty::Const { literal: cnst.stable(tables) };
+                TyKind::RigidTy(RigidTy::Array(tables.intern_ty(*ty), cnst))
             }
             ty::Slice(ty) => TyKind::RigidTy(RigidTy::Slice(tables.intern_ty(*ty))),
             ty::RawPtr(ty::TypeAndMut { ty, mutbl }) => {
diff --git a/compiler/rustc_smir/src/stable_mir/ty.rs b/compiler/rustc_smir/src/stable_mir/ty.rs
index 875d5ae70da..f8ff6741208 100644
--- a/compiler/rustc_smir/src/stable_mir/ty.rs
+++ b/compiler/rustc_smir/src/stable_mir/ty.rs
@@ -15,7 +15,11 @@ impl Ty {
     }
 }
 
-pub(crate) type Const = Opaque;
+#[derive(Debug, Clone)]
+pub struct Const {
+    pub literal: ConstantKind,
+}
+
 type Ident = Opaque;
 pub(crate) type Region = Opaque;
 type Span = Opaque;