foundry-rs / compilers

Utilities for working with native solc and compiling projects.
Apache License 2.0
58 stars 34 forks source link

fix: better tracking of cache entries #138

Closed klkvr closed 4 weeks ago

klkvr commented 4 weeks ago

Currently, during sparse compilation (and probably in some other cases) we might end up in a situation when cache contains empty entries which can actually produce artifacts when compied.

For example, if A.sol imports B.sol and sparse filter tells us to only compile A.sol, then B.sol will appear in cache (because we have to track its source hash to invalidate A.sol's cache), however, we will erase its output selection when invoking solc, so it will not have any artifacts.

Thus, if compiler is invoked later without sparse filter, it will simply skip compiling B.sol because it will assume that it just does not contain any contract definitions: https://github.com/foundry-rs/compilers/blob/4cf78434b21481c78a8236c95ac82eb945a01758/src/cache.rs#L658-L663

Because of that, artifact for B.sol will be missing until the cache is cleared.

The issue is basically that we might have two situations:

This PR adds seenByCompiler flag which is set to false by default for all newly created entries and switched when entries are compiled as dirty files (without pruned output selection).