]> git.lizzy.rs Git - rust.git/commitdiff
don't do any work towards ptr provenance in const mode
authorRalf Jung <post@ralfj.de>
Wed, 17 Oct 2018 15:36:26 +0000 (17:36 +0200)
committerRalf Jung <post@ralfj.de>
Thu, 18 Oct 2018 10:09:00 +0000 (12:09 +0200)
src/librustc_mir/const_eval.rs
src/librustc_mir/interpret/cast.rs
src/librustc_mir/interpret/machine.rs
src/librustc_mir/interpret/place.rs

index ebe877484c620831c703f78b061e599c2e1f4873..bc917140bbd679a7907d8ffdc54b63ba21499bc7 100644 (file)
@@ -348,6 +348,7 @@ impl<'a, 'mir, 'tcx> interpret::Machine<'a, 'mir, 'tcx>
     type MemoryMap = FxHashMap<AllocId, (MemoryKind<!>, Allocation)>;
 
     const STATIC_KIND: Option<!> = None; // no copying of statics allowed
+    const ENABLE_PTR_TRACKING_HOOKS: bool = false; // we don't have no provenance
 
     #[inline(always)]
     fn enforce_validity(_ecx: &EvalContext<'a, 'mir, 'tcx, Self>) -> bool {
index 9b11a1637c632088bb445cd150c4564ddd1c125a..62c42c4a49380e208e4fccc4aa28dd10457dfd46 100644 (file)
@@ -47,7 +47,9 @@ pub fn cast(
             Misc => {
                 let src = self.read_value(src)?;
 
-                if src.layout.ty.is_region_ptr() && dest.layout.ty.is_unsafe_ptr() {
+                if M::ENABLE_PTR_TRACKING_HOOKS &&
+                    src.layout.ty.is_region_ptr() && dest.layout.ty.is_unsafe_ptr()
+                {
                     // For the purpose of the "ptr tag hooks", treat this as creating
                     // a new, raw reference.
                     let place = self.ref_to_mplace(src)?;
index 8f7abea47d87d06a39f573dba1c20a114d80a7b5..1318bbe1c2bf286d22ec255726afd7e001061f9c 100644 (file)
@@ -101,6 +101,11 @@ pub trait Machine<'a, 'mir, 'tcx>: Sized {
     /// that is added to the memory so that the work is not done twice.
     const STATIC_KIND: Option<Self::MemoryKinds>;
 
+    /// As an optimization, you can prevent the pointer tracking hooks from ever being
+    /// called.  You should only do this if you do not care about provenance tracking.
+    /// This controls the `tag_reference` and `tag_dereference` hooks.
+    const ENABLE_PTR_TRACKING_HOOKS: bool;
+
     /// Whether to enforce the validity invariant
     fn enforce_validity(ecx: &EvalContext<'a, 'mir, 'tcx, Self>) -> bool;
 
index 6ee70bac583dc5d765ea0a54ffd4a0f43ecf15b8..af3d6948628398cb7b8134bf4fc17b6a18c6a3fb 100644 (file)
@@ -265,12 +265,12 @@ pub fn ref_to_mplace(
         val: ValTy<'tcx, M::PointerTag>,
     ) -> EvalResult<'tcx, MPlaceTy<'tcx, M::PointerTag>> {
         let ptr = match val.to_scalar_ptr()? {
-            Scalar::Ptr(ptr) => {
+            Scalar::Ptr(ptr) if M::ENABLE_PTR_TRACKING_HOOKS => {
                 // Machine might want to track the `*` operator
                 let tag = M::tag_dereference(self, ptr, val.layout.ty)?;
                 Scalar::Ptr(Pointer::new_with_tag(ptr.alloc_id, ptr.offset, tag))
             }
-            scalar @ Scalar::Bits { .. } => scalar,
+            other => other,
         };
 
         let pointee_type = val.layout.ty.builtin_deref(true).unwrap().ty;
@@ -294,14 +294,14 @@ pub fn create_ref(
         borrow_kind: Option<mir::BorrowKind>,
     ) -> EvalResult<'tcx, Value<M::PointerTag>> {
         let ptr = match place.ptr {
-            Scalar::Ptr(ptr) => {
+            Scalar::Ptr(ptr) if M::ENABLE_PTR_TRACKING_HOOKS => {
                 // Machine might want to track the `&` operator
                 let (size, _) = self.size_and_align_of_mplace(place)?
                     .expect("create_ref cannot determine size");
                 let tag = M::tag_reference(self, ptr, place.layout.ty, size, borrow_kind)?;
                 Scalar::Ptr(Pointer::new_with_tag(ptr.alloc_id, ptr.offset, tag))
             },
-            scalar @ Scalar::Bits { .. } => scalar,
+            other => other,
         };
         Ok(match place.meta {
             None => Value::Scalar(ptr.into()),