Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 3 additions & 1 deletion compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ import dotty.tools.dotc.core.quoted._
class ReifyQuotes extends MacroTransformWithImplicits with InfoTransformer {
import ast.tpd._

private lazy val splicer: Splicer = new Splicer

override def phaseName: String = "reifyQuotes"

override def run(implicit ctx: Context): Unit =
Expand Down Expand Up @@ -542,7 +544,7 @@ class ReifyQuotes extends MacroTransformWithImplicits with InfoTransformer {
// Simplification of the call done in PostTyper for non-macros can also be performed now
// see PostTyper `case Inlined(...) =>` for description of the simplification
val call2 = Ident(call.symbol.topLevelClass.typeRef).withPos(call.pos)
val spliced = Splicer.splice(body, call, bindings, tree.pos).withPos(tree.pos)
val spliced = splicer.splice(body, call, bindings, tree.pos).withPos(tree.pos)
transform(cpy.Inlined(tree)(call2, bindings, spliced))
}
else super.transform(tree)
Expand Down
8 changes: 5 additions & 3 deletions compiler/src/dotty/tools/dotc/transform/Splicer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ import dotty.tools.dotc.util.Positions.Position
import scala.reflect.ClassTag

/** Utility class to splice quoted expressions */
object Splicer {
class Splicer {
Copy link
Member

@smarter smarter Apr 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's weird to make the whole thing a class if the only bit of state is the classloader cache used in a single method, the cache could be passed as an argument instead

import tpd._

private var classLoader: URLClassLoader = _

/** Splice the Tree for a Quoted expression. `~'(xyz)` becomes `xyz`
* and for `~xyz` the tree of `xyz` is interpreted for which the
* resulting expression is returned as a `Tree`
Expand Down Expand Up @@ -100,9 +102,9 @@ object Splicer {
*/
private class Interpreter(pos: Position)(implicit ctx: Context) {

private[this] val classLoader = {
if (classLoader == null) {
val urls = ctx.settings.classpath.value.split(':').map(cp => java.nio.file.Paths.get(cp).toUri.toURL)
new URLClassLoader(urls, getClass.getClassLoader)
classLoader = new URLClassLoader(urls, getClass.getClassLoader)
}

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