]> git.lizzy.rs Git - rust.git/commitdiff
Merge branch 'master' into eq-hash
authorRalf Jung <post@ralfj.de>
Fri, 13 Jul 2018 06:29:42 +0000 (08:29 +0200)
committerGitHub <noreply@github.com>
Fri, 13 Jul 2018 06:29:42 +0000 (08:29 +0200)
1  2 
src/lib.rs
src/locks.rs
src/range_map.rs

diff --combined src/lib.rs
index ffb17527ad04f7235d75d85286229d7b8d6bc0b8,88bca91aa2de5ab2c0ff251e50976be06c9de031..75397262b225a1d0d30b1d0b75e8c6f8d83fbae9
@@@ -5,6 -5,8 +5,8 @@@
      inclusive_range_methods,
  )]
  
+ #![cfg_attr(feature = "cargo-clippy", allow(cast_lossless))]
  #[macro_use]
  extern crate log;
  
@@@ -24,15 -26,11 +26,14 @@@ use rustc::ty::layout::{TyLayout, Layou
  use rustc::ty::subst::Subst;
  use rustc::hir::def_id::DefId;
  use rustc::mir;
- use rustc::middle::const_val;
  
 +use rustc_data_structures::fx::FxHasher;
 +
  use syntax::ast::Mutability;
  use syntax::codemap::Span;
  
  use std::collections::{HashMap, BTreeMap};
 +use std::hash::{Hash, Hasher};
  
  pub use rustc::mir::interpret::*;
  pub use rustc_mir::interpret::*;
@@@ -175,7 -173,7 +176,7 @@@ pub fn create_ecx<'a, 'mir: 'a, 'tcx: '
          // Return value
          let size = ecx.tcx.data_layout.pointer_size;
          let align = ecx.tcx.data_layout.pointer_align;
-         let ret_ptr = ecx.memory_mut().allocate(size, align, Some(MemoryKind::Stack))?;
+         let ret_ptr = ecx.memory_mut().allocate(size, align, MemoryKind::Stack)?;
          cleanup_ptr = Some(ret_ptr);
  
          // Push our stack frame
          let foo = ecx.memory.allocate_bytes(b"foo\0");
          let ptr_size = ecx.memory.pointer_size();
          let ptr_align = ecx.tcx.data_layout.pointer_align;
-         let foo_ptr = ecx.memory.allocate(ptr_size, ptr_align, None)?;
+         let foo_ptr = ecx.memory.allocate(ptr_size, ptr_align, MemoryKind::Stack)?;
          ecx.memory.write_scalar(foo_ptr.into(), ptr_align, Scalar::Ptr(foo), ptr_size, false)?;
          ecx.memory.mark_static_initialized(foo_ptr.alloc_id, Mutability::Immutable)?;
          ecx.write_ptr(dest, foo_ptr.into(), ty)?;
@@@ -273,10 -271,10 +274,10 @@@ pub fn eval_main<'a, 'tcx: 'a>
                      block.terminator().source_info.span
                  };
  
-                 let mut err = const_val::struct_error(ecx.tcx.tcx.at(span), "constant evaluation error");
+                 let mut err = struct_error(ecx.tcx.tcx.at(span), "constant evaluation error");
                  let (frames, span) = ecx.generate_stacktrace(None);
                  err.span_label(span, e.to_string());
