Skip to content

Commit 3ec7392

Browse files
committed
Switch to using ImmTy instead of OpTy, as we don't use the MPlace variant at all
1 parent cbecba9 commit 3ec7392

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

Diff for: compiler/rustc_mir_transform/src/const_prop_lint.rs

+16-21
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use std::fmt::Debug;
55

66
use rustc_const_eval::interpret::{ImmTy, Projectable};
7-
use rustc_const_eval::interpret::{InterpCx, InterpResult, OpTy, Scalar};
7+
use rustc_const_eval::interpret::{InterpCx, InterpResult, Scalar};
88
use rustc_data_structures::fx::FxHashSet;
99
use rustc_hir::def::DefKind;
1010
use rustc_hir::HirId;
@@ -83,20 +83,14 @@ struct ConstPropagator<'mir, 'tcx> {
8383

8484
#[derive(Debug, Clone)]
8585
enum Value<'tcx> {
86-
Immediate(OpTy<'tcx>),
86+
Immediate(ImmTy<'tcx>),
8787
Aggregate { variant: VariantIdx, fields: IndexVec<FieldIdx, Value<'tcx>> },
8888
Uninit,
8989
}
9090

91-
impl<'tcx> From<OpTy<'tcx>> for Value<'tcx> {
92-
fn from(v: OpTy<'tcx>) -> Self {
93-
Self::Immediate(v)
94-
}
95-
}
96-
9791
impl<'tcx> From<ImmTy<'tcx>> for Value<'tcx> {
9892
fn from(v: ImmTy<'tcx>) -> Self {
99-
Self::Immediate(v.into())
93+
Self::Immediate(v)
10094
}
10195
}
10296

@@ -149,7 +143,7 @@ impl<'tcx> Value<'tcx> {
149143
Some(this)
150144
}
151145

152-
fn immediate(&self) -> Option<&OpTy<'tcx>> {
146+
fn immediate(&self) -> Option<&ImmTy<'tcx>> {
153147
match self {
154148
Value::Immediate(op) => Some(op),
155149
_ => None,
@@ -260,7 +254,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
260254
}
261255

262256
/// Returns the value, if any, of evaluating `c`.
263-
fn eval_constant(&mut self, c: &ConstOperand<'tcx>) -> Option<OpTy<'tcx>> {
257+
fn eval_constant(&mut self, c: &ConstOperand<'tcx>) -> Option<ImmTy<'tcx>> {
264258
// FIXME we need to revisit this for #67176
265259
if c.has_param() {
266260
return None;
@@ -274,22 +268,24 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
274268
// manually normalized.
275269
let val = self.tcx.try_normalize_erasing_regions(self.param_env, c.const_).ok()?;
276270

277-
self.use_ecx(|this| this.ecx.eval_mir_constant(&val, Some(c.span), None))
271+
self.use_ecx(|this| this.ecx.eval_mir_constant(&val, Some(c.span), None))?
272+
.as_mplace_or_imm()
273+
.right()
278274
}
279275

280276
/// Returns the value, if any, of evaluating `place`.
281277
#[instrument(level = "trace", skip(self), ret)]
282-
fn eval_place(&mut self, place: Place<'tcx>) -> Option<OpTy<'tcx>> {
278+
fn eval_place(&mut self, place: Place<'tcx>) -> Option<ImmTy<'tcx>> {
283279
match self.get_const(place)? {
284-
Value::Immediate(op) => Some(op.clone()),
280+
Value::Immediate(imm) => Some(imm.clone()),
285281
Value::Aggregate { .. } => None,
286282
Value::Uninit => None,
287283
}
288284
}
289285

290286
/// Returns the value, if any, of evaluating `op`. Calls upon `eval_constant`
291287
/// or `eval_place`, depending on the variant of `Operand` used.
292-
fn eval_operand(&mut self, op: &Operand<'tcx>) -> Option<OpTy<'tcx>> {
288+
fn eval_operand(&mut self, op: &Operand<'tcx>) -> Option<ImmTy<'tcx>> {
293289
match *op {
294290
Operand::Constant(ref c) => self.eval_constant(c),
295291
Operand::Move(place) | Operand::Copy(place) => self.eval_place(place),
@@ -668,13 +664,12 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
668664
let to = self.ecx.layout_of(to).ok()?;
669665
// `offset` for immediates only supports scalar/scalar-pair ABIs,
670666
// so bail out if the target is not one.
671-
if value.as_mplace_or_imm().is_right() {
672-
match (value.layout.abi, to.abi) {
673-
(Abi::Scalar(..), Abi::Scalar(..)) => {}
674-
(Abi::ScalarPair(..), Abi::ScalarPair(..)) => {}
675-
_ => return None,
676-
}
667+
match (value.layout.abi, to.abi) {
668+
(Abi::Scalar(..), Abi::Scalar(..)) => {}
669+
(Abi::ScalarPair(..), Abi::ScalarPair(..)) => {}
670+
_ => return None,
677671
}
672+
678673
value.offset(Size::ZERO, to, &self.ecx).ok()?.into()
679674
}
680675
_ => return None,

0 commit comments

Comments
 (0)