Skip to content

Commit aee2a0f

Browse files
committed
Merge pull request typesafehub#2 from Duhemm/incremental-scenarios
New testing framework for the incremental compiler
2 parents 5fb69a7 + 35eaf4d commit aee2a0f

27 files changed

+1722
-47
lines changed

Diff for: build.sbt

+18-22
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ lazy val compileRoot: Project = (project in file(".")).
6767
classpathProj,
6868
classfileProj,
6969
compileInterfaceProj,
70-
compileInterfaceOldProj,
7170
compileIncrementalProj,
7271
compilePersistProj,
7372
compilerProj,
@@ -150,38 +149,35 @@ lazy val compileInterfaceProj = (project in internalPath / "compile-bridge").
150149
// compiler instances that are memory hungry
151150
javaOptions in Test += "-Xmx1G",
152151
libraryDependencies ++= Seq(sbtIO, utilLogging),
153-
scalaVersion := scala211,
154-
crossScalaVersions := Nil
152+
scalaSource in Compile := {
153+
scalaVersion.value match {
154+
case v if v startsWith "2.11" => baseDirectory.value / "src" / "main" / "scala"
155+
case _ => baseDirectory.value / "src-2.10" / "main" / "scala"
156+
}
157+
},
158+
scalacOptions := {
159+
scalaVersion.value match {
160+
case v if v startsWith "2.11" => scalacOptions.value
161+
case _ => scalacOptions.value filterNot (Set("-Xfatal-warnings", "-deprecation") contains _)
162+
}
163+
}
155164
// artifact in (Compile, packageSrc) := Artifact(srcID).copy(configurations = Compile :: Nil).extra("e:component" -> srcID)
156165
)
157166

158-
lazy val compileInterfaceOldProj = (project in internalPath / "compile-bridge-2.10").
159-
dependsOn(interfaceProj % "compile;test->test", apiProj % "test->test").
167+
// Implements the core functionality of detecting and propagating changes incrementally.
168+
// Defines the data structures for representing file fingerprints and relationships and the overall source analysis
169+
lazy val compileIncrementalProj = (project in internalPath / "compile-inc").
170+
dependsOn (apiProj, classpathProj, compileInterfaceProj % Test).
160171
settings(
161-
baseSettings,
162-
libraryDependencies += scalaCompiler.value,
163-
name := "Compiler Interface for pre 2.11 Scala",
164-
exportJars := true,
172+
testedBaseSettings,
173+
libraryDependencies ++= Seq(sbtIO, utilLogging, utilRelation),
165174
// we need to fork because in unit tests we set usejavacp = true which means
166175
// we are expecting all of our dependencies to be on classpath so Scala compiler
167176
// can use them while constructing its own classpath for compilation
168177
fork in Test := true,
169178
// needed because we fork tests and tests are ran in parallel so we have multiple Scala
170179
// compiler instances that are memory hungry
171180
javaOptions in Test += "-Xmx1G",
172-
libraryDependencies ++= Seq(sbtIO, utilLogging),
173-
crossScalaVersions := Seq(scala210, scala293, scala282),
174-
scalacOptions := { scalacOptions.value filterNot (Set("-Xfatal-warnings", "-deprecation") contains _) },
175-
scalaSource in Test := (scalaSource in compileInterfaceProj in Test).value
176-
)
177-
178-
// Implements the core functionality of detecting and propagating changes incrementally.
179-
// Defines the data structures for representing file fingerprints and relationships and the overall source analysis
180-
lazy val compileIncrementalProj = (project in internalPath / "compile-inc").
181-
dependsOn (apiProj, classpathProj).
182-
settings(
183-
testedBaseSettings,
184-
libraryDependencies ++= Seq(sbtIO, utilLogging, utilRelation),
185181
name := "Incremental Compiler"
186182
)
187183

Diff for: internal/compile-bridge-2.10/NOTICE

-7
This file was deleted.

