coverage: Attribute macro-generated function bodies to their invocation site#158833
Open
alex wants to merge 1 commit into
Open
coverage: Attribute macro-generated function bodies to their invocation site#158833alex wants to merge 1 commit into
alex wants to merge 1 commit into
Conversation
…on site Functions whose bodies are entirely proc-macro-generated (e.g. the impls from a `#[derive(...)]` macro) have every statement span pointing at the macro invocation site, because proc-macro output tokens get call-site spans. Before Rust 1.84, the empty invocation-site spans that survived span refinement were widened by one column, so the invocation line reported the generated code's execution count via the entry counter. PR rust-lang#132675 (1.84) restricted that widening to spans adjacent to '{' or '}', which as a side effect left such functions either completely uninstrumented, or with a single leftover sliver region wired to an arbitrary non-entry counter that reads 0 even when the function runs. Restore the pre-1.84 semantics deliberately: when a function body is entirely macro-expanded and its spans point back into the invocation site (distinguishing proc-macro output from `macro_rules!` definition-site tokens, which normal refinement still handles), emit a single code region over the visible invocation site - the derive-macro path, the attribute, or `name!` - wired to the function's entry counter. Never-called generated functions get the same region as an unused-function mapping (count 0); executed siblings from the same invocation share the span, so llvm-cov's aggregation covers the line. `#[automatically_derived]` impls remain uninstrumented, as before. Co-Authored-By: Claude Fable 5 <[email protected]>
Collaborator
Collaborator
|
r? @wesleywiser rustbot has assigned @wesleywiser. Use Why was this reviewer chosen?The reviewer was selected based on:
|
Collaborator
|
Member
Author
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.
Functions whose bodies are entirely proc-macro-generated (e.g. the impls from a
#[derive(...)]macro) have every statement span pointing at the macro invocation site, because proc-macro output tokens get call-site spans.Before Rust 1.84, the empty invocation-site spans that survived span refinement were widened by one column, so the invocation line reported the generated code's execution count via the entry counter. PR #132675 (1.84) restricted that widening to spans adjacent to '{' or '}', which as a side effect left such functions either completely uninstrumented, or with a single leftover sliver region wired to an arbitrary non-entry counter that reads 0 even when the function runs.
Restore the pre-1.84 semantics deliberately: when a function body is entirely macro-expanded and its spans point back into the invocation site (distinguishing proc-macro output from
macro_rules!definition-site tokens, which normal refinement still handles), emit a single code region over the visible invocation site - the derive-macro path, the attribute, orname!- wired to the function's entry counter.Never-called generated functions get the same region as an unused-function mapping (count 0); executed siblings from the same invocation share the span, so llvm-cov's aggregation covers the line.
#[automatically_derived]impls remain uninstrumented, as before.