-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix coverage serialization when encountering macro suspension (#22303)
Fixes #22247 The fix is simple, as we mainly move the coverage object to a global ContextBase object, which persists it between runs. Initially I thought that appending the newly generated coverage indices would be enough, but if the macro suspends after the InstrumentCoverage phase runs, we end up with duplicate indices. For that reason, when generating indexes for a compilation unit, we also remove the previously generated ones for the same compilation unit. To support having multiple scala files compiled in the coverage tests I had to slightly adjust the suite. While doing that, I noticed that some check files for run tests were ignored, as they were incorrectly named. I added an assertion that throws when `.check` do not exist and renamed the files appropriately (having to add some additional ones as well).
- Loading branch information
Showing
23 changed files
with
378 additions
and
32 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package example | ||
|
||
sealed trait Test | ||
|
||
object Test { | ||
case object Foo extends Test | ||
|
||
val visitorType = mkVisitorType[Test] | ||
|
||
trait Visitor[A] { | ||
type V[a] = visitorType.Out[a] | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package example | ||
|
||
val _ = Test.Foo |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package example | ||
|
||
import scala.quoted.* | ||
|
||
private def mkVisitorTypeImpl[T: Type](using q: Quotes): Expr[VisitorType[T]] = | ||
'{new VisitorType[T]{}} | ||
|
||
transparent inline def mkVisitorType[T]: VisitorType[T] = ${ mkVisitorTypeImpl[T] } | ||
|
||
trait VisitorType[T] { | ||
type Out[A] | ||
} |
88 changes: 88 additions & 0 deletions
88
tests/coverage/pos/macro-late-suspend/test.scoverage.check
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# Coverage data, format version: 3.0 | ||
# Statement data: | ||
# - id | ||
# - source path | ||
# - package name | ||
# - class name | ||
# - class type (Class, Object or Trait) | ||
# - full class name | ||
# - method name | ||
# - start offset | ||
# - end offset | ||
# - line number | ||
# - symbol name | ||
# - tree name | ||
# - is branch | ||
# - invocations count | ||
# - is ignored | ||
# - description (can be multi-line) | ||
# '' sign | ||
# ------------------------------------------ | ||
1 | ||
macro-late-suspend/VisitorMacros.scala | ||
example | ||
VisitorMacros$package | ||
Object | ||
example.VisitorMacros$package | ||
mkVisitorTypeImpl | ||
124 | ||
144 | ||
6 | ||
unpickleExprV2 | ||
Apply | ||
false | ||
0 | ||
false | ||
new VisitorType[T]{} | ||
|
||
2 | ||
macro-late-suspend/VisitorMacros.scala | ||
example | ||
VisitorMacros$package | ||
Object | ||
example.VisitorMacros$package | ||
mkVisitorTypeImpl | ||
40 | ||
69 | ||
5 | ||
mkVisitorTypeImpl | ||
DefDef | ||
false | ||
0 | ||
false | ||
private def mkVisitorTypeImpl | ||
|
||
3 | ||
macro-late-suspend/Test.scala | ||
example | ||
Test | ||
Object | ||
example.Test | ||
<init> | ||
102 | ||
121 | ||
8 | ||
<init> | ||
Apply | ||
false | ||
0 | ||
false | ||
mkVisitorType[Test] | ||
|
||
4 | ||
macro-late-suspend/UsesTest.scala | ||
example | ||
UsesTest$package | ||
Object | ||
example.UsesTest$package | ||
<init> | ||
22 | ||
22 | ||
3 | ||
<none> | ||
Literal | ||
true | ||
0 | ||
false | ||
|
||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
2 |
File renamed without changes.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
List() | ||
List(abc, def) |
File renamed without changes.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Baz |
File renamed without changes.
File renamed without changes.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
>>> hello <<< |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import scala.quoted.{Expr, Quotes} | ||
|
||
object Macro: | ||
inline def decorate(inline s: String): String = ${ decorateQuotes('s) } | ||
def decorateQuotes(s: Expr[String])(using Quotes): Expr[String] = '{ ">>> " + $s + " <<<" } | ||
|
||
object Greeting: | ||
def greet() = "hello" |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
object Test: | ||
def main(args: Array[String]): Unit = | ||
println(Macro.decorate(Greeting.greet())) | ||
|
Oops, something went wrong.