Skip to content

fix(traces): map DTL backtrace offsets to disk sources - #17904

Merged
figtracer merged 10 commits into
masterfrom
fix/dtl-backtrace-locations
Nov 3, 2026
Merged

figtracer merged 10 commits into
masterfrom
fix/dtl-backtrace-locations

Conversation

@figtracer

@figtracer figtracer commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

With dynamic test linking, solc compiles the preprocessor's rewritten test sources, but load_build_sources maps source-map offsets against the files on disk. Everything after a rewritten new X() is shifted, so forge test -vvvvv backtraces 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's BuildContext, and exposes SourceEdit::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 the new, 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

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>
mattsse
mattsse previously approved these changes Oct 28, 2026

@mattsse mattsse left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm

@stevencartavia stevencartavia left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@figtracer, conflicts

ampagent and others added 2 commits October 29, 2026 16:17
…ocations

Co-authored-by: Gustavo Figueiredo <me@figtracer.com>

@mattsse mattsse left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please preserve the current Solar revision when updating foundry-core.

Comment thread Cargo.toml Resolved
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>
mattsse
mattsse previously approved these changes Oct 29, 2026

@mattsse mattsse left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm

mattsse
mattsse previously approved these changes Nov 2, 2026

@mattsse mattsse left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm

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>

@mattsse mattsse left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm

@figtracer
figtracer merged commit a1647a2 into master Nov 3, 2026
27 of 46 checks passed
@figtracer
figtracer deleted the fix/dtl-backtrace-locations branch November 3, 2026 09:34
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.

forge test -vvvvv backtraces have no test-file location with dynamic test linking

5 participants