-                 for const_val::FrameInfo { span, location, .. } in frames {
+                 for FrameInfo { span, location, .. } in frames {
                      err.span_note(span, &format!("inside call to `{}`", location));
                  }
                  err.emit();
      }
  }
  
 -#[derive(Default)]
 +#[derive(Clone, Default, PartialEq, Eq)]
  pub struct Evaluator<'tcx> {
      /// Environment variables set by `setenv`
      /// Miri does not expose env vars from the host to the emulated program
      pub(crate) suspended: HashMap<DynamicLifetime, Vec<ValidationQuery<'tcx>>>,
  }
  
 +impl<'tcx> Hash for Evaluator<'tcx> {
 +    fn hash<H: Hasher>(&self, state: &mut H) {
 +        let Evaluator {
 +            env_vars,
 +            suspended: _,
 +        } = self;
 +
 +        env_vars.iter()
 +            .map(|(env, ptr)| {
 +                let mut h = FxHasher::default();
 +                env.hash(&mut h);
 +                ptr.hash(&mut h);
 +                h.finish()
 +            })
 +            .fold(0u64, |acc, hash| acc.wrapping_add(hash))
 +            .hash(state);
 +    }
 +}
 +
  pub type TlsKey = u128;
  
 -#[derive(Copy, Clone, Debug)]
 +#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
  pub struct TlsEntry<'tcx> {
      data: Scalar, // Will eventually become a map from thread IDs to `Scalar`s, if we ever support more than one thread.
      dtor: Option<ty::Instance<'tcx>>,
  }
  
 -#[derive(Default)]
 +#[derive(Clone, Default, PartialEq, Eq)]
  pub struct MemoryData<'tcx> {
      /// The Key to use for the next thread-local allocation.
      next_thread_local: TlsKey,
      statics: HashMap<GlobalId<'tcx>, AllocId>,
  }
  
 +impl<'tcx> Hash for MemoryData<'tcx> {
 +    fn hash<H: Hasher>(&self, state: &mut H) {
 +        let MemoryData {
 +            next_thread_local: _,
 +            thread_local,
 +            locks: _,
 +            statics: _,
 +        } = self;
 +
 +        thread_local.hash(state);
 +    }
 +}
 +
  impl<'mir, 'tcx: 'mir> Machine<'mir, 'tcx> for Evaluator<'tcx> {
      type MemoryData = MemoryData<'tcx>;
      type MemoryKinds = memory::MemoryKind;
          let ptr = ecx.memory.allocate(
              layout.size,
              layout.align,
-             None,
+             MemoryKind::Stack,
          )?;
  
          // Step 4: Cache allocation id for recursive statics
                  let frame = ecx.frame_mut();
                  let bb = &frame.mir.basic_blocks()[frame.block];
                  if bb.statements.len() == frame.stmt && !bb.is_cleanup {
-                     match bb.terminator().kind {
-                         ::rustc::mir::TerminatorKind::Return => {
-                             for (local, _local_decl) in mir.local_decls.iter_enumerated().skip(1) {
-                                 // Don't deallocate locals, because the return value might reference them
-                                 frame.storage_dead(local);
-                             }
+                     if let ::rustc::mir::TerminatorKind::Return = bb.terminator().kind {
+                         for (local, _local_decl) in mir.local_decls.iter_enumerated().skip(1) {
+                             // Don't deallocate locals, because the return value might reference them
+                             frame.storage_dead(local);
                          }
-                         _ => {}
                      }
                  }
              }
                  value: Value::Scalar(Scalar::from_u128(match layout.size.bytes() {
                      0 => 1 as u128,
                      size => size as u128,
-                 }.into())),
+                 })),
                  ty: usize,
              },
              dest,
diff --combined src/locks.rs
index 9947609d37550a23ccb32abc983ae51899810ee1,3b67c9bb7f3e4ef020095a2f25a45fc253f30fb5..9f4126ad82b60002e105863b78712e8f10ae5278
@@@ -7,7 -7,7 +7,7 @@@ use rustc::ty::layout::Size
  ////////////////////////////////////////////////////////////////////////////////
  
  /// Information about a lock that is currently held.
 -#[derive(Clone, Debug)]
 +#[derive(Clone, Debug, PartialEq, Eq)]
  pub struct LockInfo<'tcx> {
      /// Stores for which lifetimes (of the original write lock) we got
      /// which suspensions.
@@@ -241,11 -241,9 +241,9 @@@ impl<'a, 'mir, 'tcx: 'mir + 'a> MemoryE
                      // All is well
                      continue 'locks;
                  }
-             } else {
-                 if !is_our_lock {
-                     // All is well.
-                     continue 'locks;
-                 }
+             } else if !is_our_lock {
+                 // All is well.
+                 continue 'locks;
              }
              // If we get here, releasing this is an error except for NoLock.
              if lock.active != NoLock {
              }
              // Clean up the map
              alloc_locks.retain(|lock| match lock.active {
-                 NoLock => lock.suspended.len() > 0,
+                 NoLock => !lock.suspended.is_empty(),
                  _ => true,
              });
          }
diff --combined src/range_map.rs
index 118be32a2993b861cc5ba9f14a8cd41b02ef1c0e,fcffaf7128f11704a663a0b41b983486868527ef..76d01ad19e3ab609e5bfafc80aed5ea3c7cf24c7
@@@ -7,7 -7,7 +7,7 @@@
  use std::collections::BTreeMap;
  use std::ops;
  
 -#[derive(Clone, Debug)]
 +#[derive(Clone, Debug, PartialEq, Eq)]
  pub struct RangeMap<T> {
      map: BTreeMap<Range, T>,
  }
@@@ -19,7 -19,7 +19,7 @@@
  // At the same time the `end` is irrelevant for the sorting and range searching, but used for the check.
  // This kind of search breaks, if `end < start`, so don't do that!
  #[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug)]
- struct Range {
pub struct Range {
      start: u64,
      end: u64, // Invariant: end > start
  }
@@@ -189,7 -189,7 +189,7 @@@ impl<T> RangeMap<T> 
          F: FnMut(&T) -> bool,
      {
          let mut remove = Vec::new();
-         for (range, data) in self.map.iter() {
+         for (range, data) in &self.map {
              if !f(data) {
                  remove.push(*range);
              }