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

Make incremental compilation aware of synthesized mirrors #18310

Merged
merged 3 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala
Original file line number Diff line number Diff line change
Expand Up @@ -676,11 +676,16 @@ private class ExtractAPICollector(using Context) extends ThunkHolder {

// In the Scala2 ExtractAPI phase we only extract annotations that extend
// StaticAnnotation, but in Dotty we currently pickle all annotations so we
// extract everything (except annotations missing from the classpath which
// we simply skip over, and inline body annotations which are handled above).
// extract everything, except:
// - annotations missing from the classpath which we simply skip over
// - inline body annotations which are handled above
// - the Child annotation since we already extract children via
// `api.ClassLike#childrenOfSealedClass` and adding this annotation would
// lead to overcompilation when using zinc's
// `IncOptions#useOptimizedSealed`.
s.annotations.foreach { annot =>
val sym = annot.symbol
if sym.exists && sym != defn.BodyAnnot then
if sym.exists && sym != defn.BodyAnnot && sym != defn.ChildAnnot then
annots += apiAnnotation(annot)
}

Expand Down
438 changes: 247 additions & 191 deletions compiler/src/dotty/tools/dotc/sbt/ExtractDependencies.scala

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions sbt-test/source-dependencies/useOptimizedSealed/Sealed.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sealed trait Sealed
class Child1 extends Sealed
3 changes: 3 additions & 0 deletions sbt-test/source-dependencies/useOptimizedSealed/Test.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Test {
val s: Sealed = new Child1
}
29 changes: 29 additions & 0 deletions sbt-test/source-dependencies/useOptimizedSealed/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
scalaVersion := sys.props("plugin.scalaVersion")

ThisBuild / incOptions ~= { _.withUseOptimizedSealed(true) }

import sbt.internal.inc.Analysis
import complete.DefaultParsers._

// Reset compiler iterations, necessary because tests run in batch mode
val recordPreviousIterations = taskKey[Unit]("Record previous iterations.")
recordPreviousIterations := {
val log = streams.value.log
CompileState.previousIterations = {
val previousAnalysis = (previousCompile in Compile).value.analysis.asScala
previousAnalysis match {
case None =>
log.info("No previous analysis detected")
0
case Some(a: Analysis) => a.compilations.allCompilations.size
}
}
}

val checkIterations = inputKey[Unit]("Verifies the accumulated number of iterations of incremental compilation.")

checkIterations := {
val expected: Int = (Space ~> NatBasic).parsed
val actual: Int = ((compile in Compile).value match { case a: Analysis => a.compilations.allCompilations.size }) - CompileState.previousIterations
assert(expected == actual, s"Expected $expected compilations, got $actual")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
sealed trait Sealed
class Child1 extends Sealed
class Child2 extends Sealed
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sealed trait Sealed
class Child1 extends Sealed
class Child2 extends Sealed
class Child3 extends Sealed
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Test {
def foo(x: Sealed): Int = x match
case _: Child1 => 1
case _: Child2 => 1

val s: Sealed = new Child1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// This is necessary because tests are run in batch mode
object CompileState {
@volatile var previousIterations: Int = -1
}
24 changes: 24 additions & 0 deletions sbt-test/source-dependencies/useOptimizedSealed/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Compile Sealed.scala and Test.scala
> compile
> recordPreviousIterations

# Add an extra children to Sealed
$ copy-file changes/Sealed1.scala Sealed.scala

# Only Sealed.scala needs to be recompiled because Test.scala does not
# match on a value of type `Sealed`.
> compile
> checkIterations 1

> clean
$ copy-file changes/Test1.scala Test.scala
> compile
> recordPreviousIterations

# Add an extra children to Sealed again
$ copy-file changes/Sealed2.scala Sealed.scala

# Test.scala will be recompiled in a second round because it matches
# on a value of type `Sealed`.
> compile
> checkIterations 2