Skip to content

Commit

Permalink
chore: more alloy_primitives::map
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes committed Oct 6, 2024
1 parent 8fdd2ed commit 7a54a44
Show file tree
Hide file tree
Showing 41 changed files with 76 additions and 138 deletions.
7 changes: 0 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ alloy-json-abi = "0.8.5"
alloy-primitives = { version = "0.8.5", features = [
"getrandom",
"rand",
"map-fxhash",
"map-foldhash",
] }
alloy-sol-macro-expander = "0.8.5"
alloy-sol-macro-input = "0.8.5"
Expand Down Expand Up @@ -249,7 +249,6 @@ k256 = "0.13"
parking_lot = "0.12"
mesc = "0.3"
rand = "0.8"
rustc-hash = "2.0"
semver = "1"
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0", features = ["arbitrary_precision"] }
Expand Down
7 changes: 2 additions & 5 deletions crates/anvil/src/eth/backend/mem/in_memory_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@ use crate::{
mem::state::state_root,
revm::{db::DbAccount, primitives::AccountInfo},
};
use alloy_primitives::{Address, B256, U256, U64};
use alloy_primitives::{map::HashMap, Address, B256, U256, U64};
use alloy_rpc_types::BlockId;
use foundry_evm::{
backend::{BlockchainDb, DatabaseResult, StateSnapshot},
hashbrown::HashMap,
};
use foundry_evm::backend::{BlockchainDb, DatabaseResult, StateSnapshot};

// reexport for convenience
pub use foundry_evm::{backend::MemDb, revm::db::DatabaseRef};
Expand Down
3 changes: 1 addition & 2 deletions crates/anvil/src/eth/backend/mem/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -581,9 +581,8 @@ pub struct MinedTransactionReceipt {
}

#[cfg(test)]
#[allow(clippy::needless_return)]
mod tests {
#![allow(clippy::needless_return)]

use super::*;
use crate::eth::backend::db::Db;
use alloy_primitives::{hex, Address};
Expand Down
14 changes: 5 additions & 9 deletions crates/anvil/src/eth/pool/transactions.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
use crate::eth::{error::PoolError, util::hex_fmt_many};
use alloy_primitives::{Address, TxHash};
use alloy_primitives::{
map::{HashMap, HashSet},
Address, TxHash,
};
use alloy_rpc_types::Transaction as RpcTransaction;
use alloy_serde::WithOtherFields;
use anvil_core::eth::transaction::{PendingTransaction, TypedTransaction};
use parking_lot::RwLock;
use std::{
cmp::Ordering,
collections::{BTreeSet, HashMap, HashSet},
fmt,
str::FromStr,
sync::Arc,
time::Instant,
};
use std::{cmp::Ordering, collections::BTreeSet, fmt, str::FromStr, sync::Arc, time::Instant};

/// A unique identifying marker for a transaction
pub type TxMarker = Vec<u8>;
Expand Down
1 change: 0 additions & 1 deletion crates/cheatcodes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ p256 = "0.13.2"
ecdsa = "0.16"
rand = "0.8"
revm.workspace = true
rustc-hash.workspace = true
semver.workspace = true
serde_json.workspace = true
thiserror.workspace = true
Expand Down
7 changes: 2 additions & 5 deletions crates/cheatcodes/src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
};
use alloy_consensus::TxEnvelope;
use alloy_genesis::{Genesis, GenesisAccount};
use alloy_primitives::{Address, Bytes, B256, U256};
use alloy_primitives::{map::HashMap, Address, Bytes, B256, U256};
use alloy_rlp::Decodable;
use alloy_sol_types::SolValue;
use foundry_common::fs::{read_json_file, write_json_file};
Expand All @@ -16,10 +16,7 @@ use foundry_evm_core::{
};
use rand::Rng;
use revm::primitives::{Account, Bytecode, SpecId, KECCAK_EMPTY};
use std::{
collections::{BTreeMap, HashMap},
path::Path,
};
use std::{collections::BTreeMap, path::Path};

