Skip to content

Commit 4ee44a3

Browse files
committed
Cleanup Toolbox
1 parent 50a0a40 commit 4ee44a3

File tree

3 files changed

+20
-33
lines changed

3 files changed

+20
-33
lines changed

library/src/scala/quoted/Toolbox.scala

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,30 @@ object Toolbox {
1616
implicit def make(implicit settings: Settings): Toolbox = Toolbox.make
1717
}
1818

19-
@forceInline def make4(implicit settings: Settings): Toolbox = {
19+
/** Create a new instance of the toolbox.
20+
*
21+
* 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.
23+
*
24+
* @param settings TODO
25+
* @return
26+
*/
27+
@forceInline def make(implicit settings: Settings): Toolbox = {
2028
// TODO find the name of the class that needs to be loaded. Maybe from a stack trace.
2129

2230
// We force inline to make forName use the classloader of the class at callsite
23-
val cl = Class.forName("hello.Main").getClassLoader
24-
make2(cl)
31+
val clazz = Class.forName("hello.Main")
32+
val cl = clazz.getClassLoader
33+
make(cl)
2534
}
2635

27-
def make2(cl: ClassLoader)(implicit settings: Settings): Toolbox = {
36+
/** Create a new instance of the toolbox
37+
*
38+
* @param cl TODO
39+
* @param settings TODO
40+
* @return A new instance of the toolbox
41+
*/
42+
def make(cl: ClassLoader)(implicit settings: Settings): Toolbox = {
2843
try {
2944
val toolboxImplCls = cl.loadClass("dotty.tools.dotc.quoted.ToolboxImpl")
3045
val makeMeth = toolboxImplCls.getMethod("make2", classOf[Settings], classOf[ClassLoader])
@@ -39,30 +54,6 @@ object Toolbox {
3954
}
4055
}
4156

42-
@inline
43-
def make3(implicit settings: Settings): Toolbox = {
44-
val cls = Class.forName("hello.Main")
45-
val cl = cls.getClassLoader()
46-
make2(cl)
47-
}
48-
49-
def make(implicit settings: Settings): Toolbox = {
50-
val cl = getClass.getClassLoader
51-
52-
try {
53-
val toolboxImplCls = cl.loadClass("dotty.tools.dotc.quoted.ToolboxImpl")
54-
val makeMeth = toolboxImplCls.getMethod("make", classOf[Settings])
55-
makeMeth.invoke(null, settings).asInstanceOf[Toolbox]
56-
}
57-
catch {
58-
case ex: ClassNotFoundException =>
59-
throw new ToolboxNotFoundException(
60-
s"""Could not load the Toolbox class `${ex.getMessage}` from the JVM classpath. Make sure that the compiler is on the JVM classpath.""",
61-
ex
62-
)
63-
}
64-
}
65-
6657
/** Setting of the Toolbox instance. */
6758
case class Settings private (outDir: Option[String], showRawTree: Boolean, compilerArgs: List[String], color: Boolean)
6859

sbt-dotty/sbt-test/sbt-dotty/quoted-example-project/src/main/scala/hello/Hello.scala

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ import scala.quoted._
55

66
object Main {
77

8-
// val cl = Class.forName("hello.Main").getClassLoader
9-
// implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make2(cl)
10-
11-
implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make4
8+
implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make
129

1310
def main(args: Array[String]): Unit = {
1411
val square = stagedPower(2)

sbt-dotty/src/dotty/tools/sbtplugin/DottyPlugin.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,6 @@ object DottyPlugin extends AutoPlugin {
393393
): ScalaInstance = {
394394
val loader = state.classLoaderCache(all.toList)
395395
val loaderLibraryOnly = state.classLoaderCache(List(dottyLibrary, scalaLibrary))
396-
397396
new ScalaInstance(
398397
dottyVersion,
399398
loader,

0 commit comments

Comments
 (0)