summary refs log tree commit diff
path: root/compiler/rustc_const_eval/src/interpret
diff options
context:
space:
mode:
authorb-naber <bn263@gmx.de>2022-04-21 19:35:06 +0200
committerb-naber <bn263@gmx.de>2022-04-21 23:11:06 +0200
commitbc698c73e90c253b0d37be8127b3fb542d9e95c2 (patch)
tree14bc8c30dbcf7e6117798bd235a92f0caaaad399 /compiler/rustc_const_eval/src/interpret
parent28af967bb9165999294250dc3f3a56c2193c35d9 (diff)
downloadrust-bc698c73e90c253b0d37be8127b3fb542d9e95c2.tar.gz
rust-bc698c73e90c253b0d37be8127b3fb542d9e95c2.zip
deduplicate a lot of code
Diffstat (limited to 'compiler/rustc_const_eval/src/interpret')
-rw-r--r--compiler/rustc_const_eval/src/interpret/mod.rs4
-rw-r--r--compiler/rustc_const_eval/src/interpret/operand.rs4
-rw-r--r--compiler/rustc_const_eval/src/interpret/place.rs16
3 files changed, 6 insertions, 18 deletions
diff --git a/compiler/rustc_const_eval/src/interpret/mod.rs b/compiler/rustc_const_eval/src/interpret/mod.rs
index dba746e72e2..69d6c8470a2 100644
--- a/compiler/rustc_const_eval/src/interpret/mod.rs
+++ b/compiler/rustc_const_eval/src/interpret/mod.rs
@@ -14,7 +14,7 @@ mod terminator;
 mod traits;
 mod util;
 mod validity;
-pub(crate) mod visitor;
+mod visitor;
 
 pub use rustc_middle::mir::interpret::*; // have all the `interpret` symbols in one place: here
 
@@ -27,7 +27,7 @@ pub use self::memory::{AllocCheck, AllocRef, AllocRefMut, FnVal, Memory, MemoryK
 pub use self::operand::{ImmTy, Immediate, OpTy, Operand};
 pub use self::place::{MPlaceTy, MemPlace, MemPlaceMeta, Place, PlaceTy};
 pub use self::validity::{CtfeValidationMode, RefTracking};
-pub use self::visitor::{MutValueVisitor, ValueVisitor};
+pub use self::visitor::{MutValueVisitor, Value, ValueVisitor};
 
 crate use self::intrinsics::eval_nullary_intrinsic;
 use eval_context::{from_known_layout, mir_assign_valid_types};
diff --git a/compiler/rustc_const_eval/src/interpret/operand.rs b/compiler/rustc_const_eval/src/interpret/operand.rs
index 170fbab2cce..f2d833b3202 100644
--- a/compiler/rustc_const_eval/src/interpret/operand.rs
+++ b/compiler/rustc_const_eval/src/interpret/operand.rs
@@ -98,7 +98,7 @@ impl<'tcx, Tag: Provenance> Immediate<Tag> {
 // as input for binary and cast operations.
 #[derive(Copy, Clone, Debug)]
 pub struct ImmTy<'tcx, Tag: Provenance = AllocId> {
-    pub imm: Immediate<Tag>,
+    imm: Immediate<Tag>,
     pub layout: TyAndLayout<'tcx>,
 }
 