mod fork;
pub(crate) mod mapping;
Expand Down
3 changes: 1 addition & 2 deletions crates/cheatcodes/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ use super::string::parse;
use crate::{Cheatcode, Cheatcodes, CheatcodesExecutor, CheatsCtxt, Result, Vm::*};
use alloy_dyn_abi::DynSolType;
use alloy_json_abi::ContractObject;
use alloy_primitives::{hex, Bytes, U256};
use alloy_primitives::{hex, map::Entry, Bytes, U256};
use alloy_sol_types::SolValue;
use dialoguer::{Input, Password};
use foundry_common::fs;
use foundry_config::fs_permissions::FsAccessKind;
use revm::interpreter::CreateInputs;
use semver::Version;
use std::{
collections::hash_map::Entry,
io::{BufRead, BufReader, Write},
path::{Path, PathBuf},
process::Command,
Expand Down
3 changes: 1 addition & 2 deletions crates/cheatcodes/src/inspector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ use revm::{
primitives::{BlockEnv, CreateScheme, EVMError, EvmStorageSlot, SpecId, EOF_MAGIC_BYTES},
EvmContext, InnerEvmContext, Inspector,
};
use rustc_hash::FxHashMap;
use serde_json::Value;
use std::{
collections::{BTreeMap, VecDeque},
Expand Down Expand Up @@ -413,7 +412,7 @@ pub struct Cheatcodes {
pub expected_emits: VecDeque<ExpectedEmit>,

/// Map of context depths to memory offset ranges that may be written to within the call depth.
pub allowed_mem_writes: FxHashMap<u64, Vec<Range<u64>>>,
pub allowed_mem_writes: HashMap<u64, Vec<Range<u64>>>,

/// Current broadcasting information
pub broadcast: Option<Broadcast>,
Expand Down
7 changes: 5 additions & 2 deletions crates/cheatcodes/src/test/expect.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
use crate::{Cheatcode, Cheatcodes, CheatsCtxt, Error, Result, Vm::*};
use alloy_primitives::{address, hex, Address, Bytes, LogData as RawLog, U256};
use alloy_primitives::{
address, hex,
map::{hash_map::Entry, HashMap},
Address, Bytes, LogData as RawLog, U256,
};
use alloy_sol_types::{SolError, SolValue};
use foundry_common::ContractsByArtifact;
use foundry_evm_core::decode::RevertDecoder;
use revm::interpreter::{
return_ok, InstructionResult, Interpreter, InterpreterAction, InterpreterResult,
};
use spec::Vm;
use std::collections::{hash_map::Entry, HashMap};

/// For some cheatcodes we may internally change the status of the call, i.e. in `expectRevert`.
/// Solidity will see a successful call and attempt to decode the return data. Therefore, we need
Expand Down
1 change: 0 additions & 1 deletion crates/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ dunce.workspace = true
eyre.workspace = true
num-format.workspace = true
reqwest.workspace = true
rustc-hash.workspace = true
semver.workspace = true
serde_json.workspace = true
serde.workspace = true
Expand Down
8 changes: 4 additions & 4 deletions crates/common/src/evm.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! cli arguments for configuring the evm settings
use alloy_primitives::{Address, B256, U256};
//! CLI arguments for configuring the EVM settings.
use alloy_primitives::{map::HashMap, Address, B256, U256};
use clap::{ArgAction, Parser};
use eyre::ContextCompat;
use foundry_config::{
Expand All @@ -11,11 +12,10 @@ use foundry_config::{
},
Chain, Config,
};
use rustc_hash::FxHashMap;
use serde::Serialize;

/// Map keyed by breakpoints char to their location (contract address, pc)
pub type Breakpoints = FxHashMap<char, (Address, usize)>;
pub type Breakpoints = HashMap<char, (Address, usize)>;

/// `EvmArgs` and `EnvArgs` take the highest precedence in the Config/Figment hierarchy.
///
Expand Down
3 changes: 1 addition & 2 deletions crates/common/src/selectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,9 +579,8 @@ pub fn parse_signatures(tokens: Vec<String>) -> ParsedSignatures {
}

#[cfg(test)]
#[allow(clippy::needless_return)]
mod tests {
#![allow(clippy::needless_return)]

use super::*;

#[tokio::test(flavor = "multi_thread")]
Expand Down
1 change: 0 additions & 1 deletion crates/evm/abi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ alloy-sol-types = { workspace = true, features = ["json"] }

derive_more.workspace = true
itertools.workspace = true
rustc-hash.workspace = true

[dev-dependencies]
foundry-test-utils.workspace = true
7 changes: 3 additions & 4 deletions crates/evm/abi/src/console/hardhat.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use alloy_primitives::Selector;
use alloy_primitives::{map::HashMap, Selector};
use alloy_sol_types::sol;
use foundry_common_fmt::*;
use foundry_macros::ConsoleFmt;
use rustc_hash::FxHashMap;
use std::sync::LazyLock;

sol!(
Expand Down Expand Up @@ -39,8 +38,8 @@ pub fn hh_console_selector(input: &[u8]) -> Option<&'static Selector> {
/// `hardhat/console.log` logs its events manually, and in functions that accept integers they're
/// encoded as `abi.encodeWithSignature("log(int)", p0)`, which is not the canonical ABI encoding
/// for `int` that Solidity and [`sol!`] use.
pub static HARDHAT_CONSOLE_SELECTOR_PATCHES: LazyLock<FxHashMap<[u8; 4], [u8; 4]>> =
LazyLock::new(|| FxHashMap::from_iter(include!("./patches.rs")));
pub static HARDHAT_CONSOLE_SELECTOR_PATCHES: LazyLock<HashMap<[u8; 4], [u8; 4]>> =
LazyLock::new(|| HashMap::from_iter(include!("./patches.rs")));

#[cfg(test)]
mod tests {
Expand Down
1 change: 0 additions & 1 deletion crates/evm/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ eyre.workspace = true
futures.workspace = true
itertools.workspace = true
parking_lot.workspace = true
rustc-hash.workspace = true
serde.workspace = true
serde_json.workspace = true
thiserror.workspace = true
Expand Down
3 changes: 1 addition & 2 deletions crates/evm/core/src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1960,9 +1960,8 @@ fn apply_state_changeset(
}

#[cfg(test)]
#[allow(clippy::needless_return)]
mod tests {
#![allow(clippy::needless_return)]

use crate::{backend::Backend, fork::CreateFork, opts::EvmOpts};
use alloy_primitives::{Address, U256};
use alloy_provider::Provider;
Expand Down
5 changes: 2 additions & 3 deletions crates/evm/core/src/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
use crate::abi::{Console, Vm};
use alloy_dyn_abi::JsonAbiExt;
use alloy_json_abi::{Error, JsonAbi};
use alloy_primitives::{hex, Log, Selector};
use alloy_primitives::{hex, map::HashMap, Log, Selector};
use alloy_sol_types::{SolEventInterface, SolInterface, SolValue};
use foundry_common::SELECTOR_LEN;
use itertools::Itertools;
use revm::interpreter::InstructionResult;
use rustc_hash::FxHashMap;
use std::{fmt, sync::OnceLock};

/// A skip reason.
Expand Down Expand Up @@ -60,7 +59,7 @@ pub fn decode_console_log(log: &Log) -> Option<String> {
#[derive(Clone, Debug, Default)]
pub struct RevertDecoder {
/// The custom errors to use for decoding.
pub errors: FxHashMap<Selector, Vec<Error>>,
pub errors: HashMap<Selector, Vec<Error>>,
}

impl Default for &RevertDecoder {
Expand Down
3 changes: 1 addition & 2 deletions crates/evm/core/src/fork/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,8 @@ impl DatabaseRef for ForkDbStateSnapshot {
}

#[cfg(test)]
#[allow(clippy::needless_return)]
mod tests {
#![allow(clippy::needless_return)]

use super::*;
use crate::backend::BlockchainDbMeta;
use foundry_common::provider::get_http_provider;
Expand Down
10 changes: 5 additions & 5 deletions crates/evm/core/src/ic.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use alloy_primitives::map::HashMap;
use revm::interpreter::opcode::{PUSH0, PUSH1, PUSH32};
use rustc_hash::FxHashMap;

/// Maps from program counter to instruction counter.
///
/// Inverse of [`IcPcMap`].
#[derive(Debug, Clone)]
pub struct PcIcMap {
pub inner: FxHashMap<usize, usize>,
pub inner: HashMap<usize, usize>,
}

impl PcIcMap {
Expand Down Expand Up @@ -35,7 +35,7 @@ impl PcIcMap {
///
/// Inverse of [`PcIcMap`].
pub struct IcPcMap {
pub inner: FxHashMap<usize, usize>,
pub inner: HashMap<usize, usize>,
}

impl IcPcMap {
Expand All @@ -60,8 +60,8 @@ impl IcPcMap {
}
}

fn make_map<const PC_FIRST: bool>(code: &[u8]) -> FxHashMap<usize, usize> {
let mut map = FxHashMap::default();
fn make_map<const PC_FIRST: bool>(code: &[u8]) -> HashMap<usize, usize> {
let mut map = HashMap::default();

let mut pc = 0;
let mut cumulative_push_size = 0;
Expand Down
1 change: 0 additions & 1 deletion crates/evm/coverage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,4 @@ eyre.workspace = true
revm.workspace = true
semver.workspace = true
tracing.workspace = true
rustc-hash.workspace = true
rayon.workspace = true
4 changes: 2 additions & 2 deletions crates/evm/coverage/src/analysis.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use super::{CoverageItem, CoverageItemKind, SourceLocation};
use alloy_primitives::map::HashMap;
use foundry_common::TestFunctionExt;
use foundry_compilers::artifacts::ast::{self, Ast, Node, NodeType};
use rayon::prelude::*;
use rustc_hash::FxHashMap;
use std::sync::Arc;

/// A visitor that walks the AST of a single contract and finds coverage items.
Expand Down Expand Up @@ -583,7 +583,7 @@ impl<'a> SourceAnalyzer<'a> {
#[derive(Debug, Default)]
pub struct SourceFiles<'a> {
/// The versioned sources.
pub sources: FxHashMap<usize, SourceFile<'a>>,
pub sources: HashMap<usize, SourceFile<'a>>,
}

/// The source code and AST of a file.
Expand Down
Loading

0 comments on commit 7a54a44

Please sign in to comment.