foundry-rs / compilers

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

feat: track and cache context of each compiler invocation #140

Closed klkvr closed 3 weeks ago

klkvr commented 3 weeks ago

ref https://github.com/foundry-rs/foundry/issues/7379 ref https://github.com/foundry-rs/foundry/issues/4981 ref https://github.com/foundry-rs/foundry/issues/2704

The way Solidity assigns source_ids is simply by order in which sources are passed in compiler input. Thus, if we have two sources A.sol and B.sol, then on the first (non-cached) compiler run, A.sol will get assigned ID 1 and B.sol will have ID 2.

Then, if we change B.sol slightly and recompile, it will be the only source in the input, so it will have ID 1.

The same ID collisions are more often appearing on multi-version and multi-compiler builds. After many cached runs such discrepancies result in debugger basically displaying random sources.

This PR adds a way to link an artifact to the build info for input that produced it, thus allowing us to track correct source_id -> source mapping for cached artifacts.

I've added BuildContext which is the foundry context we are tracking for each compiler invocation. It is getting inlined into BuildInfo, and read along with cached artifacts. BuildContexts are indexed by the same IDs BuildInfos are, and each ArtifactId now has a reference to build_id which produced it.

Build info now produced on every compiler run, however, it does not include complete input and output unless project.build_info is true, to avoid overhead while keeping our internal logic working correctly.

mattsse commented 3 weeks ago

error[rejected]: failed to satisfy license requirements ┌─ icu_locid 1.5.0 (registry+https://github.com/rust-lang/crates.io-index):4:12 │ 4 │ license = "Unicode-3.0"

we can add "Unicode-3.0" to allowed in deny.toml