Skip to content

Commit 04c18a5

Browse files
committed
Make splicer only valid for this run
1 parent d985903 commit 04c18a5

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ import dotty.tools.dotc.core.quoted._
8888
class ReifyQuotes extends MacroTransformWithImplicits with InfoTransformer {
8989
import ast.tpd._
9090

91+
private lazy val splicer: Splicer = new Splicer
92+
9193
override def phaseName: String = "reifyQuotes"
9294

9395
override def run(implicit ctx: Context): Unit =
@@ -542,7 +544,7 @@ class ReifyQuotes extends MacroTransformWithImplicits with InfoTransformer {
542544
// Simplification of the call done in PostTyper for non-macros can also be performed now
543545
// see PostTyper `case Inlined(...) =>` for description of the simplification
544546
val call2 = Ident(call.symbol.topLevelClass.typeRef).withPos(call.pos)
545-
val spliced = Splicer.splice(body, call, bindings, tree.pos).withPos(tree.pos)
547+
val spliced = splicer.splice(body, call, bindings, tree.pos).withPos(tree.pos)
546548
transform(cpy.Inlined(tree)(call2, bindings, spliced))
547549
}
548550
else super.transform(tree)

compiler/src/dotty/tools/dotc/transform/Splicer.scala

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ import dotty.tools.dotc.util.Positions.Position
2121
import scala.reflect.ClassTag
2222

2323
/** Utility class to splice quoted expressions */
24-
object Splicer {
24+
class Splicer {
2525
import tpd._
2626

27+
private var classLoader: URLClassLoader = _
28+
2729
/** Splice the Tree for a Quoted expression. `~'(xyz)` becomes `xyz`
2830
* and for `~xyz` the tree of `xyz` is interpreted for which the
2931
* resulting expression is returned as a `Tree`
@@ -93,22 +95,16 @@ object Splicer {
9395
}
9496
}
9597

96-
private val classLoaders = scala.collection.mutable.HashMap.empty[String, URLClassLoader]
97-
9898
/** Tree interpreter that can interpret calls to static methods with it's default arguments
9999
*
100100
* The interpreter assumes that all calls in the trees are to code that was
101101
* previously compiled and is present in the classpath of the current context.
102102
*/
103103
private class Interpreter(pos: Position)(implicit ctx: Context) {
104104

105-
private[this] val classLoader = {
106-
val cp = ctx.settings.classpath.value
107-
def newClassLoader = {
108-
val urls = cp.split(':').map(cp => java.nio.file.Paths.get(cp).toUri.toURL)
109-
new URLClassLoader(urls, getClass.getClassLoader)
110-
}
111-
classLoaders.getOrElseUpdate(cp, newClassLoader)
105+
if (classLoader == null) {
106+
val urls = ctx.settings.classpath.value.split(':').map(cp => java.nio.file.Paths.get(cp).toUri.toURL)
107+
classLoader = new URLClassLoader(urls, getClass.getClassLoader)
112108
}
113109

114110
/** Returns the interpreted result of interpreting the code a call to the symbol with default arguments.

0 commit comments

Comments
 (0)