Fix tracing::instrument async block coverage - #158276
Conversation
|
Some changes occurred in coverage instrumentation. cc @Zalathar Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
|
r? @nnethercote rustbot has assigned @nnethercote. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
6ccf282 to
e741c23
Compare
This comment has been minimized.
This comment has been minimized.
|
This is a small and simple change and it seems reasonable. But I will defer to someone who knows a lot more about this code than I do. r? @Zalathar |
|
|
e741c23 to
8ad73df
Compare
This comment has been minimized.
This comment has been minimized.
|
Okay @Zalathar using codex to help with debugging I managed to narrow it down better than my own semi-blind println stumbling around! The actual issue is that the instrumented function contains dummy spans and is evaluated but the actual user code is somewhere else in the expansion tree. This solution should hopefully be better Removed my old incorrect processing and rebased on latest version. No tests currently for it as I'm not sure what the testing requirements are for the coverage stuff |
Attribute proc macros such as `#[tracing::instrument]` can wrap the body of an async function in another async block. The generated block's body span belongs to the attribute expansion context, while the interpolated user code retains spans in the root syntax context. Coverage refinement uses the generated body's expansion-tree node. When that node contains only dummy or empty spans, no mappings are produced for the user code, even though useful spans exist in the root node for the same MIR body. When an attribute proc macro produces this shape, use the root-context node for coverage mapping. The expansion tree contains spans from only one MIR body, so the fallback cannot select spans from another function.
8ad73df to
401941a
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
(Sorry for this taking so long. The code in question is delicate enough that I don’t want to add more heuristics without properly understanding them, and the interaction of async and proc-macros is a very tricky business.) |
|
Sure no problem, I could try to make a project using numerous proc macro crates and async and see how this pr impacts coverage accuracy and then compare against sync proc macro projects as well if that'll help |
Fixes #131119 (or tries to...)
Using tracing::instrument code such as:
Often results in functions with no coverage counters.
Using the following MRE:
That was all wrong, a new approach has been done! It seems it was caused by looking at the wrong place in the macro expansion tree