Keep 'fun' and 'args' together when instrumenting TypeApply for coverage#15739
Merged
Conversation
e0ae65e to
b363ef3
Compare
b363ef3 to
c484d83
Compare
23 tasks
sjrd
reviewed
Jul 26, 2022
sjrd
approved these changes
Jul 27, 2022
smarter
added a commit
that referenced
this pull request
Oct 24, 2022
*As with the last coverage PR, don't worry: most of the changes are "expect" files for tests. On top of that, many files have only changed by the order in which the statements are recorded, but this order doesn't matter.* Small changes which, together, make the instrumentation more robust and fix many bugs: 1. Address comments in #15739 by introducing a type `InstrumentedParts`. The initial problem was that `TypeApply` cannot be instrumented in a straightforward way: `expr[T]` cannot be turned into `{invoked(...); expr}[T]` but must be `{invoked(...); expr[T]}`. To do this, we first try to instrument `expr` and then, if it was successfully instrumented, we move the call to `invoked(...)` to the right place. This gives us the following code in `transform`: ```scala case TypeApply(fun, args) => val InstrumentedParts(pre, coverageCall, expr) = tryInstrument(fun) // may generate a call to invoked(...), but it's not part of the resulting tree yet if coverageCall.isEmpty then tree else Block( pre :+ coverageCall, // put the call at the right place (pre contains lifted definitions, if any) cpy.TypeApply(tree)(expr, args) ) ``` 2. Exclude more trees from instrumentation, like `Erased` trees and calls to the parents' constructor in `Template#parents`. 3. Escape special characters in `Serializer`. 4. Reposition `Inlined` trees to the current source in order to avoid referencing an unreachable compilation unit. This might be the most controversial change because I've called `Inlines.dropInlined` 👀. Any suggestion is welcome!
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.
Based on PR #15648.edit: rebased on main because #15648 has been mergedFixes #15705 :)
Note: most of the changes in #15648 (and thus in this PR) are tests, the interesting code is in
InstrumentCoverage.scala.