Skip to content
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

Keep 'fun' and 'args' together when instrumenting TypeApply for coverage #15739

Merged
merged 1 commit into from
Jul 27, 2022

Conversation

TheElectronWill
Copy link
Contributor

@TheElectronWill TheElectronWill commented Jul 23, 2022

Based on PR #15648. edit: rebased on main because #15648 has been merged

Fixes #15705 :)

Note: most of the changes in #15648 (and thus in this PR) are tests, the interesting code is in InstrumentCoverage.scala.

@TheElectronWill TheElectronWill added the backport:nominated If we agree to backport this PR, replace this tag with "backport:accepted", otherwise delete it. label Jul 25, 2022
@TheElectronWill TheElectronWill requested a review from griggt July 26, 2022 13:22
@Kordyjan Kordyjan mentioned this pull request Jul 26, 2022
23 tasks
@sjrd sjrd merged commit 4d1dbc7 into scala:main Jul 27, 2022
@Kordyjan Kordyjan added backport:done This PR was successfully backported. and removed backport:nominated If we agree to backport this PR, replace this tag with "backport:accepted", otherwise delete it. labels 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!
@Kordyjan Kordyjan added this to the 3.2.1 milestone Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:done This PR was successfully backported.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Compiler crash using -coverage-out with polymorphic extension methods
3 participants