forked from scala/scala3
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from smarter/incremental
Add support for incremental compilation
- Loading branch information
Showing
487 changed files
with
4,108 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
libraryDependencies <+= (sbtVersion) { sv => | ||
"org.scala-sbt" % "scripted-plugin" % sv | ||
} |
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,90 @@ | ||
package xsbt | ||
|
||
import java.net.{URL, URLClassLoader} | ||
|
||
/** A classloader to run the compiler | ||
* | ||
* A CompilerClassLoader is constructed from a list of `urls` that need to be on | ||
* the classpath to run the compiler and the classloader used by sbt. | ||
* | ||
* To understand why a custom classloader is needed for the compiler, let us | ||
* describe some alternatives that wouldn't work. | ||
* - `new URLClassLoader(urls)`: | ||
* The compiler contains sbt phases that callback to sbt using the `xsbti.*` | ||
* interfaces. If `urls` does not contain the sbt interfaces we'll get a | ||
* `ClassNotFoundException` in the compiler when we try to use them, if | ||
* `urls` does contain the interfaces we'll get a `ClassCastException` or a | ||
* `LinkageError` because if the same class is loaded by two different | ||
* classloaders, they are considered distinct by the JVM. | ||
* - `new URLClassLoader(urls, sbtLoader)`: | ||
* Because of the JVM delegation model, this means that we will only load | ||
* a class from `urls` if it's not present in the parent `sbtLoader`, but | ||
* sbt uses its own version of the scala compiler and scala library which | ||
* is not the one we need to run the compiler. | ||
* | ||
* Our solution is to implement a subclass of URLClassLoader with no parent, instead | ||
* we override `loadClass` to load the `xsbti.*` interfaces from `sbtLoader`. | ||
*/ | ||
class CompilerClassLoader(urls: Array[URL], sbtLoader: ClassLoader) | ||
extends URLClassLoader(urls, null) { | ||
override def loadClass(className: String, resolve: Boolean): Class[_] = | ||
if (className.startsWith("xsbti.")) { | ||
// We can't use the loadClass overload with two arguments because it's | ||
// protected, but we can do the same by hand (the classloader instance | ||
// from which we call resolveClass does not matter). | ||
val c = sbtLoader.loadClass(className) | ||
if (resolve) | ||
resolveClass(c) | ||
c | ||
} else { | ||
super.loadClass(className, resolve) | ||
} | ||
} | ||
|
||
object CompilerClassLoader { | ||
/** Fix the compiler bridge ClassLoader | ||
* | ||
* Soundtrack: https://www.youtube.com/watch?v=imamcajBEJs | ||
* | ||
* The classloader that we get from sbt looks like: | ||
* | ||
* URLClassLoader(bridgeURLs, | ||
* DualLoader(scalaLoader, notXsbtiFilter, sbtLoader, xsbtiFilter)) | ||
* | ||
* DualLoader will load the `xsbti.*` interfaces using `sbtLoader` and | ||
* everything else with `scalaLoader`. Once we have loaded the dotty Main | ||
* class using `scalaLoader`, subsequent classes in the dotty compiler will | ||
* also be loaded by `scalaLoader` and _not_ by the DualLoader. But the sbt | ||
* compiler phases are part of dotty and still need access to the `xsbti.*` | ||
* interfaces in `sbtLoader`, therefore DualLoader does not work for us | ||
* (this issue is not present with scalac because the sbt phases are | ||
* currently defined in the compiler bridge itself, not in scalac). | ||
* | ||
* CompilerClassLoader is a replacement for DualLoader. Until we can fix | ||
* this in sbt proper, we need to use reflection to construct our own | ||
* fixed classloader: | ||
* | ||
* URLClassLoader(bridgeURLs, | ||
* CompilerClassLoader(scalaLoader.getURLs, sbtLoader)) | ||
* | ||
* @param bridgeLoader The classloader that sbt uses to load the compiler bridge | ||
* @return A fixed classloader that works with dotty | ||
*/ | ||
def fixBridgeLoader(bridgeLoader: ClassLoader) = bridgeLoader match { | ||
case bridgeLoader: URLClassLoader => | ||
val dualLoader = bridgeLoader.getParent | ||
val dualLoaderClass = dualLoader.getClass | ||
|
||
// DualLoader#parentA and DualLoader#parentB are private | ||
val parentAField = dualLoaderClass.getDeclaredField("parentA") | ||
parentAField.setAccessible(true) | ||
val parentBField = dualLoaderClass.getDeclaredField("parentB") | ||
parentBField.setAccessible(true) | ||
val scalaLoader = parentAField.get(dualLoader).asInstanceOf[URLClassLoader] | ||
val sbtLoader = parentBField.get(dualLoader).asInstanceOf[URLClassLoader] | ||
|
||
val bridgeURLs = bridgeLoader.getURLs | ||
new URLClassLoader(bridgeURLs, | ||
new CompilerClassLoader(scalaLoader.getURLs, sbtLoader)) | ||
} | ||
} |
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
3 changes: 3 additions & 0 deletions
3
bridge/src/sbt-test/source-dependencies/abstract-override/A.scala
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 @@ | ||
trait A { | ||
def x: Int | ||
} |
3 changes: 3 additions & 0 deletions
3
bridge/src/sbt-test/source-dependencies/abstract-override/B.scala
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 @@ | ||
trait B extends A { | ||
override def x = 2 | ||
} |
3 changes: 3 additions & 0 deletions
3
bridge/src/sbt-test/source-dependencies/abstract-override/C.scala
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 @@ | ||
trait C extends A { | ||
def x = 5 | ||
} |
1 change: 1 addition & 0 deletions
1
bridge/src/sbt-test/source-dependencies/abstract-override/D.scala
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 @@ | ||
trait D extends C with B |
3 changes: 3 additions & 0 deletions
3
bridge/src/sbt-test/source-dependencies/abstract-override/changes/C2.scala
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 @@ | ||
trait C extends A { | ||
abstract override def x = super.x + 5 | ||
} |
16 changes: 16 additions & 0 deletions
16
bridge/src/sbt-test/source-dependencies/abstract-override/project/DottyInjectedPlugin.scala
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,16 @@ | ||
import sbt._ | ||
import Keys._ | ||
|
||
object DottyInjectedPlugin extends AutoPlugin { | ||
override def requires = plugins.JvmPlugin | ||
override def trigger = allRequirements | ||
|
||
override val projectSettings = Seq( | ||
scalaVersion := "0.1-SNAPSHOT", | ||
scalacOptions += "-language:Scala2", | ||
scalaBinaryVersion := "2.11", | ||
autoScalaLibrary := false, | ||
libraryDependencies ++= Seq("org.scala-lang" % "scala-library" % "2.11.5"), | ||
scalaCompilerBridgeSource := ("ch.epfl.lamp" % "dotty-bridge" % "0.1-SNAPSHOT" % "component").sources() | ||
) | ||
} |
3 changes: 3 additions & 0 deletions
3
bridge/src/sbt-test/source-dependencies/abstract-override/test
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 @@ | ||
> compile | ||
$ copy-file changes/C2.scala C.scala | ||
-> compile |
7 changes: 7 additions & 0 deletions
7
bridge/src/sbt-test/source-dependencies/abstract-type-override/build.sbt
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,7 @@ | ||
InputKey[Unit]("check-number-of-compiler-iterations") <<= inputTask { (argTask: TaskKey[Seq[String]]) => | ||
(argTask, compile in Compile) map { (args: Seq[String], a: sbt.inc.Analysis) => | ||
assert(args.size == 1) | ||
val expectedIterationsNumber = args(0).toInt | ||
assert(a.compilations.allCompilations.size == expectedIterationsNumber, "a.compilations.allCompilations.size = %d (expected %d)".format(a.compilations.allCompilations.size, expectedIterationsNumber)) | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
bridge/src/sbt-test/source-dependencies/abstract-type-override/changes/Bar1.scala
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 Bar { | ||
def bar: Outer.TypeInner = null | ||
// comment to trigger recompilation | ||
} |
16 changes: 16 additions & 0 deletions
16
...src/sbt-test/source-dependencies/abstract-type-override/project/DottyInjectedPlugin.scala
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,16 @@ | ||
import sbt._ | ||
import Keys._ | ||
|
||
object DottyInjectedPlugin extends AutoPlugin { | ||
override def requires = plugins.JvmPlugin | ||
override def trigger = allRequirements | ||
|
||
override val projectSettings = Seq( | ||
scalaVersion := "0.1-SNAPSHOT", | ||
scalacOptions += "-language:Scala2", | ||
scalaBinaryVersion := "2.11", | ||
autoScalaLibrary := false, | ||
libraryDependencies ++= Seq("org.scala-lang" % "scala-library" % "2.11.5"), | ||
scalaCompilerBridgeSource := ("ch.epfl.lamp" % "dotty-bridge" % "0.1-SNAPSHOT" % "component").sources() | ||
) | ||
} |
3 changes: 3 additions & 0 deletions
3
bridge/src/sbt-test/source-dependencies/abstract-type-override/src/main/scala/Bar.scala
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 @@ | ||
object Bar { | ||
def bar: Outer.TypeInner = null | ||
} |
5 changes: 5 additions & 0 deletions
5
bridge/src/sbt-test/source-dependencies/abstract-type-override/src/main/scala/Foo.scala
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,5 @@ | ||
object Outer { | ||
class Inner { type Xyz } | ||
|
||
type TypeInner = Inner { type Xyz = Int } | ||
} |
3 changes: 3 additions & 0 deletions
3
bridge/src/sbt-test/source-dependencies/abstract-type-override/src/main/scala/Impl.scala
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 @@ | ||
class Impl { | ||
def bleep = Bar.bar | ||
} |
14 changes: 14 additions & 0 deletions
14
bridge/src/sbt-test/source-dependencies/abstract-type-override/test
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,14 @@ | ||
# Test for separate compilation and proper value of | ||
# the OVERRIDE flag when abstract types, type alias | ||
# and structural type are involved | ||
# See https://github.com/sbt/sbt/issues/726 for details | ||
|
||
# introduces first compile iteration | ||
> compile | ||
# this change adds a comment and does not change api so introduces | ||
# only one additional compile iteration | ||
$ copy-file changes/Bar1.scala src/main/scala/Bar.scala | ||
# second iteration | ||
#> compile | ||
# check if there are only two compile iterations performed | ||
> check-number-of-compiler-iterations 2 |
3 changes: 3 additions & 0 deletions
3
bridge/src/sbt-test/source-dependencies/abstract-type/A.scala
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 @@ | ||
trait A { | ||
type S[_] | ||
} |
3 changes: 3 additions & 0 deletions
3
bridge/src/sbt-test/source-dependencies/abstract-type/B.scala
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 @@ | ||
trait B extends A { | ||
type F = S[Int] | ||
} |
3 changes: 3 additions & 0 deletions
3
bridge/src/sbt-test/source-dependencies/abstract-type/changes/A.scala
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 @@ | ||
trait A { | ||
type S | ||
} |
16 changes: 16 additions & 0 deletions
16
bridge/src/sbt-test/source-dependencies/abstract-type/project/DottyInjectedPlugin.scala
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,16 @@ | ||
import sbt._ | ||
import Keys._ | ||
|
||
object DottyInjectedPlugin extends AutoPlugin { | ||
override def requires = plugins.JvmPlugin | ||
override def trigger = allRequirements | ||
|
||
override val projectSettings = Seq( | ||
scalaVersion := "0.1-SNAPSHOT", | ||
scalacOptions += "-language:Scala2", | ||
scalaBinaryVersion := "2.11", | ||
autoScalaLibrary := false, | ||
libraryDependencies ++= Seq("org.scala-lang" % "scala-library" % "2.11.5"), | ||
scalaCompilerBridgeSource := ("ch.epfl.lamp" % "dotty-bridge" % "0.1-SNAPSHOT" % "component").sources() | ||
) | ||
} |
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,7 @@ | ||
> compile | ||
|
||
# remove type arguments from S | ||
$ copy-file changes/A.scala A.scala | ||
|
||
# Both A.scala and B.scala should be recompiled, producing a compile error | ||
-> compile |
6 changes: 6 additions & 0 deletions
6
bridge/src/sbt-test/source-dependencies/added/changes/A1.scala
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,6 @@ | ||
package example | ||
|
||
object A | ||
{ | ||
val x: Int = 3 | ||
} |
6 changes: 6 additions & 0 deletions
6
bridge/src/sbt-test/source-dependencies/added/changes/A2.scala
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,6 @@ | ||
package example | ||
|
||
object A | ||
{ | ||
val x: Int = B.y | ||
} |
6 changes: 6 additions & 0 deletions
6
bridge/src/sbt-test/source-dependencies/added/changes/A3.scala
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,6 @@ | ||
package example | ||
|
||
object A | ||
{ | ||
val x: String = B.y | ||
} |
Oops, something went wrong.