diff --git a/Cargo.toml b/Cargo.toml index b5d90c47..5b787913 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,7 +43,6 @@ cfg-if = "1.0" dunce = "1.0" md-5 = "0.10" memmap2 = "0.9" -once_cell = "1.19" path-slash = "0.2" rayon = "1.8" regex = "1.10" @@ -54,7 +53,7 @@ similar-asserts = "1" solar-parse = { version = "=0.1.0", default-features = false } svm = { package = "svm-rs", version = "0.5", default-features = false } tempfile = "3.9" -thiserror = "1" +thiserror = "2" tracing = "0.1" walkdir = "2.5" yansi = "1.0" diff --git a/crates/compilers/Cargo.toml b/crates/compilers/Cargo.toml index 3d7f6339..5da761c1 100644 --- a/crates/compilers/Cargo.toml +++ b/crates/compilers/Cargo.toml @@ -29,7 +29,6 @@ thiserror.workspace = true path-slash.workspace = true yansi.workspace = true solar-parse.workspace = true -once_cell = { workspace = true, optional = true } futures-util = { workspace = true, optional = true } tokio = { workspace = true, optional = true } @@ -85,7 +84,6 @@ svm-solc = [ "dep:svm-builds", "dep:sha2", "foundry-compilers-core/svm-solc", - "dep:once_cell", ] # Utilities for creating and testing project workspaces. project-util = [ diff --git a/crates/compilers/src/compilers/solc/compiler.rs b/crates/compilers/src/compilers/solc/compiler.rs index aefcc629..86e7fb51 100644 --- a/crates/compilers/src/compilers/solc/compiler.rs +++ b/crates/compilers/src/compilers/solc/compiler.rs @@ -45,8 +45,8 @@ macro_rules! take_solc_installer_lock { /// we should download. /// The boolean value marks whether there was an error accessing the release list #[cfg(feature = "svm-solc")] -pub static RELEASES: once_cell::sync::Lazy<(svm::Releases, Vec, bool)> = - once_cell::sync::Lazy::new(|| { +pub static RELEASES: std::sync::LazyLock<(svm::Releases, Vec, bool)> = + std::sync::LazyLock::new(|| { match serde_json::from_str::(svm_builds::RELEASE_LIST_JSON) { Ok(releases) => { let sorted_versions = releases.clone().into_versions(); diff --git a/crates/compilers/src/resolver/parse.rs b/crates/compilers/src/resolver/parse.rs index 3bb4f1be..d4e27090 100644 --- a/crates/compilers/src/resolver/parse.rs +++ b/crates/compilers/src/resolver/parse.rs @@ -133,6 +133,11 @@ impl SolData { if imports.is_empty() { imports = capture_imports(content); } + if contract_names.is_empty() { + utils::RE_CONTRACT_NAMES.captures_iter(content).for_each(|cap| { + contract_names.push(cap[1].to_owned()); + }); + } } let license = content.lines().next().and_then(|line| { utils::capture_outer_and_inner( @@ -313,6 +318,12 @@ mod tests { assert_eq!(data.version_req, version_req.map(|v| v.parse().unwrap()), "src:\n{src}"); } + #[track_caller] + fn assert_contract_names(names: &[&str], src: &str) { + let data = SolData::parse(src, "test.sol".as_ref()); + assert_eq!(data.contract_names, names, "src:\n{src}"); + } + #[test] fn soldata_parsing() { assert_version(None, ""); @@ -332,6 +343,18 @@ contract BugReport { } "#, ); + + assert_contract_names( + &["A", "B69$_", "C_", "$D"], + r#" + contract A {} +library B69$_ {} +abstract contract C_ {} interface $D {} + +uint constant x = .1e10; +uint constant y = .1 ether; + "#, + ); } #[test] diff --git a/crates/compilers/tests/project.rs b/crates/compilers/tests/project.rs index 8bb36917..1f9af8d8 100644 --- a/crates/compilers/tests/project.rs +++ b/crates/compilers/tests/project.rs @@ -30,7 +30,6 @@ use foundry_compilers_core::{ error::SolcError, utils::{self, canonicalize, RuntimeOrHandle}, }; -use once_cell::sync::Lazy; use semver::Version; use similar_asserts::assert_eq; use std::{ @@ -39,10 +38,11 @@ use std::{ io, path::{Path, PathBuf, MAIN_SEPARATOR}, str::FromStr, + sync::LazyLock, }; use svm::{platform, Platform}; -pub static VYPER: Lazy = Lazy::new(|| { +pub static VYPER: LazyLock = LazyLock::new(|| { RuntimeOrHandle::new().block_on(async { #[cfg(target_family = "unix")] use std::{fs::Permissions, os::unix::fs::PermissionsExt}; diff --git a/crates/core/Cargo.toml b/crates/core/Cargo.toml index d132dedc..09512aaa 100644 --- a/crates/core/Cargo.toml +++ b/crates/core/Cargo.toml @@ -18,7 +18,6 @@ workspace = true alloy-primitives.workspace = true cfg-if.workspace = true dunce.workspace = true -once_cell.workspace = true path-slash.workspace = true regex.workspace = true semver.workspace = true diff --git a/crates/core/src/utils.rs b/crates/core/src/utils.rs index 62441497..4a591527 100644 --- a/crates/core/src/utils.rs +++ b/crates/core/src/utils.rs @@ -3,7 +3,6 @@ use crate::error::{SolcError, SolcIoError}; use alloy_primitives::{hex, keccak256}; use cfg_if::cfg_if; -use once_cell::sync::Lazy; use regex::{Match, Regex}; use semver::{Version, VersionReq}; use serde::{de::DeserializeOwned, Serialize}; @@ -13,6 +12,7 @@ use std::{ io::Write, ops::Range, path::{Component, Path, PathBuf}, + sync::LazyLock as Lazy, }; use walkdir::WalkDir; @@ -46,6 +46,11 @@ pub static RE_THREE_OR_MORE_NEWLINES: Lazy = Lazy::new(|| Regex::new("\n{ pub static RE_VYPER_VERSION: Lazy = Lazy::new(|| Regex::new(r"#(?:pragma version|@version)\s+(?P.+)").unwrap()); +/// A regex that matches the contract names in a Solidity file. +pub static RE_CONTRACT_NAMES: Lazy = Lazy::new(|| { + Regex::new(r"\b(?:contract|library|abstract\s+contract|interface)\s+([\w$]+)").unwrap() +}); + /// Extensions acceptable by solc compiler. pub const SOLC_EXTENSIONS: &[&str] = &["sol", "yul"];