about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2024-01-16 11:28:07 +0000
committerOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2024-01-23 16:35:27 +0000
commit271821fbc335b22c030f9193a7872105f766eea6 (patch)
tree86f95943e50e3280761dcbd31e0a8d790deeb395 /compiler
parentc5e371da19eed3154ce6794a3e13bbbc763ca435 (diff)
downloadrust-271821fbc335b22c030f9193a7872105f766eea6.tar.gz
rust-271821fbc335b22c030f9193a7872105f766eea6.zip
Switch to using `ImmTy` instead of `OpTy`, as we don't use the `MPlace` variant at all
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_mir_transform/src/const_prop_lint.rs37
1 files changed, 16 insertions, 21 deletions
diff --git a/compiler/rustc_mir_transform/src/const_prop_lint.rs b/compiler/rustc_mir_transform/src/const_prop_lint.rs
index 8bbb81354d8..8d25dc5b718 100644
--- a/compiler/rustc_mir_transform/src/const_prop_lint.rs
+++ b/compiler/rustc_mir_transform/src/const_prop_lint.rs
@@ -4,7 +4,7 @@
 use std::fmt::Debug;
 
 use rustc_const_eval::interpret::{ImmTy, Projectable};
-use rustc_const_eval::interpret::{InterpCx, InterpResult, OpTy, Scalar};
+use rustc_const_eval::interpret::{InterpCx, InterpResult, Scalar};
 use rustc_data_structures::fx::FxHashSet;
 use rustc_hir::def::DefKind;
 use rustc_hir::HirId;
@@ -83,20 +83,14 @@ struct ConstPropagator<'mir, 'tcx> {
 
 #[derive(Debug, Clone)]
 enum Value<'tcx> {
-    Immediate(OpTy<'tcx>),
+    Immediate(ImmTy<'tcx>),
     Aggregate { variant: VariantIdx, fields: IndexVec<FieldIdx, Value<'tcx>> },
     Uninit,
 }
 
-impl<'tcx> From<OpTy<'tcx>> for Value<'tcx> {
-    fn from(v: OpTy<'tcx>) -> Self {
-        Self::Immediate(v)
-    }
-}
-
 impl<'tcx> From<ImmTy<'tcx>> for Value<'tcx> {
     fn from(v: ImmTy<'tcx>) -> Self {
-        Self::Immediate(v.into())
+        Self::Immediate(v)
     }
 }
 
@@ -149,7 +143,7 @@ impl<'tcx> Value<'tcx> {
         Some(this)
     }
 
-    fn immediate(&self) -> Option<&OpTy<'tcx>> {
+    fn immediate(&self) -> Option<&ImmTy<'tcx>> {
         match self {
             Value::Immediate(op) => Some(op),
             _ => None,
@@ -260,7 +254,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
     }
 
     /// Returns the value, if any, of evaluating `c`.
-    fn eval_constant(&mut self, c: &ConstOperand<'tcx>) -> Option<OpTy<'tcx>> {
+    fn eval_constant(&mut self, c: &ConstOperand<'tcx>) -> Option<ImmTy<'tcx>> {
         // FIXME we need to revisit this for #67176
         if c.has_param() {
             return None;
@@ -274,14 +268,16 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
         // manually normalized.
         let val = self.tcx.try_normalize_erasing_regions(self.param_env, c.const_).ok()?;
 
-        self.use_ecx(|this| this.ecx.eval_mir_constant(&val, Some(c.span), None))
+        self.use_ecx(|this| this.ecx.eval_mir_constant(&val, Some(c.span), None))?
+            .as_mplace_or_imm()
+            .right()
     }
 
     /// Returns the value, if any, of evaluating `place`.
     #[instrument(level = "trace", skip(self), ret)]
-    fn eval_place(&mut self, place: Place<'tcx>) -> Option<OpTy<'tcx>> {
+    fn eval_place(&mut self, place: Place<'tcx>) -> Option<ImmTy<'tcx>> {
         match self.get_const(place)? {
-            Value::Immediate(op) => Some(op.clone()),
+            Value::Immediate(imm) => Some(imm.clone()),
             Value::Aggregate { .. } => None,
             Value::Uninit => None,
         }
@@ -289,7 +285,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
 
     /// Returns the value, if any, of evaluating `op`. Calls upon `eval_constant`
     /// or `eval_place`, depending on the variant of `Operand` used.
-    fn eval_operand(&mut self, op: &Operand<'tcx>) -> Option<OpTy<'tcx>> {
+    fn eval_operand(&mut self, op: &Operand<'tcx>) -> Option<ImmTy<'tcx>> {
         match *op {
             Operand::Constant(ref c) => self.eval_constant(c),
             Operand::Move(place) | Operand::Copy(place) => self.eval_place(place),
@@ -668,13 +664,12 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
                     let to = self.ecx.layout_of(to).ok()?;
                     // `offset` for immediates only supports scalar/scalar-pair ABIs,
                     // so bail out if the target is not one.
-                    if value.as_mplace_or_imm().is_right() {
-                        match (value.layout.abi, to.abi) {
-                            (Abi::Scalar(..), Abi::Scalar(..)) => {}
-                            (Abi::ScalarPair(..), Abi::ScalarPair(..)) => {}
-                            _ => return None,
-                        }
+                    match (value.layout.abi, to.abi) {
+                        (Abi::Scalar(..), Abi::Scalar(..)) => {}
+                        (Abi::ScalarPair(..), Abi::ScalarPair(..)) => {}
+                        _ => return None,
                     }
+
                     value.offset(Size::ZERO, to, &self.ecx).ok()?.into()
                 }
                 _ => return None,