@@ -248,7 +248,7 @@ impl<'tcx, Tag: Provenance> ImmTy<'tcx, Tag> {
 impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
     /// Try reading an immediate in memory; this is interesting particularly for `ScalarPair`.
     /// Returns `None` if the layout does not permit loading this as a value.
-    pub(crate) fn try_read_immediate_from_mplace(
+    fn try_read_immediate_from_mplace(
         &self,
         mplace: &MPlaceTy<'tcx, M::PointerTag>,
     ) -> InterpResult<'tcx, Option<ImmTy<'tcx, M::PointerTag>>> {
diff --git a/compiler/rustc_const_eval/src/interpret/place.rs b/compiler/rustc_const_eval/src/interpret/place.rs
index 8caf9eee2d9..3bc6494f008 100644
--- a/compiler/rustc_const_eval/src/interpret/place.rs
+++ b/compiler/rustc_const_eval/src/interpret/place.rs
@@ -82,7 +82,7 @@ rustc_data_structures::static_assert_size!(Place, 56);
 
 #[derive(Copy, Clone, Debug)]
 pub struct PlaceTy<'tcx, Tag: Provenance = AllocId> {
-    pub(crate) place: Place<Tag>, // Keep this private; it helps enforce invariants.
+    place: Place<Tag>, // Keep this private; it helps enforce invariants.
     pub layout: TyAndLayout<'tcx>,
 }
 
@@ -100,7 +100,7 @@ impl<'tcx, Tag: Provenance> std::ops::Deref for PlaceTy<'tcx, Tag> {
 /// A MemPlace with its layout. Constructing it is only possible in this module.
 #[derive(Copy, Clone, Hash, Eq, PartialEq, Debug)]
 pub struct MPlaceTy<'tcx, Tag: Provenance = AllocId> {
-    pub(crate) mplace: MemPlace<Tag>,
+    mplace: MemPlace<Tag>,
     pub layout: TyAndLayout<'tcx>,
 }
 
@@ -589,7 +589,6 @@ where
     }
 
     /// Projects into a place.
-    #[instrument(skip(self), level = "debug")]
     pub fn place_projection(
         &mut self,
         base: &PlaceTy<'tcx, M::PointerTag>,
@@ -626,18 +625,15 @@ where
         &mut self,
         place: mir::Place<'tcx>,
     ) -> InterpResult<'tcx, PlaceTy<'tcx, M::PointerTag>> {
-        debug!("projection: {:?}", place.projection);
         let mut place_ty = PlaceTy {
             // This works even for dead/uninitialized locals; we check further when writing
             place: Place::Local { frame: self.frame_idx(), local: place.local },
             layout: self.layout_of_local(self.frame(), place.local, None)?,
         };
-        debug!(?place_ty);
 
         for elem in place.projection.iter() {
             place_ty = self.place_projection(&place_ty, &elem)?
         }
-        debug!("place after projections: {:?}", place_ty);
 
         trace!("{:?}", self.dump_place(place_ty.place));
         // Sanity-check the type we ended up with.
@@ -693,7 +689,6 @@ where
     /// Write an immediate to a place.
     /// If you use this you are responsible for validating that things got copied at the
     /// right type.
-    #[instrument(skip(self), level = "debug")]
     fn write_immediate_no_validate(
         &mut self,
         src: Immediate<M::PointerTag>,
@@ -746,7 +741,6 @@ where
     /// Write an immediate to memory.
     /// If you use this you are responsible for validating that things got copied at the
     /// right type.
-    #[instrument(skip(self), level = "debug")]
     fn write_immediate_to_mplace_no_validate(
         &mut self,
         value: Immediate<M::PointerTag>,
@@ -769,7 +763,6 @@ where
         // cover all the bytes!
         match value {
             Immediate::Scalar(scalar) => {
-                debug!(?scalar);
                 match dest.layout.abi {
                     Abi::Scalar(_) => {} // fine
                     _ => span_bug!(
@@ -882,7 +875,6 @@ where
         // Let us see if the layout is simple so we take a shortcut, avoid force_allocation.
         let src = match self.try_read_immediate(src)? {
             Ok(src_val) => {
-                debug!("immediate from src is {:?}", src_val);
                 assert!(!src.layout.is_unsized(), "cannot have unsized immediates");
                 // Yay, we got a value that we can write directly.
                 // FIXME: Add a check to make sure that if `src` is indirect,
@@ -978,7 +970,6 @@ where
     ) -> InterpResult<'tcx, (MPlaceTy<'tcx, M::PointerTag>, Option<Size>)> {
         let (mplace, size) = match place.place {
             Place::Local { frame, local } => {
-                debug!("LocalPlace");
                 match M::access_local_mut(self, frame, local)? {
                     Ok(&mut local_val) => {
                         // We need to make an allocation.
@@ -992,12 +983,9 @@ where
                         let (size, align) = self
                             .size_and_align_of(&meta, &local_layout)?
                             .expect("Cannot allocate for non-dyn-sized type");
-                        debug!(?size, ?align);
                         let ptr = self.allocate_ptr(size, align, MemoryKind::Stack)?;
-                        debug!("allocated ptr: {:?}", ptr);
                         let mplace = MemPlace { ptr: ptr.into(), align, meta };
                         if let LocalValue::Live(Operand::Immediate(value)) = local_val {
-                            debug!("LocalValue::Live: immediate value {:?}", value);
                             // Preserve old value.
                             // We don't have to validate as we can assume the local
                             // was already valid for its type.