Skip to content

Commit

Permalink
Switch zinc from fork to original one.
Browse files Browse the repository at this point in the history
  • Loading branch information
tgodzik committed Mar 8, 2021
1 parent 09d45cb commit 7392f98
Show file tree
Hide file tree
Showing 35 changed files with 73 additions and 1,282 deletions.
27 changes: 0 additions & 27 deletions backend/src/main/scala/bloop/CompileMode.scala

This file was deleted.

3 changes: 1 addition & 2 deletions backend/src/main/scala/bloop/CompileProducts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,5 @@ case class CompileProducts(
resultForDependentCompilationsInSameRun: PreviousResult,
resultForFutureCompilationRuns: PreviousResult,
invalidatedCompileProducts: Set[File],
generatedRelativeClassFilePaths: Map[String, File],
definedMacroSymbols: Array[String]
generatedRelativeClassFilePaths: Map[String, File]
)
31 changes: 12 additions & 19 deletions backend/src/main/scala/bloop/Compiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import bloop.tracing.BraveTracer
import bloop.logging.{ObservedLogger, Logger}
import bloop.reporter.{ProblemPerPhase, ZincReporter}
import bloop.util.{AnalysisUtils, UUIDUtil, CacheHashCode}
import bloop.CompileMode.Pipelined
import bloop.CompileMode.Sequential

import xsbti.compile._
import xsbti.T2
Expand All @@ -23,7 +21,6 @@ import sbt.util.InterfaceUtil
import sbt.internal.inc.Analysis
import sbt.internal.inc.bloop.BloopZincCompiler
import sbt.internal.inc.{FreshCompilerCache, InitialChanges, Locate}
import sbt.internal.inc.bloop.internal.StopPipelining
import sbt.internal.inc.{ConcreteAnalysisContents, FileAnalysisStore}

