From 271821fbc335b22c030f9193a7872105f766eea6 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 16 Jan 2024 11:28:07 +0000 Subject: [PATCH] Switch to using `ImmTy` instead of `OpTy`, as we don't use the `MPlace` variant at all --- .../src/const_prop_lint.rs | 37 ++++++++----------- 1 file 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> }, Uninit, } -impl<'tcx> From> for Value<'tcx> { - fn from(v: OpTy<'tcx>) -> Self { - Self::Immediate(v) - } -} - impl<'tcx> From> for Value<'tcx> { fn from(v: ImmTy<'tcx>) -> Self { - Self::Immediate(v.into()) + Self::Immediate(v) } } @@ -149,7 +143,7 @@ fn project_mut(&mut self, proj: &[PlaceElem<'_>]) -> Option<&mut 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 @@ fn use_ecx(&mut self, f: F) -> Option } /// Returns the value, if any, of evaluating `c`. - fn eval_constant(&mut self, c: &ConstOperand<'tcx>) -> Option> { + fn eval_constant(&mut self, c: &ConstOperand<'tcx>) -> Option> { // FIXME we need to revisit this for #67176 if c.has_param() { return None; @@ -274,14 +268,16 @@ fn eval_constant(&mut self, c: &ConstOperand<'tcx>) -> Option> { // 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> { + fn eval_place(&mut self, place: Place<'tcx>) -> Option> { 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 @@ fn eval_place(&mut self, place: Place<'tcx>) -> Option> { /// 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> { + fn eval_operand(&mut self, op: &Operand<'tcx>) -> Option> { match *op { Operand::Constant(ref c) => self.eval_constant(c), Operand::Move(place) | Operand::Copy(place) => self.eval_place(place), @@ -668,13 +664,12 @@ fn eval_rvalue( 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,