Skip to content

Fix cache invalidation of compiler instance #5921

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

Merged
merged 1 commit into from
Feb 14, 2019
Merged
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
33 changes: 19 additions & 14 deletions project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -227,28 +227,33 @@ object Build {
// Compile using the non-bootstrapped and non-published dotty
managedScalaInstance := false,
scalaInstance := {
// TODO: Here we use the output class directories directly, this might impact
// performance when running the compiler (especially on Windows where file
// IO is slow). We should benchmark whether using jars is actually faster
// in practice (especially on our CI), this could be done using
// `exportJars := true`.
val all = fullClasspath.in(`dotty-doc`, Compile).value
def getArtifact(name: String): File =
all.find(_.get(artifact.key).exists(_.name == name))
.getOrElse(throw new MessageOnlyException(s"Artifact for $name not found in $all"))
val externalDeps = externalDependencyClasspath.in(`dotty-doc`, Compile).value
def getExternalDep(name: String): File =
externalDeps.find(_.get(artifact.key).exists(_.name == name))
.getOrElse(throw new MessageOnlyException(s"Artifact for $name not found in $externalDeps"))
.data

val scalaLibrary = getArtifact("scala-library")
val dottyLibrary = getArtifact("dotty-library")
val compiler = getArtifact("dotty-compiler")
val scalaLibrary = getExternalDep("scala-library")

// IMPORTANT: We need to use actual jars to form the ScalaInstance and not
// just directories containing classfiles because sbt maintains a cache of
// compiler instances. This cache is invalidated based on timestamps
// however this is only implemented on jars, directories are never
// invalidated.
val dottyLibrary = packageBin.in(`dotty-library`, Compile).value
val dottyInterfaces = packageBin.in(`dotty-interfaces`, Compile).value
val dottyCompiler = packageBin.in(`dotty-compiler`, Compile).value
val dottyDoc = packageBin.in(`dotty-doc`, Compile).value

val allJars = Seq(dottyLibrary, dottyInterfaces, dottyCompiler, dottyDoc) ++ externalDeps.map(_.data)

makeScalaInstance(
state.value,
scalaVersion.value,
scalaLibrary,
dottyLibrary,
compiler,
all.map(_.data)
dottyCompiler,
allJars
)
}
)
Expand Down