diff --git a/compiler/src/dotty/tools/dotc/quoted/QuoteDriver.scala b/compiler/src/dotty/tools/dotc/quoted/QuoteDriver.scala index 65090bb5e5bc..4c4ff5193730 100644 --- a/compiler/src/dotty/tools/dotc/quoted/QuoteDriver.scala +++ b/compiler/src/dotty/tools/dotc/quoted/QuoteDriver.scala @@ -2,20 +2,21 @@ package dotty.tools.dotc.quoted import dotty.tools.dotc.ast.tpd import dotty.tools.dotc.Driver -import dotty.tools.dotc.core.Contexts.Context +import dotty.tools.dotc.core.Contexts.{Context, ContextBase} import dotty.tools.io.{AbstractFile, Directory, PlainDirectory, VirtualDirectory} import dotty.tools.repl.AbstractFileClassLoader import scala.quoted.{Expr, Type} import java.net.URLClassLoader -import Toolbox.{Run, Settings, Show} import dotty.tools.dotc.tastyreflect.TastyImpl class QuoteDriver extends Driver { import tpd._ - def run[T](expr: Expr[T], settings: Settings[Run]): T = { + private[this] val contextBase: ContextBase = new ContextBase + + def run[T](expr: Expr[T], settings: ToolboxSettings): T = { val (_, ctx: Context) = setup(settings.compilerArgs.toArray :+ "dummy.scala", initCtx.fresh) val outDir: AbstractFile = settings.outDir match { @@ -39,7 +40,7 @@ class QuoteDriver extends Driver { method.invoke(instance).asInstanceOf[T] } - def show(expr: Expr[_], settings: Settings[Show]): String = { + def show(expr: Expr[_], settings: ToolboxSettings): String = { def show(tree: Tree, ctx: Context): String = { val tree1 = if (settings.rawTree) tree else (new TreeCleaner).transform(tree)(ctx) TastyImpl.showSourceCode.showTree(tree1)(ctx) @@ -47,7 +48,7 @@ class QuoteDriver extends Driver { withTree(expr, show, settings) } - def withTree[T](expr: Expr[_], f: (Tree, Context) => T, settings: Settings[_]): T = { + def withTree[T](expr: Expr[_], f: (Tree, Context) => T, settings: ToolboxSettings): T = { val (_, ctx: Context) = setup(settings.compilerArgs.toArray :+ "dummy.scala", initCtx.fresh) var output: Option[T] = None @@ -59,7 +60,7 @@ class QuoteDriver extends Driver { output.getOrElse(throw new Exception("Could not extract " + expr)) } - def withTypeTree[T](tpe: Type[_], f: (TypTree, Context) => T, settings: Settings[_]): T = { + def withTypeTree[T](tpe: Type[_], f: (TypTree, Context) => T, settings: ToolboxSettings): T = { val (_, ctx: Context) = setup(settings.compilerArgs.toArray :+ "dummy.scala", initCtx.fresh) var output: Option[T] = None @@ -72,7 +73,7 @@ class QuoteDriver extends Driver { } override def initCtx: Context = { - val ictx = super.initCtx.fresh + val ictx = contextBase.initialCtx var classpath = System.getProperty("java.class.path") this.getClass.getClassLoader match { case cl: URLClassLoader => diff --git a/compiler/src/dotty/tools/dotc/quoted/Toolbox.scala b/compiler/src/dotty/tools/dotc/quoted/Toolbox.scala index 1d369ed19057..fa18a4843331 100644 --- a/compiler/src/dotty/tools/dotc/quoted/Toolbox.scala +++ b/compiler/src/dotty/tools/dotc/quoted/Toolbox.scala @@ -4,67 +4,25 @@ import dotty.tools.dotc.ast.tpd import scala.quoted.Expr import scala.quoted.Exprs.{LiftedExpr, TastyTreeExpr} -import scala.runtime.quoted._ /** Default runners for quoted expressions */ object Toolbox { import tpd._ - type Run - type Show + implicit def make(implicit settings: ToolboxSettings): scala.quoted.Toolbox = new scala.quoted.Toolbox { - implicit def toolbox[T](implicit - runSettings: Settings[Run] = Settings.run(), - showSettings: Settings[Show] = Settings.show() - ): Toolbox[T] = new Toolbox[T] { + private[this] val driver: QuoteDriver = new QuoteDriver() - def run(expr: Expr[T]): T = expr match { + def run[T](expr: Expr[T]): T = expr match { case expr: LiftedExpr[T] => expr.value case expr: TastyTreeExpr[Tree] @unchecked => throw new Exception("Cannot call `Expr.run` on an `Expr` that comes from an inline macro argument.") case _ => - new QuoteDriver().run(expr, runSettings) + driver.run(expr, settings) } - def show(expr: Expr[T]): String = new QuoteDriver().show(expr, showSettings) + def show[T](expr: Expr[T]): String = driver.show(expr, settings) } - - class Settings[T] private (val outDir: Option[String], val rawTree: Boolean, val compilerArgs: List[String]) - - object Settings { - - /** Quote run settings - * @param optimise Enable optimisation when compiling the quoted code - * @param outDir Output directory for the compiled quote. If set to None the output will be in memory - * @param compilerArgs Compiler arguments. Use only if you know what you are doing. - */ - def run( - optimise: Boolean = false, - outDir: Option[String] = None, - compilerArgs: List[String] = Nil - ): Settings[Run] = { - var compilerArgs1 = compilerArgs - if (optimise) compilerArgs1 = "-optimise" :: compilerArgs1 - new Settings(outDir, false, compilerArgs1) - } - - /** Quote show settings - * @param color Print output with colors - * @param rawTree Do not remove quote tree artifacts - * @param compilerArgs Compiler arguments. Use only if you know what you are doing. - */ - def show( - color: Boolean = false, - rawTree: Boolean = false, - compilerArgs: List[String] = Nil - ): Settings[Show] = { - var compilerArgs1 = compilerArgs - compilerArgs1 = s"-color:${if (color) "always" else "never"}" :: compilerArgs1 - new Settings(None, rawTree, compilerArgs1) - } - - } - } diff --git a/compiler/src/dotty/tools/dotc/quoted/ToolboxSettings.scala b/compiler/src/dotty/tools/dotc/quoted/ToolboxSettings.scala new file mode 100644 index 000000000000..98027f4c694e --- /dev/null +++ b/compiler/src/dotty/tools/dotc/quoted/ToolboxSettings.scala @@ -0,0 +1,28 @@ +package dotty.tools.dotc.quoted + +class ToolboxSettings private (val outDir: Option[String], val rawTree: Boolean, val compilerArgs: List[String]) + +object ToolboxSettings { + + implicit def default: ToolboxSettings = make() + + /** Make toolbox settings + * @param optimise Enable optimisation when compiling the quoted code + * @param outDir Output directory for the compiled quote. If set to None the output will be in memory + * @param color Print output with colors + * @param rawTree Do not remove quote tree artifacts + * @param compilerArgs Compiler arguments. Use only if you know what you are doing. + */ + def make( + optimise: Boolean = false, + color: Boolean = false, + rawTree: Boolean = false, + outDir: Option[String] = None, + compilerArgs: List[String] = Nil + ): ToolboxSettings = { + var compilerArgs1 = compilerArgs + if (optimise) compilerArgs1 = "-optimise" :: compilerArgs1 + new ToolboxSettings(outDir, rawTree, compilerArgs1) + } + +} diff --git a/library/src/scala/quoted/Expr.scala b/library/src/scala/quoted/Expr.scala index f6fe2d478389..4c87ca4a5b7f 100644 --- a/library/src/scala/quoted/Expr.scala +++ b/library/src/scala/quoted/Expr.scala @@ -1,6 +1,5 @@ package scala.quoted -import scala.runtime.quoted.Toolbox import scala.runtime.quoted.Unpickler.Pickled sealed abstract class Expr[T] { @@ -10,10 +9,10 @@ sealed abstract class Expr[T] { * * May throw a FreeVariableError on expressions that came from an inline macro. */ - final def run(implicit toolbox: Toolbox[T]): T = toolbox.run(this) + final def run(implicit toolbox: Toolbox): T = toolbox.run(this) /** Show a source code like representation of this expression */ - final def show(implicit toolbox: Toolbox[T]): String = toolbox.show(this) + final def show(implicit toolbox: Toolbox): String = toolbox.show(this) } object Expr { diff --git a/library/src/scala/quoted/Toolbox.scala b/library/src/scala/quoted/Toolbox.scala new file mode 100644 index 000000000000..066eabd14c74 --- /dev/null +++ b/library/src/scala/quoted/Toolbox.scala @@ -0,0 +1,9 @@ +package scala.quoted + +import scala.annotation.implicitNotFound + +@implicitNotFound("Could not find implicit quoted.Toolbox.\n\nDefault toolbox can be instantiated with:\n `implicit val toolbox: scala.quoted.Toolbox = dotty.tools.dotc.quoted.Toolbox.make`\n\nIf only needed once it can also be imported with:\n `import dotty.tools.dotc.quoted.Toolbox._`") +trait Toolbox { + def run[T](expr: Expr[T]): T + def show[T](expr: Expr[T]): String +} diff --git a/library/src/scala/runtime/quoted/Toolbox.scala b/library/src/scala/runtime/quoted/Toolbox.scala deleted file mode 100644 index d7982d09da13..000000000000 --- a/library/src/scala/runtime/quoted/Toolbox.scala +++ /dev/null @@ -1,10 +0,0 @@ -package scala.runtime.quoted - -import scala.annotation.implicitNotFound -import scala.quoted.Expr - -@implicitNotFound("Could not find implicit quoted.Toolbox. Default toolbox can be imported with `import dotty.tools.dotc.quoted.Toolbox._`") -trait Toolbox[T] { - def run(expr: Expr[T]): T - def show(expr: Expr[T]): String -} diff --git a/tests/run-with-compiler-custom-args/staged-streams_1.check b/tests/run-with-compiler-custom-args/staged-streams_1.check index 3b74b7e538ac..82ff46515903 100644 --- a/tests/run-with-compiler-custom-args/staged-streams_1.check +++ b/tests/run-with-compiler-custom-args/staged-streams_1.check @@ -2,3 +2,18 @@ 12 +36 + +2 + +3 + +7 + +12 + +15 + +15 + +72 \ No newline at end of file diff --git a/tests/run-with-compiler-custom-args/staged-streams_1.scala b/tests/run-with-compiler-custom-args/staged-streams_1.scala index 9cb319cf8940..ef2f2a6b86ee 100644 --- a/tests/run-with-compiler-custom-args/staged-streams_1.scala +++ b/tests/run-with-compiler-custom-args/staged-streams_1.scala @@ -1,4 +1,3 @@ -import dotty.tools.dotc.quoted.Toolbox._ import scala.quoted._ /** @@ -674,26 +673,27 @@ object Test { .fold('{0}, ((a: Expr[Int], b : Expr[Int]) => '{ ~a + ~b })) def main(args: Array[String]): Unit = { + implicit val toolbox: scala.quoted.Toolbox = dotty.tools.dotc.quoted.Toolbox.make + println(test1().run) println println(test2().run) println - // FIXME re-enable in #4643 when we can cache the compiler context -// println(test3().run) -// println -// println(test4().run) -// println -// println(test5().run) -// println -// println(test6().run) -// println -// println(test7().run) -// println -// println(test8().run) -// println -// println(test9().run) -// println -// println(test10().run) + println(test3().run) + println + println(test4().run) + println + println(test5().run) + println + println(test6().run) + println + println(test7().run) + println + println(test8().run) + println + println(test9().run) + println + println(test10().run) } } diff --git a/tests/run-with-compiler/i3876-b.scala b/tests/run-with-compiler/i3876-b.scala index 3385ec217997..876eaa7a226c 100644 --- a/tests/run-with-compiler/i3876-b.scala +++ b/tests/run-with-compiler/i3876-b.scala @@ -2,6 +2,8 @@ import dotty.tools.dotc.quoted.Toolbox._ import scala.quoted._ object Test { def main(args: Array[String]): Unit = { + implicit val toolbox: scala.quoted.Toolbox = dotty.tools.dotc.quoted.Toolbox.make + val x: Expr[Int] = '(3) val f2: Expr[Int => Int] = '{ diff --git a/tests/run-with-compiler/i3876-c.scala b/tests/run-with-compiler/i3876-c.scala index 4bdbaa1f67a7..3ba15e3a6afc 100644 --- a/tests/run-with-compiler/i3876-c.scala +++ b/tests/run-with-compiler/i3876-c.scala @@ -2,6 +2,8 @@ import dotty.tools.dotc.quoted.Toolbox._ import scala.quoted._ object Test { def main(args: Array[String]): Unit = { + implicit val toolbox: scala.quoted.Toolbox = dotty.tools.dotc.quoted.Toolbox.make + val x: Expr[Int] = '(3) val f3: Expr[Int => Int] = '{ diff --git a/tests/run-with-compiler/i3876-d.scala b/tests/run-with-compiler/i3876-d.scala index bd346b86a5ec..3f11547d4522 100644 --- a/tests/run-with-compiler/i3876-d.scala +++ b/tests/run-with-compiler/i3876-d.scala @@ -2,6 +2,8 @@ import dotty.tools.dotc.quoted.Toolbox._ import scala.quoted._ object Test { def main(args: Array[String]): Unit = { + implicit val toolbox: scala.quoted.Toolbox = dotty.tools.dotc.quoted.Toolbox.make + val x: Expr[Int] = '(3) val f4: Expr[Int => Int] = '{ diff --git a/tests/run-with-compiler/i3876.scala b/tests/run-with-compiler/i3876.scala index dbce45bd42d0..13b951da2d07 100644 --- a/tests/run-with-compiler/i3876.scala +++ b/tests/run-with-compiler/i3876.scala @@ -2,6 +2,8 @@ import dotty.tools.dotc.quoted.Toolbox._ import scala.quoted._ object Test { def main(args: Array[String]): Unit = { + implicit val toolbox: scala.quoted.Toolbox = dotty.tools.dotc.quoted.Toolbox.make + val x: Expr[Int] = '(3) val f: Expr[Int => Int] = '{ (x: Int) => x + x } diff --git a/tests/run-with-compiler/i3946.scala b/tests/run-with-compiler/i3946.scala index 4aed7255379c..60fd96a9ee11 100644 --- a/tests/run-with-compiler/i3946.scala +++ b/tests/run-with-compiler/i3946.scala @@ -2,6 +2,8 @@ import dotty.tools.dotc.quoted.Toolbox._ import scala.quoted._ object Test { def main(args: Array[String]): Unit = { + implicit val toolbox: scala.quoted.Toolbox = dotty.tools.dotc.quoted.Toolbox.make + val u: Expr[Unit] = '() println(u.show) println(u.run) diff --git a/tests/run-with-compiler/i3947.scala b/tests/run-with-compiler/i3947.scala index cb387260e232..513525e383f0 100644 --- a/tests/run-with-compiler/i3947.scala +++ b/tests/run-with-compiler/i3947.scala @@ -5,6 +5,7 @@ import dotty.tools.dotc.quoted.Toolbox._ object Test { def main(args: Array[String]): Unit = { + implicit val toolbox: scala.quoted.Toolbox = dotty.tools.dotc.quoted.Toolbox.make def test[T](clazz: java.lang.Class[T]): Unit = { val lclazz = clazz.toExpr diff --git a/tests/run-with-compiler/i3947b.scala b/tests/run-with-compiler/i3947b.scala index 365dd7e0085d..3b4ef0cf70a1 100644 --- a/tests/run-with-compiler/i3947b.scala +++ b/tests/run-with-compiler/i3947b.scala @@ -5,6 +5,7 @@ import dotty.tools.dotc.quoted.Toolbox._ object Test { def main(args: Array[String]): Unit = { + implicit val toolbox: scala.quoted.Toolbox = dotty.tools.dotc.quoted.Toolbox.make def test[T](clazz: java.lang.Class[T]): Unit = { val lclazz = clazz.toExpr diff --git a/tests/run-with-compiler/i3947b2.scala b/tests/run-with-compiler/i3947b2.scala index 0e536e0a224e..0f138899fabd 100644 --- a/tests/run-with-compiler/i3947b2.scala +++ b/tests/run-with-compiler/i3947b2.scala @@ -5,6 +5,7 @@ import dotty.tools.dotc.quoted.Toolbox._ object Test { def main(args: Array[String]): Unit = { + implicit val toolbox: scala.quoted.Toolbox = dotty.tools.dotc.quoted.Toolbox.make def test[T](clazz: java.lang.Class[T]): Unit = { val lclazz = clazz.toExpr diff --git a/tests/run-with-compiler/i3947b3.scala b/tests/run-with-compiler/i3947b3.scala index a701166caaa9..052dfa883cc7 100644 --- a/tests/run-with-compiler/i3947b3.scala +++ b/tests/run-with-compiler/i3947b3.scala @@ -5,6 +5,7 @@ import dotty.tools.dotc.quoted.Toolbox._ object Test { def main(args: Array[String]): Unit = { + implicit val toolbox: scala.quoted.Toolbox = dotty.tools.dotc.quoted.Toolbox.make def test[T](clazz: java.lang.Class[T]): Unit = { val lclazz = clazz.toExpr diff --git a/tests/run-with-compiler/i3947c.scala b/tests/run-with-compiler/i3947c.scala index 0f770bea54be..b63d954b969c 100644 --- a/tests/run-with-compiler/i3947c.scala +++ b/tests/run-with-compiler/i3947c.scala @@ -5,6 +5,7 @@ import dotty.tools.dotc.quoted.Toolbox._ object Test { def main(args: Array[String]): Unit = { + implicit val toolbox: scala.quoted.Toolbox = dotty.tools.dotc.quoted.Toolbox.make def test[T](clazz: java.lang.Class[T]): Unit = { val lclazz = clazz.toExpr diff --git a/tests/run-with-compiler/i3947d.scala b/tests/run-with-compiler/i3947d.scala index 63977a8f6543..affcdb6c003d 100644 --- a/tests/run-with-compiler/i3947d.scala +++ b/tests/run-with-compiler/i3947d.scala @@ -5,6 +5,7 @@ import dotty.tools.dotc.quoted.Toolbox._ object Test { def main(args: Array[String]): Unit = { + implicit val toolbox: scala.quoted.Toolbox = dotty.tools.dotc.quoted.Toolbox.make def test[T](clazz: java.lang.Class[T]): Unit = { val lclazz = clazz.toExpr diff --git a/tests/run-with-compiler/i3947d2.scala b/tests/run-with-compiler/i3947d2.scala index 3c4ea585b4e7..59c9c742e918 100644 --- a/tests/run-with-compiler/i3947d2.scala +++ b/tests/run-with-compiler/i3947d2.scala @@ -5,6 +5,7 @@ import dotty.tools.dotc.quoted.Toolbox._ object Test { def main(args: Array[String]): Unit = { + implicit val toolbox: scala.quoted.Toolbox = dotty.tools.dotc.quoted.Toolbox.make def test[T](clazz: java.lang.Class[T]): Unit = { val lclazz = clazz.toExpr diff --git a/tests/run-with-compiler/i3947e.scala b/tests/run-with-compiler/i3947e.scala index 08b0548e059e..7cc8c1785d32 100644 --- a/tests/run-with-compiler/i3947e.scala +++ b/tests/run-with-compiler/i3947e.scala @@ -5,6 +5,7 @@ import dotty.tools.dotc.quoted.Toolbox._ object Test { def main(args: Array[String]): Unit = { + implicit val toolbox: scala.quoted.Toolbox = dotty.tools.dotc.quoted.Toolbox.make def test[T](clazz: java.lang.Class[T]): Unit = { val lclazz = clazz.toExpr diff --git a/tests/run-with-compiler/i3947f.scala b/tests/run-with-compiler/i3947f.scala index 1f968f3936a8..35c945685210 100644 --- a/tests/run-with-compiler/i3947f.scala +++ b/tests/run-with-compiler/i3947f.scala @@ -5,6 +5,7 @@ import dotty.tools.dotc.quoted.Toolbox._ object Test { def main(args: Array[String]): Unit = { + implicit val toolbox: scala.quoted.Toolbox = dotty.tools.dotc.quoted.Toolbox.make def test[T](clazz: java.lang.Class[T]): Unit = { val lclazz = clazz.toExpr diff --git a/tests/run-with-compiler/i3947g.scala b/tests/run-with-compiler/i3947g.scala index a49e8986b115..8dad3bf4cbae 100644 --- a/tests/run-with-compiler/i3947g.scala +++ b/tests/run-with-compiler/i3947g.scala @@ -5,6 +5,7 @@ import dotty.tools.dotc.quoted.Toolbox._ object Test { def main(args: Array[String]): Unit = { + implicit val toolbox: scala.quoted.Toolbox = dotty.tools.dotc.quoted.Toolbox.make def test[T](clazz: java.lang.Class[T]): Unit = { val lclazz = clazz.toExpr diff --git a/tests/run-with-compiler/i3947i.scala b/tests/run-with-compiler/i3947i.scala index a3bc862ab4b0..df7091ca1559 100644 --- a/tests/run-with-compiler/i3947i.scala +++ b/tests/run-with-compiler/i3947i.scala @@ -5,6 +5,7 @@ import dotty.tools.dotc.quoted.Toolbox._ object Test { def main(args: Array[String]): Unit = { + implicit val toolbox: scala.quoted.Toolbox = dotty.tools.dotc.quoted.Toolbox.make def test[T](clazz: java.lang.Class[T]): Unit = { val lclazz = clazz.toExpr diff --git a/tests/run-with-compiler/i3947j.scala b/tests/run-with-compiler/i3947j.scala index 04e75012acb8..e41bf2037a4e 100644 --- a/tests/run-with-compiler/i3947j.scala +++ b/tests/run-with-compiler/i3947j.scala @@ -5,6 +5,7 @@ import dotty.tools.dotc.quoted.Toolbox._ object Test { def main(args: Array[String]): Unit = { + implicit val toolbox: scala.quoted.Toolbox = dotty.tools.dotc.quoted.Toolbox.make def test[T](clazz: java.lang.Class[T]): Unit = { val lclazz = clazz.toExpr diff --git a/tests/run-with-compiler/i4350.scala b/tests/run-with-compiler/i4350.scala index 9657144f609d..647190212fb0 100644 --- a/tests/run-with-compiler/i4350.scala +++ b/tests/run-with-compiler/i4350.scala @@ -8,6 +8,7 @@ class Foo[T: Type] { object Test { def main(args: Array[String]): Unit = { + implicit val toolbox: scala.quoted.Toolbox = dotty.tools.dotc.quoted.Toolbox.make println((new Foo[Object]).q.show) println((new Foo[String]).q.show) } diff --git a/tests/run-with-compiler/quote-lib.scala b/tests/run-with-compiler/quote-lib.scala index 4d648889b16c..688a7913b9d1 100644 --- a/tests/run-with-compiler/quote-lib.scala +++ b/tests/run-with-compiler/quote-lib.scala @@ -11,6 +11,7 @@ import liftable.Exprs._ object Test { def main(args: Array[String]): Unit = { + implicit val toolbox: scala.quoted.Toolbox = dotty.tools.dotc.quoted.Toolbox.make val liftedUnit: Expr[Unit] = '() diff --git a/tests/run-with-compiler/quote-owners-2.scala b/tests/run-with-compiler/quote-owners-2.scala index 7e2d11e9b374..f5017b45a840 100644 --- a/tests/run-with-compiler/quote-owners-2.scala +++ b/tests/run-with-compiler/quote-owners-2.scala @@ -4,6 +4,8 @@ import dotty.tools.dotc.quoted.Toolbox._ object Test { def main(args: Array[String]): Unit = { + implicit val toolbox: scala.quoted.Toolbox = dotty.tools.dotc.quoted.Toolbox.make + val q = f(g(Type.IntTag)) println(q.run) println(q.show) diff --git a/tests/run-with-compiler/quote-owners.scala b/tests/run-with-compiler/quote-owners.scala index 1ccadf592d0a..58047cbb9257 100644 --- a/tests/run-with-compiler/quote-owners.scala +++ b/tests/run-with-compiler/quote-owners.scala @@ -3,6 +3,8 @@ import dotty.tools.dotc.quoted.Toolbox._ object Test { def main(args: Array[String]): Unit = { + implicit val toolbox: scala.quoted.Toolbox = dotty.tools.dotc.quoted.Toolbox.make + val q = f println(q.run) println(q.show) diff --git a/tests/run-with-compiler/quote-run-2.scala b/tests/run-with-compiler/quote-run-2.scala index cf27218340cd..a5613a5c85f7 100644 --- a/tests/run-with-compiler/quote-run-2.scala +++ b/tests/run-with-compiler/quote-run-2.scala @@ -5,6 +5,8 @@ import scala.quoted._ object Test { def main(args: Array[String]): Unit = { + implicit val toolbox: scala.quoted.Toolbox = dotty.tools.dotc.quoted.Toolbox.make + def powerCode(n: Int, x: Expr[Double]): Expr[Double] = if (n == 0) '(1.0) else if (n == 1) x diff --git a/tests/run-with-compiler/quote-run-b.scala b/tests/run-with-compiler/quote-run-b.scala index 8c4e2dac2b41..957388374111 100644 --- a/tests/run-with-compiler/quote-run-b.scala +++ b/tests/run-with-compiler/quote-run-b.scala @@ -5,6 +5,8 @@ import scala.quoted._ object Test { def main(args: Array[String]): Unit = { + implicit val toolbox: scala.quoted.Toolbox = dotty.tools.dotc.quoted.Toolbox.make + val lambdaExpr = '{ (x: Int) => println("lambda(" + x + ")") } diff --git a/tests/run-with-compiler/quote-run-c.scala b/tests/run-with-compiler/quote-run-c.scala index 56df25a84cba..c52639f2b4ff 100644 --- a/tests/run-with-compiler/quote-run-c.scala +++ b/tests/run-with-compiler/quote-run-c.scala @@ -5,6 +5,8 @@ import scala.quoted._ object Test { def main(args: Array[String]): Unit = { + implicit val toolbox: scala.quoted.Toolbox = dotty.tools.dotc.quoted.Toolbox.make + val classExpr = '{ class A { override def toString: String = "Foo" diff --git a/tests/run-with-compiler/quote-run-constants.scala b/tests/run-with-compiler/quote-run-constants.scala index 6e432baba955..997ac779e1be 100644 --- a/tests/run-with-compiler/quote-run-constants.scala +++ b/tests/run-with-compiler/quote-run-constants.scala @@ -5,6 +5,8 @@ import scala.quoted._ object Test { def main(args: Array[String]): Unit = { + implicit val toolbox: scala.quoted.Toolbox = dotty.tools.dotc.quoted.Toolbox.make + def run[T](expr: Expr[T]): Unit = println(expr.run) def show[T](expr: Expr[T]): Unit = println(expr.show) diff --git a/tests/run-with-compiler/quote-run-many.scala b/tests/run-with-compiler/quote-run-many.scala new file mode 100644 index 000000000000..9525ecaa14fa --- /dev/null +++ b/tests/run-with-compiler/quote-run-many.scala @@ -0,0 +1,14 @@ +import scala.quoted._ + +object Test { + def main(args: Array[String]): Unit = { + implicit val toolbox: scala.quoted.Toolbox = dotty.tools.dotc.quoted.Toolbox.make + + def expr(i: Int) = '{ + val a = 3 + ~i.toExpr + 2 + a + } + for (i <- 0 to 200) + expr(i).run + } +} diff --git a/tests/run-with-compiler/quote-run-with-settings.scala b/tests/run-with-compiler/quote-run-with-settings.scala index 7c4471b0b85c..8d2c677735ca 100644 --- a/tests/run-with-compiler/quote-run-with-settings.scala +++ b/tests/run-with-compiler/quote-run-with-settings.scala @@ -2,11 +2,13 @@ import java.nio.file.{Files, Paths} import dotty.tools.dotc.quoted.Toolbox._ +import dotty.tools.dotc.quoted.ToolboxSettings import scala.quoted._ object Test { def main(args: Array[String]): Unit = { + implicit val toolbox: scala.quoted.Toolbox = dotty.tools.dotc.quoted.Toolbox.make val expr = '{ val a = 3 println("foo") @@ -22,7 +24,8 @@ object Test { Files.deleteIfExists(classFile) { - implicit val settings = Settings.run(optimise = true, outDir = Some(outDir.toString)) + implicit val settings = ToolboxSettings.make(optimise = true, outDir = Some(outDir.toString)) + implicit val toolbox2: scala.quoted.Toolbox = dotty.tools.dotc.quoted.Toolbox.make println(expr.run) assert(Files.exists(classFile)) } diff --git a/tests/run-with-compiler/quote-run.scala b/tests/run-with-compiler/quote-run.scala index 5e23ab134d40..45ee3e3fabf4 100644 --- a/tests/run-with-compiler/quote-run.scala +++ b/tests/run-with-compiler/quote-run.scala @@ -5,6 +5,8 @@ import scala.quoted._ object Test { def main(args: Array[String]): Unit = { + implicit val toolbox: scala.quoted.Toolbox = dotty.tools.dotc.quoted.Toolbox.make + val expr = '{ val a = 3 println("foo") diff --git a/tests/run-with-compiler/quote-show-blocks-raw.scala b/tests/run-with-compiler/quote-show-blocks-raw.scala index bcd6480451dc..31770a9c9f1f 100644 --- a/tests/run-with-compiler/quote-show-blocks-raw.scala +++ b/tests/run-with-compiler/quote-show-blocks-raw.scala @@ -1,11 +1,12 @@ import dotty.tools.dotc.quoted.Toolbox._ +import dotty.tools.dotc.quoted.ToolboxSettings import scala.quoted._ object Test { def main(args: Array[String]): Unit = { - implicit val settings = Settings.show(rawTree = true) + implicit val settings = ToolboxSettings.make(rawTree = true) def a(n: Int, x: Expr[Unit]): Expr[Unit] = if (n == 0) x diff --git a/tests/run-with-compiler/quote-show-blocks.scala b/tests/run-with-compiler/quote-show-blocks.scala index 1b84dde97a9c..b7400cd53e24 100644 --- a/tests/run-with-compiler/quote-show-blocks.scala +++ b/tests/run-with-compiler/quote-show-blocks.scala @@ -1,10 +1,8 @@ - -import dotty.tools.dotc.quoted.Toolbox._ - import scala.quoted._ object Test { def main(args: Array[String]): Unit = { + implicit val toolbox: scala.quoted.Toolbox = dotty.tools.dotc.quoted.Toolbox.make def a(n: Int, x: Expr[Unit]): Expr[Unit] = if (n == 0) x diff --git a/tests/run-with-compiler/quote-two-captured-ref.scala b/tests/run-with-compiler/quote-two-captured-ref.scala index a04da52aad15..19f8f8c2fa72 100644 --- a/tests/run-with-compiler/quote-two-captured-ref.scala +++ b/tests/run-with-compiler/quote-two-captured-ref.scala @@ -1,8 +1,9 @@ import quoted._ -import dotty.tools.dotc.quoted.Toolbox._ object Test { def main(args: Array[String]): Unit = { + implicit val toolbox: scala.quoted.Toolbox = dotty.tools.dotc.quoted.Toolbox.make + val q = '{ val x = 1 println(~{ diff --git a/tests/run-with-compiler/quote-type-tags.scala b/tests/run-with-compiler/quote-type-tags.scala index 4a2bb94300de..95a421637edd 100644 --- a/tests/run-with-compiler/quote-type-tags.scala +++ b/tests/run-with-compiler/quote-type-tags.scala @@ -1,10 +1,9 @@ - -import dotty.tools.dotc.quoted.Toolbox._ - import scala.quoted._ object Test { def main(args: Array[String]): Unit = { + implicit val toolbox: scala.quoted.Toolbox = dotty.tools.dotc.quoted.Toolbox.make + def asof[T, U](x: Expr[T], t: Type[U]): Expr[U] = '((~x).asInstanceOf[~t])