Skip to content

Commit fb73a43

Browse files
committed
Cleanup
1 parent f91731d commit fb73a43

File tree

6 files changed

+29
-36
lines changed

6 files changed

+29
-36
lines changed

compiler/src/dotty/tools/dotc/quoted/QuoteCompiler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class QuoteCompiler extends Compiler {
3737
new ExprRun(this, ctx.addMode(Mode.ReadPositions))
3838
}
3939

40-
def outputClassName: TypeName = "Quoted$Code".toTypeName
40+
def outputClassName: TypeName = "Generated$Code$From$Quoted".toTypeName
4141

4242
/** Frontend that receives a scala.quoted.Expr or scala.quoted.Type as input */
4343
class QuotedFrontend(putInClass: Boolean) extends Phase {

compiler/src/dotty/tools/dotc/quoted/QuoteDriver.scala

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ import scala.quoted.{Expr, Type}
1111
import scala.quoted.Toolbox
1212
import java.net.URLClassLoader
1313

14-
class QuoteDriver(cl: ClassLoader) extends Driver {
14+
/** Driver to compile quoted code
15+
*
16+
* @param appClassloader classloader of the application that generated the quotes
17+
*/
18+
class QuoteDriver(appClassloader: ClassLoader) extends Driver {
1519
import tpd._
1620

1721
private[this] val contextBase: ContextBase = new ContextBase
@@ -34,7 +38,7 @@ class QuoteDriver(cl: ClassLoader) extends Driver {
3438

3539
assert(!ctx.reporter.hasErrors)
3640

37-
val classLoader = new AbstractFileClassLoader(outDir, this.getClass.getClassLoader)
41+
val classLoader = new AbstractFileClassLoader(outDir, appClassloader)
3842

3943
val clazz = classLoader.loadClass(driver.outputClassName.toString)
4044
val method = clazz.getMethod("apply")
@@ -84,7 +88,7 @@ class QuoteDriver(cl: ClassLoader) extends Driver {
8488

8589
override def initCtx: Context = {
8690
val ictx = contextBase.initialCtx
87-
ictx.settings.classpath.update(QuoteDriver.currentClasspath(cl))(ictx)
91+
ictx.settings.classpath.update(QuoteDriver.currentClasspath(appClassloader))(ictx)
8892
ictx
8993
}
9094

compiler/src/dotty/tools/dotc/quoted/ToolboxImpl.scala

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,15 @@ import scala.quoted.Exprs.{LiftedExpr, TastyTreeExpr}
99
object ToolboxImpl {
1010
import tpd._
1111

12-
def make(settings: scala.quoted.Toolbox.Settings): scala.quoted.Toolbox = new scala.quoted.Toolbox {
13-
14-
private[this] val driver: QuoteDriver = new QuoteDriver(getClass.getClassLoader)
15-
16-
def run[T](expr: Expr[T]): T = expr match {
17-
case expr: LiftedExpr[T] =>
18-
expr.value
19-
case expr: TastyTreeExpr[Tree] @unchecked =>
20-
throw new Exception("Cannot call `Expr.run` on an `Expr` that comes from a macro argument.")
21-
case _ =>
22-
synchronized(driver.run(expr, settings))
23-
}
24-
25-
def show[T](expr: Expr[T]): String = synchronized(driver.show(expr, settings))
26-
27-
def show[T](tpe: Type[T]): String = synchronized(driver.show(tpe, settings))
28-
}
29-
30-
def make2(settings: scala.quoted.Toolbox.Settings, cl: ClassLoader): scala.quoted.Toolbox = new scala.quoted.Toolbox {
31-
32-
private[this] val driver: QuoteDriver = new QuoteDriver(cl)
12+
/** Create a new instance of the toolbox using the the classloader of the application.
13+
*
14+
* @param appClassloader classloader of the application that generated the quotes
15+
* @param settings toolbox settings
16+
* @return A new instance of the toolbox
17+
*/
18+
def make(settings: scala.quoted.Toolbox.Settings, appClassloader: ClassLoader): scala.quoted.Toolbox = new scala.quoted.Toolbox {
19+
20+
private[this] val driver: QuoteDriver = new QuoteDriver(appClassloader)
3321

3422
def run[T](expr: Expr[T]): T = expr match {
3523
case expr: LiftedExpr[T] =>

library/src/scala/quoted/Toolbox.scala

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ object Toolbox {
1919
/** Create a new instance of the toolbox.
2020
*
2121
* This instance of the toolbox tries to recover the classloader of the application based on
22-
* the classloader of the class that call make. This may not always be the correct classloader.
22+
* the classloader of the class that call make. This may not always be the correct classloader,
23+
* in which case the classloader must be passed explicitly.
2324
*
2425
* @param settings TODO
25-
* @return
26+
* @return A new instance of the toolbox
2627
*/
2728
@forceInline def make(implicit settings: Settings): Toolbox = {
2829
// Get the name of the class at call site
@@ -33,17 +34,17 @@ object Toolbox {
3334
make(cl)
3435
}
3536

36-
/** Create a new instance of the toolbox
37+
/** Create a new instance of the toolbox using the the classloader of the application.
3738
*
38-
* @param cl TODO
39-
* @param settings TODO
39+
* @param appClassloader classloader of the application that generated the quotes
40+
* @param settings toolbox settings
4041
* @return A new instance of the toolbox
4142
*/
42-
def make(cl: ClassLoader)(implicit settings: Settings): Toolbox = {
43+
def make(appClassloader: ClassLoader)(implicit settings: Settings): Toolbox = {
4344
try {
44-
val toolboxImplCls = cl.loadClass("dotty.tools.dotc.quoted.ToolboxImpl")
45-
val makeMeth = toolboxImplCls.getMethod("make2", classOf[Settings], classOf[ClassLoader])
46-
makeMeth.invoke(null, settings, cl).asInstanceOf[Toolbox]
45+
val toolboxImplCls = appClassloader.loadClass("dotty.tools.dotc.quoted.ToolboxImpl")
46+
val makeMeth = toolboxImplCls.getMethod("make", classOf[Settings], classOf[ClassLoader])
47+
makeMeth.invoke(null, settings, appClassloader).asInstanceOf[Toolbox]
4748
}
4849
catch {
4950
case ex: ClassNotFoundException =>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
Foo
22
false
33
Bar
4-
class Quoted$A$1
4+
class Generated$Code$From$Quoted$A$1

tests/run-with-compiler/quote-run-with-settings.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ object Test {
1919
println()
2020

2121
val outDir = Paths.get("out/out-quoted-1")
22-
val classFile = outDir.resolve("Quoted.class")
22+
val classFile = outDir.resolve("Generated$Code$From$Quoted.class")
2323

2424
Files.deleteIfExists(classFile)
2525

0 commit comments

Comments
 (0)