Skip to content

Commit 121f284

Browse files
authored
chore: clarify version cache lock (foundry-rs#160)
idk if this changes anything, make the lock a separate variable
1 parent d4ec340 commit 121f284

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

crates/compilers/src/artifact_output/mod.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,8 @@ impl<T> Artifacts<T> {
276276
pub fn artifacts<O: ArtifactOutput<Artifact = T>>(
277277
&self,
278278
) -> impl Iterator<Item = (ArtifactId, &T)> + '_ {
279-
self.0.iter().flat_map(|(file, contract_artifacts)| {
279+
self.0.iter().flat_map(|(source, contract_artifacts)| {
280280
contract_artifacts.iter().flat_map(move |(_contract_name, artifacts)| {
281-
let source = file.clone();
282281
artifacts.iter().filter_map(move |artifact| {
283282
O::contract_name(&artifact.file).map(|name| {
284283
(
@@ -302,9 +301,9 @@ impl<T> Artifacts<T> {
302301
pub fn into_artifacts<O: ArtifactOutput<Artifact = T>>(
303302
self,
304303
) -> impl Iterator<Item = (ArtifactId, T)> {
305-
self.0.into_iter().flat_map(|(file, contract_artifacts)| {
304+
self.0.into_iter().flat_map(|(source, contract_artifacts)| {
306305
contract_artifacts.into_iter().flat_map(move |(_contract_name, artifacts)| {
307-
let source = file.clone();
306+
let source = source.clone();
308307
artifacts.into_iter().filter_map(move |artifact| {
309308
O::contract_name(&artifact.file).map(|name| {
310309
(

crates/compilers/src/compilers/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,11 @@ pub(crate) fn cache_version(
279279
f: impl FnOnce(&Path) -> Result<Version>,
280280
) -> Result<Version> {
281281
static VERSION_CACHE: OnceLock<Mutex<HashMap<PathBuf, Version>>> = OnceLock::new();
282-
Ok(match VERSION_CACHE.get_or_init(|| Mutex::new(HashMap::new())).lock().unwrap().entry(path) {
282+
let mut lock = VERSION_CACHE
283+
.get_or_init(|| Mutex::new(HashMap::new()))
284+
.lock()
285+
.unwrap_or_else(std::sync::PoisonError::into_inner);
286+
Ok(match lock.entry(path) {
283287
std::collections::hash_map::Entry::Occupied(entry) => entry.into_mut(),
284288
std::collections::hash_map::Entry::Vacant(entry) => {
285289
let value = f(entry.key())?;

0 commit comments

Comments
 (0)