about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2022-07-11 13:42:08 -0400
committerRalf Jung <post@ralfj.de>2022-07-11 22:51:33 -0400
commit04b3cd9f7c8366490590d839ab814d03406eed4a (patch)
tree2f55f78056b52a71892966f97d6cfb7831649a13
parentab225ade1ec401ae990904326fccf54936a5e990 (diff)
downloadrust-04b3cd9f7c8366490590d839ab814d03406eed4a.tar.gz
rust-04b3cd9f7c8366490590d839ab814d03406eed4a.zip
use a loop rather than try_fold
-rw-r--r--compiler/rustc_const_eval/src/interpret/operand.rs19
-rw-r--r--compiler/rustc_const_eval/src/interpret/place.rs25
2 files changed, 21 insertions, 23 deletions
diff --git a/compiler/rustc_const_eval/src/interpret/operand.rs b/compiler/rustc_const_eval/src/interpret/operand.rs
index 4f8dbdeabae..1465b986293 100644
--- a/compiler/rustc_const_eval/src/interpret/operand.rs
+++ b/compiler/rustc_const_eval/src/interpret/operand.rs
@@ -524,19 +524,18 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
     /// avoid allocations.
     pub fn eval_place_to_op(
         &self,
-        place: mir::Place<'tcx>,
+        mir_place: mir::Place<'tcx>,
         layout: Option<TyAndLayout<'tcx>>,
     ) -> InterpResult<'tcx, OpTy<'tcx, M::PointerTag>> {
         // Do not use the layout passed in as argument if the base we are looking at
         // here is not the entire place.
-        let layout = if place.projection.is_empty() { layout } else { None };
+        let layout = if mir_place.projection.is_empty() { layout } else { None };
 
-        let base_op = self.local_to_op(self.frame(), place.local, layout)?;
-
-        let op = place
-            .projection
-            .iter()
-            .try_fold(base_op, |op, elem| self.operand_projection(&op, elem))?;
+        let mut op = self.local_to_op(self.frame(), mir_place.local, layout)?;
+        // Using `try_fold` turned out to be bad for performance, hence the loop.
+        for elem in mir_place.projection.iter() {
+            op = self.operand_projection(&op, elem)?
+        }
 
         trace!("eval_place_to_op: got {:?}", *op);
         // Sanity-check the type we ended up with.
@@ -545,12 +544,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
                 *self.tcx,
                 self.param_env,
                 self.layout_of(self.subst_from_current_frame_and_normalize_erasing_regions(
-                    place.ty(&self.frame().body.local_decls, *self.tcx).ty
+                    mir_place.ty(&self.frame().body.local_decls, *self.tcx).ty
                 )?)?,
                 op.layout,
             ),
             "eval_place of a MIR place with type {:?} produced an interpreter operand with type {:?}",
-            place.ty(&self.frame().body.local_decls, *self.tcx).ty,
+            mir_place.ty(&self.frame().body.local_decls, *self.tcx).ty,
             op.layout.ty,
         );
         Ok(op)
diff --git a/compiler/rustc_const_eval/src/interpret/place.rs b/compiler/rustc_const_eval/src/interpret/place.rs
index 39a737f4aca..2001359d199 100644
--- a/compiler/rustc_const_eval/src/interpret/place.rs
+++ b/compiler/rustc_const_eval/src/interpret/place.rs
@@ -432,31 +432,30 @@ where
     #[instrument(skip(self), level = "debug")]
     pub fn eval_place(
         &mut self,
-        place: mir::Place<'tcx>,
+        mir_place: mir::Place<'tcx>,
     ) -> InterpResult<'tcx, PlaceTy<'tcx, M::PointerTag>> {
-        let base_place = self.local_to_place(self.frame_idx(), place.local)?;
-
-        let final_place = place
-            .projection
-            .iter()
-            .try_fold(base_place, |op, elem| self.place_projection(&op, elem))?;
+        let mut place = self.local_to_place(self.frame_idx(), mir_place.local)?;
+        // Using `try_fold` turned out to be bad for performance, hence the loop.
+        for elem in mir_place.projection.iter() {
+            place = self.place_projection(&place, elem)?
+        }
 
-        trace!("{:?}", self.dump_place(final_place.place));
+        trace!("{:?}", self.dump_place(place.place));
         // Sanity-check the type we ended up with.
         debug_assert!(
             mir_assign_valid_types(
                 *self.tcx,
                 self.param_env,
                 self.layout_of(self.subst_from_current_frame_and_normalize_erasing_regions(
-                    place.ty(&self.frame().body.local_decls, *self.tcx).ty
+                    mir_place.ty(&self.frame().body.local_decls, *self.tcx).ty
                 )?)?,
-                final_place.layout,
+                place.layout,
             ),
             "eval_place of a MIR place with type {:?} produced an interpreter place with type {:?}",
-            place.ty(&self.frame().body.local_decls, *self.tcx).ty,
-            final_place.layout.ty,
+            mir_place.ty(&self.frame().body.local_decls, *self.tcx).ty,
+            place.layout.ty,
         );
-        Ok(final_place)
+        Ok(place)
     }
 
     /// Write an immediate to a place