Skip to content

Commit

Permalink
Stop using Zinc's ClassLoaderCache as it seems to cause determinism p…
Browse files Browse the repository at this point in the history
…roblems

It's not totally certain whether the determinism issues come from the
intersection of our AnnexScalaInstance + the CloassLoaderCache or from
the ClassLoaderCache cache itself.
  • Loading branch information
James Judd committed Jul 7, 2024
1 parent 4656049 commit 8152a41
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import java.util.Properties

object AnnexScalaInstance {
// Check the comment on ScalaInstanceDualLoader to understand why this is necessary.
private val dualClassLoader: ScalaInstanceDualLoader = {
private def getDualClassLoader(): ScalaInstanceDualLoader = {
new ScalaInstanceDualLoader(
// Classloader for xsbti classes
getClass.getClassLoader,
Expand All @@ -24,7 +24,7 @@ object AnnexScalaInstance {
private def getClassLoader(jars: Array[File]): URLClassLoader = {
new URLClassLoader(
jars.map(_.toURI.toURL),
dualClassLoader,
getDualClassLoader(),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,6 @@ import xsbti.compile.{AnalysisContents, AnalysisStore, Changes, ClasspathOptions
//format: on
object ZincRunner extends WorkerMain[Namespace] {

private[this] val classloaderCache = new ClassLoaderCache(new URLClassLoader(Array()))

private[this] val compilerCache = CompilerCache.fresh

// prevents GC of the soft reference in classloaderCache
private[this] var lastCompiler: AnyRef = null

private[this] def labelToPath(label: String) = Paths.get(label.replaceAll("^/+", "").replaceAll(raw"[^\w/]", "_"))

Expand Down Expand Up @@ -196,10 +190,13 @@ object ZincRunner extends WorkerMain[Namespace] {
)

val compilers = {
val scalaCompiler = ZincUtil
.scalaCompiler(scalaInstance, namespace.get[File]("compiler_bridge"))
.withClassLoaderCache(classloaderCache)
lastCompiler = scalaCompiler
val scalaCompiler = new AnalyzingCompiler(
scalaInstance,
ZincUtil.constantBridgeProvider(scalaInstance, namespace.get[File]("compiler_bridge").toPath()),
ClasspathOptionsUtil.noboot(scalaInstance.version),
_ => (),
None
)
ZincUtil.compilers(scalaInstance, ClasspathOptionsUtil.boot, None, scalaCompiler)
}

Expand Down Expand Up @@ -243,7 +240,7 @@ object ZincRunner extends WorkerMain[Namespace] {
lookup,
skip,
file,
compilerCache,
CompilerCache.fresh,
incOptions,
reporter,
Optional.empty[CompileProgress](),
Expand Down

0 comments on commit 8152a41

Please sign in to comment.