Diff for: internal/compile-bridge/src/main/scala/xsbt/Dependency.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ object Dependency {
2929
* where it originates from. The Symbol->Classfile mapping is implemented by
3030
* LocateClassFile that we inherit from.
3131
*/
32-
final class Dependency(val global: CallbackGlobal) extends LocateClassFile {
32+
final class Dependency(val global: CallbackGlobal) extends LocateClassFile with GlobalHelpers {
3333
import global._
3434

3535
def newPhase(prev: Phase): Phase = new DependencyPhase(prev)

Diff for: internal/compile-bridge/src/main/scala/xsbt/ExtractAPI.scala

+6-6
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ class ExtractAPI[GlobalType <: CallbackGlobal](val global: GlobalType,
193193
build(base, typeParameters(in, typeParams0), Nil)
194194
case MethodType(params, resultType) =>
195195
build(resultType, typeParams, parameterList(params) :: valueParameters)
196-
case Nullary(resultType) => // 2.9 and later
196+
case NullaryMethodType(resultType) =>
197197
build(resultType, typeParams, valueParameters)
198198
case returnType =>
199199
val t2 = processType(in, dropConst(returnType))
@@ -231,8 +231,8 @@ class ExtractAPI[GlobalType <: CallbackGlobal](val global: GlobalType,
231231
case _ => t
232232
}
233233
private def dropNullary(t: Type): Type = t match {
234-
case Nullary(un) => un
235-
case _ => t
234+
case NullaryMethodType(un) => un
235+
case _ => t
236236
}
237237

238238
private def typeDef(in: Symbol, s: Symbol): xsbti.api.TypeMember =
@@ -309,7 +309,7 @@ class ExtractAPI[GlobalType <: CallbackGlobal](val global: GlobalType,
309309
None
310310
}
311311
private def ignoreClass(sym: Symbol): Boolean =
312-
sym.isLocalClass || sym.isAnonymousClass || sym.fullName.endsWith(LocalChild.toString)
312+
sym.isLocalClass || sym.isAnonymousClass || sym.fullName.endsWith(tpnme.LOCAL_CHILD.toString)
313313

314314
// This filters private[this] vals/vars that were not in the original source.
315315
// The getter will be used for processing instead.
@@ -326,7 +326,7 @@ class ExtractAPI[GlobalType <: CallbackGlobal](val global: GlobalType,
326326
val absOver = s.hasFlag(ABSOVERRIDE)
327327
val abs = s.hasFlag(ABSTRACT) || s.hasFlag(DEFERRED) || absOver
328328
val over = s.hasFlag(OVERRIDE) || absOver
329-
new xsbti.api.Modifiers(abs, over, s.isFinal, s.hasFlag(SEALED), isImplicit(s), s.hasFlag(LAZY), hasMacro(s))
329+
new xsbti.api.Modifiers(abs, over, s.isFinal, s.hasFlag(SEALED), isImplicit(s), s.hasFlag(LAZY), s.hasFlag(MACRO))
330330
}
331331

332332
private def isImplicit(s: Symbol) = s.hasFlag(Flags.IMPLICIT)
@@ -412,7 +412,7 @@ class ExtractAPI[GlobalType <: CallbackGlobal](val global: GlobalType,
412412
case t: ExistentialType => makeExistentialType(in, t)
413413
case NoType => Constants.emptyType // this can happen when there is an error that will be reported by a later phase
414414
case PolyType(typeParams, resultType) => new xsbti.api.Polymorphic(processType(in, resultType), typeParameters(in, typeParams))
415-
case Nullary(resultType) =>
415+
case NullaryMethodType(resultType) =>
416416
warning("sbt-api: Unexpected nullary method type " + in + " in " + in.owner); Constants.emptyType
417417
case _ => warning("sbt-api: Unhandled type " + t.getClass + " : " + t); Constants.emptyType
418418
}

Diff for: internal/compile-bridge/src/main/scala/xsbt/ExtractUsedNames.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import scala.tools.nsc._
3838
* The tree walking algorithm walks into TypeTree.original explicitly.
3939
*
4040
*/
41-
class ExtractUsedNames[GlobalType <: CallbackGlobal](val global: GlobalType) {
41+
class ExtractUsedNames[GlobalType <: CallbackGlobal](val global: GlobalType) extends GlobalHelpers {
4242
import global._
4343

4444
def extract(unit: CompilationUnit): Set[String] = {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package xsbt
2+
3+
import scala.tools.nsc.Global
4+
5+
trait GlobalHelpers {
6+
val global: CallbackGlobal
7+
import global.{ analyzer, Tree }
8+
9+
object MacroExpansionOf {
10+
def unapply(tree: Tree): Option[Tree] = {
11+
tree.attachments.all.collect {
12+
case att: analyzer.MacroExpansionAttachment => att.expandee
13+
}.headOption
14+
}
15+
}
16+
}

Diff for: internal/compile-bridge/src/main/scala/xsbt/LocateClassFile.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ abstract class LocateClassFile {
2121
// catch package objects (that do not have this flag set)
2222
if (sym hasFlag scala.tools.nsc.symtab.Flags.PACKAGE) None else {
2323
import scala.tools.nsc.symtab.Flags
24-
val name = flatname(sym, classSeparator) + moduleSuffix(sym)
24+
val name = flatname(sym, classSeparator) + sym.moduleSuffix
2525
findClass(name).map { case (file, inOut) => (file, name, inOut) } orElse {
2626
if (isTopLevelModule(sym)) {
2727
val linked = sym.companionClass

Diff for: internal/compile-bridge/src/test/scala/xsbt/ExtractUsedNamesSpecification.scala

+6-9
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,18 @@ class ExtractUsedNamesSpecification extends UnitSpec {
6565
assert(usedNames === expectedNames)
6666
}
6767

68-
// test for https://issues.scala-lang.org/browse/SI-7173
69-
// Note: This tests is disabled for Scala pre-2.11 because of the issue mentioned above.
70-
it should "extract names of constants (only for 2.11)" in {
68+
// pending test for https://issues.scala-lang.org/browse/SI-7173
69+
it should "extract names of constants" in pendingUntilFixed {
7170
val src = "class A { final val foo = 12; def bar: Int = foo }"
7271
val compilerForTesting = new ScalaCompilerForUnitTesting(nameHashing = true)
7372
val usedNames = compilerForTesting.extractUsedNamesFromSrc(src)
7473
val expectedNames = standardNames ++ Set("A", "foo", "Int")
75-
assert(!isScala211 || usedNames === expectedNames)
74+
assert(usedNames === expectedNames)
7675
}
7776

7877
// test for https://github.com/gkossakowski/sbt/issues/4
79-
// Note: This tests is disabled for Scala pre-2.11 because of the issue mentioned above.
80-
it should "extract names from method calls on Dynamic (only for 2.11)" in {
78+
// TODO: we should fix it by having special treatment of `selectDynamic` and `applyDynamic` calls
79+
it should "extract names from method calls on Dynamic" in pendingUntilFixed {
8180
val srcA = """|import scala.language.dynamics
8281
|class A extends Dynamic {
8382
| def selectDynamic(name: String): Int = name.length
@@ -86,11 +85,9 @@ class ExtractUsedNamesSpecification extends UnitSpec {
8685
val compilerForTesting = new ScalaCompilerForUnitTesting(nameHashing = true)
8786
val usedNames = compilerForTesting.extractUsedNamesFromSrc(srcA, srcB)
8887
val expectedNames = standardNames ++ Set("B", "A", "a", "Int", "selectDynamic", "bla")
89-
assert(!isScala211 || usedNames === expectedNames)
88+
assert(usedNames === expectedNames)
9089
}
9190

92-
private val isScala211 = scala.util.Properties.versionNumberString.startsWith("2.11")
93-
9491
/**
9592
* Standard names that appear in every compilation unit that has any class
9693
* definition.

0 commit comments

Comments
 (0)