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.
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_id
s is simply by order in which sources are passed in compiler input. Thus, if we have two sourcesA.sol
andB.sol
, then on the first (non-cached) compiler run,A.sol
will get assigned ID 1 andB.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 intoBuildInfo
, and read along with cached artifacts.BuildContext
s are indexed by the same IDsBuildInfo
s are, and eachArtifactId
now has a reference tobuild_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.