Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: caching logic #90

Merged
merged 23 commits into from
Mar 13, 2024
Merged

refactor: caching logic #90

merged 23 commits into from
Mar 13, 2024

Conversation

klkvr
Copy link
Member

@klkvr klkvr commented Mar 12, 2024

Currently we are not keeping cache entries for files which were out of scope of compiler (might be dirty or not)

Because of that, when running forge compile, then running forge compile --skip ... which will filter some artifacts out, and then running forge compile again, some artifacts will be recompiled, because --skip run removed those entries from cache.

Solution is to keep those entries in cache (we already silently keep artifacts anyway).

@klkvr klkvr requested a review from mattsse March 12, 2024 01:14
@@ -708,9 +704,8 @@ mod tests {
let prep = compiler.preprocess().unwrap();
let cache = prep.cache.as_cached().unwrap();
// 3 contracts
assert_eq!(cache.dirty_source_files.len(), 3);
assert!(cache.filtered.is_empty());
assert!(cache.cache.is_empty());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are now adding entries for dirty files to cache during preprocessing

Copy link
Member

@onbjerg onbjerg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense to me, ptal @mattsse

src/cache.rs Show resolved Hide resolved
Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great!
this makes a lot of sense

@klkvr
Copy link
Member Author

klkvr commented Mar 12, 2024

Patched foundry-rs/foundry#7334 with this PR branch, will merge after it succeeds

@klkvr
Copy link
Member Author

klkvr commented Mar 13, 2024

@mattsse @onbjerg mind taking one more look? updated impl after failed foundry ci

it should become a little bit more safer now, there were some edge cases with multiple versions when we could have dirty artifacts staying in cache

Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks great!
clean

Copy link
Member

@onbjerg onbjerg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm as well :shipit:

@klkvr klkvr merged commit 70c6f8b into foundry-rs:main Mar 13, 2024
14 checks passed
mattsse pushed a commit that referenced this pull request Apr 17, 2024
missed this in #90

ref https://t.me/foundry_support/52331

after #90 we stopped removing out of scope sources from cache, however,
we never validated if they are dirty, this results in invalid cached
artifacts in certain cases.

with this PR we iterate over all cache entries out of scope of current
compiler run, then build graph with them to find if they import any of
files marked as dirty.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants