Skip to content

Commit 89a87d3

Browse files
authored
Merge pull request #5921 from dotty-staging/fix/scalainstance-cache
Fix cache invalidation of compiler instance
2 parents 84d68d5 + 3138bde commit 89a87d3

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

project/Build.scala

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -227,28 +227,33 @@ object Build {
227227
// Compile using the non-bootstrapped and non-published dotty
228228
managedScalaInstance := false,
229229
scalaInstance := {
230-
// TODO: Here we use the output class directories directly, this might impact
231-
// performance when running the compiler (especially on Windows where file
232-
// IO is slow). We should benchmark whether using jars is actually faster
233-
// in practice (especially on our CI), this could be done using
234-
// `exportJars := true`.
235-
val all = fullClasspath.in(`dotty-doc`, Compile).value
236-
def getArtifact(name: String): File =
237-
all.find(_.get(artifact.key).exists(_.name == name))
238-
.getOrElse(throw new MessageOnlyException(s"Artifact for $name not found in $all"))
230+
val externalDeps = externalDependencyClasspath.in(`dotty-doc`, Compile).value
231+
def getExternalDep(name: String): File =
232+
externalDeps.find(_.get(artifact.key).exists(_.name == name))
233+
.getOrElse(throw new MessageOnlyException(s"Artifact for $name not found in $externalDeps"))
239234
.data
240235

241-
val scalaLibrary = getArtifact("scala-library")
242-
val dottyLibrary = getArtifact("dotty-library")
243-
val compiler = getArtifact("dotty-compiler")
236+
val scalaLibrary = getExternalDep("scala-library")
237+
238+
// IMPORTANT: We need to use actual jars to form the ScalaInstance and not
239+
// just directories containing classfiles because sbt maintains a cache of
240+
// compiler instances. This cache is invalidated based on timestamps
241+
// however this is only implemented on jars, directories are never
242+
// invalidated.
243+
val dottyLibrary = packageBin.in(`dotty-library`, Compile).value
244+
val dottyInterfaces = packageBin.in(`dotty-interfaces`, Compile).value
245+
val dottyCompiler = packageBin.in(`dotty-compiler`, Compile).value
246+
val dottyDoc = packageBin.in(`dotty-doc`, Compile).value
247+
248+
val allJars = Seq(dottyLibrary, dottyInterfaces, dottyCompiler, dottyDoc) ++ externalDeps.map(_.data)
244249

245250
makeScalaInstance(
246251
state.value,
247252
scalaVersion.value,
248253
scalaLibrary,
249254
dottyLibrary,
250-
compiler,
251-
all.map(_.data)
255+
dottyCompiler,
256+
allJars
252257
)
253258
}
254259
)

0 commit comments

Comments
 (0)