import scala.concurrent.Promise
Expand Down Expand Up @@ -55,7 +52,6 @@ case class CompileInputs(
previousCompilerResult: Compiler.Result,
reporter: ZincReporter,
logger: ObservedLogger[Logger],
mode: CompileMode,
dependentResults: Map[File, PreviousResult],
cancelPromise: Promise[Unit],
tracer: BraveTracer,
Expand Down Expand Up @@ -300,7 +296,6 @@ object Compiler {
.withClasspath(classpath)
.withScalacOptions(optionsWithoutFatalWarnings)
.withJavacOptions(inputs.javacOptions)
.withClasspathOptions(inputs.classpathOptions)
.withOrder(inputs.compileOrder)
}

Expand Down Expand Up @@ -344,19 +339,12 @@ object Compiler {

import ch.epfl.scala.bsp
import scala.util.{Success, Failure}
val mode = compileInputs.mode
val reporter = compileInputs.reporter

def cancel(): Unit = {
// Complete all pending promises when compilation is cancelled
logger.debug(s"Cancelling compilation from ${readOnlyClassesDirPath} to ${newClassesDirPath}")
compileInputs.cancelPromise.trySuccess(())
mode match {
case _: Sequential => ()
case Pipelined(completeJava, finishedCompilation, _, _, _) =>
completeJava.trySuccess(())
finishedCompilation.tryFailure(CompileExceptions.FailedOrCancelledPromise)
}

// Always report the compilation of a project no matter if it's completed
reporter.reportCancelledCompilation()
Expand All @@ -379,7 +367,16 @@ object Compiler {
val uniqueInputs = compileInputs.uniqueInputs
reporter.reportStartCompilation(previousProblems)
BloopZincCompiler
.compile(inputs, mode, reporter, logger, uniqueInputs, newFileManager, cancelPromise, tracer)
.compile(
inputs,
reporter,
logger,
uniqueInputs,
newFileManager,
cancelPromise,
tracer,
classpathOptions
)
.materialize
.doOnCancel(Task(cancel()))
.map {
Expand Down Expand Up @@ -444,7 +441,6 @@ object Compiler {
}

val isNoOp = previousAnalysis.contains(analysis)
val definedMacroSymbols = mode.oracle.collectDefinedMacroSymbols
if (isNoOp) {
// If no-op, return previous result with updated classpath hashes
val noOpPreviousResult = {
Expand All @@ -460,8 +456,7 @@ object Compiler {
noOpPreviousResult,
noOpPreviousResult,
Set(),
Map.empty,
definedMacroSymbols
Map.empty
)

val backgroundTasks = new CompileBackgroundTasks {
Expand Down Expand Up @@ -578,8 +573,7 @@ object Compiler {
resultForDependentCompilationsInSameRun,
resultForFutureCompilationRuns,
allInvalidated.toSet,
allGeneratedProducts,
definedMacroSymbols
allGeneratedProducts
)

Result.Success(
Expand All @@ -599,7 +593,6 @@ object Compiler {
reporter.reportEndCompilation()

cause match {
case f: StopPipelining => Result.Blocked(f.failedProjectNames)
case f: xsbti.CompileFailed =>
// We cannot guarantee reporter.problems == f.problems, so we aggregate them together
val reportedProblems = reporter.allProblemsPerPhase.toList
Expand Down
56 changes: 4 additions & 52 deletions backend/src/main/scala/bloop/CompilerCache.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import sbt.internal.util.LoggerWriter
import java.io.IOException
import scala.concurrent.ExecutionContext
import xsbti.compile.ScalaCompiler
import xsbti.compile.ClasspathOptions

final class CompilerCache(
componentProvider: ComponentProvider,
Expand Down Expand Up @@ -159,49 +160,8 @@ final class CompilerCache(
logger.error("Missing classpath option for forked Java compiler")
false
} else {
import sbt.util.InterfaceUtil
InterfaceUtil.toOption(topts.classFileManager()) match {
case None => logger.error("Missing class file manager for forked Java compiler"); false
case Some(classFileManager) =>
import java.nio.file.Files
val newInvalidatedEntry = AbsolutePath(
Files.createTempDirectory("invalidated-forked-javac")
)

val invalidatedPaths =
classFileManager.invalidatedClassFiles().map(_.getAbsolutePath())
val classpathValueIndex = classpathIndex + 1
val classpathValue = options.apply(classpathValueIndex)
val classpathEntries = classpathValue.split(File.pathSeparatorChar)

invalidatedPaths.foreach { invalidatedPath =>
val relativePath = classpathEntries.collectFirst {
case classpathEntry if invalidatedPath.startsWith(classpathEntry) =>
invalidatedPath.stripPrefix(classpathEntry)
}

relativePath.foreach { relative =>
val relativeParts = relative.split(File.separatorChar)
val invalidatedClassFile = relativeParts.foldLeft(newInvalidatedEntry) {
case (path, relativePart) => path.resolve(relativePart)
}

val invalidatedClassFilePath = invalidatedClassFile.underlying
Files.createDirectories(invalidatedClassFilePath.getParent)
Files.write(invalidatedClassFilePath, "".getBytes())
}
}

val newClasspathValue = newInvalidatedEntry.toFile + File.pathSeparator + classpathValue
options(classpathValueIndex) = newClasspathValue

try {
import sbt.internal.inc.javac.BloopForkedJavaUtils
BloopForkedJavaUtils.launch(javaHome, "javac", sources, options, log, reporter)
} finally {
Paths.delete(newInvalidatedEntry)
}
}
import sbt.internal.inc.javac.BloopForkedJavaUtils
BloopForkedJavaUtils.launch(javaHome, "javac", sources, options, log, reporter)
}
}
}
Expand Down Expand Up @@ -306,15 +266,7 @@ final class CompilerCache(
kinds: ju.Set[Kind],
recurse: Boolean
): Iterable[JavaFileObject] = {
val invalidated = {
zincManager match {
case m: bloop.BloopClassFileManager => m.invalidatedClassFilesSet
case _ => zincManager.invalidatedClassFiles().toSet
}
}

val ls = super.list(location, packageName, kinds, recurse)
ls.asScala.filter(o => !invalidated.contains(new File(o.getName))).asJava
super.list(location, packageName, kinds, recurse)
}

// Needed because JavaFileManager doesn't expect WriteReportingJavaFileObjects in isSameFile, fixes #956
Expand Down
70 changes: 0 additions & 70 deletions backend/src/main/scala/bloop/CompilerOracle.scala

This file was deleted.

3 changes: 1 addition & 2 deletions backend/src/main/scala/bloop/PartialCompileProducts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ import bloop.io.AbsolutePath
*/
case class PartialCompileProducts(
readOnlyClassesDir: AbsolutePath,
newClassesDir: AbsolutePath,
definedMacroSymbols: Array[String]
newClassesDir: AbsolutePath
)
16 changes: 7 additions & 9 deletions backend/src/main/scala/bloop/ScalaInstance.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,15 @@ final class ScalaInstance private (
override val version: String,
override val allJars: Array[File]
) extends xsbti.compile.ScalaInstance {
override val compilerJar: File = {

override def libraryJars(): Array[File] = {
allJars
.find(f => isJar(f.getName) && hasScalaCompilerName(f.getName))
.getOrElse(
sys.error(s"Missing compiler jar in Scala jars ${allJars.mkString(", ")}")
)
.filter(f => isJar(f.getName) && hasScalaLibraryName(f.getName))
}

override val libraryJar: File = {
override val compilerJar: File = {
allJars
.find(f => isJar(f.getName) && hasScalaLibraryName(f.getName))
.find(f => isJar(f.getName) && hasScalaCompilerName(f.getName))
.getOrElse(
sys.error(s"Missing compiler jar in Scala jars ${allJars.mkString(", ")}")
)
Expand All @@ -47,10 +45,10 @@ final class ScalaInstance private (
(organization == "org.scala-lang" && version.startsWith("3."))

override lazy val loaderLibraryOnly: ClassLoader =
new URLClassLoader(Array(libraryJar.toURI.toURL), ScalaInstance.topClassLoader)
new URLClassLoader(libraryJars.map(_.toURI.toURL), ScalaInstance.topClassLoader)
override lazy val loader: ClassLoader = {
// For some exceptionally weird reason, we need to load all jars for dotty here
val jarsToLoad = if (isDotty) allJars else allJars.filterNot(_ == libraryJar)
val jarsToLoad = if (isDotty) allJars else allJars.filterNot(jar => libraryJars.contains(jar))
new URLClassLoader(jarsToLoad.map(_.toURI.toURL), loaderLibraryOnly)
}

Expand Down
60 changes: 0 additions & 60 deletions backend/src/main/scala/bloop/scalasig/PickleMarker.scala

This file was deleted.

Loading

0 comments on commit 7392f98

Please sign in to comment.