Skip to content

Commit

Permalink
chore: replace once_cell with std::sync (#8718)
Browse files Browse the repository at this point in the history
* chore: replace `once_cell` with `std::sync`

* chore: fmt

* docs
  • Loading branch information
DaniPopes authored Aug 22, 2024
1 parent 6f0fdff commit 91656a2
Show file tree
Hide file tree
Showing 31 changed files with 80 additions and 101 deletions.
10 changes: 0 additions & 10 deletions Cargo.lock

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

5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ resolver = "2"
version = "0.2.0"
edition = "2021"
# Remember to update clippy.toml as well
rust-version = "1.79"
rust-version = "1.80"
authors = ["Foundry Contributors"]
license = "MIT OR Apache-2.0"
homepage = "https://github.com/foundry-rs/foundry"
Expand Down Expand Up @@ -230,7 +230,6 @@ futures = "0.3"
itertools = "0.13"
jsonpath_lib = "0.3"
k256 = "0.13"
once_cell = "1"
parking_lot = "0.12"
rand = "0.8"
rustc-hash = "2.0"
Expand Down Expand Up @@ -287,4 +286,4 @@ alloy-transport-http = { git = "https://github.com/alloy-rs/alloy", rev = "511ae
alloy-transport-ipc = { git = "https://github.com/alloy-rs/alloy", rev = "511ae98" }
alloy-transport-ws = { git = "https://github.com/alloy-rs/alloy", rev = "511ae98" }
revm = { git = "https://github.com/bluealloy/revm", rev = "caadc71" }
revm-primitives = { git = "https://github.com/bluealloy/revm", rev = "caadc71" }
revm-primitives = { git = "https://github.com/bluealloy/revm", rev = "caadc71" }
2 changes: 1 addition & 1 deletion clippy.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
msrv = "1.79"
msrv = "1.80"
# bytes::Bytes is included by default and alloy_primitives::Bytes is a wrapper around it,
# so it is safe to ignore it as well
ignore-interior-mutability = ["bytes::Bytes", "alloy_primitives::Bytes"]
1 change: 0 additions & 1 deletion crates/chisel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ alloy-rpc-types.workspace = true
clap = { version = "4", features = ["derive", "env", "wrap_help"] }
dirs = "5"
eyre.workspace = true
once_cell = "1.18.0"
regex = "1"
reqwest.workspace = true
revm.workspace = true
Expand Down
8 changes: 4 additions & 4 deletions crates/chisel/benches/session_source.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use chisel::session_source::{SessionSource, SessionSourceConfig};
use criterion::{criterion_group, Criterion};
use foundry_compilers::solc::Solc;
use once_cell::sync::Lazy;
use semver::Version;
use std::hint::black_box;
use std::{hint::black_box, sync::LazyLock};
use tokio::runtime::Runtime;

static SOLC: Lazy<Solc> = Lazy::new(|| Solc::find_or_install(&Version::new(0, 8, 19)).unwrap());
static SOLC: LazyLock<Solc> =
LazyLock::new(|| Solc::find_or_install(&Version::new(0, 8, 19)).unwrap());

/// Benchmark for the `clone_with_new_line` function in [SessionSource]
fn clone_with_new_line(c: &mut Criterion) {
Expand Down Expand Up @@ -74,7 +74,7 @@ fn rt() -> Runtime {

fn main() {
// Install before benches if not present
let _ = Lazy::force(&SOLC);
let _ = LazyLock::force(&SOLC);

session_source_benches();

Expand Down
8 changes: 4 additions & 4 deletions crates/chisel/src/dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use foundry_evm::{
render_trace_arena, CallTraceDecoder, CallTraceDecoderBuilder, TraceKind,
},
};
use once_cell::sync::Lazy;
use regex::Regex;
use reqwest::Url;
use serde::{Deserialize, Serialize};
Expand All @@ -33,6 +32,7 @@ use std::{
io::Write,
path::{Path, PathBuf},
process::Command,
sync::LazyLock,
};
use strum::IntoEnumIterator;
use tracing::debug;
Expand All @@ -48,11 +48,11 @@ pub static COMMAND_LEADER: char = '!';
pub static CHISEL_CHAR: &str = "⚒️";

/// Matches Solidity comments
static COMMENT_RE: Lazy<Regex> =
Lazy::new(|| Regex::new(r"^\s*(?://.*\s*$)|(/*[\s\S]*?\*/\s*$)").unwrap());
static COMMENT_RE: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"^\s*(?://.*\s*$)|(/*[\s\S]*?\*/\s*$)").unwrap());

/// Matches Ethereum addresses that are not strings
static ADDRESS_RE: Lazy<Regex> = Lazy::new(|| {
static ADDRESS_RE: LazyLock<Regex> = LazyLock::new(|| {
Regex::new(r#"(?m)(([^"']\s*)|^)(?P<address>0x[a-fA-F0-9]{40})((\s*[^"'\w])|$)"#).unwrap()
});

Expand Down
1 change: 0 additions & 1 deletion crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ dotenvy = "0.15"
eyre.workspace = true
futures.workspace = true
indicatif = "0.17"
once_cell.workspace = true
regex = { version = "1", default-features = false }
serde.workspace = true
strsim = "0.11"
Expand Down
7 changes: 3 additions & 4 deletions crates/cli/src/opts/dependency.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
//! CLI dependency parsing
use eyre::Result;
use once_cell::sync::Lazy;
use regex::Regex;
use std::str::FromStr;
use std::{str::FromStr, sync::LazyLock};

static GH_REPO_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"[\w-]+/[\w.-]+").unwrap());
static GH_REPO_REGEX: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"[\w-]+/[\w.-]+").unwrap());

/// Git repo prefix regex
pub static GH_REPO_PREFIX_REGEX: Lazy<Regex> = Lazy::new(|| {
pub static GH_REPO_PREFIX_REGEX: LazyLock<Regex> = LazyLock::new(|| {
Regex::new(r"((git@)|(git\+https://)|(https://)|(org-([A-Za-z0-9-])+@))?(?P<brand>[A-Za-z0-9-]+)\.(?P<tld>[A-Za-z0-9-]+)(/|:)")
.unwrap()
});
Expand Down
1 change: 0 additions & 1 deletion crates/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ comfy-table.workspace = true
dunce.workspace = true
eyre.workspace = true
num-format.workspace = true
once_cell.workspace = true
reqwest.workspace = true
rustc-hash.workspace = true
semver.workspace = true
Expand Down
5 changes: 2 additions & 3 deletions crates/common/src/shell.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
//! Helpers for printing to output
use once_cell::sync::OnceCell;
use serde::Serialize;
use std::{
error::Error,
fmt, io,
io::Write,
sync::{Arc, Mutex},
sync::{Arc, Mutex, OnceLock},
};

/// Stores the configured shell for the duration of the program
static SHELL: OnceCell<Shell> = OnceCell::new();
static SHELL: OnceLock<Shell> = OnceLock::new();

/// Error indicating that `set_hook` was unable to install the provided ErrorHook
#[derive(Clone, Copy, Debug)]
Expand Down
8 changes: 5 additions & 3 deletions crates/common/src/term.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ use foundry_compilers::{
artifacts::remappings::Remapping,
report::{self, BasicStdoutReporter, Reporter},
};
use once_cell::sync::Lazy;
use semver::Version;
use std::{
io,
io::{prelude::*, IsTerminal},
path::{Path, PathBuf},
sync::mpsc::{self, TryRecvError},
sync::{
mpsc::{self, TryRecvError},
LazyLock,
},
thread,
time::Duration,
};
Expand All @@ -25,7 +27,7 @@ pub static SPINNERS: &[&[&str]] = &[
&[" ", "▘", "▀", "▜", "█", "▟", "▄", "▖"],
];

static TERM_SETTINGS: Lazy<TermSettings> = Lazy::new(TermSettings::from_env);
static TERM_SETTINGS: LazyLock<TermSettings> = LazyLock::new(TermSettings::from_env);

/// Helper type to determine the current tty
pub struct TermSettings {
Expand Down
1 change: 0 additions & 1 deletion crates/config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ globset = "0.4"
glob = "0.3"
Inflector = "0.11"
number_prefix = "0.4"
once_cell.workspace = true
regex = "1"
reqwest.workspace = true
semver = { workspace = true, features = ["serde"] }
Expand Down
5 changes: 2 additions & 3 deletions crates/config/src/inline/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::Config;
use once_cell::sync::Lazy;
use std::collections::HashMap;
use std::{collections::HashMap, sync::LazyLock};

mod conf_parser;
pub use conf_parser::*;
Expand All @@ -15,7 +14,7 @@ pub const INLINE_CONFIG_FUZZ_KEY: &str = "fuzz";
pub const INLINE_CONFIG_INVARIANT_KEY: &str = "invariant";
const INLINE_CONFIG_PREFIX: &str = "forge-config";

static INLINE_CONFIG_PREFIX_SELECTED_PROFILE: Lazy<String> = Lazy::new(|| {
static INLINE_CONFIG_PREFIX_SELECTED_PROFILE: LazyLock<String> = LazyLock::new(|| {
let selected_profile = Config::selected_profile().to_string();
format!("{INLINE_CONFIG_PREFIX}:{selected_profile}.")
});
Expand Down
7 changes: 3 additions & 4 deletions crates/config/src/resolve.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
//! Helper for resolving env vars
use once_cell::sync::Lazy;
use regex::Regex;
use std::{env, env::VarError, fmt};
use std::{env, env::VarError, fmt, sync::LazyLock};

/// A regex that matches `${val}` placeholders
pub static RE_PLACEHOLDER: Lazy<Regex> =
Lazy::new(|| Regex::new(r"(?m)(?P<outer>\$\{\s*(?P<inner>.*?)\s*})").unwrap());
pub static RE_PLACEHOLDER: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"(?m)(?P<outer>\$\{\s*(?P<inner>.*?)\s*})").unwrap());

/// Error when we failed to resolve an env var
#[derive(Clone, Debug, PartialEq, Eq)]
Expand Down
1 change: 0 additions & 1 deletion crates/doc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ derive_more = "0.99"
eyre.workspace = true
itertools.workspace = true
mdbook = { version = "0.4", default-features = false, features = ["search"] }
once_cell.workspace = true
rayon.workspace = true
serde_json.workspace = true
serde.workspace = true
Expand Down
4 changes: 2 additions & 2 deletions crates/doc/src/preprocessor/infer_hyperlinks.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
use super::{Preprocessor, PreprocessorId};
use crate::{Comments, Document, ParseItem, ParseSource};
use forge_fmt::solang_ext::SafeUnwrap;
use once_cell::sync::Lazy;
use regex::{Captures, Match, Regex};
use std::{
borrow::Cow,
path::{Path, PathBuf},
sync::LazyLock,
};

/// A regex that matches `{identifier-part}` placeholders
///
/// Overloaded functions are referenced by including the exact function arguments in the `part`
/// section of the placeholder.
static RE_INLINE_LINK: Lazy<Regex> = Lazy::new(|| {
static RE_INLINE_LINK: LazyLock<Regex> = LazyLock::new(|| {
Regex::new(r"(?m)(\{(?P<xref>xref-)?(?P<identifier>[a-zA-Z_][0-9a-zA-Z_]*)(-(?P<part>[a-zA-Z_][0-9a-zA-Z_-]*))?}(\[(?P<link>(.*?))\])?)").unwrap()
});

Expand Down
14 changes: 8 additions & 6 deletions crates/doc/src/writer/buf_writer.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
use crate::{writer::traits::ParamLike, AsDoc, CommentTag, Comments, Deployment, Markdown};
use itertools::Itertools;
use once_cell::sync::Lazy;
use solang_parser::pt::{ErrorParameter, EventParameter, Parameter, VariableDeclaration};
use std::fmt::{self, Display, Write};
use std::{
fmt::{self, Display, Write},
sync::LazyLock,
};

/// Solidity language name.
const SOLIDITY: &str = "solidity";

/// Headers and separator for rendering parameter table.
const PARAM_TABLE_HEADERS: &[&str] = &["Name", "Type", "Description"];
static PARAM_TABLE_SEPARATOR: Lazy<String> =
Lazy::new(|| PARAM_TABLE_HEADERS.iter().map(|h| "-".repeat(h.len())).join("|"));
static PARAM_TABLE_SEPARATOR: LazyLock<String> =
LazyLock::new(|| PARAM_TABLE_HEADERS.iter().map(|h| "-".repeat(h.len())).join("|"));

/// Headers and separator for rendering the deployments table.
const DEPLOYMENTS_TABLE_HEADERS: &[&str] = &["Network", "Address"];
static DEPLOYMENTS_TABLE_SEPARATOR: Lazy<String> =
Lazy::new(|| DEPLOYMENTS_TABLE_HEADERS.iter().map(|h| "-".repeat(h.len())).join("|"));
static DEPLOYMENTS_TABLE_SEPARATOR: LazyLock<String> =
LazyLock::new(|| DEPLOYMENTS_TABLE_HEADERS.iter().map(|h| "-".repeat(h.len())).join("|"));

/// The buffered writer.
/// Writes various display items into the internal buffer.
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
once_cell.workspace = true
rustc-hash.workspace = true

[dev-dependencies]
Expand Down
6 changes: 3 additions & 3 deletions crates/evm/abi/src/console/hardhat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use alloy_primitives::Selector;
use alloy_sol_types::sol;
use foundry_common_fmt::*;
use foundry_macros::ConsoleFmt;
use once_cell::sync::Lazy;
use rustc_hash::FxHashMap;
use std::sync::LazyLock;

sol!(
#[sol(abi)]
Expand Down Expand Up @@ -39,8 +39,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: Lazy<FxHashMap<[u8; 4], [u8; 4]>> =
Lazy::new(|| FxHashMap::from_iter(include!("./patches.rs")));
pub static HARDHAT_CONSOLE_SELECTOR_PATCHES: LazyLock<FxHashMap<[u8; 4], [u8; 4]>> =
LazyLock::new(|| FxHashMap::from_iter(include!("./patches.rs")));

#[cfg(test)]
mod tests {
Expand Down
1 change: 0 additions & 1 deletion crates/evm/traces/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ revm-inspectors.workspace = true
eyre.workspace = true
futures.workspace = true
itertools.workspace = true
once_cell.workspace = true
serde.workspace = true
tokio = { workspace = true, features = ["time", "macros"] }
tracing.workspace = true
Expand Down
Loading

0 comments on commit 91656a2

Please sign in to comment.