Scoverage: instrument chained calls correctly#26166
Draft
anatoliykmetyuk wants to merge 3 commits into
Draft
Conversation
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.
Fixes #26088
Root Issue
The issue in question is actually a manifestation of a larger issue:
Will correctly get instrumented by coverage to roughly:
But:
Will incorrectly get instrumented to roughly:
So, in case of chained calls
foo(x).bar(y).baz(z), only the last callbaz(z)will get proper instrumentation that respects argument evaluation order.Reported Issue Impact
Consider code:
Its line:
Coverage instrumentation of that line:
Ycheckthen fails because the result type is tied to the method parameter placeholder?1, while the block result is tied to the lifted local$1$:Solution
Ensure call chains such as
foo(x).bar(y).baz(z)have all their calls lifted and instrumented properly to preserve evaluation order.In the case of the issue in question, this will have the following effect:
c.typeis preserved inaddMode, andaddMode(...)is traced the same way inaddMode(...).setA(...)as it is inaddMode(...).How much have you relied on LLM-based tools in this contribution?
Moderately, for minimization, codebase analysis, tracing, test generation.
How was the solution tested?
New automated tests. Added
tests/pos-custom-args/captures/coverage-freshcontext-addmode.scalaandtests/coverage/run/chained-apply/test.scala. The coverage run test checks direct, single-chain, multi-chain, and receiver-dependent chained applications.