HashMap -> FxHashMap

This commit is contained in:
Ralf Jung 2020-03-02 22:36:15 +01:00
parent 0e021ad76c
commit 92a28f8d8f
6 changed files with 23 additions and 22 deletions

View file

@ -1,9 +1,10 @@
use std::cell::RefCell;
use std::cmp::max;
use std::collections::{hash_map::Entry, HashMap};
use std::collections::hash_map::Entry;
use rand::Rng;
use rustc_data_structures::fx::FxHashMap;
use rustc::ty::layout::HasDataLayout;
use rustc_mir::interpret::{AllocCheck, AllocId, InterpResult, Memory, Machine, Pointer, PointerArithmetic};
use rustc_target::abi::Size;
@ -21,7 +22,7 @@ pub struct GlobalState {
/// `AllocExtra` because function pointers also have a base address, and
/// they do not have an `AllocExtra`.
/// This is the inverse of `int_to_ptr_map`.
pub base_addr: HashMap<AllocId, u64>,
pub base_addr: FxHashMap<AllocId, u64>,
/// This is used as a memory address when a new pointer is casted to an integer. It
/// is always larger than any address that was previously made part of a block.
pub next_base_addr: u64,
@ -31,7 +32,7 @@ impl Default for GlobalState {
fn default() -> Self {
GlobalState {
int_to_ptr_map: Vec::default(),
base_addr: HashMap::default(),
base_addr: FxHashMap::default(),
next_base_addr: STACK_ADDR,
}
}

View file

@ -3,12 +3,12 @@
use std::borrow::Cow;
use std::cell::RefCell;
use std::collections::HashMap;
use std::num::NonZeroU64;
use std::rc::Rc;
use rand::rngs::StdRng;
use rustc_data_structures::fx::FxHashMap;
use rustc::mir;
use rustc::ty::{
self,
@ -75,7 +75,7 @@ pub struct MemoryExtra {
pub intptrcast: intptrcast::MemoryExtra,
/// Mapping extern static names to their canonical allocation.
pub(crate) extern_statics: HashMap<Symbol, AllocId>,
pub(crate) extern_statics: FxHashMap<Symbol, AllocId>,
/// The random number generator used for resolving non-determinism.
/// Needs to be queried by ptr_to_int, hence needs interior mutability.
@ -92,7 +92,7 @@ impl MemoryExtra {
MemoryExtra {
stacked_borrows,
intptrcast: Default::default(),
extern_statics: HashMap::default(),
extern_statics: FxHashMap::default(),
rng: RefCell::new(rng),
}
}

View file

@ -1,6 +1,6 @@
//! This is a "monotonic `HashMap`": A `HashMap` that, when shared, can be pushed to but not
//! This is a "monotonic `FxHashMap`": A `FxHashMap` that, when shared, can be pushed to but not
//! otherwise mutated. We also box items in the map. This means we can safely provide
//! shared references into existing items in the `HashMap`, because they will not be dropped
//! shared references into existing items in the `FxHashMap`, because they will not be dropped
//! (from being removed) or moved (because they are boxed).
//! The API is is completely tailored to what `memory.rs` needs. It is still in
//! a separate file to minimize the amount of code that has to care about the unsafety.
@ -21,8 +21,8 @@ impl<K: Hash + Eq, V> MonoHashMap<K, V> {
/// This function exists for priroda to be able to iterate over all evaluator memory.
///
/// The function is somewhat roundabout with the closure argument because internally the
/// `MonoHashMap` uses a `RefCell`. When iterating over the `HashMap` inside the `RefCell`,
/// we need to keep a borrow to the `HashMap` inside the iterator. The borrow is only alive
/// `MonoHashMap` uses a `RefCell`. When iterating over the `FxHashMap` inside the `RefCell`,
/// we need to keep a borrow to the `FxHashMap` inside the iterator. The borrow is only alive
/// as long as the `Ref` returned by `RefCell::borrow()` is alive. So we can't return the
/// iterator, as that would drop the `Ref`. We can't return both, as it's not possible in Rust
/// to have a struct/tuple with a field that refers to another field.

View file

@ -1,10 +1,10 @@
use std::collections::HashMap;
use std::ffi::{OsString, OsStr};
use std::env;
use crate::stacked_borrows::Tag;
use crate::*;
use rustc_data_structures::fx::FxHashMap;
use rustc::ty::layout::Size;
use rustc_mir::interpret::Pointer;
@ -12,7 +12,7 @@ use rustc_mir::interpret::Pointer;
pub struct EnvVars {
/// Stores pointers to the environment variables. These variables must be stored as
/// null-terminated C strings with the `"{name}={value}"` format.
map: HashMap<OsString, Pointer<Tag>>,
map: FxHashMap<OsString, Pointer<Tag>>,
}
impl EnvVars {

View file

@ -1,11 +1,11 @@
use std::collections::BTreeMap;
use std::collections::HashMap;
use std::convert::{TryFrom, TryInto};
use std::fs::{read_dir, remove_dir, remove_file, rename, DirBuilder, File, FileType, OpenOptions, ReadDir};
use std::io::{Read, Seek, SeekFrom, Write};
use std::path::PathBuf;
use std::time::SystemTime;
use rustc_data_structures::fx::FxHashMap;
use rustc::ty::layout::{Align, LayoutOf, Size};
use crate::stacked_borrows::Tag;
@ -212,10 +212,10 @@ pub struct DirHandler {
/// When opendir is called, a directory iterator is created on the host for the target
/// directory, and an entry is stored in this hash map, indexed by an ID which represents
/// the directory stream. When readdir is called, the directory stream ID is used to look up
/// the corresponding ReadDir iterator from this HashMap, and information from the next
/// the corresponding ReadDir iterator from this map, and information from the next
/// directory entry is returned. When closedir is called, the ReadDir iterator is removed from
/// this HashMap.
streams: HashMap<u64, ReadDir>,
/// the map.
streams: FxHashMap<u64, ReadDir>,
/// ID number to be used by the next call to opendir
next_id: u64,
}
@ -232,7 +232,7 @@ impl DirHandler {
impl Default for DirHandler {
fn default() -> DirHandler {
DirHandler {
streams: HashMap::new(),
streams: FxHashMap::default(),
// Skip 0 as an ID, because it looks like a null pointer to libc
next_id: 1,
}

View file

@ -2,11 +2,11 @@
//! for further information.
use std::cell::RefCell;
use std::collections::{HashMap, HashSet};
use std::fmt;
use std::num::NonZeroU64;
use std::rc::Rc;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc::mir::RetagKind;
use rustc::ty::{self, layout::Size};
use rustc_hir::Mutability;
@ -96,11 +96,11 @@ pub struct GlobalState {
/// Table storing the "base" tag for each allocation.
/// The base tag is the one used for the initial pointer.
/// We need this in a separate table to handle cyclic statics.
base_ptr_ids: HashMap<AllocId, Tag>,
base_ptr_ids: FxHashMap<AllocId, Tag>,
/// Next unused call ID (for protectors).
next_call_id: CallId,
/// Those call IDs corresponding to functions that are still running.
active_calls: HashSet<CallId>,
active_calls: FxHashSet<CallId>,
/// The id to trace in this execution run
tracked_pointer_tag: Option<PtrId>,
}
@ -153,9 +153,9 @@ impl GlobalState {
pub fn new(tracked_pointer_tag: Option<PtrId>) -> Self {
GlobalState {
next_ptr_id: NonZeroU64::new(1).unwrap(),
base_ptr_ids: HashMap::default(),
base_ptr_ids: FxHashMap::default(),
next_call_id: NonZeroU64::new(1).unwrap(),
active_calls: HashSet::default(),
active_calls: FxHashSet::default(),
tracked_pointer_tag,
}
}