]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_mir/transform/const_prop.rs
Rollup merge of #59430 - kenta7777:rename-evalcontext-to-interpretcx, r=oli-obk
[rust.git] / src / librustc_mir / transform / const_prop.rs
index bbe62fa2d7b37e23e26baf40c8092ecac399950f..b3ef7407a7c3dfb8234200bf314724f1ab7d67da 100644 (file)
@@ -4,7 +4,7 @@
 
 use rustc::hir::def::Def;
 use rustc::mir::{Constant, Location, Place, PlaceBase, Mir, Operand, Rvalue, Local};
-use rustc::mir::{NullOp, UnOp, StatementKind, Statement, BasicBlock, LocalKind};
+use rustc::mir::{NullOp, UnOp, StatementKind, Statement, BasicBlock, LocalKind, Static, StaticKind};
 use rustc::mir::{TerminatorKind, ClearCrossCrate, SourceInfo, BinOp, ProjectionElem};
 use rustc::mir::visit::{Visitor, PlaceContext, MutatingUseContext, NonMutatingUseContext};
 use rustc::mir::interpret::{EvalErrorKind, Scalar, GlobalId, EvalResult};
@@ -18,7 +18,7 @@
     HasTyCtxt, TargetDataLayout, HasDataLayout,
 };
 
-use crate::interpret::{EvalContext, ScalarMaybeUndef, Immediate, OpTy, ImmTy, MemoryKind};
+use crate::interpret::{InterpretCx, ScalarMaybeUndef, Immediate, OpTy, ImmTy, MemoryKind};
 use crate::const_eval::{
     CompileTimeInterpreter, error_to_const_error, eval_promoted, mk_eval_cx,
 };
@@ -70,7 +70,7 @@ fn run_pass<'a, 'tcx>(&self,
 
 /// Finds optimization opportunities on the MIR.
 struct ConstPropagator<'a, 'mir, 'tcx:'a+'mir> {
-    ecx: EvalContext<'a, 'mir, 'tcx, CompileTimeInterpreter<'a, 'mir, 'tcx>>,
+    ecx: InterpretCx<'a, 'mir, 'tcx, CompileTimeInterpreter<'a, 'mir, 'tcx>>,
     mir: &'mir Mir<'tcx>,
     tcx: TyCtxt<'a, 'tcx, 'tcx>,
     source: MirSource<'tcx>,
@@ -237,6 +237,7 @@ fn use_ecx<F, T>(
                             self.ecx.tcx,
                             "this expression will panic at runtime",
                             lint_root,
+                            None,
                         );
                     }
                 }
@@ -282,31 +283,27 @@ fn eval_place(&mut self, place: &Place<'tcx>, source_info: SourceInfo) -> Option
                 // an `Index` projection would throw us off-track.
                 _ => None,
             },
-            Place::Base(PlaceBase::Static(ref static_)) => {
-                match static_.promoted {
-                    Some(promoted) => {
-                        let generics = self.tcx.generics_of(self.source.def_id());
-                        if generics.requires_monomorphization(self.tcx) {
-                            // FIXME: can't handle code with generics
-                            return None;
-                        }
-                        let substs = InternalSubsts::identity_for_item(self.tcx, self.source.def_id());
-                        let instance = Instance::new(self.source.def_id(), substs);
-                        let cid = GlobalId {
-                            instance,
-                            promoted: Some(promoted),
-                        };
-                        // cannot use `const_eval` here, because that would require having the MIR
-                        // for the current function available, but we're producing said MIR right now
-                        let res = self.use_ecx(source_info, |this| {
-                            eval_promoted(this.tcx, cid, this.mir, this.param_env)
-                        })?;
-                        trace!("evaluated promoted {:?} to {:?}", promoted, res);
-                        Some((res.into(), source_info.span))
-                    }
-                    None => None
+            Place::Base(
+                PlaceBase::Static(box Static {kind: StaticKind::Promoted(promoted), ..})
+            ) => {
+                let generics = self.tcx.generics_of(self.source.def_id());
+                if generics.requires_monomorphization(self.tcx) {
+                    // FIXME: can't handle code with generics
+                    return None;
                 }
-
+                let substs = InternalSubsts::identity_for_item(self.tcx, self.source.def_id());
+                let instance = Instance::new(self.source.def_id(), substs);
+                let cid = GlobalId {
+                    instance,
+                    promoted: Some(promoted),
+                };
+                // cannot use `const_eval` here, because that would require having the MIR
+                // for the current function available, but we're producing said MIR right now
+                let res = self.use_ecx(source_info, |this| {
+                    eval_promoted(this.tcx, cid, this.mir, this.param_env)
+                })?;
+                trace!("evaluated promoted {:?} to {:?}", promoted, res);
+                Some((res.into(), source_info.span))
             },
             _ => None,
         }