-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
coverage: Avoid splitting spans during span extraction/refinement #139102
Conversation
r? @fee1-dead rustbot has assigned @fee1-dead. Use |
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
I don't feel like I have enough context to review this, sorry.. r? compiler |
r? compiler |
if let mir::Operand::Constant(box constant) = func { | ||
if constant.span.lo() > span.lo() { | ||
span = span.with_lo(constant.span.lo()); | ||
} | ||
if let mir::Operand::Constant(constant) = func | ||
&& span.contains(constant.span) | ||
{ | ||
span = constant.span; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this to method calls?
And wouldn't you also make this work in case of let x = func; x(foo);
to point at the x
part of the function call?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original version of this heuristic predates me, but I think the intention was to deal with chained calls like this:
data.foo().bar().baz(args);
// ^^^^^^^^^^^^^^^^^^^^^^^^^^ (original span of the MIR call to baz)
// ^^^^^^^^^ (modified call span before this PR)
// ^^^ (modified call span after this PR)
In practice, a lot of these small differences are hard to observe in the output, because there's a subsequent step that merges nearby spans that are considered to have the same control-flow for coverage purposes.
(This merging even happens for non-adjacent/overlapping spans in some cases, which is a behaviour I would eventually like to get rid of.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly, I don't know the original reason for restricting this heuristic to “constant” function/method names, but I suspect it comes down to the fact that evaluating a non-constant callee can potentially have its own internal control flow, which can potentially result in confusing spans.
That said, such code is (a) relatively uncommon in practice, and (b) will probably cause the current span-refinement code to just discard the whole call span.
So I guess my reason for not changing it in this PR is to mostly just to avoid changes beyond my intended scope.
This test is intended to demonstrate that a particular macro-argument span doesn't get lost during span-refinement, but it turns out that span-extraction currently doesn't yield any MIR spans for this position. This patch therefore tweaks the test to add a function call in that position, so that it still remains relevant to span refinement.
This is a way to shrink call spans that doesn't involve mixing different spans, and avoids overlap with argument spans. This patch also removes some low-value comments that were causing rustfmt to ignore the match arms.
(Rebased to resolve snapshot conflicts in |
@bors r+ rollup |
coverage: Avoid splitting spans during span extraction/refinement This PR removes or simplifies some of the steps involved in extracting coverage-relevant spans from MIR, and preparing them for use in coverage instrumentation metadata. A common theme is that we now try harder to avoid modifying or combining spans in non-trivial ways, because those modifications present the most risk for weird behaviour or ICEs. The main changes are: - When extracting spans from MIR call terminators, try to restrict them to just the function name. - Instead of splitting spans around “holes”, just discard any span that overlaps with a hole. - Instead of splitting macro-invocation spans into two parts, truncate them to just the macro name and subsequent `!`. --- This results in a lot of tiny changes to the spans that end up in coverage metadata, and a few changes to coverage reports. Judging by test snapshots, these changes appear to be quite minor in practice.
coverage: Avoid splitting spans during span extraction/refinement This PR removes or simplifies some of the steps involved in extracting coverage-relevant spans from MIR, and preparing them for use in coverage instrumentation metadata. A common theme is that we now try harder to avoid modifying or combining spans in non-trivial ways, because those modifications present the most risk for weird behaviour or ICEs. The main changes are: - When extracting spans from MIR call terminators, try to restrict them to just the function name. - Instead of splitting spans around “holes”, just discard any span that overlaps with a hole. - Instead of splitting macro-invocation spans into two parts, truncate them to just the macro name and subsequent `!`. --- This results in a lot of tiny changes to the spans that end up in coverage metadata, and a few changes to coverage reports. Judging by test snapshots, these changes appear to be quite minor in practice.
Rollup of 12 pull requests Successful merges: - rust-lang#110406 (rustdoc-json: Add test for #[automatically_derived] attribute) - rust-lang#137738 (Make slice iterator constructors unstably const) - rust-lang#138492 (remove `feature(inline_const_pat)`) - rust-lang#138928 (Fix UWP reparse point check) - rust-lang#138950 (replace extra_filename with strict version hash in metrics file names) - rust-lang#139002 (Add release notes for 1.86.0) - rust-lang#139022 (increment depth of nested obligations) - rust-lang#139060 (replace commit placeholder in vendor status with actual commit) - rust-lang#139102 (coverage: Avoid splitting spans during span extraction/refinement) - rust-lang#139129 (Add tests for slice bounds check optimization) - rust-lang#139188 (PassWrapper: adapt for llvm/llvm-project@94122d58fc77079a291a3d008914…) - rust-lang#139193 (Feed HIR for by-move coroutine body def, since the inliner tries to read its attrs) r? `@ghost` `@rustbot` modify labels: rollup
Rollup of 14 pull requests Successful merges: - rust-lang#135295 (Check empty SIMD vector in inline asm) - rust-lang#138003 (Add the new `amx` target features and the `movrs` target feature) - rust-lang#138823 (rustc_target: RISC-V: add base `I`-related important extensions) - rust-lang#138913 (Remove even more instances of `@ts-expect-error` from search.js) - rust-lang#138941 (Do not mix normalized and unnormalized caller bounds when constructing param-env for `receiver_is_dispatchable`) - rust-lang#139060 (replace commit placeholder in vendor status with actual commit) - rust-lang#139102 (coverage: Avoid splitting spans during span extraction/refinement) - rust-lang#139191 (small opaque type/borrowck cleanup) - rust-lang#139200 (Skip suggest impl or dyn when poly trait is not a real trait) - rust-lang#139208 (fix dead link netbsd.md) - rust-lang#139210 (chore: remove redundant backtick) - rust-lang#139212 (Update mdbook to 0.4.48) - rust-lang#139214 (Tell rustfmt to use the 2024 edition in ./x.py fmt) - rust-lang#139225 (move autodiff from EnzymeAD/Enzyme to our rust-lang/Enzyme soft-fork) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#139102 - Zalathar:no-split, r=oli-obk coverage: Avoid splitting spans during span extraction/refinement This PR removes or simplifies some of the steps involved in extracting coverage-relevant spans from MIR, and preparing them for use in coverage instrumentation metadata. A common theme is that we now try harder to avoid modifying or combining spans in non-trivial ways, because those modifications present the most risk for weird behaviour or ICEs. The main changes are: - When extracting spans from MIR call terminators, try to restrict them to just the function name. - Instead of splitting spans around “holes”, just discard any span that overlaps with a hole. - Instead of splitting macro-invocation spans into two parts, truncate them to just the macro name and subsequent `!`. --- This results in a lot of tiny changes to the spans that end up in coverage metadata, and a few changes to coverage reports. Judging by test snapshots, these changes appear to be quite minor in practice.
Culprit PR: rust-lang/rust#139102 Resolves #3986 By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.
This PR removes or simplifies some of the steps involved in extracting coverage-relevant spans from MIR, and preparing them for use in coverage instrumentation metadata.
A common theme is that we now try harder to avoid modifying or combining spans in non-trivial ways, because those modifications present the most risk for weird behaviour or ICEs.
The main changes are:
!
.This results in a lot of tiny changes to the spans that end up in coverage metadata, and a few changes to coverage reports. Judging by test snapshots, these changes appear to be quite minor in practice.