Repository navigation
fix(traces): map DTL backtrace offsets to disk sources - #17904
Merged
Merged
Conversation
With dynamic test linking, solc compiles the preprocessor's rewritten test sources, so source-map offsets after a rewritten `new X()` no longer match the file on disk and backtraces lose or misreport test-file locations. Record the preprocessor's edits in each build context through foundry-core and map offsets back to the disk file before computing line and column. Edits are only recorded for preprocessed input that reached solc, so the native fallback and incremental builds stay exact. Bump the preprocessor cache version so existing DTL build infos without edits are rebuilt. Fixes #17901. Amp-Thread-ID: https://ampcode.com/threads/T-fb60a919-56bb-46f7-bebd-cc77edafc998 Co-authored-by: Gustavo Figueiredo <me@figtracer.com>
figtracer
requested review from
0xrusowsky,
DaniPopes,
grandizzy,
mablr,
mattsse and
stevencartavia
as code owners
October 28, 2026 22:06
…ocations Co-authored-by: Gustavo Figueiredo <me@figtracer.com>
Amp-Thread-ID: https://ampcode.com/threads/T-40078ab4-e5cf-4c09-a81d-69d19b79b2b3 Co-authored-by: Gustavo Figueiredo <me@figtracer.com>
mattsse
requested changes
Oct 29, 2026
mattsse
left a comment
Member
There was a problem hiding this comment.
Please preserve the current Solar revision when updating foundry-core.
Resolving the master merge took the whole manifest and lockfile from this branch, which rolled Solar back from 4935059a to 80dda839. Take both from master and change only the foundry-core revision. Amp-Thread-ID: https://ampcode.com/threads/T-40078ab4-e5cf-4c09-a81d-69d19b79b2b3 Co-authored-by: Gustavo Figueiredo <me@figtracer.com>
…ocations # Conflicts: # Cargo.lock # Cargo.toml
The cached run of the DTL backtrace test now asserts that compilation was skipped, so it proves the edits survive in cached build infos. Drop the unused SourceLocation length, which stayed in compiled coordinates while the offset is now mapped to the file on disk, and end the changed comments with periods. Amp-Thread-ID: https://ampcode.com/threads/T-01a19b5e-2472-7381-b12e-4dcf9808d2d4 Co-authored-by: Mablr <59505383+mablr@users.noreply.github.com>
stevencartavia
approved these changes
Nov 2, 2026
mablr
approved these changes
Nov 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With dynamic test linking, solc compiles the preprocessor's rewritten test sources, but
load_build_sourcesmaps source-map offsets against the files on disk. Everything after a rewrittennew X()is shifted, soforge test -vvvvvbacktraces either drop the test-file location (offset past the end of the file) or report the wrong line, as described in #17901.This takes option B from the issue: record the preprocessor's edits instead of the compiled text. foundry-rs/foundry-core#292 lets a preprocessor record the updates it applied through
PreprocessorState, stores them per source id in the job'sBuildContext, and exposesSourceEdit::original_offset. The DTL preprocessor records its updates only when they stay in the compiler input, and the backtrace maps each offset back to the disk file before computing line and column. Columns are exact outside a rewritten expression, offsets inside one point at thenew, and the appended helper interface maps past the end of the file and is ignored.Because the edits travel with the build that solc actually compiled, the two cases where regenerating the rewrite went wrong stay exact: the native fallback compiles without the preprocessor and records nothing, and incremental builds record only what each job received. Build infos already persist the build context, so cached runs keep the edits without a compiler cache format change; the preprocessor cache version is bumped so existing DTL build infos without edits are rebuilt once.
The new backtrace test uses a test contract that does not inherit from
src/, so the preprocessor rewrites it, and checks fresh and cached runs. On master it reports no test-file locations.Fixes #17901