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

Prevent overcompilation in mixed projects without pipelining #868

Merged
merged 6 commits into from
Aug 3, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ version = 2.1.0-RC1
maxColumn = 100
project.git = true
project.excludeFilters = [ /sbt-test/, /input_sources/, /contraband-scala/ ]
lineEndings = preserve

# http://docs.scala-lang.org/style/scaladoc.html recommends the JavaDoc style.
# scala/scala is written that way too https://github.com/scala/scala/blob/v2.12.2/src/library/scala/Predef.scala
Expand Down
1 change: 1 addition & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ lazy val zincRoot: Project = (project in file("."))
mimaPreviousArtifacts := Set.empty,
scriptedBufferLog := true,
scripted := scriptedTask.evaluated,
scripted / watchTriggers += baseDirectory.value.toGlob / "zinc" / "src" / "sbt-test" / **,
Scripted.scriptedSource := (zinc212 / sourceDirectory).value / "sbt-test",
Scripted.scriptedCompileToJar := false,
noPublish,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,10 @@ final class LocalJavaCompiler(compiler: javax.tools.JavaCompiler) extends XJavaC
log.warn(invalidOptions.mkString("\t", ", ", ""))
}
val outputOption = CompilerArguments.outputOption(output)
output.getSingleOutputAsPath match {
case p if p.isPresent => Files.createDirectories(p.get)
case _ =>
}

val fileManager = {
if (cleanedOptions.contains("-XDuseOptimizedZip=false")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,18 +339,18 @@ object Incremental {
val (initialInvClasses, initialInvSources0) =
incremental.invalidateInitial(previous.relations, initialChanges)

// If there's any compilation at all, invalidate all java sources too, so we have access to their type information.
val javaSources: Set[VirtualFileRef] = sources
.filter(_.name.endsWith(".java"))
.map(_.asInstanceOf[VirtualFileRef])
// During pipelining, if there's any compilation at all, invalidate all Java sources too, so the downstream Scala subprojects would have type information via early output (pickle jar).
val javaSources: Set[VirtualFileRef] = sources.collect {
case s: VirtualFileRef if s.name.endsWith(".java") => s
}
val isPickleJava = currentSetup.options.scalacOptions.contains("-Ypickle-java")
assert(
javaSources.isEmpty || !options.pipelining || isPickleJava,
s"-Ypickle-java must be included into scalacOptions if pipelining is enabled with Java sources"
)
val initialInvSources =
if (initialInvSources0.nonEmpty) initialInvSources0 ++ javaSources
else Set.empty[VirtualFileRef]
if (isPickleJava && initialInvSources0.nonEmpty) initialInvSources0 ++ javaSources
else initialInvSources0
Comment on lines -352 to +353
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 There's no point in invalidating Java sources unless isPickleJava is on.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool. I was about to submit a comment justifying this choice but I don't need to since you've confirmed my intuition.

if (initialInvClasses.nonEmpty || initialInvSources.nonEmpty) {
if (initialInvSources == sources)
incremental.log.debug(s"all ${initialInvSources.size} sources are invalidated")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,7 @@ final class MixedAnalyzingCompiler(
val dir =
if (d.toString.endsWith(".jar")) d.getParent
else d
if (!Files.exists(dir)) {
Files.createDirectories(dir)
}
Files.createDirectories(dir)
}
outputDirs
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ $ copy-file changes/A2.java A.java
# 1 iteration to recompile all descendents and direct dependencies
# no further iteration, because APIs of directs don't change
> run
> checkIterations 2
> checkIterations 3
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
object A {
val x = 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
object B {
val foo = new Foo
val y = 2
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# turn off pipelining because compileAllJava over-compiles
pipelining = false
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
public class Foo {}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
object A
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
object B {
val foo = new Foo
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
> compile
> checkIterations 1

$ copy-file changes/A.scala src/main/scala/A.scala
> compile
> checkIterations 2

$ copy-file changes/B.scala src/main/scala/B.scala
> compile
> checkIterations 3