File tree 3 files changed +16
-8
lines changed
3 files changed +16
-8
lines changed Original file line number Diff line number Diff line change @@ -60,10 +60,14 @@ trait MacroRuntimes extends JavaReflectionRuntimes {
60
60
* a classloader mapped to that virtual directory.
61
61
*/
62
62
private lazy val defaultMacroClassloaderCache = {
63
- def attemptClose (loader : ClassLoader ): Unit = loader match {
64
- case u : URLClassLoader => debuglog(" Closing macro runtime classloader" ); u.close()
65
- case afcl : AbstractFileClassLoader => attemptClose(afcl.getParent)
66
- case _ => ???
63
+ def attemptClose (loader : ClassLoader ): Unit = {
64
+ if (! scala.tools.nsc.typechecker.Macros .macroClassLoadersCache.owns(loader)) {
65
+ loader match {
66
+ case u : URLClassLoader => debuglog(" Closing macro runtime classloader" ); u.close()
67
+ case afcl : AbstractFileClassLoader => attemptClose(afcl.getParent)
68
+ case _ => ???
69
+ }
70
+ }
67
71
}
68
72
perRunCaches.newGeneric(findMacroClassLoader, attemptClose _)
69
73
}
Original file line number Diff line number Diff line change @@ -190,6 +190,7 @@ final class FileBasedCache[T] {
190
190
import java .nio .file .Path
191
191
private case class Stamp (lastModified : FileTime , fileKey : Object )
192
192
private val cache = collection.mutable.Map .empty[Seq [Path ], (Seq [Stamp ], T )]
193
+ def owns (t : T ): Boolean = cache.valuesIterator.exists(_._2.asInstanceOf [AnyRef ] eq t.asInstanceOf [AnyRef ])
193
194
194
195
def getOrCreate (paths : Seq [Path ], create : () => T ): T = cache.synchronized {
195
196
val stamps = paths.map { path =>
Original file line number Diff line number Diff line change @@ -67,9 +67,6 @@ trait Macros extends MacroRuntimes with Traces with Helpers {
67
67
68
68
def globalSettings = global.settings
69
69
70
- private final val macroClassLoadersCache =
71
- new scala.tools.nsc.classpath.FileBasedCache [ScalaClassLoader ]()
72
-
73
70
/** Obtains a `ClassLoader` instance used for macro expansion.
74
71
*
75
72
* By default a new `ScalaClassLoader` is created using the classpath
@@ -109,7 +106,7 @@ trait Macros extends MacroRuntimes with Traces with Helpers {
109
106
macroLogVerbose(s " macro classloader: caching is disabled because the following paths are not supported: ${nonJarZips.mkString(" ," )}. " )
110
107
newLoader()
111
108
} else {
112
- macroClassLoadersCache.getOrCreate(locations.map(_.jfile.toPath()), newLoader)
109
+ Macros . macroClassLoadersCache.getOrCreate(locations.map(_.jfile.toPath()), newLoader)
113
110
}
114
111
}
115
112
}
@@ -944,6 +941,12 @@ trait Macros extends MacroRuntimes with Traces with Helpers {
944
941
}.transform(expandee)
945
942
}
946
943
944
+ object Macros {
945
+ final val macroClassLoadersCache =
946
+ new scala.tools.nsc.classpath.FileBasedCache [ScalaClassLoader ]()
947
+
948
+ }
949
+
947
950
trait MacrosStats {
948
951
self : TypesStats with Statistics =>
949
952
val macroExpandCount = newCounter (" #macro expansions" , " typer" )
You can’t perform that action at this time.
0 commit comments