]> git.lizzy.rs Git - rust.git/blobdiff - src/machine.rs
Rustfmt
[rust.git] / src / machine.rs
index 19be5b547ba846da42ed48bf0fec31da207b610e..c8962612c658bc07e9c5a334a8e5a238ff8ce89f 100644 (file)
@@ -1,24 +1,28 @@
 //! Global machine state as well as implementation of the interpreter engine
 //! `Machine` trait.
 
-use std::rc::Rc;
 use std::borrow::Cow;
 use std::cell::RefCell;
+use std::rc::Rc;
 
 use rand::rngs::StdRng;
 
-use syntax::attr;
-use syntax::symbol::sym;
 use rustc::hir::def_id::DefId;
-use rustc::ty::{self, Ty, TyCtxt, layout::{Size, LayoutOf}};
 use rustc::mir;
+use rustc::ty::{
+    self,
+    layout::{LayoutOf, Size},
+    Ty, TyCtxt,
+};
+use syntax::attr;
+use syntax::symbol::sym;
 
 use crate::*;
 
 // Some global facts about the emulated machine.
-pub const PAGE_SIZE: u64 = 4*1024; // FIXME: adjust to target architecture
-pub const STACK_ADDR: u64 = 32*PAGE_SIZE; // not really about the "stack", but where we start assigning integer addresses to allocations
-pub const STACK_SIZE: u64 = 16*PAGE_SIZE; // whatever
+pub const PAGE_SIZE: u64 = 4 * 1024; // FIXME: adjust to target architecture
+pub const STACK_ADDR: u64 = 32 * PAGE_SIZE; // not really about the "stack", but where we start assigning integer addresses to allocations
+pub const STACK_SIZE: u64 = 16 * PAGE_SIZE; // whatever
 pub const NUM_CPUS: u64 = 1;
 
 /// Extra memory kinds
@@ -146,7 +150,13 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
     type PointerTag = Tag;
     type ExtraFnVal = Dlsym;
 
-    type MemoryMap = MonoHashMap<AllocId, (MemoryKind<MiriMemoryKind>, Allocation<Tag, Self::AllocExtra>)>;
+    type MemoryMap = MonoHashMap<
+        AllocId,
+        (
+            MemoryKind<MiriMemoryKind>,
+            Allocation<Tag, Self::AllocExtra>,
+        ),
+    >;
 
     const STATIC_KIND: Option<MiriMemoryKind> = Some(MiriMemoryKind::Static);
 
@@ -264,8 +274,7 @@ fn find_foreign_static(
     }
 
     #[inline(always)]
-    fn before_terminator(_ecx: &mut InterpCx<'mir, 'tcx, Self>) -> InterpResult<'tcx>
-    {
+    fn before_terminator(_ecx: &mut InterpCx<'mir, 'tcx, Self>) -> InterpResult<'tcx> {
         // We are not interested in detecting loops.
         Ok(())
     }
@@ -275,7 +284,10 @@ fn tag_allocation<'b>(
         id: AllocId,
         alloc: Cow<'b, Allocation>,
         kind: Option<MemoryKind<Self::MemoryKinds>>,
-    ) -> (Cow<'b, Allocation<Self::PointerTag, Self::AllocExtra>>, Self::PointerTag) {
+    ) -> (
+        Cow<'b, Allocation<Self::PointerTag, Self::AllocExtra>>,
+        Self::PointerTag,
+    ) {
         let kind = kind.expect("we set our STATIC_KIND so this cannot be None");
         let alloc = alloc.into_owned();
         let (stacks, base_tag) = if !memory_extra.validate {
@@ -291,12 +303,14 @@ fn tag_allocation<'b>(
         };
         let mut stacked_borrows = memory_extra.stacked_borrows.borrow_mut();
         let alloc: Allocation<Tag, Self::AllocExtra> = alloc.with_tags_and_extra(
-            |alloc| if !memory_extra.validate {
-                Tag::Untagged
-            } else {
-                // Only statics may already contain pointers at this point
-                assert_eq!(kind, MiriMemoryKind::Static.into());
-                stacked_borrows.static_base_ptr(alloc)
+            |alloc| {
+                if !memory_extra.validate {
+                    Tag::Untagged
+                } else {
+                    // Only statics may already contain pointers at this point
+                    assert_eq!(kind, MiriMemoryKind::Static.into());
+                    stacked_borrows.static_base_ptr(alloc)
+                }
             },
             AllocExtra {
                 stacked_borrows: stacks,
@@ -306,14 +320,14 @@ fn tag_allocation<'b>(
     }
 
     #[inline(always)]
-    fn tag_static_base_pointer(
-        memory_extra: &MemoryExtra,
-        id: AllocId,
-    ) -> Self::PointerTag {
+    fn tag_static_base_pointer(memory_extra: &MemoryExtra, id: AllocId) -> Self::PointerTag {
         if !memory_extra.validate {
             Tag::Untagged
         } else {
-            memory_extra.stacked_borrows.borrow_mut().static_base_ptr(id)
+            memory_extra
+                .stacked_borrows
+                .borrow_mut()
+                .static_base_ptr(id)
         }
     }
 
@@ -325,7 +339,7 @@ fn retag(
     ) -> InterpResult<'tcx> {
         if !Self::enforce_validity(ecx) {
             // No tracking.
-             Ok(())
+            Ok(())
         } else {
             ecx.retag(kind, place)
         }
@@ -343,7 +357,12 @@ fn stack_pop(
         ecx: &mut InterpCx<'mir, 'tcx, Self>,
         extra: stacked_borrows::CallId,
     ) -> InterpResult<'tcx> {
-        Ok(ecx.memory().extra.stacked_borrows.borrow_mut().end_call(extra))
+        Ok(ecx
+            .memory()
+            .extra
+            .stacked_borrows
+            .borrow_mut()
+            .end_call(extra))
     }
 
     #[inline(always)]