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

Minor incremental compilation bugfixes #985

Merged
merged 7 commits into from
Jun 25, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@ package xsbt

import java.io.PrintWriter
import xsbti.compile.Output
import scala.tools.nsc.Global
import scala.tools.nsc.Settings

abstract class Compat
abstract class Compat {
val global: Global
import global._

protected def processOriginalTreeAttachment(in: Tree)(func: Tree => Unit): Unit = ()
}
object Compat {
// IR is renamed to Results
val Results = scala.tools.nsc.interpreter.IR
Expand Down
14 changes: 13 additions & 1 deletion internal/compiler-bridge/src/main/scala-2.12/xsbt/Compat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,21 @@ package xsbt

import java.io.PrintWriter
import xsbti.compile.Output
import scala.tools.nsc.Global
import scala.tools.nsc.Settings

abstract class Compat
abstract class Compat {
val global: Global
import global._

/** If given tree contains object tree attachment calls func on tree from attachment. */
protected def processOriginalTreeAttachment(in: Tree)(func: Tree => Unit): Unit = {
import analyzer._
in.attachments.get[OriginalTreeAttachment].foreach { a =>
func(a.original)
}
}
}
object Compat {
// IR is renamed to Results
val Results = scala.tools.nsc.interpreter.IR
Expand Down
6 changes: 6 additions & 0 deletions internal/compiler-bridge/src/main/scala/xsbt/Dependency.scala
Original file line number Diff line number Diff line change
Expand Up @@ -455,9 +455,15 @@ final class Dependency(val global: CallbackGlobal) extends LocateClassFile with
inspectedOriginalTrees.add(original)
}
addTypeDependencies(typeTree.tpe)

case m @ MacroExpansionOf(original) if inspectedOriginalTrees.add(original) =>
traverse(original)
super.traverse(m)

case l: Literal =>
processOriginalTreeAttachment(l)(traverse)
super.traverse(l)

case _: ClassDef | _: ModuleDef if !ignoredSymbol(tree.symbol) =>
// make sure we cache lookups for all classes declared in the compilation unit; the recorded information
// will be used in Analyzer phase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ class ExtractUsedNames[GlobalType <: CallbackGlobal](val global: GlobalType)
TypeDependencyTraverser.setCacheAndOwner(cache, _currentOwner)
TypeDependencyTraverser.traverse(tpe)
}
case l: Literal =>
processOriginalTreeAttachment(l)(traverse)
case _ =>
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ abstract class Compat {
// `original` has been renamed to `expandee` in 2.11.x
@inline final def expandee: Tree = self.original
}

protected def processOriginalTreeAttachment(in: Tree)(func: Tree => Unit): Unit = ()
}

/** Defines compatibility utils for [[ZincCompiler]]. */
Expand Down
14 changes: 13 additions & 1 deletion internal/compiler-bridge/src/main/scala_2.13/xsbt/Compat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,22 @@ package xsbt

import java.io.PrintWriter
import xsbti.compile.Output
import scala.tools.nsc.Global
import scala.tools.nsc.Settings
import scala.tools.nsc.interpreter.shell.ReplReporterImpl

abstract class Compat
abstract class Compat {
val global: Global
import global._

/** If given tree contains object tree attachment calls func on tree from attachment. */
protected def processOriginalTreeAttachment(in: Tree)(func: Tree => Unit): Unit = {
import analyzer._
in.attachments.get[OriginalTreeAttachment].foreach { a =>
func(a.original)
}
}
}
object Compat {
// IR is renamed to Results
val Results = scala.tools.nsc.interpreter.Results
Expand Down
12 changes: 0 additions & 12 deletions zinc/src/sbt-test/source-dependencies/constants/pending

This file was deleted.

6 changes: 6 additions & 0 deletions zinc/src/sbt-test/source-dependencies/constants/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
$ copy-file changes/B.scala B.scala

$ copy-file changes/A1.scala A.scala
> run 1
$ copy-file changes/A2.scala A.scala
> run 2
24 changes: 23 additions & 1 deletion zinc/src/test/scala/sbt/inc/IncrementalCompilerSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class IncrementalCompilerSpec extends BaseCompilerSpec {
}
}

it should "track dependencies for nested inner Java classes" in withTmpDir { tmp =>
it should "track dependencies from nested inner Java classes" in withTmpDir { tmp =>
val project = VirtualSubproject(tmp.toPath / "p1")
val comp = project.setup.createCompiler()
try {
Expand Down Expand Up @@ -189,4 +189,26 @@ class IncrementalCompilerSpec extends BaseCompilerSpec {
comp.close()
}
}

it should "track dependencies on constants" in withTmpDir { tmp =>
val project = VirtualSubproject(tmp.toPath / "p1")
val comp = project.setup.createCompiler()
try {
val s1 = "object A { final val i = 1 }"
val s1b = "object A { final val i = 2 }"
val s2 = "class B { def i = A.i }"
val s3 = "class C { def i = 3 }"

val f1 = StringVirtualFile("A.scala", s1)
val f1b = StringVirtualFile("A.scala", s1b)
val f2 = StringVirtualFile("B.scala", s2)
val f3 = StringVirtualFile("C.scala", s3)

val res1 = comp.compile(f1, f2, f3)
val res2 = comp.compile(f1b, f2, f3)
assert(recompiled(res1, res2) == Set("A", "B"))
} finally {
comp.close()
}
}
}