From 36216cb433cb9efd37bfd2bc6c10d4b4b4ef3620 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 17 Jun 2019 15:44:17 +0200 Subject: [PATCH 01/12] Fix #5161: Add QuoteContext to handle compiler instance for `show` The main idea is to correctly keep track of the current compiler. This is paramount to support correctly `show` and quote patterns. This PR only contains the addition of the `QuoteContext` to the `run` but not the top level `$` (which will come in a second step). * Add `QuoteContext` * Define a single `Expr.show` entry point in `QuoteContext`(for `expr.show`) * Define `show(expr)` which is an alias of `run(expr.show.toExpr)` that provides a `QuoteContext` * Remove coloring options from the `Reflection.Context` and `Toolbox` settings (`show` never has colors unless a coloring format is given) * Replace `TreeCleaner` with `@quoteTypeTag` and logic in the printers * Fix #5161 * Regression local definitions are not renamed in quotes (postponed for future PR). See tests/run-with-compiler/quote-run-2.check. --- community-build/community-projects/scalatest | 2 +- .../dotty/tools/dotc/core/Definitions.scala | 1 + .../dotc/quoted/ExprCompilationUnit.scala | 4 +- .../tools/dotc/quoted/QuoteCompiler.scala | 17 +- .../dotty/tools/dotc/quoted/QuoteDriver.scala | 41 +--- .../dotty/tools/dotc/quoted/ToolboxImpl.scala | 12 +- .../dotty/tools/dotc/quoted/TreeCleaner.scala | 49 ---- .../tools/dotc/tastyreflect/KernelImpl.scala | 6 - .../dotc/tastyreflect/ReflectionImpl.scala | 2 +- .../tools/dotc/transform/ReifyQuotes.scala | 7 +- compiler/test-resources/repl-macros/i6007 | 2 +- library/src-3.x/scala/internal/Quoted.scala | 2 + library/src-3.x/scala/quoted/Expr.scala | 5 +- library/src-3.x/scala/quoted/Type.scala | 7 +- library/src-3.x/scala/quoted/package.scala | 4 +- .../scala/tasty/reflect/QuotedOps.scala | 8 - library/src/scala/quoted/QuoteContext.scala | 17 ++ library/src/scala/quoted/Toolbox.scala | 10 +- library/src/scala/tasty/Reflection.scala | 6 + .../src/scala/tasty/reflect/ContextOps.scala | 8 - library/src/scala/tasty/reflect/Kernel.scala | 10 - .../src/scala/tasty/reflect/Printers.scala | 66 ++++-- .../quote-run-in-macro-1/quoted_1.scala | 2 +- .../quote-run-in-macro-2/quoted_1.scala | 2 +- tests/run-with-compiler/i3823-b.scala | 4 +- tests/run-with-compiler/i3823-c.scala | 3 +- tests/run-with-compiler/i3823.scala | 2 +- tests/run-with-compiler/i3847-b.scala | 2 +- tests/run-with-compiler/i3847.scala | 4 +- tests/run-with-compiler/i3876-b.scala | 3 +- tests/run-with-compiler/i3876-c.scala | 3 +- tests/run-with-compiler/i3876-d.scala | 2 +- tests/run-with-compiler/i3876-e.scala | 2 +- tests/run-with-compiler/i3876.scala | 3 +- tests/run-with-compiler/i3946.scala | 2 +- tests/run-with-compiler/i3947.scala | 4 +- tests/run-with-compiler/i3947b.scala | 4 +- tests/run-with-compiler/i3947b2.scala | 4 +- tests/run-with-compiler/i3947b3.scala | 4 +- tests/run-with-compiler/i3947c.scala | 4 +- tests/run-with-compiler/i3947d.scala | 4 +- tests/run-with-compiler/i3947d2.scala | 4 +- tests/run-with-compiler/i3947e.scala | 4 +- tests/run-with-compiler/i3947f.scala | 4 +- tests/run-with-compiler/i3947g.scala | 4 +- tests/run-with-compiler/i3947i.scala | 4 +- tests/run-with-compiler/i3947j.scala | 4 +- tests/run-with-compiler/i4044a.scala | 2 +- tests/run-with-compiler/i4044b.scala | 2 +- tests/run-with-compiler/i4044c.scala | 2 +- tests/run-with-compiler/i4044d.scala | 19 +- tests/run-with-compiler/i4044e.scala | 2 +- tests/run-with-compiler/i4044f.scala | 2 +- tests/run-with-compiler/i4350.scala | 6 +- tests/run-with-compiler/i5144.scala | 2 +- tests/run-with-compiler/i5144b.scala | 3 +- tests/run-with-compiler/i5152.scala | 4 +- tests/run-with-compiler/i5161.check | 7 + tests/run-with-compiler/i5161.scala | 31 +++ tests/run-with-compiler/i5161b.check | 10 + tests/run-with-compiler/i5161b.scala | 17 ++ tests/run-with-compiler/i5247.scala | 4 +- tests/run-with-compiler/i5965.check | 6 +- tests/run-with-compiler/i5965.scala | 6 +- tests/run-with-compiler/i5965b.scala | 6 +- tests/run-with-compiler/i5997.scala | 3 +- tests/run-with-compiler/i6270/Macro_1.scala | 4 +- .../quote-function-applied-to.scala | 90 +++---- tests/run-with-compiler/quote-lib.scala | 5 +- .../quote-macro-in-splice/quoted_2.scala | 2 +- tests/run-with-compiler/quote-nested-1.scala | 2 +- tests/run-with-compiler/quote-nested-2.scala | 4 +- tests/run-with-compiler/quote-nested-3.scala | 4 +- tests/run-with-compiler/quote-nested-4.scala | 2 +- tests/run-with-compiler/quote-nested-5.scala | 2 +- tests/run-with-compiler/quote-owners-2.check | 4 +- tests/run-with-compiler/quote-owners-2.scala | 6 +- tests/run-with-compiler/quote-owners.scala | 2 +- tests/run-with-compiler/quote-run-2.check | 10 +- tests/run-with-compiler/quote-run-2.scala | 10 +- .../quote-run-constants.scala | 30 +-- tests/run-with-compiler/quote-run-large.check | 0 tests/run-with-compiler/quote-run-large.scala | 8 +- .../quote-run-staged-interpreter.scala | 14 +- .../quote-run-with-settings.scala | 2 +- tests/run-with-compiler/quote-run.scala | 2 +- .../run-with-compiler/quote-show-blocks.scala | 5 +- .../quote-two-captured-ref.scala | 5 +- tests/run-with-compiler/quote-type-tags.scala | 5 +- .../quote-unrolled-foreach.scala | 4 +- .../run-with-compiler/shonan-hmm-simple.scala | 12 +- tests/run-with-compiler/shonan-hmm.check | 220 +++++++++--------- tests/run-with-compiler/shonan-hmm/Test.scala | 18 +- .../quoted_1.scala | 6 +- 94 files changed, 494 insertions(+), 486 deletions(-) delete mode 100644 compiler/src/dotty/tools/dotc/quoted/TreeCleaner.scala create mode 100644 library/src/scala/quoted/QuoteContext.scala create mode 100644 tests/run-with-compiler/i5161.check create mode 100644 tests/run-with-compiler/i5161.scala create mode 100644 tests/run-with-compiler/i5161b.check create mode 100644 tests/run-with-compiler/i5161b.scala delete mode 100644 tests/run-with-compiler/quote-run-large.check diff --git a/community-build/community-projects/scalatest b/community-build/community-projects/scalatest index 21952c83832b..cd51c7a08e1c 160000 --- a/community-build/community-projects/scalatest +++ b/community-build/community-projects/scalatest @@ -1 +1 @@ -Subproject commit 21952c83832b1fdaa31e97314a8ac7fa28b737aa +Subproject commit cd51c7a08e1ca26d5c0616fd5efc9b5ea8d25fe8 diff --git a/compiler/src/dotty/tools/dotc/core/Definitions.scala b/compiler/src/dotty/tools/dotc/core/Definitions.scala index 6d345a1550cc..f0d6177e09b0 100644 --- a/compiler/src/dotty/tools/dotc/core/Definitions.scala +++ b/compiler/src/dotty/tools/dotc/core/Definitions.scala @@ -773,6 +773,7 @@ class Definitions { @threadUnsafe lazy val InternalQuoted_patternHoleR: TermRef = InternalQuotedModule.requiredMethodRef("patternHole") def InternalQuoted_patternHole(implicit ctx: Context): Symbol = InternalQuoted_patternHoleR.symbol @threadUnsafe lazy val InternalQuoted_patternBindHoleAnnot: ClassSymbol = InternalQuotedModule.requiredClass("patternBindHole") + @threadUnsafe lazy val InternalQuoted_QuoteTypeTagAnnot: ClassSymbol = InternalQuotedModule.requiredClass("quoteTypeTag") @threadUnsafe lazy val InternalQuotedMatcherModuleRef: TermRef = ctx.requiredModuleRef("scala.internal.quoted.Matcher") def InternalQuotedMatcherModule(implicit ctx: Context): Symbol = InternalQuotedMatcherModuleRef.symbol diff --git a/compiler/src/dotty/tools/dotc/quoted/ExprCompilationUnit.scala b/compiler/src/dotty/tools/dotc/quoted/ExprCompilationUnit.scala index 0dffbb82b7a3..2f3de88ab401 100644 --- a/compiler/src/dotty/tools/dotc/quoted/ExprCompilationUnit.scala +++ b/compiler/src/dotty/tools/dotc/quoted/ExprCompilationUnit.scala @@ -6,6 +6,4 @@ import dotty.tools.dotc.util.NoSource import scala.quoted.Expr /* Compilation unit containing the contents of a quoted expression */ -class ExprCompilationUnit(val expr: Expr[_]) extends CompilationUnit(NoSource) { - override def toString: String = s"Expr($expr)" -} +class ExprCompilationUnit(val expr: scala.quoted.QuoteContext => Expr[_]) extends CompilationUnit(NoSource) diff --git a/compiler/src/dotty/tools/dotc/quoted/QuoteCompiler.scala b/compiler/src/dotty/tools/dotc/quoted/QuoteCompiler.scala index 490b11f683ad..7c6d6ea43ae8 100644 --- a/compiler/src/dotty/tools/dotc/quoted/QuoteCompiler.scala +++ b/compiler/src/dotty/tools/dotc/quoted/QuoteCompiler.scala @@ -14,12 +14,13 @@ import dotty.tools.dotc.core.StdNames.nme import dotty.tools.dotc.core.Symbols.defn import dotty.tools.dotc.core.Types.ExprType import dotty.tools.dotc.core.quoted.PickledQuotes +import dotty.tools.dotc.tastyreflect.ReflectionImpl import dotty.tools.dotc.transform.Staging import dotty.tools.dotc.util.Spans.Span import dotty.tools.dotc.util.SourceFile import dotty.tools.io.{Path, VirtualFile} -import scala.quoted.{Expr, Type} +import scala.quoted.{Expr, Type, QuoteContext} /** Compiler that takes the contents of a quoted expression `expr` and produces * a class file with `class ' { def apply: Object = expr }`. @@ -50,7 +51,7 @@ class QuoteCompiler extends Compiler { case exprUnit: ExprCompilationUnit => val tree = if (putInClass) inClass(exprUnit.expr) - else PickledQuotes.quotedExprToTree(exprUnit.expr) + else PickledQuotes.quotedExprToTree(checkValidRunExpr(exprUnit.expr.apply(new QuoteContext(ReflectionImpl(ctx))))) val source = SourceFile.virtual("", "") CompilationUnit(source, tree, forceTrees = true) case typeUnit: TypeCompilationUnit => @@ -61,11 +62,17 @@ class QuoteCompiler extends Compiler { } } + private def checkValidRunExpr(expr: Expr[_]): Expr[_] = expr match { + case expr: scala.internal.quoted.TastyTreeExpr[Tree] @unchecked => + throw new Exception("Cannot call `Expr.run` on an `Expr` that comes from a macro argument.") + case _ => expr + } + /** Places the contents of expr in a compilable tree for a class * with the following format. * `package __root__ { class ' { def apply: Any = } }` */ - private def inClass(expr: Expr[_])(implicit ctx: Context): Tree = { + private def inClass(expr: scala.quoted.QuoteContext => Expr[_])(implicit ctx: Context): Tree = { val pos = Span(0) val assocFile = new VirtualFile("") @@ -74,7 +81,7 @@ class QuoteCompiler extends Compiler { cls.enter(ctx.newDefaultConstructor(cls), EmptyScope) val meth = ctx.newSymbol(cls, nme.apply, Method, ExprType(defn.AnyType), coord = pos).entered - val quoted = PickledQuotes.quotedExprToTree(expr)(ctx.withOwner(meth)) + val quoted = PickledQuotes.quotedExprToTree(checkValidRunExpr(expr.apply(new QuoteContext(ReflectionImpl(ctx)))))(ctx.withOwner(meth)) val run = DefDef(meth, quoted) val classTree = ClassDef(cls, DefDef(cls.primaryConstructor.asTerm), run :: Nil) @@ -85,7 +92,7 @@ class QuoteCompiler extends Compiler { } class ExprRun(comp: Compiler, ictx: Context) extends Run(comp, ictx) { - def compileExpr(expr: Expr[_]): Unit = { + def compileExpr(expr: scala.quoted.QuoteContext => Expr[_]): Unit = { val units = new ExprCompilationUnit(expr) :: Nil compileUnits(units) } diff --git a/compiler/src/dotty/tools/dotc/quoted/QuoteDriver.scala b/compiler/src/dotty/tools/dotc/quoted/QuoteDriver.scala index adddbb7d94d9..f08f6ef95674 100644 --- a/compiler/src/dotty/tools/dotc/quoted/QuoteDriver.scala +++ b/compiler/src/dotty/tools/dotc/quoted/QuoteDriver.scala @@ -20,7 +20,7 @@ class QuoteDriver(appClassloader: ClassLoader) extends Driver { private[this] val contextBase: ContextBase = new ContextBase - def run[T](expr: Expr[T], settings: Toolbox.Settings): T = { + def run[T](expr: scala.quoted.QuoteContext => Expr[T], settings: Toolbox.Settings): T = { val outDir: AbstractFile = settings.outDir match { case Some(out) => val dir = Directory(out) @@ -47,44 +47,6 @@ class QuoteDriver(appClassloader: ClassLoader) extends Driver { method.invoke(inst).asInstanceOf[T] } - private def doShow(tree: Tree, ctx: Context): String = { - implicit val c: Context = ctx - val tree1 = - if (ctx.settings.YshowRawQuoteTrees.value) tree - else (new TreeCleaner).transform(tree) - ReflectionImpl.showTree(tree1) - } - - def show(expr: Expr[_], settings: Toolbox.Settings): String = - withTree(expr, doShow, settings) - - def show(tpe: Type[_], settings: Toolbox.Settings): String = - withTypeTree(tpe, doShow, settings) - - def withTree[T](expr: Expr[_], f: (Tree, Context) => T, settings: Toolbox.Settings): T = { - val ctx = setToolboxSettings(setup(settings.compilerArgs.toArray :+ "dummy.scala", initCtx.fresh)._2.fresh, settings) - - var output: Option[T] = None - def registerTree(tree: tpd.Tree)(ctx: Context): Unit = { - assert(output.isEmpty) - output = Some(f(tree, ctx)) - } - new QuoteDecompiler(registerTree).newRun(ctx).compileExpr(expr) - output.getOrElse(throw new Exception("Could not extract " + expr)) - } - - def withTypeTree[T](tpe: Type[_], f: (TypTree, Context) => T, settings: Toolbox.Settings): T = { - val ctx = setToolboxSettings(setup(settings.compilerArgs.toArray :+ "dummy.scala", initCtx.fresh)._2.fresh, settings) - - var output: Option[T] = None - def registerTree(tree: tpd.Tree)(ctx: Context): Unit = { - assert(output.isEmpty) - output = Some(f(tree.asInstanceOf[TypTree], ctx)) - } - new QuoteDecompiler(registerTree).newRun(ctx).compileType(tpe) - output.getOrElse(throw new Exception("Could not extract " + tpe)) - } - override def initCtx: Context = { val ictx = contextBase.initialCtx ictx.settings.classpath.update(QuoteDriver.currentClasspath(appClassloader))(ictx) @@ -92,7 +54,6 @@ class QuoteDriver(appClassloader: ClassLoader) extends Driver { } private def setToolboxSettings(ctx: FreshContext, settings: Toolbox.Settings): ctx.type = { - ctx.setSetting(ctx.settings.color, if (settings.color) "always" else "never") ctx.setSetting(ctx.settings.YshowRawQuoteTrees, settings.showRawTree) // An error in the generated code is a bug in the compiler // Setting the throwing reporter however will report any exception diff --git a/compiler/src/dotty/tools/dotc/quoted/ToolboxImpl.scala b/compiler/src/dotty/tools/dotc/quoted/ToolboxImpl.scala index 2e11424b4b38..3ecd82a50b25 100644 --- a/compiler/src/dotty/tools/dotc/quoted/ToolboxImpl.scala +++ b/compiler/src/dotty/tools/dotc/quoted/ToolboxImpl.scala @@ -19,18 +19,10 @@ object ToolboxImpl { private[this] val driver: QuoteDriver = new QuoteDriver(appClassloader) - 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 a macro argument.") - case _ => - synchronized(driver.run(expr, settings)) + def run[T](expr: scala.quoted.QuoteContext => Expr[T]): T = synchronized { + driver.run(expr, settings) } - def show[T](expr: Expr[T]): String = synchronized(driver.show(expr, settings)) - - def show[T](tpe: Type[T]): String = synchronized(driver.show(tpe, settings)) } } diff --git a/compiler/src/dotty/tools/dotc/quoted/TreeCleaner.scala b/compiler/src/dotty/tools/dotc/quoted/TreeCleaner.scala deleted file mode 100644 index 93c203fffb12..000000000000 --- a/compiler/src/dotty/tools/dotc/quoted/TreeCleaner.scala +++ /dev/null @@ -1,49 +0,0 @@ -package dotty.tools.dotc.quoted - -import dotty.tools.dotc.ast.Trees._ -import dotty.tools.dotc.ast.tpd -import dotty.tools.dotc.core.Contexts._ -import dotty.tools.dotc.core.Constants._ -import dotty.tools.dotc.core.Symbols._ -import dotty.tools.dotc.core.Types._ - -/** Clean up quote artifacts from the tree to make it simpler to read. - * - Flattens block and remove blocks with not statements - * - Inline type aliases in the tree - */ -class TreeCleaner extends tpd.TreeMap { - import tpd._ - - /** List of symbols and their types for type aliases `type T = U` */ - private[this] var aliasesSyms: List[Symbol] = Nil - private[this] var aliasesTypes: List[Type] = Nil - private[this] val aliases = newMutableSymbolMap[Tree] - - override def transform(tree: Tree)(implicit ctx: Context): Tree = { - val tree0 = tree match { - case TypeDef(_, TypeBoundsTree(lo, hi)) if lo == hi => - aliasesSyms = tree.symbol :: aliasesSyms - aliasesTypes = lo.tpe :: aliasesTypes - aliases(tree.symbol) = ref(lo.tpe.typeSymbol) - Literal(Constant(())) - case _ => tree - } - - super.transform(tree0) match { - case Block(Nil, expr1) => expr1 - case Block(stats1, expr1) => - val flatStats = stats1.flatMap { - case Block(stats2, expr2) => stats2 ::: expr2 :: Nil - case Literal(Constant(())) => Nil - case stat => stat :: Nil - } - expr1 match { - case Block(stats3, expr3) => seq(flatStats ::: stats3, expr3) - case expr3 => seq(flatStats, expr3) - } - case tree1: TypeTree => TypeTree(tree1.tpe.subst(aliasesSyms, aliasesTypes)) - case tree1: Ident => aliases.get(tree1.symbol).getOrElse(tree1) - case tree1 => tree1 - } - } -} diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala index 6877fb22c450..7afe4afea413 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala @@ -35,12 +35,6 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. def Context_source(self: Context): java.nio.file.Path = self.compilationUnit.source.file.jpath - def Context_printColors(self: Context): Boolean = self.settings.color.value(self) == "always" - - def Context_withColors(self: Context): Context = ctx.fresh.setSetting(ctx.settings.color, "always") - - def Context_withoutColors(self: Context): Context = ctx.fresh.setSetting(ctx.settings.color, "never") - // // REPORTING // diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionImpl.scala index e6a5d9a6a84d..ba7eae91fdbf 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionImpl.scala @@ -16,7 +16,7 @@ object ReflectionImpl { val refl = new scala.tasty.Reflection(new KernelImpl(ctx, tree.sourcePos)) val reflCtx = ctx.asInstanceOf[refl.Context] val reflTree = tree.asInstanceOf[refl.Tree] - new refl.SourceCodePrinter().showTree(reflTree)(reflCtx) + new refl.SourceCodePrinter(ctx.settings.color.value == "always").showTree(reflTree)(reflCtx) } } diff --git a/compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala b/compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala index 4e506dfd7864..37e44fc63b52 100644 --- a/compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala +++ b/compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala @@ -19,6 +19,7 @@ import dotty.tools.dotc.ast.tpd import typer.Implicits.SearchFailureType import scala.collection.mutable +import dotty.tools.dotc.core.Annotations.Annotation import dotty.tools.dotc.core.StdNames._ import dotty.tools.dotc.core.quoted._ import dotty.tools.dotc.transform.TreeMapWithStages._ @@ -115,9 +116,9 @@ class ReifyQuotes extends MacroTransform { /** Assuming contains types `${}, ..., ${}`, the expression * - * { type = ${} + * { @quoteTypeTag type = ${} * ... - * type = ${} + * @quoteTypeTag type = ${} * * } * @@ -137,7 +138,7 @@ class ReifyQuotes extends MacroTransform { flags = Synthetic, info = TypeAlias(splicedTree.tpe.select(tpnme.splice)), coord = spliced.termSymbol.coord).asType - + local.addAnnotation(Annotation(defn.InternalQuoted_QuoteTypeTagAnnot)) ctx.typeAssigner.assignType(untpd.TypeDef(local.name, alias), local) } diff --git a/compiler/test-resources/repl-macros/i6007 b/compiler/test-resources/repl-macros/i6007 index 4f3d9dfafa1f..9a4bee6e7027 100644 --- a/compiler/test-resources/repl-macros/i6007 +++ b/compiler/test-resources/repl-macros/i6007 @@ -2,7 +2,7 @@ scala> implicit def toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(ge def toolbox: quoted.Toolbox scala> val v = '{ (if true then Some(1) else None).map(v => v+1) } val v: quoted.Expr[Option[Int]] = Expr() -scala> v.show +scala> scala.quoted.show(v) val res0: String = (if (true) scala.Some.apply[scala.Int](1) else scala.None).map[scala.Int](((v: scala.Int) => v.+(1))) scala> scala.quoted.run(v) val res1: Option[Int] = Some(2) diff --git a/library/src-3.x/scala/internal/Quoted.scala b/library/src-3.x/scala/internal/Quoted.scala index 25af38de4c9a..b006a10ff1f5 100644 --- a/library/src-3.x/scala/internal/Quoted.scala +++ b/library/src-3.x/scala/internal/Quoted.scala @@ -25,4 +25,6 @@ object Quoted { @compileTimeOnly("Illegal reference to `scala.internal.Quoted.patternBindHole`") class patternBindHole extends Annotation + /** Artifact of type splicing */ + class quoteTypeTag extends Annotation } diff --git a/library/src-3.x/scala/quoted/Expr.scala b/library/src-3.x/scala/quoted/Expr.scala index c9d0271ed6cb..0a2bb160595a 100644 --- a/library/src-3.x/scala/quoted/Expr.scala +++ b/library/src-3.x/scala/quoted/Expr.scala @@ -9,7 +9,7 @@ package quoted { * May throw a FreeVariableError on expressions that came from a macro. */ @deprecated("Use scala.quoted.run", "") - final def run(implicit toolbox: Toolbox): T = toolbox.run(this) + final def run(implicit toolbox: Toolbox): T = toolbox.run(_ => this) } @@ -19,7 +19,8 @@ package quoted { implicit class ExprOps[T](expr: Expr[T]) { /** Show a source code like representation of this expression */ - def show(implicit toolbox: Toolbox): String = toolbox.show(expr) + def show(implicit qctx: QuoteContext): String = qctx.show(expr, false) + def showFormatted(implicit qctx: QuoteContext): String = qctx.show(expr, true) } /** Converts a tuple `(T1, ..., Tn)` to `(Expr[T1], ..., Expr[Tn])` */ diff --git a/library/src-3.x/scala/quoted/Type.scala b/library/src-3.x/scala/quoted/Type.scala index d217445d4980..6278ec8a82a9 100644 --- a/library/src-3.x/scala/quoted/Type.scala +++ b/library/src-3.x/scala/quoted/Type.scala @@ -10,9 +10,10 @@ package quoted { /** Some basic type tags, currently incomplete */ object Type { - implicit object TypeOps { - /** Show a source code like representation of this type */ - def (tpe: Type[T]) show[T] given Toolbox: String = the[Toolbox].show(tpe.asInstanceOf[Type[Any]]) + implicit class TypeOps[T](tpe: Type[T]) { + /** Show a source code like representation of this expression */ + def show(implicit qctx: QuoteContext): String = qctx.show(tpe, false) + def showFormatted(implicit qctx: QuoteContext): String = qctx.show(tpe, true) } implicit val UnitTag: Type[Unit] = new TaggedType[Unit] diff --git a/library/src-3.x/scala/quoted/package.scala b/library/src-3.x/scala/quoted/package.scala index abfc93786018..209228160b66 100644 --- a/library/src-3.x/scala/quoted/package.scala +++ b/library/src-3.x/scala/quoted/package.scala @@ -14,7 +14,9 @@ package object quoted { * * May throw a FreeVariableError on expressions that came from a macro. */ - def run[T](expr: Expr[T]) given (toolbox: Toolbox): T = toolbox.run(expr) + def run[T](expr: given QuoteContext => Expr[T]) given (toolbox: Toolbox): T = toolbox.run(expr given _) + + def show[T](expr: given QuoteContext => Expr[T]) given (toolbox: Toolbox): String = run(expr.show.toExpr) object autolift { implicit def autoToExpr[T: Liftable](x: T): Expr[T] = x.toExpr diff --git a/library/src-3.x/scala/tasty/reflect/QuotedOps.scala b/library/src-3.x/scala/tasty/reflect/QuotedOps.scala index 1e42d9070740..6ef2b8b5fc90 100644 --- a/library/src-3.x/scala/tasty/reflect/QuotedOps.scala +++ b/library/src-3.x/scala/tasty/reflect/QuotedOps.scala @@ -11,20 +11,12 @@ trait QuotedOps extends Core { self: Printers => /** Checked cast to a `quoted.Expr[U]` */ def cast[U: scala.quoted.Type](implicit ctx: Context): scala.quoted.Expr[U] = kernel.QuotedExpr_cast[U](expr) - - /** Show a source code like representation of this expression */ - def show(implicit ctx: Context): String = - unseal.show } implicit class QuotedTypeAPI[T <: AnyKind](tpe: scala.quoted.Type[T]) { /** View this expression `quoted.Type[T]` as a `TypeTree` */ def unseal(implicit ctx: Context): TypeTree = kernel.QuotedType_unseal(tpe) - - /** Show a source code like representation of this type */ - def show(implicit ctx: Context): String = - unseal.show } implicit class TermToQuotedAPI(term: Term) { diff --git a/library/src/scala/quoted/QuoteContext.scala b/library/src/scala/quoted/QuoteContext.scala new file mode 100644 index 000000000000..31667a24b2d2 --- /dev/null +++ b/library/src/scala/quoted/QuoteContext.scala @@ -0,0 +1,17 @@ +package scala.quoted + +class QuoteContext(reflection: tasty.Reflection) { + + def show[T](expr: Expr[T], formatted: Boolean): String = { + import reflection._ + if (formatted) expr.unseal.showFormatted + else expr.unseal.show + } + + def show[T](tpe: Type[T], formatted: Boolean): String = { + import reflection._ + if (formatted) tpe.unseal.showFormatted + else tpe.unseal.show + } + +} diff --git a/library/src/scala/quoted/Toolbox.scala b/library/src/scala/quoted/Toolbox.scala index ee834bdf236c..42fdb2d895fa 100644 --- a/library/src/scala/quoted/Toolbox.scala +++ b/library/src/scala/quoted/Toolbox.scala @@ -4,9 +4,7 @@ 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 = scala.quoted.Toolbox.make(getClass.getClassLoader)`\n\n") trait Toolbox { - def run[T](expr: Expr[T]): T - def show[T](expr: Expr[T]): String - def show[T](tpe: Type[T]): String + def run[T](expr: QuoteContext => Expr[T]): T } object Toolbox { @@ -38,7 +36,7 @@ object Toolbox { } /** Setting of the Toolbox instance. */ - case class Settings private (outDir: Option[String], showRawTree: Boolean, compilerArgs: List[String], color: Boolean) + case class Settings private (outDir: Option[String], showRawTree: Boolean, compilerArgs: List[String]) object Settings { @@ -46,17 +44,15 @@ object Toolbox { /** Make toolbox settings * @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 showRawTree Do not remove quote tree artifacts * @param compilerArgs Compiler arguments. Use only if you know what you are doing. */ def make( // TODO avoid using default parameters (for binary compat) - color: Boolean = false, showRawTree: Boolean = false, outDir: Option[String] = None, compilerArgs: List[String] = Nil ): Settings = - new Settings(outDir, showRawTree, compilerArgs, color) + new Settings(outDir, showRawTree, compilerArgs) } class ToolboxNotFoundException(msg: String, cause: ClassNotFoundException) extends Exception(msg, cause) diff --git a/library/src/scala/tasty/Reflection.scala b/library/src/scala/tasty/Reflection.scala index eafa6e3c12c2..503e61ebd7d6 100644 --- a/library/src/scala/tasty/Reflection.scala +++ b/library/src/scala/tasty/Reflection.scala @@ -41,6 +41,12 @@ class Reflection(val kernel: Kernel) val util: reflect.utils.TreeUtils { val reflect: self.type } = new reflect.utils.TreeUtils { val reflect: self.type = self } + + // TODO remove + // For backward compat with macros + implicit def reflectionToQuoteContext(implicit reflect: Reflection): scala.quoted.QuoteContext = + new scala.quoted.QuoteContext(reflect) + } object Reflection { diff --git a/library/src/scala/tasty/reflect/ContextOps.scala b/library/src/scala/tasty/reflect/ContextOps.scala index 470b071fd240..82a0230e14de 100644 --- a/library/src/scala/tasty/reflect/ContextOps.scala +++ b/library/src/scala/tasty/reflect/ContextOps.scala @@ -10,14 +10,6 @@ trait ContextOps extends Core { /** Returns the source file being compiled. The path is relative to the current working directory. */ def source: java.nio.file.Path = kernel.Context_source(self) - /** Returns true if the generated strings are allowed to use colors */ - def printColors: Boolean = kernel.Context_printColors(self) - - /** Returns a new context where printColors is true */ - def withColors: Context = kernel.Context_withColors(self) - - /** Returns a new context where printColors is false */ - def withoutColors: Context = kernel.Context_withoutColors(self) } /** Context of the macro expansion */ diff --git a/library/src/scala/tasty/reflect/Kernel.scala b/library/src/scala/tasty/reflect/Kernel.scala index 18e4ba66acb6..b36d4e0ff343 100644 --- a/library/src/scala/tasty/reflect/Kernel.scala +++ b/library/src/scala/tasty/reflect/Kernel.scala @@ -140,16 +140,6 @@ trait Kernel { /** Returns the source file being compiled. The path is relative to the current working directory. */ def Context_source(self: Context): java.nio.file.Path - /** Returns true if the generated strings are allowed to use colors */ - def Context_printColors(self: Context): Boolean - - /** Returns a new context where printColors is true */ - def Context_withColors(self: Context): Context - - /** Returns a new context where printColors is false */ - def Context_withoutColors(self: Context): Context - - // // REPORTING // diff --git a/library/src/scala/tasty/reflect/Printers.scala b/library/src/scala/tasty/reflect/Printers.scala index f27106fe0a43..47a4a48dced5 100644 --- a/library/src/scala/tasty/reflect/Printers.scala +++ b/library/src/scala/tasty/reflect/Printers.scala @@ -24,10 +24,12 @@ trait Printers implicit class TreeShowDeco(tree: Tree) { /** Shows the tree as extractors */ def showExtractors(implicit ctx: Context): String = new ExtractorsPrinter().showTree(tree) - /** Shows the tree as fully typed source code. - * Will print Ansi colors if ctx.printColors is enabled. - */ - def show(implicit ctx: Context): String = new SourceCodePrinter().showTree(tree) + + /** Shows the tree as fully typed source code */ + def show(implicit ctx: Context): String = new SourceCodePrinter(false).showTree(tree) + + /** Shows the tree as fully typed source code. Will print Ansi colors. */ + def showFormatted(implicit ctx: Context): String = new SourceCodePrinter(true).showTree(tree) } /** Adds `show` as an extension method of a `TypeOrBounds` */ @@ -37,7 +39,10 @@ trait Printers /** Shows the tree as fully typed source code. * Will print Ansi colors if ctx.printColors is enabled. */ - def show(implicit ctx: Context): String = new SourceCodePrinter().showTypeOrBounds(tpe) + def show(implicit ctx: Context): String = new SourceCodePrinter(false).showTypeOrBounds(tpe) + + /** Shows the tree as fully typed source code. Will print Ansi colors. */ + def showFormatted(implicit ctx: Context): String = new SourceCodePrinter(true).showTypeOrBounds(tpe) } /** Adds `show` as an extension method of a `Pattern` */ @@ -47,7 +52,10 @@ trait Printers /** Shows the tree as fully typed source code. * Will print Ansi colors if ctx.printColors is enabled. */ - def show(implicit ctx: Context): String = new SourceCodePrinter().showPattern(pattern) + def show(implicit ctx: Context): String = new SourceCodePrinter(false).showPattern(pattern) + + /** Shows the tree as fully typed source code. Will print Ansi colors. */ + def showFormatted(implicit ctx: Context): String = new SourceCodePrinter(true).showPattern(pattern) } /** Adds `show` as an extension method of a `Constant` */ @@ -57,7 +65,10 @@ trait Printers /** Shows the tree as fully typed source code. * Will print Ansi colors if ctx.printColors is enabled. */ - def show(implicit ctx: Context): String = new SourceCodePrinter().showConstant(const) + def show(implicit ctx: Context): String = new SourceCodePrinter(false).showConstant(const) + + /** Shows the tree as fully typed source code. Will print Ansi colors. */ + def showFormatted(implicit ctx: Context): String = new SourceCodePrinter(true).showConstant(const) } /** Adds `show` as an extension method of a `Symbol` */ @@ -65,7 +76,10 @@ trait Printers /** Shows the tree as extractors */ def showExtractors(implicit ctx: Context): String = new ExtractorsPrinter().showSymbol(symbol) /** Shows the tree as fully typed source code */ - def show(implicit ctx: Context): String = new SourceCodePrinter().showSymbol(symbol) + def show(implicit ctx: Context): String = new SourceCodePrinter(false).showSymbol(symbol) + + /** Shows the tree as fully typed source code. Will print Ansi colors. */ + def showFormatted(implicit ctx: Context): String = new SourceCodePrinter(true).showSymbol(symbol) } /** Adds `show` as an extension method of a `Flags` */ @@ -75,7 +89,10 @@ trait Printers /** Shows the tree as fully typed source code. * Will print Ansi colors if ctx.printColors is enabled. */ - def show(implicit ctx: Context): String = new SourceCodePrinter().showFlags(flags) + def show(implicit ctx: Context): String = new SourceCodePrinter(false).showFlags(flags) + + /** Shows the tree as fully typed source code. Will print Ansi colors. */ + def showFormatted(implicit ctx: Context): String = new SourceCodePrinter(true).showFlags(flags) } abstract class Printer { @@ -435,9 +452,7 @@ trait Printers } - class SourceCodePrinter extends Printer { - - private def color(implicit ctx: Context): Boolean = kernel.Context_printColors(ctx) + class SourceCodePrinter(color: Boolean) extends Printer { def showTree(tree: Tree)(implicit ctx: Context): String = (new Buffer).printTree(tree).result() @@ -999,7 +1014,11 @@ trait Printers def printFlatBlock(stats: List[Statement], expr: Term)(implicit elideThis: Option[Symbol]): Buffer = { val (stats1, expr1) = flatBlock(stats, expr) // Remove Lambda nodes, lambdas are printed by their definition - val stats2 = stats1.filter { case Lambda(_, _) => false; case _ => true } + val stats2 = stats1.filter { + case Lambda(_, _) => false + case IsTypeDef(tree) => !tree.symbol.annots.exists(_.symbol.owner.fullName == "scala.internal.Quoted$.quoteTypeTag") + case _ => true + } val (stats3, expr3) = expr1 match { case Lambda(_, _) => val init :+ last = stats2 @@ -1467,11 +1486,8 @@ trait Printers case TypeBind(name, _) => this += highlightTypeDef(name, color) - case TypeBlock(aliases, tpt) => - inBlock { - printTrees(aliases, lineBreak()) - printTypeTree(tpt) - } + case TypeBlock(_, tpt) => + printTypeTree(tpt) case _ => throw new MatchError(tree.showExtractors) @@ -1499,6 +1515,9 @@ trait Printers case Type.ConstantType(const) => printConstant(const) + case Type.SymRef(sym, _) if sym.annots.exists(_.symbol.owner.fullName == "scala.internal.Quoted$.quoteTypeTag") => + printType(tpe.dealias) + case Type.SymRef(sym, prefix) if sym.isType => prefix match { case Type.ThisType(Types.EmptyPackage() | Types.RootPackage()) => @@ -1556,7 +1575,9 @@ trait Printers printRefinement(tpe) case Type.AppliedType(tp, args) => - tp match { + normalize(tp) match { + case Type.IsTypeLambda(tp) => + printType(tpe.dealias) case Type.TypeRef("", Types.ScalaPackage()) => this += "_*" case _ => @@ -1653,6 +1674,13 @@ trait Printers throw new MatchError(tpe.showExtractors) } + private def normalize(tpe: TypeOrBounds): TypeOrBounds = tpe match { + case Type.IsSymRef(tpe) + if tpe.typeSymbol.annots.exists(_.symbol.owner.fullName == "scala.internal.Quoted$.quoteTypeTag") => + tpe.dealias + case _ => tpe + } + def printImportSelector(sel: ImportSelector): Buffer = sel match { case SimpleSelector(Id(name)) => this += name case OmitSelector(Id(name)) => this += name += " => _" diff --git a/tests/neg-with-compiler/quote-run-in-macro-1/quoted_1.scala b/tests/neg-with-compiler/quote-run-in-macro-1/quoted_1.scala index 27590f387487..b734f4998388 100644 --- a/tests/neg-with-compiler/quote-run-in-macro-1/quoted_1.scala +++ b/tests/neg-with-compiler/quote-run-in-macro-1/quoted_1.scala @@ -6,7 +6,7 @@ object Macros { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) inline def foo(i: => Int): Int = ${ fooImpl('i) } def fooImpl(i: Expr[Int]): Expr[Int] = { - val y: Int = i.run + val y: Int = run(i) y } } diff --git a/tests/neg-with-compiler/quote-run-in-macro-2/quoted_1.scala b/tests/neg-with-compiler/quote-run-in-macro-2/quoted_1.scala index 1f1f38ec20a1..e2aa77480563 100644 --- a/tests/neg-with-compiler/quote-run-in-macro-2/quoted_1.scala +++ b/tests/neg-with-compiler/quote-run-in-macro-2/quoted_1.scala @@ -6,7 +6,7 @@ object Macros { inline def foo(i: => Int): Int = ${ fooImpl('i) } def fooImpl(i: Expr[Int]): Expr[Int] = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - val y: Int = i.run + val y: Int = run(i) y } } diff --git a/tests/run-with-compiler/i3823-b.scala b/tests/run-with-compiler/i3823-b.scala index 958ef94e1b56..a9b0e5aa2317 100644 --- a/tests/run-with-compiler/i3823-b.scala +++ b/tests/run-with-compiler/i3823-b.scala @@ -5,6 +5,6 @@ object Test { val z: $t = $x } implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - println(f('{2})(Type.IntTag).show) + println(show(f('{2})(Type.IntTag))) } -} \ No newline at end of file +} diff --git a/tests/run-with-compiler/i3823-c.scala b/tests/run-with-compiler/i3823-c.scala index 3efe37610519..a1541e0afffc 100644 --- a/tests/run-with-compiler/i3823-c.scala +++ b/tests/run-with-compiler/i3823-c.scala @@ -5,7 +5,6 @@ object Test { val z = $x } implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - println(f('{2})(Type.IntTag).show) + println(show(f('{2})(Type.IntTag))) } } - diff --git a/tests/run-with-compiler/i3823.scala b/tests/run-with-compiler/i3823.scala index 3e207e307d42..f7e953e1f178 100644 --- a/tests/run-with-compiler/i3823.scala +++ b/tests/run-with-compiler/i3823.scala @@ -5,6 +5,6 @@ object Test { val z: $t = $x } implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - println(f('{2})('[Int]).show) + println(show(f('{2})('[Int]))) } } \ No newline at end of file diff --git a/tests/run-with-compiler/i3847-b.scala b/tests/run-with-compiler/i3847-b.scala index 3c76fb547c15..43384fc0566f 100644 --- a/tests/run-with-compiler/i3847-b.scala +++ b/tests/run-with-compiler/i3847-b.scala @@ -18,6 +18,6 @@ object Test { import Arrays._ implicit val ct: Expr[ClassTag[Int]] = '{ClassTag.Int} val arr: Expr[Array[List[Int]]] = Array[List[Int]](List(1, 2, 3)).toExpr - println(arr.show) + println(show(arr)) } } \ No newline at end of file diff --git a/tests/run-with-compiler/i3847.scala b/tests/run-with-compiler/i3847.scala index a8b071cc7bdb..d6864705603e 100644 --- a/tests/run-with-compiler/i3847.scala +++ b/tests/run-with-compiler/i3847.scala @@ -18,6 +18,6 @@ object Test { import Arrays._ implicit val ct: Expr[ClassTag[Int]] = '{ClassTag.Int} val arr: Expr[Array[Int]] = Array[Int](1, 2, 3).toExpr - println(arr.show) + println(show(arr)) } -} \ No newline at end of file +} diff --git a/tests/run-with-compiler/i3876-b.scala b/tests/run-with-compiler/i3876-b.scala index ba854e80eee6..a4eba0812d05 100644 --- a/tests/run-with-compiler/i3876-b.scala +++ b/tests/run-with-compiler/i3876-b.scala @@ -9,7 +9,8 @@ object Test { def f(x: Int): Int = x + x f } + println(run(f2(x))) - println(f2(x).show) + println(show(f2(x))) } } diff --git a/tests/run-with-compiler/i3876-c.scala b/tests/run-with-compiler/i3876-c.scala index aad2bfd063e8..d8a4efe9f117 100644 --- a/tests/run-with-compiler/i3876-c.scala +++ b/tests/run-with-compiler/i3876-c.scala @@ -9,7 +9,8 @@ object Test { val f: (x: Int) => Int = x => x + x f } + println(run(f3(x))) - println(f3(x).show) // TODO improve printer + println(show(f3(x))) // TODO improve printer } } diff --git a/tests/run-with-compiler/i3876-d.scala b/tests/run-with-compiler/i3876-d.scala index a64dd09213bc..e1334115e1ea 100644 --- a/tests/run-with-compiler/i3876-d.scala +++ b/tests/run-with-compiler/i3876-d.scala @@ -9,7 +9,7 @@ object Test { inlineLambda } println(run(f4(x))) - println(f4(x).show) + println(show(f4(x))) } inline def inlineLambda <: Int => Int = x => x + x diff --git a/tests/run-with-compiler/i3876-e.scala b/tests/run-with-compiler/i3876-e.scala index a6cb5ab158d5..345d2aa6d881 100644 --- a/tests/run-with-compiler/i3876-e.scala +++ b/tests/run-with-compiler/i3876-e.scala @@ -9,7 +9,7 @@ object Test { inlineLambda } println(run(f4(x))) - println(f4(x).show) + println(show(f4(x))) } inline def inlineLambda <: Int => Int = x => x + x diff --git a/tests/run-with-compiler/i3876.scala b/tests/run-with-compiler/i3876.scala index 0b76e6c534c3..f473476b6bcb 100644 --- a/tests/run-with-compiler/i3876.scala +++ b/tests/run-with-compiler/i3876.scala @@ -6,7 +6,8 @@ object Test { val x: Expr[Int] = '{3} val f: Expr[Int => Int] = '{ (x: Int) => x + x } + println(run(f(x))) - println(f(x).show) + println(show(f(x))) } } diff --git a/tests/run-with-compiler/i3946.scala b/tests/run-with-compiler/i3946.scala index 73aece729e0b..62e90b61e6e3 100644 --- a/tests/run-with-compiler/i3946.scala +++ b/tests/run-with-compiler/i3946.scala @@ -3,7 +3,7 @@ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) val u: Expr[Unit] = '{} - println(u.show) + println(show(u)) println(run(u)) } } diff --git a/tests/run-with-compiler/i3947.scala b/tests/run-with-compiler/i3947.scala index d6fb9b9c81c1..4984b17deda6 100644 --- a/tests/run-with-compiler/i3947.scala +++ b/tests/run-with-compiler/i3947.scala @@ -5,12 +5,12 @@ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - def test[T: Type](clazz: java.lang.Class[T]): Unit = { + def test[T: Type](clazz: java.lang.Class[T]): Unit = run { val lclazz = clazz.toExpr val name = '{ ($lclazz).getCanonicalName } println() println(name.show) - println(run(name)) + '{ println($name) } } // classOf[Object] diff --git a/tests/run-with-compiler/i3947b.scala b/tests/run-with-compiler/i3947b.scala index f27cd8c04d64..93ea766e2f07 100644 --- a/tests/run-with-compiler/i3947b.scala +++ b/tests/run-with-compiler/i3947b.scala @@ -5,12 +5,12 @@ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - def test[T: Type](clazz: java.lang.Class[T]): Unit = { + def test[T: Type](clazz: java.lang.Class[T]): Unit = run { val lclazz = clazz.toExpr val name = '{ ($lclazz).getCanonicalName } println() println(name.show) - println(run(name)) + '{ println($name) } } // primitives diff --git a/tests/run-with-compiler/i3947b2.scala b/tests/run-with-compiler/i3947b2.scala index 5956b3da4df7..ecd892c81d58 100644 --- a/tests/run-with-compiler/i3947b2.scala +++ b/tests/run-with-compiler/i3947b2.scala @@ -5,12 +5,12 @@ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - def test[T: Type](clazz: java.lang.Class[T]): Unit = { + def test[T: Type](clazz: java.lang.Class[T]): Unit = run { val lclazz = clazz.toExpr val name = '{ ($lclazz).getCanonicalName } println() println(name.show) - println(run(name)) + '{ println($name) } } // primitives diff --git a/tests/run-with-compiler/i3947b3.scala b/tests/run-with-compiler/i3947b3.scala index cc5bfd616d48..5eccdc6334ce 100644 --- a/tests/run-with-compiler/i3947b3.scala +++ b/tests/run-with-compiler/i3947b3.scala @@ -5,12 +5,12 @@ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - def test[T: Type](clazz: java.lang.Class[T]): Unit = { + def test[T: Type](clazz: java.lang.Class[T]): Unit = run { val lclazz = clazz.toExpr val name = '{ ($lclazz).getCanonicalName } println() println(name.show) - println(run(name)) + '{ println($name) } } // primitives diff --git a/tests/run-with-compiler/i3947c.scala b/tests/run-with-compiler/i3947c.scala index ffd458237a05..851b8c9ebe94 100644 --- a/tests/run-with-compiler/i3947c.scala +++ b/tests/run-with-compiler/i3947c.scala @@ -5,12 +5,12 @@ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - def test[T: Type](clazz: java.lang.Class[T]): Unit = { + def test[T: Type](clazz: java.lang.Class[T]): Unit = run { val lclazz = clazz.toExpr val name = '{ ($lclazz).getCanonicalName } println() println(name.show) - println(run(name)) + '{ println($name) } } test(classOf[Null]) diff --git a/tests/run-with-compiler/i3947d.scala b/tests/run-with-compiler/i3947d.scala index 78da0408257e..91140bfd28ba 100644 --- a/tests/run-with-compiler/i3947d.scala +++ b/tests/run-with-compiler/i3947d.scala @@ -5,12 +5,12 @@ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - def test[T: Type](clazz: java.lang.Class[T]): Unit = { + def test[T: Type](clazz: java.lang.Class[T]): Unit = run { val lclazz = clazz.toExpr val name = '{ ($lclazz).getCanonicalName } println() println(name.show) - println(run(name)) + '{ println($name) } } test(classOf[Foo]) diff --git a/tests/run-with-compiler/i3947d2.scala b/tests/run-with-compiler/i3947d2.scala index 38852e71fbfd..dd923aaad160 100644 --- a/tests/run-with-compiler/i3947d2.scala +++ b/tests/run-with-compiler/i3947d2.scala @@ -5,12 +5,12 @@ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - def test[T: Type](clazz: java.lang.Class[T]): Unit = { + def test[T: Type](clazz: java.lang.Class[T]): Unit = run { val lclazz = clazz.toExpr val name = '{ ($lclazz).getCanonicalName } println() println(name.show) - println(run(name)) + '{ println($name) } } test(classOf[foo.Foo]) diff --git a/tests/run-with-compiler/i3947e.scala b/tests/run-with-compiler/i3947e.scala index 39b6f54c2e3a..862a9a21a80e 100644 --- a/tests/run-with-compiler/i3947e.scala +++ b/tests/run-with-compiler/i3947e.scala @@ -6,12 +6,12 @@ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - def test[T: Type](clazz: java.lang.Class[T]): Unit = { + def test[T: Type](clazz: java.lang.Class[T]): Unit = run { val lclazz = clazz.toExpr val name = '{ ($lclazz).getCanonicalName } println() println(name.show) - println(run(name)) + '{ println($name) } } // class Object diff --git a/tests/run-with-compiler/i3947f.scala b/tests/run-with-compiler/i3947f.scala index 68b4c562f01c..a6930736c103 100644 --- a/tests/run-with-compiler/i3947f.scala +++ b/tests/run-with-compiler/i3947f.scala @@ -5,12 +5,12 @@ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - def test[T: Type](clazz: java.lang.Class[T]): Unit = { + def test[T: Type](clazz: java.lang.Class[T]): Unit = run { val lclazz = clazz.toExpr val name = '{ ($lclazz).getCanonicalName } println() println(name.show) - println(run(name)) + '{ println($name) } } // class Array[Object] diff --git a/tests/run-with-compiler/i3947g.scala b/tests/run-with-compiler/i3947g.scala index 59343ddf9035..05b8c033df11 100644 --- a/tests/run-with-compiler/i3947g.scala +++ b/tests/run-with-compiler/i3947g.scala @@ -5,12 +5,12 @@ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - def test[T: Type](clazz: java.lang.Class[T]): Unit = { + def test[T: Type](clazz: java.lang.Class[T]): Unit = run { val lclazz = clazz.toExpr val name = '{ ($lclazz).getCanonicalName } println() println(name.show) - println(run(name)) + '{ println($name) } } // primitive arrays diff --git a/tests/run-with-compiler/i3947i.scala b/tests/run-with-compiler/i3947i.scala index 9739e27d207e..113b2d492e4d 100644 --- a/tests/run-with-compiler/i3947i.scala +++ b/tests/run-with-compiler/i3947i.scala @@ -5,12 +5,12 @@ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - def test[T: Type](clazz: java.lang.Class[T]): Unit = { + def test[T: Type](clazz: java.lang.Class[T]): Unit = run { val lclazz = clazz.toExpr val name = '{ ($lclazz).getCanonicalName } println() println(name.show) - println(run(name)) + '{ println($name) } } // primitive arrays diff --git a/tests/run-with-compiler/i3947j.scala b/tests/run-with-compiler/i3947j.scala index c8f2b121f174..37788b716a3e 100644 --- a/tests/run-with-compiler/i3947j.scala +++ b/tests/run-with-compiler/i3947j.scala @@ -5,12 +5,12 @@ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - def test[T: Type](clazz: java.lang.Class[T]): Unit = { + def test[T: Type](clazz: java.lang.Class[T]): Unit = run { val lclazz = clazz.toExpr val name = '{ ($lclazz).getCanonicalName } println() println(name.show) - println(run(name)) + '{ println($name) } } test(classOf[Array[Array[Int]]]) diff --git a/tests/run-with-compiler/i4044a.scala b/tests/run-with-compiler/i4044a.scala index 30886ca3dfc7..4e2872967ede 100644 --- a/tests/run-with-compiler/i4044a.scala +++ b/tests/run-with-compiler/i4044a.scala @@ -5,7 +5,7 @@ class Foo { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) val e: Expr[Int] = '{3} val q = '{ ${ '{ $e } } } - println(q.show) + println(show(q)) } } diff --git a/tests/run-with-compiler/i4044b.scala b/tests/run-with-compiler/i4044b.scala index b70f9882cee1..7d9cc171d8aa 100644 --- a/tests/run-with-compiler/i4044b.scala +++ b/tests/run-with-compiler/i4044b.scala @@ -22,6 +22,6 @@ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) val q = VarRef('{4})(varRef => '{ ${varRef.update('{3})}; ${varRef.expr} }) - println(q.show) + println(show(q)) } } diff --git a/tests/run-with-compiler/i4044c.scala b/tests/run-with-compiler/i4044c.scala index 558ec2d1b045..affdcff7eca0 100644 --- a/tests/run-with-compiler/i4044c.scala +++ b/tests/run-with-compiler/i4044c.scala @@ -4,7 +4,7 @@ class Foo { def foo: Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) val q = '{ ${ '{ ${ '{ 5 } } } } } - println(q.show) + println(show(q)) } } diff --git a/tests/run-with-compiler/i4044d.scala b/tests/run-with-compiler/i4044d.scala index 512448e49f8d..583e9c4a2352 100644 --- a/tests/run-with-compiler/i4044d.scala +++ b/tests/run-with-compiler/i4044d.scala @@ -3,17 +3,20 @@ import scala.quoted._ class Foo { def foo: Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - val a: Expr[Int] = '{3} - val q: Expr[Int] = '{ - val b = 3 - ${ - println("evaluating inner quote") - '{ - b + $a + run { + val a: Expr[Int] = '{3} + val q: Expr[Int] = '{ + val b = 3 + ${ + println("evaluating inner quote") + '{ + b + $a + } } } + println(q.show) + '{} } - println(q.show) } } diff --git a/tests/run-with-compiler/i4044e.scala b/tests/run-with-compiler/i4044e.scala index bef7315f5e81..f7ee8d110bbe 100644 --- a/tests/run-with-compiler/i4044e.scala +++ b/tests/run-with-compiler/i4044e.scala @@ -7,7 +7,7 @@ class Foo { val f: Expr[Int] = '{5} val t: Type[Int] = '[Int] val q = '{ ${ '{ ($e + $f).asInstanceOf[$t] } } } - println(q.show) + println(show(q)) } } diff --git a/tests/run-with-compiler/i4044f.scala b/tests/run-with-compiler/i4044f.scala index bad5c8859a3b..8d2ccb0d6aa1 100644 --- a/tests/run-with-compiler/i4044f.scala +++ b/tests/run-with-compiler/i4044f.scala @@ -14,7 +14,7 @@ class Foo { foo('{e1 + $u}, '{f1}) } } - println(q.show) + println(show(q)) } } diff --git a/tests/run-with-compiler/i4350.scala b/tests/run-with-compiler/i4350.scala index c1be9e8570dd..d865af2e1855 100644 --- a/tests/run-with-compiler/i4350.scala +++ b/tests/run-with-compiler/i4350.scala @@ -1,5 +1,5 @@ -import scala.quoted.Type +import scala.quoted._ class Foo[T: Type] { def q = '{(null: Any).asInstanceOf[T]} @@ -8,7 +8,7 @@ class Foo[T: Type] { object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - println((new Foo[Object]).q.show) - println((new Foo[String]).q.show) + println(show((new Foo[Object]).q)) + println(show((new Foo[String]).q)) } } diff --git a/tests/run-with-compiler/i5144.scala b/tests/run-with-compiler/i5144.scala index 6f124d2402f9..3380ac4da830 100644 --- a/tests/run-with-compiler/i5144.scala +++ b/tests/run-with-compiler/i5144.scala @@ -10,7 +10,7 @@ object Test { def main(args: Array[String]): Unit = { val p = peval1() - println(p.show) + println(show(p)) } } \ No newline at end of file diff --git a/tests/run-with-compiler/i5144b.scala b/tests/run-with-compiler/i5144b.scala index ebbc72e5780e..34ffb2a067f1 100644 --- a/tests/run-with-compiler/i5144b.scala +++ b/tests/run-with-compiler/i5144b.scala @@ -8,9 +8,10 @@ object Test { def f(x: Int): Int = ${eval1('f)} } - def main(args: Array[String]): Unit = { + def main(args: Array[String]): Unit = run { val p = peval1() println(p.show) + '{} } } \ No newline at end of file diff --git a/tests/run-with-compiler/i5152.scala b/tests/run-with-compiler/i5152.scala index be9532ed2c43..56a46359a6cb 100644 --- a/tests/run-with-compiler/i5152.scala +++ b/tests/run-with-compiler/i5152.scala @@ -10,7 +10,7 @@ object Test { def main(args: Array[String]): Unit = { val p = peval1() - println(p.show) + println(show(p)) } -} \ No newline at end of file +} diff --git a/tests/run-with-compiler/i5161.check b/tests/run-with-compiler/i5161.check new file mode 100644 index 000000000000..27c72498d7f1 --- /dev/null +++ b/tests/run-with-compiler/i5161.check @@ -0,0 +1,7 @@ +run : Some(2) +show : scala.Tuple2.apply[scala.Option[scala.Int], scala.Option[scala.Int]](scala.Some.apply[scala.Int](1), scala.Some.apply[scala.Int](1)) match { + case scala.Tuple2(scala.Some(x), scala.Some(y)) => + scala.Some.apply[scala.Int](x.+(y)) + case _ => + scala.None +} diff --git a/tests/run-with-compiler/i5161.scala b/tests/run-with-compiler/i5161.scala new file mode 100644 index 000000000000..6fd945a33d5c --- /dev/null +++ b/tests/run-with-compiler/i5161.scala @@ -0,0 +1,31 @@ +import scala.quoted._ + +object Test { + implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + + enum Exp { + case Int2(x: Int) + case Add(e1: Exp, e2: Exp) + } + import Exp._ + + def evalTest(e: Exp): Expr[Option[Int]] = e match { + case Int2(x) => '{ Some(${x.toExpr}) } + case Add(e1, e2) => + '{ + (${evalTest(e1)}, ${evalTest(e2)}) match { + case (Some(x), Some(y)) => Some(x+y) + case _ => None + } + } + case null => '{ None } + } + + + def main(args: Array[String]): Unit = { + val test = Add(Int2(1), Int2(1)) + val res = evalTest(test) + println("run : " + run(res)) + println("show : " + show(res)) + } +} diff --git a/tests/run-with-compiler/i5161b.check b/tests/run-with-compiler/i5161b.check new file mode 100644 index 000000000000..a93920fde48e --- /dev/null +++ b/tests/run-with-compiler/i5161b.check @@ -0,0 +1,10 @@ +show0 : { + val x: scala.Option[scala.Int] = scala.Option.apply[scala.Int](3) + if (x.isInstanceOf[scala.Some[_ >: scala.Nothing <: scala.Any]]) scala.Option.apply[scala.Int](1) else scala.None +} +run1 : Some(1) +run2 : Some(1) +show3 : { + val x: scala.Option[scala.Int] = scala.Option.apply[scala.Int](3) + if (x.isInstanceOf[scala.Some[_ >: scala.Nothing <: scala.Any]]) scala.Option.apply[scala.Int](1) else scala.None +} diff --git a/tests/run-with-compiler/i5161b.scala b/tests/run-with-compiler/i5161b.scala new file mode 100644 index 000000000000..a27d3b0cb188 --- /dev/null +++ b/tests/run-with-compiler/i5161b.scala @@ -0,0 +1,17 @@ +import scala.quoted._ + +object Test { + implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + + def main(args: Array[String]): Unit = { + val res = '{ + val x: Option[Int] = Option(3) + if (x.isInstanceOf[Some[_]]) Option(1) + else None + } + println("show0 : " + show(res)) + println("run1 : " + run(res)) + println("run2 : " + run(res)) + println("show3 : " + show(res)) + } +} diff --git a/tests/run-with-compiler/i5247.scala b/tests/run-with-compiler/i5247.scala index 1fb8793d6822..a33afdfaf2e8 100644 --- a/tests/run-with-compiler/i5247.scala +++ b/tests/run-with-compiler/i5247.scala @@ -2,8 +2,8 @@ import scala.quoted._ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - println(foo[Object].show) - println(bar[Object].show) + println(show(foo[Object])) + println(show(bar[Object])) } def foo[H : Type]: Expr[H] = { val t = '[H] diff --git a/tests/run-with-compiler/i5965.check b/tests/run-with-compiler/i5965.check index f88ef8f53869..0f1c479d2902 100644 --- a/tests/run-with-compiler/i5965.check +++ b/tests/run-with-compiler/i5965.check @@ -1,17 +1,17 @@ { - val y: scala.collection.immutable.List[scala.Int] = scala.List.apply[scala.Int](1, 2, 3) + val y: [+A >: scala.Nothing <: scala.Any] => scala.collection.immutable.List[+A][scala.Int] = scala.List.apply[scala.Int](1, 2, 3) (y: scala.collection.immutable.List[scala.Int]) } List(1, 2, 3) { - val y: scala.Option[scala.Int] = scala.Option.apply[scala.Int](4) + val y: [+A >: scala.Nothing <: scala.Any] => scala.Option[+A][scala.Int] = scala.Option.apply[scala.Int](4) (y: scala.Option[scala.Int]) } Some(4) { - val y: scala.collection.immutable.Map[scala.Int, scala.Int] = scala.Predef.Map.apply[scala.Int, scala.Int](scala.Predef.ArrowAssoc[scala.Int](4).->[scala.Int](1)) + val y: [V >: scala.Nothing <: scala.Any] => scala.collection.immutable.Map[scala.Int, V][scala.Int] = scala.Predef.Map.apply[scala.Int, scala.Int](scala.Predef.ArrowAssoc[scala.Int](4).->[scala.Int](1)) (y: scala.collection.immutable.Map[scala.Int, scala.Int]) } diff --git a/tests/run-with-compiler/i5965.scala b/tests/run-with-compiler/i5965.scala index 58fa88f15e88..c42d47c5af6c 100644 --- a/tests/run-with-compiler/i5965.scala +++ b/tests/run-with-compiler/i5965.scala @@ -8,15 +8,15 @@ object Test { def main(args: Array[String]): Unit = { '[List] val list = bound('{List(1, 2, 3)}) - println(list.show) + println(show(list)) println(run(list)) val opt = bound('{Option(4)}) - println(opt.show) + println(show(opt)) println(run(opt)) val map = bound('{Map(4 -> 1)}) - println(map.show) + println(show(map)) println(run(map)) } diff --git a/tests/run-with-compiler/i5965b.scala b/tests/run-with-compiler/i5965b.scala index fc1fc9eb0a59..5ce1d34f94e2 100644 --- a/tests/run-with-compiler/i5965b.scala +++ b/tests/run-with-compiler/i5965b.scala @@ -9,15 +9,15 @@ object Test { '[List] val list = bound('{List(1, 2, 3)}) - println(list.show) + println(show(list)) println(run(list)) val opt = bound('{Option(4)}) - println(opt.show) + println(show(opt)) println(run(opt)) val map = bound('{Map(4 -> 1)}) - println(map.show) + println(show(map)) println(run(map)) } diff --git a/tests/run-with-compiler/i5997.scala b/tests/run-with-compiler/i5997.scala index 84bb27d0e2d5..8d187e76ec69 100644 --- a/tests/run-with-compiler/i5997.scala +++ b/tests/run-with-compiler/i5997.scala @@ -1,7 +1,8 @@ +import scala.quoted._ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) val v = '{ (if true then Some(1) else None).map(v => v+1) } - println(v.show) + println(show(v)) } } diff --git a/tests/run-with-compiler/i6270/Macro_1.scala b/tests/run-with-compiler/i6270/Macro_1.scala index a6a9020833b6..b45e55500c7b 100644 --- a/tests/run-with-compiler/i6270/Macro_1.scala +++ b/tests/run-with-compiler/i6270/Macro_1.scala @@ -7,7 +7,7 @@ object api { private def reflImpl(x: Expr[String])(implicit refl: Reflection): Expr[String] = { import refl._ - x.show(the[Context].withoutColors).toExpr + x.show.toExpr } inline def (x: => String) reflectColor : String = @@ -15,6 +15,6 @@ object api { private def reflImplColor(x: Expr[String])(implicit refl: Reflection): Expr[String] = { import refl._ - x.show(the[Context].withColors).toExpr + x.showFormatted.toExpr } } diff --git a/tests/run-with-compiler/quote-function-applied-to.scala b/tests/run-with-compiler/quote-function-applied-to.scala index 8720ff612417..a39fa0f42f81 100644 --- a/tests/run-with-compiler/quote-function-applied-to.scala +++ b/tests/run-with-compiler/quote-function-applied-to.scala @@ -3,52 +3,52 @@ import quoted._ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - println(('{ () => x(0) }).apply().show) - println(('{ (x1: Int) => x1 }).apply('{x(1)}).show) - println(('{ (x1: Int, x2: Int) => x1 + x2 }).apply('{x(1)}, '{x(2)}).show) - println(('{ (x1: Int, x2: Int, x3: Int) => x1 + x2 + x3 }).apply('{x(1)}, '{x(2)}, '{x(3)}).show) - println(('{ (x1: Int, x2: Int, x3: Int, x4: Int) => x1 + x2 + x3 + x4 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}).show) - println(('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int) => x1 + x2 + x3 + x4 + x5 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}).show) - println(('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int) => x1 + x2 + x3 + x4 + x5 + x6 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}).show) - println(('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}).show) - println(('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}).show) - println(('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}).show) - println(('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}).show) - println(('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}).show) - println(('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}).show) - println(('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}, '{x(13)}).show) - println(('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}, '{x(13)}, '{x(14)}).show) - println(('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}, '{x(13)}, '{x(14)}, '{x(15)}).show) - println(('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}, '{x(13)}, '{x(14)}, '{x(15)}, '{x(16)}).show) - println(('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}, '{x(13)}, '{x(14)}, '{x(15)}, '{x(16)}, '{x(17)}).show) - println(('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}, '{x(13)}, '{x(14)}, '{x(15)}, '{x(16)}, '{x(17)}, '{x(18)}).show) - println(('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int, x19: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18 + x19 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}, '{x(13)}, '{x(14)}, '{x(15)}, '{x(16)}, '{x(17)}, '{x(18)}, '{x(19)}).show) - println(('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int, x19: Int, x20: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18 + x19 + x20 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}, '{x(13)}, '{x(14)}, '{x(15)}, '{x(16)}, '{x(17)}, '{x(18)}, '{x(19)}, '{x(20)}).show) - println(('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int, x19: Int, x20: Int, x21: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18 + x19 + x20 + x21 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}, '{x(13)}, '{x(14)}, '{x(15)}, '{x(16)}, '{x(17)}, '{x(18)}, '{x(19)}, '{x(20)}, '{x(21)}).show) - println(('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int, x19: Int, x20: Int, x21: Int, x22: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18 + x19 + x20 + x21 + x22 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}, '{x(13)}, '{x(14)}, '{x(15)}, '{x(16)}, '{x(17)}, '{x(18)}, '{x(19)}, '{x(20)}, '{x(21)}, '{x(22)}).show) + println(show(('{ () => x(0) }).apply())) + println(show(('{ (x1: Int) => x1 }).apply('{x(1)}))) + println(show(('{ (x1: Int, x2: Int) => x1 + x2 }).apply('{x(1)}, '{x(2)}))) + println(show(('{ (x1: Int, x2: Int, x3: Int) => x1 + x2 + x3 }).apply('{x(1)}, '{x(2)}, '{x(3)}))) + println(show(('{ (x1: Int, x2: Int, x3: Int, x4: Int) => x1 + x2 + x3 + x4 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}))) + println(show(('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int) => x1 + x2 + x3 + x4 + x5 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}))) + println(show(('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int) => x1 + x2 + x3 + x4 + x5 + x6 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}))) + println(show(('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}))) + println(show(('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}))) + println(show(('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}))) + println(show(('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}))) + println(show(('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}))) + println(show(('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}))) + println(show(('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}, '{x(13)}))) + println(show(('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}, '{x(13)}, '{x(14)}))) + println(show(('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}, '{x(13)}, '{x(14)}, '{x(15)}))) + println(show(('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}, '{x(13)}, '{x(14)}, '{x(15)}, '{x(16)}))) + println(show(('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}, '{x(13)}, '{x(14)}, '{x(15)}, '{x(16)}, '{x(17)}))) + println(show(('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}, '{x(13)}, '{x(14)}, '{x(15)}, '{x(16)}, '{x(17)}, '{x(18)}))) + println(show(('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int, x19: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18 + x19 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}, '{x(13)}, '{x(14)}, '{x(15)}, '{x(16)}, '{x(17)}, '{x(18)}, '{x(19)}))) + println(show(('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int, x19: Int, x20: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18 + x19 + x20 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}, '{x(13)}, '{x(14)}, '{x(15)}, '{x(16)}, '{x(17)}, '{x(18)}, '{x(19)}, '{x(20)}))) + println(show(('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int, x19: Int, x20: Int, x21: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18 + x19 + x20 + x21 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}, '{x(13)}, '{x(14)}, '{x(15)}, '{x(16)}, '{x(17)}, '{x(18)}, '{x(19)}, '{x(20)}, '{x(21)}))) + println(show(('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int, x19: Int, x20: Int, x21: Int, x22: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18 + x19 + x20 + x21 + x22 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}, '{x(13)}, '{x(14)}, '{x(15)}, '{x(16)}, '{x(17)}, '{x(18)}, '{x(19)}, '{x(20)}, '{x(21)}, '{x(22)}))) - println(('{ given (x1: Int) => x1 }).apply('{x(1)}).show) - println(('{ given (x1: Int, x2: Int) => x1 + x2 }).apply('{x(1)}, '{x(2)}).show) - println(('{ given (x1: Int, x2: Int, x3: Int) => x1 + x2 + x3 }).apply('{x(1)}, '{x(2)}, '{x(3)}).show) - println(('{ given (x1: Int, x2: Int, x3: Int, x4: Int) => x1 + x2 + x3 + x4 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}).show) - println(('{ given (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int) => x1 + x2 + x3 + x4 + x5 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}).show) - println(('{ given (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int) => x1 + x2 + x3 + x4 + x5 + x6 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}).show) - println(('{ given (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}).show) - println(('{ given (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}).show) - println(('{ given (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}).show) - println(('{ given (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}).show) - println(('{ given (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}).show) - println(('{ given (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}).show) - println(('{ given (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}, '{x(13)}).show) - println(('{ given (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}, '{x(13)}, '{x(14)}).show) - println(('{ given (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}, '{x(13)}, '{x(14)}, '{x(15)}).show) - println(('{ given (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}, '{x(13)}, '{x(14)}, '{x(15)}, '{x(16)}).show) - println(('{ given (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}, '{x(13)}, '{x(14)}, '{x(15)}, '{x(16)}, '{x(17)}).show) - println(('{ given (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}, '{x(13)}, '{x(14)}, '{x(15)}, '{x(16)}, '{x(17)}, '{x(18)}).show) - println(('{ given (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int, x19: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18 + x19 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}, '{x(13)}, '{x(14)}, '{x(15)}, '{x(16)}, '{x(17)}, '{x(18)}, '{x(19)}).show) - println(('{ given (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int, x19: Int, x20: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18 + x19 + x20 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}, '{x(13)}, '{x(14)}, '{x(15)}, '{x(16)}, '{x(17)}, '{x(18)}, '{x(19)}, '{x(20)}).show) - println(('{ given (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int, x19: Int, x20: Int, x21: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18 + x19 + x20 + x21 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}, '{x(13)}, '{x(14)}, '{x(15)}, '{x(16)}, '{x(17)}, '{x(18)}, '{x(19)}, '{x(20)}, '{x(21)}).show) - println(('{ given (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int, x19: Int, x20: Int, x21: Int, x22: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18 + x19 + x20 + x21 + x22 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}, '{x(13)}, '{x(14)}, '{x(15)}, '{x(16)}, '{x(17)}, '{x(18)}, '{x(19)}, '{x(20)}, '{x(21)}, '{x(22)}).show) + println(show(('{ given (x1: Int) => x1 }).apply('{x(1)}))) + println(show(('{ given (x1: Int, x2: Int) => x1 + x2 }).apply('{x(1)}, '{x(2)}))) + println(show(('{ given (x1: Int, x2: Int, x3: Int) => x1 + x2 + x3 }).apply('{x(1)}, '{x(2)}, '{x(3)}))) + println(show(('{ given (x1: Int, x2: Int, x3: Int, x4: Int) => x1 + x2 + x3 + x4 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}))) + println(show(('{ given (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int) => x1 + x2 + x3 + x4 + x5 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}))) + println(show(('{ given (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int) => x1 + x2 + x3 + x4 + x5 + x6 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}))) + println(show(('{ given (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}))) + println(show(('{ given (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}))) + println(show(('{ given (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}))) + println(show(('{ given (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}))) + println(show(('{ given (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}))) + println(show(('{ given (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}))) + println(show(('{ given (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}, '{x(13)}))) + println(show(('{ given (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}, '{x(13)}, '{x(14)}))) + println(show(('{ given (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}, '{x(13)}, '{x(14)}, '{x(15)}))) + println(show(('{ given (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}, '{x(13)}, '{x(14)}, '{x(15)}, '{x(16)}))) + println(show(('{ given (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}, '{x(13)}, '{x(14)}, '{x(15)}, '{x(16)}, '{x(17)}))) + println(show(('{ given (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}, '{x(13)}, '{x(14)}, '{x(15)}, '{x(16)}, '{x(17)}, '{x(18)}))) + println(show(('{ given (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int, x19: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18 + x19 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}, '{x(13)}, '{x(14)}, '{x(15)}, '{x(16)}, '{x(17)}, '{x(18)}, '{x(19)}))) + println(show(('{ given (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int, x19: Int, x20: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18 + x19 + x20 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}, '{x(13)}, '{x(14)}, '{x(15)}, '{x(16)}, '{x(17)}, '{x(18)}, '{x(19)}, '{x(20)}))) + println(show(('{ given (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int, x19: Int, x20: Int, x21: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18 + x19 + x20 + x21 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}, '{x(13)}, '{x(14)}, '{x(15)}, '{x(16)}, '{x(17)}, '{x(18)}, '{x(19)}, '{x(20)}, '{x(21)}))) + println(show(('{ given (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int, x19: Int, x20: Int, x21: Int, x22: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18 + x19 + x20 + x21 + x22 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}, '{x(13)}, '{x(14)}, '{x(15)}, '{x(16)}, '{x(17)}, '{x(18)}, '{x(19)}, '{x(20)}, '{x(21)}, '{x(22)}))) } def x(i: Int): Int = i diff --git a/tests/run-with-compiler/quote-lib.scala b/tests/run-with-compiler/quote-lib.scala index 0db100f12028..0c5c58d21d3b 100644 --- a/tests/run-with-compiler/quote-lib.scala +++ b/tests/run-with-compiler/quote-lib.scala @@ -10,8 +10,8 @@ import liftable.Lists._ import liftable.Exprs._ object Test { - def main(args: Array[String]): Unit = { - implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + def main(args: Array[String]): Unit = run { val liftedUnit: Expr[Unit] = '{} letVal('{1})(a => '{ $a + 1 }).show @@ -36,6 +36,7 @@ object Test { list.unrolledForeach('{ (x: Int) => println(x) }).show println("quote lib ok") + '{} } } diff --git a/tests/run-with-compiler/quote-macro-in-splice/quoted_2.scala b/tests/run-with-compiler/quote-macro-in-splice/quoted_2.scala index e2625c0a9388..4182b15d1bde 100644 --- a/tests/run-with-compiler/quote-macro-in-splice/quoted_2.scala +++ b/tests/run-with-compiler/quote-macro-in-splice/quoted_2.scala @@ -12,7 +12,7 @@ object Test { '{ y + $b } } } - println(x.show) + println(show(x)) } } diff --git a/tests/run-with-compiler/quote-nested-1.scala b/tests/run-with-compiler/quote-nested-1.scala index 78b4c52e7508..84ca448bd387 100644 --- a/tests/run-with-compiler/quote-nested-1.scala +++ b/tests/run-with-compiler/quote-nested-1.scala @@ -4,6 +4,6 @@ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) val q = '{ '{3} } - println(q.show) + println(show(q)) } } diff --git a/tests/run-with-compiler/quote-nested-2.scala b/tests/run-with-compiler/quote-nested-2.scala index 6d5eca0029fd..17b2a42092f1 100644 --- a/tests/run-with-compiler/quote-nested-2.scala +++ b/tests/run-with-compiler/quote-nested-2.scala @@ -1,14 +1,14 @@ import quoted._ object Test { + def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - val q = '{ val a = '{4} '{${a}} } - println(q.show) + println(show(q)) } } diff --git a/tests/run-with-compiler/quote-nested-3.scala b/tests/run-with-compiler/quote-nested-3.scala index 827ce44d5cd2..52432ac9743f 100644 --- a/tests/run-with-compiler/quote-nested-3.scala +++ b/tests/run-with-compiler/quote-nested-3.scala @@ -1,9 +1,9 @@ import quoted._ object Test { + def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - val q = '{ type T = String val x = "foo" @@ -14,6 +14,6 @@ object Test { x } - println(q.show) + println(show(q)) } } diff --git a/tests/run-with-compiler/quote-nested-4.scala b/tests/run-with-compiler/quote-nested-4.scala index 850095f2ace3..363c8125333a 100644 --- a/tests/run-with-compiler/quote-nested-4.scala +++ b/tests/run-with-compiler/quote-nested-4.scala @@ -9,6 +9,6 @@ object Test { t } - println(q.show) + println(show(q)) } } diff --git a/tests/run-with-compiler/quote-nested-5.scala b/tests/run-with-compiler/quote-nested-5.scala index 3ba3f6a43bd1..9889fb792d71 100644 --- a/tests/run-with-compiler/quote-nested-5.scala +++ b/tests/run-with-compiler/quote-nested-5.scala @@ -12,6 +12,6 @@ object Test { } - println(q.show) + println(show(q)) } } diff --git a/tests/run-with-compiler/quote-owners-2.check b/tests/run-with-compiler/quote-owners-2.check index 847c2e2d84e1..fc038fc486a3 100644 --- a/tests/run-with-compiler/quote-owners-2.check +++ b/tests/run-with-compiler/quote-owners-2.check @@ -1,7 +1,6 @@ -3 { def ff: scala.Int = { - val a: scala.collection.immutable.List[scala.Int] = { + val a: scala.List[scala.Int] = { type T = scala.List[scala.Int] val b: T = scala.Nil.::[scala.Int](3) @@ -13,3 +12,4 @@ (ff: scala.Int) } +3 diff --git a/tests/run-with-compiler/quote-owners-2.scala b/tests/run-with-compiler/quote-owners-2.scala index 6ead29442eba..030db133a456 100644 --- a/tests/run-with-compiler/quote-owners-2.scala +++ b/tests/run-with-compiler/quote-owners-2.scala @@ -2,11 +2,11 @@ import quoted._ object Test { - def main(args: Array[String]): Unit = { - implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + def main(args: Array[String]): Unit = run { val q = f(g(Type.IntTag)) - println(run(q)) println(q.show) + '{ println($q) } } def f(t: Type[List[Int]]): Expr[Int] = '{ diff --git a/tests/run-with-compiler/quote-owners.scala b/tests/run-with-compiler/quote-owners.scala index 9811c4bcebde..66f2692e2493 100644 --- a/tests/run-with-compiler/quote-owners.scala +++ b/tests/run-with-compiler/quote-owners.scala @@ -5,7 +5,7 @@ object Test { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) val q = f println(run(q)) - println(q.show) + println(show(q)) } def f: Expr[Int] = '{ diff --git a/tests/run-with-compiler/quote-run-2.check b/tests/run-with-compiler/quote-run-2.check index 0821d5fb001e..7e9019bb7aa9 100644 --- a/tests/run-with-compiler/quote-run-2.check +++ b/tests/run-with-compiler/quote-run-2.check @@ -11,11 +11,11 @@ { val y: scala.Double = 5.0.*(5.0) y.*({ - val y$2: scala.Double = y.*(y) - y$2.*({ - val y$3: scala.Double = y$2.*(y$2) - val y$4: scala.Double = y$3.*(y$3) - y$4 + val y: scala.Double = y.*(y) + y.*({ + val y: scala.Double = y.*(y) + val y: scala.Double = y.*(y) + y }) }) } diff --git a/tests/run-with-compiler/quote-run-2.scala b/tests/run-with-compiler/quote-run-2.scala index 25e527baaafb..6c59a77c04ae 100644 --- a/tests/run-with-compiler/quote-run-2.scala +++ b/tests/run-with-compiler/quote-run-2.scala @@ -10,10 +10,10 @@ object Test { else if (n % 2 == 0) '{ { val y = $x * $x; ${powerCode(n / 2, 'y)} } } else '{ $x * ${powerCode(n - 1, x)} } - println(powerCode(0, '{5}).show) - println(powerCode(1, '{5}).show) - println(powerCode(2, '{5}).show) - println(powerCode(3, '{5}).show) - println(powerCode(22, '{5}).show) + println(show(powerCode(0, '{5}))) + println(show(powerCode(1, '{5}))) + println(show(powerCode(2, '{5}))) + println(show(powerCode(3, '{5}))) + println(show(powerCode(22, '{5}))) } } diff --git a/tests/run-with-compiler/quote-run-constants.scala b/tests/run-with-compiler/quote-run-constants.scala index b69247dcd3f8..3e715d600557 100644 --- a/tests/run-with-compiler/quote-run-constants.scala +++ b/tests/run-with-compiler/quote-run-constants.scala @@ -7,7 +7,7 @@ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) def runAndPrint[T](expr: Expr[T]): Unit = println(run(expr)) - def show[T](expr: Expr[T]): Unit = println(expr.show) + def showAndPrint[T](expr: Expr[T]): Unit = println(show(expr)) runAndPrint(true) runAndPrint('a') @@ -24,20 +24,20 @@ object Test { println("======") - show(true) - show('a') - show('\n') - show('"') - show('\'') - show('\\') - show(1) - show(2) - show(3L) - show(4.0f) - show(5.0d) - show("xyz") - show("\n\\\"'") - show("""abc + showAndPrint(true) + showAndPrint('a') + showAndPrint('\n') + showAndPrint('"') + showAndPrint('\'') + showAndPrint('\\') + showAndPrint(1) + showAndPrint(2) + showAndPrint(3L) + showAndPrint(4.0f) + showAndPrint(5.0d) + showAndPrint("xyz") + showAndPrint("\n\\\"'") + showAndPrint("""abc xyz""") } } diff --git a/tests/run-with-compiler/quote-run-large.check b/tests/run-with-compiler/quote-run-large.check deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/tests/run-with-compiler/quote-run-large.scala b/tests/run-with-compiler/quote-run-large.scala index 043f549ef05a..fc6961c741ea 100644 --- a/tests/run-with-compiler/quote-run-large.scala +++ b/tests/run-with-compiler/quote-run-large.scala @@ -1,3 +1,4 @@ +import scala.quoted._ object Test { def main(args: Array[String]): Unit = { @@ -61,6 +62,9 @@ object Test { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) assert(a.asInstanceOf[scala.internal.quoted.TastyExpr[_]].tasty.size > 1, "Test should be testing a quote with TastyExpr encoded in more than one string") - a.show // Force unpiclking of the expression + run { + a.show// Force unpiclking of the expression + '{} + } } -} \ No newline at end of file +} diff --git a/tests/run-with-compiler/quote-run-staged-interpreter.scala b/tests/run-with-compiler/quote-run-staged-interpreter.scala index e6babd0f6287..aec2f1de06d4 100644 --- a/tests/run-with-compiler/quote-run-staged-interpreter.scala +++ b/tests/run-with-compiler/quote-run-staged-interpreter.scala @@ -34,7 +34,7 @@ object Test { val res1 = '{ (x: Int) => ${compile(exp, Map("x" -> 'x), false)} } - println(res1.show) + println(show(res1)) val fn = run { res1 @@ -46,17 +46,13 @@ object Test { println("---") val res2 = compile(letExp, Map(), false) - println(res2.show) - println(run { - res2 - }) + println(show(res2)) + println(run(res2)) println("---") val res3 = compile(letExp, Map(), true) - println(res3.show) - println(run { - res3 - }) + println(show(res3)) + println(run(res3)) } } diff --git a/tests/run-with-compiler/quote-run-with-settings.scala b/tests/run-with-compiler/quote-run-with-settings.scala index a77029c9f349..6edd2ed3f5ff 100644 --- a/tests/run-with-compiler/quote-run-with-settings.scala +++ b/tests/run-with-compiler/quote-run-with-settings.scala @@ -11,7 +11,7 @@ object Test { println("foo") 2 + a } - println(expr.show) + println(show(expr)) println(run(expr)) println() diff --git a/tests/run-with-compiler/quote-run.scala b/tests/run-with-compiler/quote-run.scala index b0d4fa33702b..3ac2638e4696 100644 --- a/tests/run-with-compiler/quote-run.scala +++ b/tests/run-with-compiler/quote-run.scala @@ -10,6 +10,6 @@ object Test { } println(run(expr)) println(run(expr)) - println(expr.show) + println(show(expr)) } } diff --git a/tests/run-with-compiler/quote-show-blocks.scala b/tests/run-with-compiler/quote-show-blocks.scala index c5fb45d1ce3a..6128ac86321f 100644 --- a/tests/run-with-compiler/quote-show-blocks.scala +++ b/tests/run-with-compiler/quote-show-blocks.scala @@ -2,8 +2,8 @@ import scala.quoted._ import scala.quoted.autolift._ object Test { - def main(args: Array[String]): Unit = { - implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + def main(args: Array[String]): Unit = run { def a(n: Int, x: Expr[Unit]): Expr[Unit] = if (n == 0) x else a(n - 1, '{ println(${n}); $x }) @@ -16,6 +16,7 @@ object Test { else b(n - 1, '{ $x; println(${n}) }) println(b(5, '{}).show) + '{} } } diff --git a/tests/run-with-compiler/quote-two-captured-ref.scala b/tests/run-with-compiler/quote-two-captured-ref.scala index 79dea2f4482f..093931d9ac78 100644 --- a/tests/run-with-compiler/quote-two-captured-ref.scala +++ b/tests/run-with-compiler/quote-two-captured-ref.scala @@ -1,8 +1,8 @@ import quoted._ object Test { - def main(args: Array[String]): Unit = { - implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + def main(args: Array[String]): Unit = run { val q = '{ val x = 1 println(${ @@ -14,5 +14,6 @@ object Test { } println(q.show) + '{} } } diff --git a/tests/run-with-compiler/quote-type-tags.scala b/tests/run-with-compiler/quote-type-tags.scala index 36534c041b03..394efe9edd9d 100644 --- a/tests/run-with-compiler/quote-type-tags.scala +++ b/tests/run-with-compiler/quote-type-tags.scala @@ -1,8 +1,8 @@ import scala.quoted._ object Test { - def main(args: Array[String]): Unit = { - implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + def main(args: Array[String]): Unit = run { def asof[T: Type, U](x: Expr[T], t: Type[U]): Expr[U] = '{$x.asInstanceOf[$t]} @@ -17,5 +17,6 @@ object Test { println(asof('{5d}, '[Double]).show) println(asof('{5d}, '[Boolean]).show) // Will clearly fail at runtime but the code can be generated + '{} } } diff --git a/tests/run-with-compiler/quote-unrolled-foreach.scala b/tests/run-with-compiler/quote-unrolled-foreach.scala index 89cee178f3cd..260c6ec7dd0d 100644 --- a/tests/run-with-compiler/quote-unrolled-foreach.scala +++ b/tests/run-with-compiler/quote-unrolled-foreach.scala @@ -4,7 +4,7 @@ import scala.quoted.autolift._ object Test { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - def main(args: Array[String]): Unit = { + def main(args: Array[String]): Unit = run { val code1 = '{ (arr: Array[Int], f: Int => Unit) => ${ foreach1('arr, 'f) } } println(code1.show) println() @@ -40,7 +40,7 @@ object Test { } println(printAll(Array(1, 3, 4, 5)).show) - + '{} } def foreach1(arrRef: Expr[Array[Int]], f: Expr[Int => Unit]): Expr[Unit] = '{ diff --git a/tests/run-with-compiler/shonan-hmm-simple.scala b/tests/run-with-compiler/shonan-hmm-simple.scala index 1c486d037d1f..7d35257e630a 100644 --- a/tests/run-with-compiler/shonan-hmm-simple.scala +++ b/tests/run-with-compiler/shonan-hmm-simple.scala @@ -146,7 +146,7 @@ object Test { vec1.map(_.toExpr), vec2.map(_.toExpr) ) - println(resCode1.show) + println(show(resCode1)) println(run(resCode1)) println() @@ -161,7 +161,7 @@ object Test { ) } } - println(resCode2.show) + println(show(resCode2)) println(run(resCode2).apply(arr1, arr2)) println() @@ -170,7 +170,7 @@ object Test { vec1.map(i => Dyn(i)), vec2.map(i => Sta(i)) ).expr - println(resCode3.show) + println(show(resCode3)) println(run(resCode3)) println() @@ -186,7 +186,7 @@ object Test { } } - println(resCode4.show) + println(show(resCode4)) println(run(resCode4).apply(arr1)) println() @@ -203,7 +203,7 @@ object Test { '{Complex(${cpx.re.expr}, ${cpx.im.expr})} } } - println(resCode5.show) + println(show(resCode5)) println(run(resCode5).apply(cmpxArr1)) println() @@ -213,7 +213,7 @@ object Test { // will generate the code '{ ((arr: scala.Array[scala.Int]) => arr.apply(1).+(arr.apply(3))) } val staticVec = Vec[Int, PV[Int]](5, i => Sta((i % 2))) val code = '{(arr: Array[Int]) => ${dotIntOptExpr(Vec(5, i => Dyn('{arr(${i})})), staticVec).expr} } - println(code.show) + println(show(code)) println() } diff --git a/tests/run-with-compiler/shonan-hmm.check b/tests/run-with-compiler/shonan-hmm.check index f39b702f17ce..20bdd42fe232 100644 --- a/tests/run-with-compiler/shonan-hmm.check +++ b/tests/run-with-compiler/shonan-hmm.check @@ -1,5 +1,5 @@ Complex(0,10) -Complex(1.*(4).-(2.*(2)), 1.*(2).+(2.*(4))) +Complex(0, 1.*(2).+(2.*(4))) List(Complex(2,0), Complex(-4,4), Complex(-2,6)) ((vout: scala.Array[Complex[scala.Int]], v1: scala.Array[Complex[scala.Int]], v2: scala.Array[Complex[scala.Int]]) => { val n: scala.Int = vout.length @@ -20,10 +20,10 @@ List(25, 30, 20, 43, 44) while (i.<(n)) { vout.update(i, { var sum: scala.Int = 0 - var i$2: scala.Int = 0 - while (i$2.<(m)) { - sum = sum.+(v.apply(i$2).*(a.apply(i).apply(i$2))) - i$2 = i$2.+(1) + var i: scala.Int = 0 + while (i.<(m)) { + sum = sum.+(v.apply(i).*(a.apply(i).apply(i))) + i = i.+(1) } (sum: scala.Int) @@ -48,49 +48,49 @@ List(25, 30, 20, 43, 44) val arr: scala.Array[scala.Array[scala.Int]] = { val array: scala.Array[scala.Array[scala.Int]] = dotty.runtime.Arrays.newGenericArray[scala.Array[scala.Int]](5)(scala.reflect.ClassTag.apply[scala.Array[scala.Int]](scala.Predef.classOf[scala.Array[scala.Int]])) array.update(0, { - val array$2: scala.Array[scala.Int] = new scala.Array[scala.Int](5) - array$2.update(0, 5) - array$2.update(1, 0) - array$2.update(2, 0) - array$2.update(3, 5) - array$2.update(4, 0) - array$2 + val array: scala.Array[scala.Int] = new scala.Array[scala.Int](5) + array.update(0, 5) + array.update(1, 0) + array.update(2, 0) + array.update(3, 5) + array.update(4, 0) + array }) array.update(1, { - val array$3: scala.Array[scala.Int] = new scala.Array[scala.Int](5) - array$3.update(0, 0) - array$3.update(1, 0) - array$3.update(2, 10) - array$3.update(3, 0) - array$3.update(4, 0) - array$3 + val array: scala.Array[scala.Int] = new scala.Array[scala.Int](5) + array.update(0, 0) + array.update(1, 0) + array.update(2, 10) + array.update(3, 0) + array.update(4, 0) + array }) array.update(2, { - val array$4: scala.Array[scala.Int] = new scala.Array[scala.Int](5) - array$4.update(0, 0) - array$4.update(1, 10) - array$4.update(2, 0) - array$4.update(3, 0) - array$4.update(4, 0) - array$4 + val array: scala.Array[scala.Int] = new scala.Array[scala.Int](5) + array.update(0, 0) + array.update(1, 10) + array.update(2, 0) + array.update(3, 0) + array.update(4, 0) + array }) array.update(3, { - val array$5: scala.Array[scala.Int] = new scala.Array[scala.Int](5) - array$5.update(0, 0) - array$5.update(1, 0) - array$5.update(2, 2) - array$5.update(3, 3) - array$5.update(4, 5) - array$5 + val array: scala.Array[scala.Int] = new scala.Array[scala.Int](5) + array.update(0, 0) + array.update(1, 0) + array.update(2, 2) + array.update(3, 3) + array.update(4, 5) + array }) array.update(4, { - val array$6: scala.Array[scala.Int] = new scala.Array[scala.Int](5) - array$6.update(0, 0) - array$6.update(1, 0) - array$6.update(2, 3) - array$6.update(3, 0) - array$6.update(4, 7) - array$6 + val array: scala.Array[scala.Int] = new scala.Array[scala.Int](5) + array.update(0, 0) + array.update(1, 0) + array.update(2, 3) + array.update(3, 0) + array.update(4, 7) + array }) array } @@ -111,49 +111,49 @@ List(25, 30, 20, 43, 44) val arr: scala.Array[scala.Array[scala.Int]] = { val array: scala.Array[scala.Array[scala.Int]] = dotty.runtime.Arrays.newGenericArray[scala.Array[scala.Int]](5)(scala.reflect.ClassTag.apply[scala.Array[scala.Int]](scala.Predef.classOf[scala.Array[scala.Int]])) array.update(0, { - val array$2: scala.Array[scala.Int] = new scala.Array[scala.Int](5) - array$2.update(0, 5) - array$2.update(1, 0) - array$2.update(2, 0) - array$2.update(3, 5) - array$2.update(4, 0) - array$2 + val array: scala.Array[scala.Int] = new scala.Array[scala.Int](5) + array.update(0, 5) + array.update(1, 0) + array.update(2, 0) + array.update(3, 5) + array.update(4, 0) + array }) array.update(1, { - val array$3: scala.Array[scala.Int] = new scala.Array[scala.Int](5) - array$3.update(0, 0) - array$3.update(1, 0) - array$3.update(2, 10) - array$3.update(3, 0) - array$3.update(4, 0) - array$3 + val array: scala.Array[scala.Int] = new scala.Array[scala.Int](5) + array.update(0, 0) + array.update(1, 0) + array.update(2, 10) + array.update(3, 0) + array.update(4, 0) + array }) array.update(2, { - val array$4: scala.Array[scala.Int] = new scala.Array[scala.Int](5) - array$4.update(0, 0) - array$4.update(1, 10) - array$4.update(2, 0) - array$4.update(3, 0) - array$4.update(4, 0) - array$4 + val array: scala.Array[scala.Int] = new scala.Array[scala.Int](5) + array.update(0, 0) + array.update(1, 10) + array.update(2, 0) + array.update(3, 0) + array.update(4, 0) + array }) array.update(3, { - val array$5: scala.Array[scala.Int] = new scala.Array[scala.Int](5) - array$5.update(0, 0) - array$5.update(1, 0) - array$5.update(2, 2) - array$5.update(3, 3) - array$5.update(4, 5) - array$5 + val array: scala.Array[scala.Int] = new scala.Array[scala.Int](5) + array.update(0, 0) + array.update(1, 0) + array.update(2, 2) + array.update(3, 3) + array.update(4, 5) + array }) array.update(4, { - val array$6: scala.Array[scala.Int] = new scala.Array[scala.Int](5) - array$6.update(0, 0) - array$6.update(1, 0) - array$6.update(2, 3) - array$6.update(3, 0) - array$6.update(4, 7) - array$6 + val array: scala.Array[scala.Int] = new scala.Array[scala.Int](5) + array.update(0, 0) + array.update(1, 0) + array.update(2, 3) + array.update(3, 0) + array.update(4, 7) + array }) array } @@ -174,49 +174,49 @@ List(25, 30, 20, 43, 44) val arr: scala.Array[scala.Array[scala.Int]] = { val array: scala.Array[scala.Array[scala.Int]] = dotty.runtime.Arrays.newGenericArray[scala.Array[scala.Int]](5)(scala.reflect.ClassTag.apply[scala.Array[scala.Int]](scala.Predef.classOf[scala.Array[scala.Int]])) array.update(0, { - val array$2: scala.Array[scala.Int] = new scala.Array[scala.Int](5) - array$2.update(0, 5) - array$2.update(1, 0) - array$2.update(2, 0) - array$2.update(3, 5) - array$2.update(4, 0) - array$2 + val array: scala.Array[scala.Int] = new scala.Array[scala.Int](5) + array.update(0, 5) + array.update(1, 0) + array.update(2, 0) + array.update(3, 5) + array.update(4, 0) + array }) array.update(1, { - val array$3: scala.Array[scala.Int] = new scala.Array[scala.Int](5) - array$3.update(0, 0) - array$3.update(1, 0) - array$3.update(2, 10) - array$3.update(3, 0) - array$3.update(4, 0) - array$3 + val array: scala.Array[scala.Int] = new scala.Array[scala.Int](5) + array.update(0, 0) + array.update(1, 0) + array.update(2, 10) + array.update(3, 0) + array.update(4, 0) + array }) array.update(2, { - val array$4: scala.Array[scala.Int] = new scala.Array[scala.Int](5) - array$4.update(0, 0) - array$4.update(1, 10) - array$4.update(2, 0) - array$4.update(3, 0) - array$4.update(4, 0) - array$4 + val array: scala.Array[scala.Int] = new scala.Array[scala.Int](5) + array.update(0, 0) + array.update(1, 10) + array.update(2, 0) + array.update(3, 0) + array.update(4, 0) + array }) array.update(3, { - val array$5: scala.Array[scala.Int] = new scala.Array[scala.Int](5) - array$5.update(0, 0) - array$5.update(1, 0) - array$5.update(2, 2) - array$5.update(3, 3) - array$5.update(4, 5) - array$5 + val array: scala.Array[scala.Int] = new scala.Array[scala.Int](5) + array.update(0, 0) + array.update(1, 0) + array.update(2, 2) + array.update(3, 3) + array.update(4, 5) + array }) array.update(4, { - val array$6: scala.Array[scala.Int] = new scala.Array[scala.Int](5) - array$6.update(0, 0) - array$6.update(1, 0) - array$6.update(2, 3) - array$6.update(3, 0) - array$6.update(4, 7) - array$6 + val array: scala.Array[scala.Int] = new scala.Array[scala.Int](5) + array.update(0, 0) + array.update(1, 0) + array.update(2, 3) + array.update(3, 0) + array.update(4, 7) + array }) array } diff --git a/tests/run-with-compiler/shonan-hmm/Test.scala b/tests/run-with-compiler/shonan-hmm/Test.scala index 44849c6e3abd..227d9b837ddd 100644 --- a/tests/run-with-compiler/shonan-hmm/Test.scala +++ b/tests/run-with-compiler/shonan-hmm/Test.scala @@ -19,7 +19,7 @@ object Test { import intExprComplex._ val res = Complex('{1}, '{2}) * Complex('{4}, '{2}) - println(s"Complex(${res.re.show}, ${res.im.show})") + println(s"Complex(${run(res.re)}, ${show(res.im)})") } // { @@ -36,7 +36,7 @@ object Test { Vmults.vmult(out, arr1, arr2) println(out.toList) - println(Vmults.vmultCA.show) + println(show(Vmults.vmultCA)) val a = Array( Array( 5, 0, 0, 5, 0), @@ -54,37 +54,37 @@ object Test { println() println() - println(MVmult.mvmult_c.show) + println(show(MVmult.mvmult_c)) println() println() println() - println(MVmult.mvmult_mc(3, 2).show) + println(show(MVmult.mvmult_mc(3, 2))) println() println() println() - println(MVmult.mvmult_ac(a).show) + println(show(MVmult.mvmult_ac(a))) println() println() println() - println(MVmult.mvmult_opt(a).show) + println(show(MVmult.mvmult_opt(a))) println() println() println() - println(MVmult.mvmult_roll(a).show) + println(show(MVmult.mvmult_roll(a))) println() println() println() - println(MVmult.mvmult_let1(a).show) + println(show(MVmult.mvmult_let1(a))) println() println() println() - println(MVmult.mvmult_let(a).show) + println(show(MVmult.mvmult_let(a))) } } diff --git a/tests/run-with-compiler/tasty-extractors-constants-2/quoted_1.scala b/tests/run-with-compiler/tasty-extractors-constants-2/quoted_1.scala index d88a0f0bed63..55077f07dc48 100644 --- a/tests/run-with-compiler/tasty-extractors-constants-2/quoted_1.scala +++ b/tests/run-with-compiler/tasty-extractors-constants-2/quoted_1.scala @@ -11,20 +11,20 @@ object Macros { def impl(implicit reflect: Reflection): Expr[Unit] = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) // 2 is a lifted constant - val show1 = power(2, 3.0).show + val show1 = show(power(2, 3.0)) val run1 = run { power(2, 3.0) } // n is a lifted constant val n = 2 - val show2 = power(n, 4.0).show + val show2 = show(power(n, 4.0)) val run2 = run { power(n, 4.0) } // n is a constant in a quote - val show3 = power('{2}, 5.0).show + val show3 = show(power('{2}, 5.0)) val run3 = run { power('{2}, 5.0) } From 1d37294e2f8fa8c603ddebfa9abd72ffeaf1aba0 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Thu, 20 Jun 2019 18:03:22 +0200 Subject: [PATCH 02/12] Move SyntaxHighlight to scala.quoted --- .../dotc/tastyreflect/ReflectionImpl.scala | 7 +- .../tools/dotc/util/NameTransformer.scala | 2 +- library/src-3.x/scala/quoted/Expr.scala | 10 +- library/src-3.x/scala/quoted/Type.scala | 11 +- library/src-3.x/scala/quoted/package.scala | 2 - library/src/scala/internal/Chars.scala | 96 +++++++ library/src/scala/quoted/QuoteContext.scala | 12 +- .../scala/quoted/show/SyntaxHighlight.scala | 47 ++++ library/src/scala/quoted/show/package.scala | 7 + .../src/scala/tasty/reflect/Printers.scala | 261 +++++++++--------- library/src/scala/tasty/util/Chars.scala | 9 +- .../tasty/util/SyntaxHighlightUtils.scala | 25 -- tests/run-with-compiler/i6270/Macro_1.scala | 3 +- 13 files changed, 320 insertions(+), 172 deletions(-) create mode 100644 library/src/scala/internal/Chars.scala create mode 100644 library/src/scala/quoted/show/SyntaxHighlight.scala create mode 100644 library/src/scala/quoted/show/package.scala delete mode 100644 library/src/scala/tasty/util/SyntaxHighlightUtils.scala diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionImpl.scala index ba7eae91fdbf..a529b69ff751 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionImpl.scala @@ -4,6 +4,8 @@ import dotty.tools.dotc.ast.tpd import dotty.tools.dotc.core._ import dotty.tools.dotc.util.{SourcePosition, Spans} +import scala.quoted.show.SyntaxHighlight + object ReflectionImpl { def apply(rootContext: Contexts.Context): scala.tasty.Reflection = @@ -16,7 +18,10 @@ object ReflectionImpl { val refl = new scala.tasty.Reflection(new KernelImpl(ctx, tree.sourcePos)) val reflCtx = ctx.asInstanceOf[refl.Context] val reflTree = tree.asInstanceOf[refl.Tree] - new refl.SourceCodePrinter(ctx.settings.color.value == "always").showTree(reflTree)(reflCtx) + val syntaxHighlight = + if (ctx.settings.color.value == "always") SyntaxHighlight.ANSI + else SyntaxHighlight.plain + new refl.SourceCodePrinter(syntaxHighlight).showTree(reflTree)(reflCtx) } } diff --git a/compiler/src/dotty/tools/dotc/util/NameTransformer.scala b/compiler/src/dotty/tools/dotc/util/NameTransformer.scala index 8e88509f58b3..f66a8675d261 100644 --- a/compiler/src/dotty/tools/dotc/util/NameTransformer.scala +++ b/compiler/src/dotty/tools/dotc/util/NameTransformer.scala @@ -4,7 +4,7 @@ package util import core.Names._ import collection.mutable -import scala.tasty.util.Chars +import scala.internal.Chars import scala.annotation.internal.sharable diff --git a/library/src-3.x/scala/quoted/Expr.scala b/library/src-3.x/scala/quoted/Expr.scala index 0a2bb160595a..6ce05e4f78c2 100644 --- a/library/src-3.x/scala/quoted/Expr.scala +++ b/library/src-3.x/scala/quoted/Expr.scala @@ -2,6 +2,8 @@ package scala package quoted { + import scala.quoted.show.SyntaxHighlight + sealed abstract class Expr[+T] { /** Evaluate the contents of this expression and return the result. @@ -18,9 +20,13 @@ package quoted { import scala.internal.quoted._ implicit class ExprOps[T](expr: Expr[T]) { + /** Show a source code like representation of this expression */ - def show(implicit qctx: QuoteContext): String = qctx.show(expr, false) - def showFormatted(implicit qctx: QuoteContext): String = qctx.show(expr, true) + def show(implicit qctx: QuoteContext): String = qctx.show(expr, SyntaxHighlight.plain) + + /** Show a source code like representation of this expression */ + def show(syntaxHighlight: SyntaxHighlight)(implicit qctx: QuoteContext): String = qctx.show(expr, syntaxHighlight) + } /** Converts a tuple `(T1, ..., Tn)` to `(Expr[T1], ..., Expr[Tn])` */ diff --git a/library/src-3.x/scala/quoted/Type.scala b/library/src-3.x/scala/quoted/Type.scala index 6278ec8a82a9..e9c890da79b1 100644 --- a/library/src-3.x/scala/quoted/Type.scala +++ b/library/src-3.x/scala/quoted/Type.scala @@ -2,6 +2,7 @@ package scala package quoted { import scala.internal.quoted.TaggedType + import scala.quoted.show.SyntaxHighlight sealed abstract class Type[T <: AnyKind] { type `$splice` = T @@ -11,9 +12,13 @@ package quoted { object Type { implicit class TypeOps[T](tpe: Type[T]) { - /** Show a source code like representation of this expression */ - def show(implicit qctx: QuoteContext): String = qctx.show(tpe, false) - def showFormatted(implicit qctx: QuoteContext): String = qctx.show(tpe, true) + + /** Show a source code like representation of this type */ + def show(implicit qctx: QuoteContext): String = qctx.show(tpe, SyntaxHighlight.plain) + + /** Show a source code like representation of this type */ + def show(syntaxHighlight: SyntaxHighlight)(implicit qctx: QuoteContext): String = qctx.show(tpe, syntaxHighlight) + } implicit val UnitTag: Type[Unit] = new TaggedType[Unit] diff --git a/library/src-3.x/scala/quoted/package.scala b/library/src-3.x/scala/quoted/package.scala index 209228160b66..df8d2a5115b4 100644 --- a/library/src-3.x/scala/quoted/package.scala +++ b/library/src-3.x/scala/quoted/package.scala @@ -16,8 +16,6 @@ package object quoted { */ def run[T](expr: given QuoteContext => Expr[T]) given (toolbox: Toolbox): T = toolbox.run(expr given _) - def show[T](expr: given QuoteContext => Expr[T]) given (toolbox: Toolbox): String = run(expr.show.toExpr) - object autolift { implicit def autoToExpr[T: Liftable](x: T): Expr[T] = x.toExpr } diff --git a/library/src/scala/internal/Chars.scala b/library/src/scala/internal/Chars.scala new file mode 100644 index 000000000000..4c0ffeb24fa7 --- /dev/null +++ b/library/src/scala/internal/Chars.scala @@ -0,0 +1,96 @@ +package scala.internal + +import scala.annotation.switch +import java.lang.{Character => JCharacter} +import java.lang.Character.LETTER_NUMBER +import java.lang.Character.LOWERCASE_LETTER +import java.lang.Character.OTHER_LETTER +import java.lang.Character.TITLECASE_LETTER +import java.lang.Character.UPPERCASE_LETTER + +/** Contains constants and classifier methods for characters */ +object Chars { + + final val LF = '\u000A' + final val FF = '\u000C' + final val CR = '\u000D' + final val SU = '\u001A' + + /** Convert a character digit to an Int according to given base, + * -1 if no success + */ + def digit2int(ch: Char, base: Int): Int = { + val num = ( + if (ch <= '9') ch - '0' + else if ('a' <= ch && ch <= 'z') ch - 'a' + 10 + else if ('A' <= ch && ch <= 'Z') ch - 'A' + 10 + else -1 + ) + if (0 <= num && num < base) num else -1 + } + /** Buffer for creating '\ u XXXX' strings. */ + private[this] val char2uescapeArray = Array[Char]('\\', 'u', 0, 0, 0, 0) + + /** Convert a character to a backslash-u escape */ + def char2uescape(c: Char): String = { + @forceInline def hexChar(ch: Int): Char = + (( if (ch < 10) '0' else 'A' - 10 ) + ch).toChar + + char2uescapeArray(2) = hexChar((c >> 12) ) + char2uescapeArray(3) = hexChar((c >> 8) % 16) + char2uescapeArray(4) = hexChar((c >> 4) % 16) + char2uescapeArray(5) = hexChar((c ) % 16) + + new String(char2uescapeArray) + } + + /** Is character a line break? */ + def isLineBreakChar(c: Char): Boolean = (c: @switch) match { + case LF|FF|CR|SU => true + case _ => false + } + + /** Is character a whitespace character (but not a new line)? */ + def isWhitespace(c: Char): Boolean = + c == ' ' || c == '\t' || c == CR + + /** Can character form part of a doc comment variable $xxx? */ + def isVarPart(c: Char): Boolean = + '0' <= c && c <= '9' || 'A' <= c && c <= 'Z' || 'a' <= c && c <= 'z' + + /** Can character start an alphanumeric Scala identifier? */ + def isIdentifierStart(c: Char): Boolean = + (c == '_') || (c == '$') || JCharacter.isUnicodeIdentifierStart(c) + + /** Can character form part of an alphanumeric Scala identifier? */ + def isIdentifierPart(c: Char): Boolean = + (c == '$') || JCharacter.isUnicodeIdentifierPart(c) + + /** Is character a math or other symbol in Unicode? */ + def isSpecial(c: Char): Boolean = { + val chtp = JCharacter.getType(c) + chtp == JCharacter.MATH_SYMBOL.toInt || chtp == JCharacter.OTHER_SYMBOL.toInt + } + + def isValidJVMChar(c: Char): Boolean = + !(c == '.' || c == ';' || c =='[' || c == '/') + + def isValidJVMMethodChar(c: Char): Boolean = + !(c == '.' || c == ';' || c =='[' || c == '/' || c == '<' || c == '>') + + private final val otherLetters = Set[Char]('\u0024', '\u005F') // '$' and '_' + private final val letterGroups = { + import JCharacter._ + Set[Byte](LOWERCASE_LETTER, UPPERCASE_LETTER, OTHER_LETTER, TITLECASE_LETTER, LETTER_NUMBER) + } + def isScalaLetter(ch: Char): Boolean = letterGroups(JCharacter.getType(ch).toByte) || otherLetters(ch) + + /** Can character form part of a Scala operator name? */ + def isOperatorPart(c : Char) : Boolean = (c: @switch) match { + case '~' | '!' | '@' | '#' | '%' | + '^' | '*' | '+' | '-' | '<' | + '>' | '?' | ':' | '=' | '&' | + '|' | '/' | '\\' => true + case c => isSpecial(c) + } +} diff --git a/library/src/scala/quoted/QuoteContext.scala b/library/src/scala/quoted/QuoteContext.scala index 31667a24b2d2..f3436f86ed47 100644 --- a/library/src/scala/quoted/QuoteContext.scala +++ b/library/src/scala/quoted/QuoteContext.scala @@ -1,17 +1,17 @@ package scala.quoted +import scala.quoted.show.SyntaxHighlight + class QuoteContext(reflection: tasty.Reflection) { - def show[T](expr: Expr[T], formatted: Boolean): String = { + def show[T](expr: Expr[T], syntaxHighlight: SyntaxHighlight): String = { import reflection._ - if (formatted) expr.unseal.showFormatted - else expr.unseal.show + expr.unseal.show(syntaxHighlight) } - def show[T](tpe: Type[T], formatted: Boolean): String = { + def show[T](tpe: Type[T], syntaxHighlight: SyntaxHighlight): String = { import reflection._ - if (formatted) tpe.unseal.showFormatted - else tpe.unseal.show + tpe.unseal.show(syntaxHighlight) } } diff --git a/library/src/scala/quoted/show/SyntaxHighlight.scala b/library/src/scala/quoted/show/SyntaxHighlight.scala new file mode 100644 index 000000000000..84e4f33e46eb --- /dev/null +++ b/library/src/scala/quoted/show/SyntaxHighlight.scala @@ -0,0 +1,47 @@ +package scala.quoted.show + +trait SyntaxHighlight { + def highlightKeyword(str: String): String + def highlightTypeDef(str: String): String + def highlightLiteral(str: String): String + def highlightValDef(str: String): String + def highlightOperator(str: String): String + def highlightAnnotation(str: String): String + def highlightString(str: String): String + def highlightTripleQs: String +} + +object SyntaxHighlight { + + def ANSI: SyntaxHighlight = new SyntaxHighlight { + // Keep in sync with SyntaxHighlighting + private val NoColor = Console.RESET + private val CommentColor = Console.BLUE + private val KeywordColor = Console.YELLOW + private val ValDefColor = Console.CYAN + private val LiteralColor = Console.RED + private val StringColor = Console.GREEN + private val TypeColor = Console.MAGENTA + private val AnnotationColor = Console.MAGENTA + + def highlightKeyword(str: String): String = KeywordColor + str + NoColor + def highlightTypeDef(str: String): String = TypeColor + str + NoColor + def highlightLiteral(str: String): String = LiteralColor + str + NoColor + def highlightValDef(str: String): String = ValDefColor + str + NoColor + def highlightOperator(str: String): String = TypeColor + str + NoColor + def highlightAnnotation(str: String): String = AnnotationColor + str + NoColor + def highlightString(str: String): String = StringColor + str + NoColor + def highlightTripleQs: String = Console.RED_B + "???" + NoColor + } + + def plain: SyntaxHighlight = new SyntaxHighlight { + def highlightKeyword(str: String): String = str + def highlightTypeDef(str: String): String = str + def highlightLiteral(str: String): String = str + def highlightValDef(str: String): String = str + def highlightOperator(str: String): String = str + def highlightAnnotation(str: String): String = str + def highlightString(str: String): String = str + def highlightTripleQs: String = "???" + } +} diff --git a/library/src/scala/quoted/show/package.scala b/library/src/scala/quoted/show/package.scala new file mode 100644 index 000000000000..edb498178b8b --- /dev/null +++ b/library/src/scala/quoted/show/package.scala @@ -0,0 +1,7 @@ +package scala.quoted + +package object show { + + def apply[T](expr: given QuoteContext => Expr[T]) given (toolbox: Toolbox): String = run(expr.show.toExpr) + +} diff --git a/library/src/scala/tasty/reflect/Printers.scala b/library/src/scala/tasty/reflect/Printers.scala index 47a4a48dced5..35e74f3aaf8f 100644 --- a/library/src/scala/tasty/reflect/Printers.scala +++ b/library/src/scala/tasty/reflect/Printers.scala @@ -1,10 +1,10 @@ package scala.tasty package reflect -import scala.annotation.switch +import java.lang.Character.{LETTER_NUMBER, LOWERCASE_LETTER, OTHER_LETTER, TITLECASE_LETTER, UPPERCASE_LETTER} -import scala.tasty.util.SyntaxHighlightUtils._ -import scala.tasty.util.Chars +import scala.annotation.switch +import scala.quoted.show.SyntaxHighlight trait Printers extends Core @@ -26,75 +26,79 @@ trait Printers def showExtractors(implicit ctx: Context): String = new ExtractorsPrinter().showTree(tree) /** Shows the tree as fully typed source code */ - def show(implicit ctx: Context): String = new SourceCodePrinter(false).showTree(tree) + def show(implicit ctx: Context): String = show(SyntaxHighlight.plain) - /** Shows the tree as fully typed source code. Will print Ansi colors. */ - def showFormatted(implicit ctx: Context): String = new SourceCodePrinter(true).showTree(tree) + /** Shows the tree as fully typed source code */ + def show(syntaxHighlight: SyntaxHighlight)(implicit ctx: Context): String = + new SourceCodePrinter(syntaxHighlight).showTree(tree) } /** Adds `show` as an extension method of a `TypeOrBounds` */ implicit class TypeOrBoundsShowDeco(tpe: TypeOrBounds) { /** Shows the tree as extractors */ def showExtractors(implicit ctx: Context): String = new ExtractorsPrinter().showTypeOrBounds(tpe) - /** Shows the tree as fully typed source code. - * Will print Ansi colors if ctx.printColors is enabled. - */ - def show(implicit ctx: Context): String = new SourceCodePrinter(false).showTypeOrBounds(tpe) - /** Shows the tree as fully typed source code. Will print Ansi colors. */ - def showFormatted(implicit ctx: Context): String = new SourceCodePrinter(true).showTypeOrBounds(tpe) + /** Shows the tree as fully typed source code */ + def show(implicit ctx: Context): String = show(SyntaxHighlight.plain) + + /** Shows the tree as fully typed source code */ + def show(syntaxHighlight: SyntaxHighlight)(implicit ctx: Context): String = + new SourceCodePrinter(syntaxHighlight).showTypeOrBounds(tpe) } /** Adds `show` as an extension method of a `Pattern` */ implicit class PatternShowDeco(pattern: Pattern) { /** Shows the tree as extractors */ def showExtractors(implicit ctx: Context): String = new ExtractorsPrinter().showPattern(pattern) - /** Shows the tree as fully typed source code. - * Will print Ansi colors if ctx.printColors is enabled. - */ - def show(implicit ctx: Context): String = new SourceCodePrinter(false).showPattern(pattern) - /** Shows the tree as fully typed source code. Will print Ansi colors. */ - def showFormatted(implicit ctx: Context): String = new SourceCodePrinter(true).showPattern(pattern) + /** Shows the tree as fully typed source code */ + def show(implicit ctx: Context): String = show(SyntaxHighlight.plain) + + /** Shows the tree as fully typed source code */ + def show(syntaxHighlight: SyntaxHighlight)(implicit ctx: Context): String = + new SourceCodePrinter(syntaxHighlight).showPattern(pattern) } /** Adds `show` as an extension method of a `Constant` */ implicit class ConstantShowDeco(const: Constant) { /** Shows the tree as extractors */ def showExtractors(implicit ctx: Context): String = new ExtractorsPrinter().showConstant(const) - /** Shows the tree as fully typed source code. - * Will print Ansi colors if ctx.printColors is enabled. - */ - def show(implicit ctx: Context): String = new SourceCodePrinter(false).showConstant(const) - /** Shows the tree as fully typed source code. Will print Ansi colors. */ - def showFormatted(implicit ctx: Context): String = new SourceCodePrinter(true).showConstant(const) + /** Shows the tree as fully typed source code */ + def show(implicit ctx: Context): String = show(SyntaxHighlight.plain) + + /** Shows the tree as fully typed source code */ + def show(syntaxHighlight: SyntaxHighlight)(implicit ctx: Context): String = + new SourceCodePrinter(syntaxHighlight).showConstant(const) } /** Adds `show` as an extension method of a `Symbol` */ implicit class SymbolShowDeco(symbol: Symbol) { /** Shows the tree as extractors */ def showExtractors(implicit ctx: Context): String = new ExtractorsPrinter().showSymbol(symbol) + /** Shows the tree as fully typed source code */ - def show(implicit ctx: Context): String = new SourceCodePrinter(false).showSymbol(symbol) + def show(implicit ctx: Context): String = show(SyntaxHighlight.plain) - /** Shows the tree as fully typed source code. Will print Ansi colors. */ - def showFormatted(implicit ctx: Context): String = new SourceCodePrinter(true).showSymbol(symbol) + /** Shows the tree as fully typed source code */ + def show(syntaxHighlight: SyntaxHighlight)(implicit ctx: Context): String = + new SourceCodePrinter(syntaxHighlight).showSymbol(symbol) } /** Adds `show` as an extension method of a `Flags` */ implicit class FlagsShowDeco(flags: Flags) { /** Shows the tree as extractors */ def showExtractors(implicit ctx: Context): String = new ExtractorsPrinter().showFlags(flags) - /** Shows the tree as fully typed source code. - * Will print Ansi colors if ctx.printColors is enabled. - */ - def show(implicit ctx: Context): String = new SourceCodePrinter(false).showFlags(flags) - /** Shows the tree as fully typed source code. Will print Ansi colors. */ - def showFormatted(implicit ctx: Context): String = new SourceCodePrinter(true).showFlags(flags) + /** Shows the tree as fully typed source code */ + def show(implicit ctx: Context): String = show(SyntaxHighlight.plain) + + /** Shows the tree as fully typed source code */ + def show(syntaxHighlight: SyntaxHighlight)(implicit ctx: Context): String = + new SourceCodePrinter(syntaxHighlight).showFlags(flags) } + abstract class Printer { def showTree(tree: Tree)(implicit ctx: Context): String @@ -452,7 +456,8 @@ trait Printers } - class SourceCodePrinter(color: Boolean) extends Printer { + class SourceCodePrinter(syntaxHighlight: SyntaxHighlight) extends Printer { + import syntaxHighlight._ def showTree(tree: Tree)(implicit ctx: Context): String = (new Buffer).printTree(tree).result() @@ -578,18 +583,18 @@ trait Printers printDefAnnotations(cdef) val flags = cdef.symbol.flags - if (flags.is(Flags.Implicit)) this += highlightKeyword("implicit ", color) - if (flags.is(Flags.Sealed)) this += highlightKeyword("sealed ", color) - if (flags.is(Flags.Final) && !flags.is(Flags.Object)) this += highlightKeyword("final ", color) - if (flags.is(Flags.Case)) this += highlightKeyword("case ", color) + if (flags.is(Flags.Implicit)) this += highlightKeyword("implicit ") + if (flags.is(Flags.Sealed)) this += highlightKeyword("sealed ") + if (flags.is(Flags.Final) && !flags.is(Flags.Object)) this += highlightKeyword("final ") + if (flags.is(Flags.Case)) this += highlightKeyword("case ") if (name == "package$") { - this += highlightKeyword("package object ", color) += highlightTypeDef(cdef.symbol.owner.name.stripSuffix("$"), color) + this += highlightKeyword("package object ") += highlightTypeDef(cdef.symbol.owner.name.stripSuffix("$")) } - else if (flags.is(Flags.Object)) this += highlightKeyword("object ", color) += highlightTypeDef(name.stripSuffix("$"), color) - else if (flags.is(Flags.Trait)) this += highlightKeyword("trait ", color) += highlightTypeDef(name, color) - else if (flags.is(Flags.Abstract)) this += highlightKeyword("abstract class ", color) += highlightTypeDef(name, color) - else this += highlightKeyword("class ", color) += highlightTypeDef(name, color) + else if (flags.is(Flags.Object)) this += highlightKeyword("object ") += highlightTypeDef(name.stripSuffix("$")) + else if (flags.is(Flags.Trait)) this += highlightKeyword("trait ") += highlightTypeDef(name) + else if (flags.is(Flags.Abstract)) this += highlightKeyword("abstract class ") += highlightTypeDef(name) + else this += highlightKeyword("class ") += highlightTypeDef(name) val typeParams = stats.collect { case IsTypeDef(targ) => targ }.filter(_.symbol.isTypeParam).zip(targs) if (!flags.is(Flags.Object)) { @@ -606,7 +611,7 @@ trait Printers case _ => true } if (parents1.nonEmpty) - this += highlightKeyword(" extends ", color) + this += highlightKeyword(" extends ") def printParent(parent: Tree /* Term | TypeTree */, needEmptyParens: Boolean = false): Unit = parent match { case IsTypeTree(parent) => @@ -632,13 +637,13 @@ trait Printers case x :: Nil => printParent(x) case x :: xs => printParent(x) - this += highlightKeyword(" with ", color) + this += highlightKeyword(" with ") printSeparated(xs) } printSeparated(parents1) if (derived.nonEmpty) { - this += highlightKeyword(" derives ", color) + this += highlightKeyword(" derives ") printTypeTrees(derived, ", ") } @@ -673,7 +678,7 @@ trait Printers val Some(ValDef(name, tpt, _)) = self indented { val name1 = if (name == "_") "this" else name - this += " " += highlightValDef(name1, color) += ": " + this += " " += highlightValDef(name1) += ": " printTypeTree(tpt)(Some(cdef.symbol)) this += " =>" } @@ -697,24 +702,24 @@ trait Printers case IsTypeDef(tdef @ TypeDef(name, rhs)) => printDefAnnotations(tdef) - this += highlightKeyword("type ", color) + this += highlightKeyword("type ") printTargDef((tdef, tdef), isMember = true) case IsValDef(vdef @ ValDef(name, tpt, rhs)) => printDefAnnotations(vdef) val flags = vdef.symbol.flags - if (flags.is(Flags.Implicit)) this += highlightKeyword("implicit ", color) - if (flags.is(Flags.Override)) this += highlightKeyword("override ", color) - if (flags.is(Flags.Final) && !flags.is(Flags.Object)) this += highlightKeyword("final ", color) + if (flags.is(Flags.Implicit)) this += highlightKeyword("implicit ") + if (flags.is(Flags.Override)) this += highlightKeyword("override ") + if (flags.is(Flags.Final) && !flags.is(Flags.Object)) this += highlightKeyword("final ") printProtectedOrPrivate(vdef) - if (flags.is(Flags.Lazy)) this += highlightKeyword("lazy ", color) - if (vdef.symbol.flags.is(Flags.Mutable)) this += highlightKeyword("var ", color) - else this += highlightKeyword("val ", color) + if (flags.is(Flags.Lazy)) this += highlightKeyword("lazy ") + if (vdef.symbol.flags.is(Flags.Mutable)) this += highlightKeyword("var ") + else this += highlightKeyword("val ") - this += highlightValDef(name, color) += ": " + this += highlightValDef(name) += ": " printTypeTree(tpt) rhs match { case Some(tree) => @@ -727,11 +732,11 @@ trait Printers case While(cond, body) => (cond, body) match { case (Block(Block(Nil, body1) :: Nil, Block(Nil, cond1)), Literal(Constant.Unit())) => - this += highlightKeyword("do ", color) - printTree(body1) += highlightKeyword(" while ", color) + this += highlightKeyword("do ") + printTree(body1) += highlightKeyword(" while ") inParens(printTree(cond1)) case _ => - this += highlightKeyword("while ", color) + this += highlightKeyword("while ") inParens(printTree(cond)) += " " printTree(body) } @@ -753,14 +758,14 @@ trait Printers val isConstructor = name == "" val flags = ddef.symbol.flags - if (flags.is(Flags.Implicit)) this += highlightKeyword("implicit ", color) - if (flags.is(Flags.Inline)) this += highlightKeyword("inline ", color) - if (flags.is(Flags.Override)) this += highlightKeyword("override ", color) - if (flags.is(Flags.Final) && !flags.is(Flags.Object)) this += highlightKeyword("final ", color) + if (flags.is(Flags.Implicit)) this += highlightKeyword("implicit ") + if (flags.is(Flags.Inline)) this += highlightKeyword("inline ") + if (flags.is(Flags.Override)) this += highlightKeyword("override ") + if (flags.is(Flags.Final) && !flags.is(Flags.Object)) this += highlightKeyword("final ") printProtectedOrPrivate(ddef) - this += highlightKeyword("def ", color) += highlightValDef((if (isConstructor) "this" else name), color) + this += highlightKeyword("def ") += highlightValDef((if (isConstructor) "this" else name)) printTargsDefs(targs.zip(targs)) val it = argss.iterator while (it.hasNext) @@ -872,12 +877,12 @@ trait Printers printTree(term) case _ => printTree(term) - this += ": " += highlightTypeDef("_*", color) + this += ": " += highlightTypeDef("_*") } case _ => inParens { printTree(term) - this += (if (Chars.isOperatorPart(sb.last)) " : " else ": ") + this += (if (scala.internal.Chars.isOperatorPart(sb.last)) " : " else ": ") def printTypeOrAnnots(tpe: Type): Unit = tpe match { case Type.AnnotatedType(tp, annot) if tp == term.tpe => printAnnotation(annot) @@ -912,32 +917,32 @@ trait Printers this case If(cond, thenp, elsep) => - this += highlightKeyword("if ", color) + this += highlightKeyword("if ") inParens(printTree(cond)) this += " " printTree(thenp) - this+= highlightKeyword(" else ", color) + this+= highlightKeyword(" else ") printTree(elsep) case Match(selector, cases) => printQualTree(selector) - this += highlightKeyword(" match", color) + this += highlightKeyword(" match") inBlock(printCases(cases, lineBreak())) case ImpliedMatch(cases) => - this += highlightKeyword("delegate match", color) + this += highlightKeyword("delegate match") inBlock(printCases(cases, lineBreak())) case Try(body, cases, finallyOpt) => - this += highlightKeyword("try ", color) + this += highlightKeyword("try ") printTree(body) if (cases.nonEmpty) { - this += highlightKeyword(" catch", color) + this += highlightKeyword(" catch") inBlock(printCases(cases, lineBreak())) } finallyOpt match { case Some(t) => - this += highlightKeyword(" finally ", color) + this += highlightKeyword(" finally ") printTree(t) case None => this @@ -1188,9 +1193,9 @@ trait Printers if (isDef) { if (argDef.symbol.flags.is(Flags.Covariant)) { - this += highlightValDef("+", color) + this += highlightValDef("+") } else if (argDef.symbol.flags.is(Flags.Contravariant)) { - this += highlightValDef("-", color) + this += highlightValDef("-") } } @@ -1286,19 +1291,19 @@ trait Printers printedPrefix = true } printedPrefix |= printProtectedOrPrivate(vdef) - if (vdef.symbol.flags.is(Flags.Mutable)) this += highlightValDef("var ", color) - else if (printedPrefix || !vdef.symbol.flags.is(Flags.CaseAcessor)) this += highlightValDef("val ", color) + if (vdef.symbol.flags.is(Flags.Mutable)) this += highlightValDef("var ") + else if (printedPrefix || !vdef.symbol.flags.is(Flags.CaseAcessor)) this += highlightValDef("val ") } } case _ => } - this += highlightValDef(name, color) += ": " + this += highlightValDef(name) += ": " printTypeTree(arg.tpt) } def printCaseDef(caseDef: CaseDef): Buffer = { - this += highlightValDef("case ", color) + this += highlightValDef("case ") printPattern(caseDef.pattern) caseDef.guard match { case Some(t) => @@ -1306,7 +1311,7 @@ trait Printers printTree(t) case None => } - this += highlightValDef(" =>", color) + this += highlightValDef(" =>") indented { caseDef.rhs match { case Block(stats, expr) => @@ -1320,9 +1325,9 @@ trait Printers } def printTypeCaseDef(caseDef: TypeCaseDef): Buffer = { - this += highlightValDef("case ", color) + this += highlightValDef("case ") printTypeTree(caseDef.pattern) - this += highlightValDef(" => ", color) + this += highlightValDef(" => ") printTypeTree(caseDef.rhs) this } @@ -1338,7 +1343,7 @@ trait Printers this += name case Pattern.Bind(name, Pattern.TypeTest(tpt)) => - this += highlightValDef(name, color) += ": " + this += highlightValDef(name) += ": " printTypeTree(tpt) case Pattern.Bind(name, pattern) => @@ -1373,22 +1378,22 @@ trait Printers } def printConstant(const: Constant): Buffer = const match { - case Constant.Unit() => this += highlightLiteral("()", color) - case Constant.Null() => this += highlightLiteral("null", color) - case Constant.Boolean(v) => this += highlightLiteral(v.toString, color) - case Constant.Byte(v) => this += highlightLiteral(v.toString, color) - case Constant.Short(v) => this += highlightLiteral(v.toString, color) - case Constant.Int(v) => this += highlightLiteral(v.toString, color) - case Constant.Long(v) => this += highlightLiteral(v.toString + "L", color) - case Constant.Float(v) => this += highlightLiteral(v.toString + "f", color) - case Constant.Double(v) => this += highlightLiteral(v.toString, color) - case Constant.Char(v) => this += highlightString('\'' + escapedChar(v) + '\'', color) - case Constant.String(v) => this += highlightString('"' + escapedString(v) + '"', color) + case Constant.Unit() => this += highlightLiteral("()") + case Constant.Null() => this += highlightLiteral("null") + case Constant.Boolean(v) => this += highlightLiteral(v.toString) + case Constant.Byte(v) => this += highlightLiteral(v.toString) + case Constant.Short(v) => this += highlightLiteral(v.toString) + case Constant.Int(v) => this += highlightLiteral(v.toString) + case Constant.Long(v) => this += highlightLiteral(v.toString + "L") + case Constant.Float(v) => this += highlightLiteral(v.toString + "f") + case Constant.Double(v) => this += highlightLiteral(v.toString) + case Constant.Char(v) => this += highlightString('\'' + escapedChar(v) + '\'') + case Constant.String(v) => this += highlightString('"' + escapedString(v) + '"') case Constant.ClassTag(v) => this += "classOf" inSquare(printType(v)) case Constant.Symbol(v) => - this += highlightLiteral("'" + v.name, color) + this += highlightLiteral("'" + v.name) } def printTypeOrBoundsTree(tpt: Tree)(implicit elideThis: Option[Symbol] = None): Buffer = tpt match { @@ -1436,10 +1441,10 @@ trait Printers printType(tree.tpe) case TypeSelect(qual, name) => - printTree(qual) += "." += highlightTypeDef(name, color) + printTree(qual) += "." += highlightTypeDef(name) case Projection(qual, name) => - printTypeTree(qual) += "#" += highlightTypeDef(name, color) + printTypeTree(qual) += "#" += highlightTypeDef(name) case Singleton(ref) => printTree(ref) @@ -1462,7 +1467,7 @@ trait Printers case Types.RepeatedAnnotation() => val Types.Sequence(tp) = tpt.tpe printType(tp) - this += highlightTypeDef("*", color) + this += highlightTypeDef("*") case _ => printTypeTree(tpt) this += " " @@ -1471,20 +1476,20 @@ trait Printers case MatchTypeTree(bound, selector, cases) => printTypeTree(selector) - this += highlightKeyword(" match ", color) + this += highlightKeyword(" match ") inBlock(printTypeCases(cases, lineBreak())) case ByName(result) => - this += highlightTypeDef("=> ", color) + this += highlightTypeDef("=> ") printTypeTree(result) case LambdaTypeTree(tparams, body) => printTargsDefs(tparams.zip(tparams), isDef = false) - this += highlightTypeDef(" => ", color) + this += highlightTypeDef(" => ") printTypeOrBoundsTree(body) case TypeBind(name, _) => - this += highlightTypeDef(name, color) + this += highlightTypeDef(name) case TypeBlock(_, tpt) => printTypeTree(tpt) @@ -1537,30 +1542,30 @@ trait Printers printType(prefix) this += "." } - this += highlightTypeDef(sym.name.stripSuffix("$"), color) + this += highlightTypeDef(sym.name.stripSuffix("$")) case Type.SymRef(sym, prefix) if sym.isTerm => prefix match { case NoPrefix() | Type.ThisType(Types.EmptyPackage() | Types.RootPackage()) => - this += highlightTypeDef(sym.name, color) + this += highlightTypeDef(sym.name) case _ => printTypeOrBound(prefix) if (sym.name != "package") - this += "." += highlightTypeDef(sym.name, color) + this += "." += highlightTypeDef(sym.name) this } case Type.TermRef(name, prefix) => prefix match { case Type.ThisType(Types.EmptyPackage()) => - this += highlightTypeDef(name, color) + this += highlightTypeDef(name) case IsType(prefix) => printType(prefix) if (name != "package") - this += "." += highlightTypeDef(name, color) + this += "." += highlightTypeDef(name) this case NoPrefix() => - this += highlightTypeDef(name, color) + this += highlightTypeDef(name) } case Type.TypeRef(name, prefix) => @@ -1568,8 +1573,8 @@ trait Printers case NoPrefix() | Type.ThisType(Types.EmptyPackage()) => case IsType(prefix) => printType(prefix) += "." } - if (name.endsWith("$")) this += highlightTypeDef(name.stripSuffix("$"), color) += ".type" - else this += highlightTypeDef(name, color) + if (name.endsWith("$")) this += highlightTypeDef(name.stripSuffix("$")) += ".type" + else this += highlightTypeDef(name) case tpe @ Type.Refinement(_, _, _) => printRefinement(tpe) @@ -1593,28 +1598,28 @@ trait Printers case Type.AndType(left, right) => printType(left) - this += highlightTypeDef(" & ", color) + this += highlightTypeDef(" & ") printType(right) case Type.OrType(left, right) => printType(left) - this += highlightTypeDef(" | ", color) + this += highlightTypeDef(" | ") printType(right) case Type.MatchType(bound, scrutinee, cases) => printType(scrutinee) - this += highlightKeyword(" match ", color) + this += highlightKeyword(" match ") inBlock(printTypes(cases, lineBreak())) case Type.ByNameType(tp) => - this += highlightTypeDef(" => ", color) + this += highlightTypeDef(" => ") printType(tp) case Type.ThisType(tp) => tp match { case Type.SymRef(cdef, _) if !cdef.flags.is(Flags.Object) => printFullClassName(tp) - this += highlightTypeDef(".this", color) + this += highlightTypeDef(".this") case Type.TypeRef(name, prefix) if name.endsWith("$") => prefix match { case NoPrefix() | Type.ThisType(Types.EmptyPackage() | Types.RootPackage()) => @@ -1622,18 +1627,18 @@ trait Printers printTypeOrBound(prefix) this += "." } - this += highlightTypeDef(name.stripSuffix("$"), color) + this += highlightTypeDef(name.stripSuffix("$")) case _ => printType(tp) } case Type.SuperType(thistpe, supertpe) => printType(supertpe) - this += highlightTypeDef(".super", color) + this += highlightTypeDef(".super") case Type.TypeLambda(paramNames, tparams, body) => inSquare(printMethodicTypeParams(paramNames, tparams)) - this += highlightTypeDef(" => ", color) + this += highlightTypeDef(" => ") printTypeOrBound(body) case Type.ParamRef(lambda, idx) => @@ -1647,7 +1652,7 @@ trait Printers printType(tpe) case Type.RecursiveThis(_) => - this += highlightTypeDef("this", color) + this += highlightTypeDef("this") case Type.IsMethodType(tpe) => this += "(" @@ -1688,11 +1693,11 @@ trait Printers } def printDefinitionName(sym: Definition): Buffer = sym match { - case ValDef(name, _, _) => this += highlightValDef(name, color) - case DefDef(name, _, _, _, _) => this += highlightValDef(name, color) - case ClassDef(name, _, _, _, _, _) => this += highlightTypeDef(name.stripSuffix("$"), color) - case TypeDef(name, _) => this += highlightTypeDef(name, color) - case PackageDef(name, _) => this += highlightTypeDef(name, color) + case ValDef(name, _, _) => this += highlightValDef(name) + case DefDef(name, _, _, _, _) => this += highlightValDef(name) + case ClassDef(name, _, _, _, _, _) => this += highlightTypeDef(name.stripSuffix("$")) + case TypeDef(name, _) => this += highlightTypeDef(name) + case PackageDef(name, _) => this += highlightTypeDef(name) } def printAnnotation(annot: Term)(implicit elideThis: Option[Symbol]): Buffer = { @@ -1742,13 +1747,13 @@ trait Printers this += lineBreak() info match { case IsTypeBounds(info) => - this += highlightKeyword("type ", color) += highlightTypeDef(name, color) + this += highlightKeyword("type ") += highlightTypeDef(name) printBounds(info) case Type.ByNameType(_) | Type.MethodType(_, _, _) | Type.TypeLambda(_, _, _) => - this += highlightKeyword("def ", color) += highlightTypeDef(name, color) + this += highlightKeyword("def ") += highlightTypeDef(name) printMethodicType(info) case IsType(info) => - this += highlightKeyword("val ", color) += highlightValDef(name, color) + this += highlightKeyword("val ") += highlightValDef(name) printMethodicType(info) } } @@ -1811,7 +1816,7 @@ trait Printers case _ => printFullClassName(within) } if (definition.symbol.flags.is(Flags.Protected)) { - this += highlightKeyword("protected", color) + this += highlightKeyword("protected") definition.symbol.protectedWithin match { case Some(within) => inSquare(printWithin(within)) @@ -1821,7 +1826,7 @@ trait Printers } else { definition.symbol.privateWithin match { case Some(within) => - this += highlightKeyword("private", color) + this += highlightKeyword("private") inSquare(printWithin(within)) prefixWasPrinted = true case _ => diff --git a/library/src/scala/tasty/util/Chars.scala b/library/src/scala/tasty/util/Chars.scala index 433b94e868a7..03726485ab37 100644 --- a/library/src/scala/tasty/util/Chars.scala +++ b/library/src/scala/tasty/util/Chars.scala @@ -8,7 +8,10 @@ import java.lang.Character.OTHER_LETTER import java.lang.Character.TITLECASE_LETTER import java.lang.Character.UPPERCASE_LETTER +import scala.annotation.switch + /** Contains constants and classifier methods for characters */ +@deprecated("Use scala.internal.Chars", "0.17") object Chars { final val LF = '\u000A' @@ -17,15 +20,15 @@ object Chars { final val SU = '\u001A' /** Convert a character digit to an Int according to given base, - * -1 if no success - */ + * -1 if no success + */ def digit2int(ch: Char, base: Int): Int = { val num = ( if (ch <= '9') ch - '0' else if ('a' <= ch && ch <= 'z') ch - 'a' + 10 else if ('A' <= ch && ch <= 'Z') ch - 'A' + 10 else -1 - ) + ) if (0 <= num && num < base) num else -1 } /** Buffer for creating '\ u XXXX' strings. */ diff --git a/library/src/scala/tasty/util/SyntaxHighlightUtils.scala b/library/src/scala/tasty/util/SyntaxHighlightUtils.scala deleted file mode 100644 index d19c700a3e90..000000000000 --- a/library/src/scala/tasty/util/SyntaxHighlightUtils.scala +++ /dev/null @@ -1,25 +0,0 @@ -package scala.tasty -package util - -object SyntaxHighlightUtils { - - // Keep in sync with SyntaxHighlighting - private val NoColor = Console.RESET - private val CommentColor = Console.BLUE - private val KeywordColor = Console.YELLOW - private val ValDefColor = Console.CYAN - private val LiteralColor = Console.RED - private val StringColor = Console.GREEN - private val TypeColor = Console.MAGENTA - private val AnnotationColor = Console.MAGENTA - - def highlightKeyword(str: String, withColor: Boolean) = if (withColor) { KeywordColor + str + NoColor } else str - def highlightTypeDef(str: String, withColor: Boolean) = if (withColor) { TypeColor + str + NoColor } else str - def highlightLiteral(str: String, withColor: Boolean) = if (withColor) { LiteralColor + str + NoColor } else str - def highlightValDef(str: String, withColor: Boolean) = if (withColor) { ValDefColor + str + NoColor } else str - def highlightOperator(str: String, withColor: Boolean) = if (withColor) { TypeColor + str + NoColor } else str - def highlightAnnotation(str: String, withColor: Boolean) = if (withColor) { AnnotationColor + str + NoColor } else str - def highlightString(str: String, withColor: Boolean) = if (withColor) { StringColor + str + NoColor } else str - val tripleQs = Console.RED_B + "???" + NoColor - -} \ No newline at end of file diff --git a/tests/run-with-compiler/i6270/Macro_1.scala b/tests/run-with-compiler/i6270/Macro_1.scala index b45e55500c7b..4ffeb31078e6 100644 --- a/tests/run-with-compiler/i6270/Macro_1.scala +++ b/tests/run-with-compiler/i6270/Macro_1.scala @@ -1,4 +1,5 @@ import scala.quoted._ +import scala.quoted.show.SyntaxHighlight.ANSI import scala.tasty._ object api { @@ -15,6 +16,6 @@ object api { private def reflImplColor(x: Expr[String])(implicit refl: Reflection): Expr[String] = { import refl._ - x.showFormatted.toExpr + x.show(ANSI).toExpr } } From 5b5853a376bcce4f6188dc6fea7892970a10ff0b Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Thu, 20 Jun 2019 23:04:00 +0200 Subject: [PATCH 03/12] Remove deadcode --- .../tools/dotc/quoted/QuoteCompiler.scala | 9 ----- .../tools/dotc/quoted/QuoteDecompiler.scala | 19 ---------- .../tools/dotc/quoted/RefreshNames.scala | 38 ------------------- .../dotc/quoted/TypeCompilationUnit.scala | 11 ------ .../src/scala/tasty/reflect/Printers.scala | 2 - 5 files changed, 79 deletions(-) delete mode 100644 compiler/src/dotty/tools/dotc/quoted/QuoteDecompiler.scala delete mode 100644 compiler/src/dotty/tools/dotc/quoted/RefreshNames.scala delete mode 100644 compiler/src/dotty/tools/dotc/quoted/TypeCompilationUnit.scala diff --git a/compiler/src/dotty/tools/dotc/quoted/QuoteCompiler.scala b/compiler/src/dotty/tools/dotc/quoted/QuoteCompiler.scala index 7c6d6ea43ae8..7ed176dd24e4 100644 --- a/compiler/src/dotty/tools/dotc/quoted/QuoteCompiler.scala +++ b/compiler/src/dotty/tools/dotc/quoted/QuoteCompiler.scala @@ -54,11 +54,6 @@ class QuoteCompiler extends Compiler { else PickledQuotes.quotedExprToTree(checkValidRunExpr(exprUnit.expr.apply(new QuoteContext(ReflectionImpl(ctx))))) val source = SourceFile.virtual("", "") CompilationUnit(source, tree, forceTrees = true) - case typeUnit: TypeCompilationUnit => - assert(!putInClass) - val tree = PickledQuotes.quotedTypeToTree(typeUnit.tpe) - val source = SourceFile.virtual("", "") - CompilationUnit(source, tree, forceTrees = true) } } @@ -96,9 +91,5 @@ class QuoteCompiler extends Compiler { val units = new ExprCompilationUnit(expr) :: Nil compileUnits(units) } - def compileType(tpe: Type[_]): Unit = { - val units = new TypeCompilationUnit(tpe) :: Nil - compileUnits(units) - } } } diff --git a/compiler/src/dotty/tools/dotc/quoted/QuoteDecompiler.scala b/compiler/src/dotty/tools/dotc/quoted/QuoteDecompiler.scala deleted file mode 100644 index 431df7aba75f..000000000000 --- a/compiler/src/dotty/tools/dotc/quoted/QuoteDecompiler.scala +++ /dev/null @@ -1,19 +0,0 @@ -package dotty.tools.dotc.quoted - -import dotty.tools.dotc.ast.tpd -import dotty.tools.dotc.core.Contexts.Context -import dotty.tools.dotc.core.Phases.Phase - -/** Compiler that takes the contents of a quoted expression (or type) and outputs it's tree. */ -class QuoteDecompiler(output: tpd.Tree => Context => Unit) extends QuoteCompiler { - override def phases: List[List[Phase]] = List( - List(new QuotedFrontend(putInClass = false)), // Create class from Expr - List(new RefreshNames), - List(new QuoteTreeOutput(output)) - ) - - class QuoteTreeOutput(output: tpd.Tree => Context => Unit) extends Phase { - override def phaseName: String = "quoteOutput" - override def run(implicit ctx: Context): Unit = output(ctx.compilationUnit.tpdTree)(ctx) - } -} diff --git a/compiler/src/dotty/tools/dotc/quoted/RefreshNames.scala b/compiler/src/dotty/tools/dotc/quoted/RefreshNames.scala deleted file mode 100644 index 4b00eb00079e..000000000000 --- a/compiler/src/dotty/tools/dotc/quoted/RefreshNames.scala +++ /dev/null @@ -1,38 +0,0 @@ -package dotty.tools.dotc.quoted - -import dotty.tools.dotc.ast.tpd -import dotty.tools.dotc.core.Contexts.Context -import dotty.tools.dotc.core.DenotTransformers.SymTransformer -import dotty.tools.dotc.core.Flags._ -import dotty.tools.dotc.core.NameKinds.{NumberedInfo, UniqueName} -import dotty.tools.dotc.core.SymDenotations.SymDenotation -import dotty.tools.dotc.transform.MegaPhase.MiniPhase - -/** Refreshes local names starting from the second use of the name. Intended for readability of the pretty printed code. */ -class RefreshNames extends MiniPhase with SymTransformer { - - def phaseName: String = "RefreshNames" - - override def transformValDef(tree: tpd.ValDef)(implicit ctx: Context): tpd.Tree = - tpd.ValDef(tree.symbol.asTerm, tree.rhs) - - override def transformDefDef(tree: tpd.DefDef)(implicit ctx: Context): tpd.Tree = - tpd.DefDef(tree.symbol.asTerm, tree.rhs) - - override def transformTypeDef(tree: tpd.TypeDef)(implicit ctx: Context): tpd.Tree = { - val newTypeDef = tpd.TypeDef(tree.symbol.asType) - // keep rhs to keep `type T = ...` instead of `type T >: ... <: ...` - cpy.TypeDef(newTypeDef)(rhs = tree.rhs) - } - - def transformSym(ref: SymDenotation)(implicit ctx: Context): SymDenotation = { - if (ref.is(Package) || ref.isClass || ref.owner != ctx.owner || ref.is(Param)) ref - else { - val newName = UniqueName.fresh(ref.symbol.name.toTermName) - newName.info match { - case info: NumberedInfo if info.num == 1 => ref // Keep the first reference as is to avoid renaming if the code has no duplicated names - case _ => ref.copySymDenotation(name = if (ref.symbol.isType) newName.toTypeName else newName) - } - } - } -} diff --git a/compiler/src/dotty/tools/dotc/quoted/TypeCompilationUnit.scala b/compiler/src/dotty/tools/dotc/quoted/TypeCompilationUnit.scala deleted file mode 100644 index 725e6e366a27..000000000000 --- a/compiler/src/dotty/tools/dotc/quoted/TypeCompilationUnit.scala +++ /dev/null @@ -1,11 +0,0 @@ -package dotty.tools.dotc.quoted - -import dotty.tools.dotc.CompilationUnit -import dotty.tools.dotc.util.NoSource - -import scala.quoted.Type - -/* Compilation unit containing the contents of a quoted type */ -class TypeCompilationUnit(val tpe: Type[_]) extends CompilationUnit(NoSource) { - override def toString: String = s"Type($tpe)" -} diff --git a/library/src/scala/tasty/reflect/Printers.scala b/library/src/scala/tasty/reflect/Printers.scala index 35e74f3aaf8f..75a473cf45c5 100644 --- a/library/src/scala/tasty/reflect/Printers.scala +++ b/library/src/scala/tasty/reflect/Printers.scala @@ -1,8 +1,6 @@ package scala.tasty package reflect -import java.lang.Character.{LETTER_NUMBER, LOWERCASE_LETTER, OTHER_LETTER, TITLECASE_LETTER, UPPERCASE_LETTER} - import scala.annotation.switch import scala.quoted.show.SyntaxHighlight From b5ccc5283e106a2e9d8c2365127b0b5b158ddc37 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Fri, 21 Jun 2019 09:59:50 +0200 Subject: [PATCH 04/12] Revert some formatting changes --- library/src/scala/tasty/util/Chars.scala | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/library/src/scala/tasty/util/Chars.scala b/library/src/scala/tasty/util/Chars.scala index 03726485ab37..795eddea4b1a 100644 --- a/library/src/scala/tasty/util/Chars.scala +++ b/library/src/scala/tasty/util/Chars.scala @@ -8,8 +8,6 @@ import java.lang.Character.OTHER_LETTER import java.lang.Character.TITLECASE_LETTER import java.lang.Character.UPPERCASE_LETTER -import scala.annotation.switch - /** Contains constants and classifier methods for characters */ @deprecated("Use scala.internal.Chars", "0.17") object Chars { @@ -20,15 +18,15 @@ object Chars { final val SU = '\u001A' /** Convert a character digit to an Int according to given base, - * -1 if no success - */ + * -1 if no success + */ def digit2int(ch: Char, base: Int): Int = { val num = ( if (ch <= '9') ch - '0' else if ('a' <= ch && ch <= 'z') ch - 'a' + 10 else if ('A' <= ch && ch <= 'Z') ch - 'A' + 10 else -1 - ) + ) if (0 <= num && num < base) num else -1 } /** Buffer for creating '\ u XXXX' strings. */ From 9531cb3690b6f371bdf4e8eea741ddf2e9dd7025 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 24 Jun 2019 13:07:05 +0200 Subject: [PATCH 05/12] Renamings --- .../tools/dotc/quoted/ExprCompilationUnit.scala | 4 ++-- .../src/dotty/tools/dotc/quoted/QuoteCompiler.scala | 12 ++++++------ .../src/dotty/tools/dotc/quoted/QuoteDriver.scala | 6 +++--- .../src/dotty/tools/dotc/quoted/ToolboxImpl.scala | 8 ++------ 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/quoted/ExprCompilationUnit.scala b/compiler/src/dotty/tools/dotc/quoted/ExprCompilationUnit.scala index 2f3de88ab401..de5d7a65cb2f 100644 --- a/compiler/src/dotty/tools/dotc/quoted/ExprCompilationUnit.scala +++ b/compiler/src/dotty/tools/dotc/quoted/ExprCompilationUnit.scala @@ -3,7 +3,7 @@ package dotty.tools.dotc.quoted import dotty.tools.dotc.CompilationUnit import dotty.tools.dotc.util.NoSource -import scala.quoted.Expr +import scala.quoted._ /* Compilation unit containing the contents of a quoted expression */ -class ExprCompilationUnit(val expr: scala.quoted.QuoteContext => Expr[_]) extends CompilationUnit(NoSource) +class ExprCompilationUnit(val exprBuilder: QuoteContext => Expr[_]) extends CompilationUnit(NoSource) diff --git a/compiler/src/dotty/tools/dotc/quoted/QuoteCompiler.scala b/compiler/src/dotty/tools/dotc/quoted/QuoteCompiler.scala index 7ed176dd24e4..1743e49d0f00 100644 --- a/compiler/src/dotty/tools/dotc/quoted/QuoteCompiler.scala +++ b/compiler/src/dotty/tools/dotc/quoted/QuoteCompiler.scala @@ -50,8 +50,8 @@ class QuoteCompiler extends Compiler { units.map { case exprUnit: ExprCompilationUnit => val tree = - if (putInClass) inClass(exprUnit.expr) - else PickledQuotes.quotedExprToTree(checkValidRunExpr(exprUnit.expr.apply(new QuoteContext(ReflectionImpl(ctx))))) + if (putInClass) inClass(exprUnit.exprBuilder) + else PickledQuotes.quotedExprToTree(checkValidRunExpr(exprUnit.exprBuilder.apply(new QuoteContext(ReflectionImpl(ctx))))) val source = SourceFile.virtual("", "") CompilationUnit(source, tree, forceTrees = true) } @@ -67,7 +67,7 @@ class QuoteCompiler extends Compiler { * with the following format. * `package __root__ { class ' { def apply: Any = } }` */ - private def inClass(expr: scala.quoted.QuoteContext => Expr[_])(implicit ctx: Context): Tree = { + private def inClass(exprBuilder: QuoteContext => Expr[_])(implicit ctx: Context): Tree = { val pos = Span(0) val assocFile = new VirtualFile("") @@ -76,7 +76,7 @@ class QuoteCompiler extends Compiler { cls.enter(ctx.newDefaultConstructor(cls), EmptyScope) val meth = ctx.newSymbol(cls, nme.apply, Method, ExprType(defn.AnyType), coord = pos).entered - val quoted = PickledQuotes.quotedExprToTree(checkValidRunExpr(expr.apply(new QuoteContext(ReflectionImpl(ctx)))))(ctx.withOwner(meth)) + val quoted = PickledQuotes.quotedExprToTree(checkValidRunExpr(exprBuilder.apply(new QuoteContext(ReflectionImpl(ctx)))))(ctx.withOwner(meth)) val run = DefDef(meth, quoted) val classTree = ClassDef(cls, DefDef(cls.primaryConstructor.asTerm), run :: Nil) @@ -87,8 +87,8 @@ class QuoteCompiler extends Compiler { } class ExprRun(comp: Compiler, ictx: Context) extends Run(comp, ictx) { - def compileExpr(expr: scala.quoted.QuoteContext => Expr[_]): Unit = { - val units = new ExprCompilationUnit(expr) :: Nil + def compileExpr(exprBuilder: QuoteContext => Expr[_]): Unit = { + val units = new ExprCompilationUnit(exprBuilder) :: Nil compileUnits(units) } } diff --git a/compiler/src/dotty/tools/dotc/quoted/QuoteDriver.scala b/compiler/src/dotty/tools/dotc/quoted/QuoteDriver.scala index f08f6ef95674..a1b0c00b83e0 100644 --- a/compiler/src/dotty/tools/dotc/quoted/QuoteDriver.scala +++ b/compiler/src/dotty/tools/dotc/quoted/QuoteDriver.scala @@ -7,7 +7,7 @@ import dotty.tools.dotc.tastyreflect.ReflectionImpl import dotty.tools.io.{AbstractFile, Directory, PlainDirectory, VirtualDirectory} import dotty.tools.repl.AbstractFileClassLoader import dotty.tools.dotc.reporting._ -import scala.quoted.{Expr, Type} +import scala.quoted._ import scala.quoted.Toolbox import java.net.URLClassLoader @@ -20,7 +20,7 @@ class QuoteDriver(appClassloader: ClassLoader) extends Driver { private[this] val contextBase: ContextBase = new ContextBase - def run[T](expr: scala.quoted.QuoteContext => Expr[T], settings: Toolbox.Settings): T = { + def run[T](exprBuilder: QuoteContext => Expr[T], settings: Toolbox.Settings): T = { val outDir: AbstractFile = settings.outDir match { case Some(out) => val dir = Directory(out) @@ -34,7 +34,7 @@ class QuoteDriver(appClassloader: ClassLoader) extends Driver { val ctx = setToolboxSettings(ctx0.fresh.setSetting(ctx0.settings.outputDir, outDir), settings) val driver = new QuoteCompiler - driver.newRun(ctx).compileExpr(expr) + driver.newRun(ctx).compileExpr(exprBuilder) assert(!ctx.reporter.hasErrors) diff --git a/compiler/src/dotty/tools/dotc/quoted/ToolboxImpl.scala b/compiler/src/dotty/tools/dotc/quoted/ToolboxImpl.scala index 3ecd82a50b25..9e2f934040ea 100644 --- a/compiler/src/dotty/tools/dotc/quoted/ToolboxImpl.scala +++ b/compiler/src/dotty/tools/dotc/quoted/ToolboxImpl.scala @@ -1,13 +1,9 @@ package dotty.tools.dotc.quoted -import dotty.tools.dotc.ast.tpd - import scala.quoted._ -import scala.internal.quoted.{LiftedExpr, TastyTreeExpr} /** Default runners for quoted expressions */ object ToolboxImpl { - import tpd._ /** Create a new instance of the toolbox using the the classloader of the application. * @@ -19,8 +15,8 @@ object ToolboxImpl { private[this] val driver: QuoteDriver = new QuoteDriver(appClassloader) - def run[T](expr: scala.quoted.QuoteContext => Expr[T]): T = synchronized { - driver.run(expr, settings) + def run[T](exprBuilder: QuoteContext => Expr[T]): T = synchronized { + driver.run(exprBuilder, settings) } } From 3d09db9e43115e0cbeadc15d3bfedadabf87f025 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 24 Jun 2019 13:32:26 +0200 Subject: [PATCH 06/12] Remove scala.quoted.show.apply and use Expr.show `scala.quoted.show.apply` was only intorduced to reduce the diff in the tests. Instead we use the equivalent `run(expr.show.toExpr)` notation explicitly. This has the added advantage of showing explicitly where new compiler runs are located. --- compiler/test-resources/repl-macros/i6007 | 3 +- library/src/scala/quoted/show/package.scala | 7 ----- .../reflect/run/position-val-def.scala | 2 +- tests/run-with-compiler/i3823-b.scala | 2 +- tests/run-with-compiler/i3823-c.scala | 2 +- tests/run-with-compiler/i3823.scala | 2 +- tests/run-with-compiler/i3847-b.scala | 2 +- tests/run-with-compiler/i3847.scala | 2 +- tests/run-with-compiler/i3876-b.scala | 2 +- tests/run-with-compiler/i3876-c.scala | 2 +- tests/run-with-compiler/i3876-d.scala | 2 +- tests/run-with-compiler/i3876-e.scala | 2 +- tests/run-with-compiler/i3876.scala | 2 +- tests/run-with-compiler/i3946.scala | 2 +- tests/run-with-compiler/i4044a.scala | 2 +- tests/run-with-compiler/i4044b.scala | 2 +- tests/run-with-compiler/i4044c.scala | 2 +- tests/run-with-compiler/i4044e.scala | 2 +- tests/run-with-compiler/i4044f.scala | 2 +- tests/run-with-compiler/i4350.scala | 4 +-- tests/run-with-compiler/i5144.scala | 2 +- tests/run-with-compiler/i5152.scala | 2 +- tests/run-with-compiler/i5161.scala | 2 +- tests/run-with-compiler/i5161b.scala | 4 +-- tests/run-with-compiler/i5247.scala | 4 +-- tests/run-with-compiler/i5965.scala | 6 ++-- tests/run-with-compiler/i5965b.scala | 6 ++-- tests/run-with-compiler/i5997.scala | 2 +- .../quote-function-applied-to.scala | 3 +- .../quote-macro-in-splice/quoted_2.scala | 2 +- tests/run-with-compiler/quote-nested-1.scala | 2 +- tests/run-with-compiler/quote-nested-2.scala | 2 +- tests/run-with-compiler/quote-nested-3.scala | 2 +- tests/run-with-compiler/quote-nested-4.scala | 2 +- tests/run-with-compiler/quote-nested-5.scala | 2 +- tests/run-with-compiler/quote-owners.scala | 2 +- tests/run-with-compiler/quote-run-2.scala | 10 +++---- .../quote-run-constants.scala | 30 +++++++++---------- .../quote-run-staged-interpreter.scala | 6 ++-- .../quote-run-with-settings.scala | 2 +- tests/run-with-compiler/quote-run.scala | 2 +- .../run-with-compiler/shonan-hmm-simple.scala | 12 ++++---- tests/run-with-compiler/shonan-hmm.check | 2 +- tests/run-with-compiler/shonan-hmm/Test.scala | 18 +++++------ .../quoted_1.scala | 18 ++++------- 45 files changed, 91 insertions(+), 102 deletions(-) delete mode 100644 library/src/scala/quoted/show/package.scala diff --git a/compiler/test-resources/repl-macros/i6007 b/compiler/test-resources/repl-macros/i6007 index 9a4bee6e7027..f65c82b3a498 100644 --- a/compiler/test-resources/repl-macros/i6007 +++ b/compiler/test-resources/repl-macros/i6007 @@ -1,8 +1,9 @@ scala> implicit def toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) def toolbox: quoted.Toolbox +scala> import scala.quoted._ scala> val v = '{ (if true then Some(1) else None).map(v => v+1) } val v: quoted.Expr[Option[Int]] = Expr() -scala> scala.quoted.show(v) +scala> scala.quoted.run(v.show.toExpr) val res0: String = (if (true) scala.Some.apply[scala.Int](1) else scala.None).map[scala.Int](((v: scala.Int) => v.+(1))) scala> scala.quoted.run(v) val res1: Option[Int] = Some(2) diff --git a/library/src/scala/quoted/show/package.scala b/library/src/scala/quoted/show/package.scala deleted file mode 100644 index edb498178b8b..000000000000 --- a/library/src/scala/quoted/show/package.scala +++ /dev/null @@ -1,7 +0,0 @@ -package scala.quoted - -package object show { - - def apply[T](expr: given QuoteContext => Expr[T]) given (toolbox: Toolbox): String = run(expr.show.toExpr) - -} diff --git a/tests/disabled/reflect/run/position-val-def.scala b/tests/disabled/reflect/run/position-val-def.scala index b79e120f746a..5191cc9db637 100644 --- a/tests/disabled/reflect/run/position-val-def.scala +++ b/tests/disabled/reflect/run/position-val-def.scala @@ -10,7 +10,7 @@ object Test { def test(expr: String): Unit = { val t = toolbox.parse(expr) println(expr) - println(show(t, printPositions = true)) + println(run(t, printPositions = true.show.toExpr)) println() } val tests = """ diff --git a/tests/run-with-compiler/i3823-b.scala b/tests/run-with-compiler/i3823-b.scala index a9b0e5aa2317..014d3b138794 100644 --- a/tests/run-with-compiler/i3823-b.scala +++ b/tests/run-with-compiler/i3823-b.scala @@ -5,6 +5,6 @@ object Test { val z: $t = $x } implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - println(show(f('{2})(Type.IntTag))) + println(run(f('{2})(Type.IntTag).show.toExpr)) } } diff --git a/tests/run-with-compiler/i3823-c.scala b/tests/run-with-compiler/i3823-c.scala index a1541e0afffc..bf678921f458 100644 --- a/tests/run-with-compiler/i3823-c.scala +++ b/tests/run-with-compiler/i3823-c.scala @@ -5,6 +5,6 @@ object Test { val z = $x } implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - println(show(f('{2})(Type.IntTag))) + println(run(f('{2})(Type.IntTag).show.toExpr)) } } diff --git a/tests/run-with-compiler/i3823.scala b/tests/run-with-compiler/i3823.scala index f7e953e1f178..2c0b66bcbda2 100644 --- a/tests/run-with-compiler/i3823.scala +++ b/tests/run-with-compiler/i3823.scala @@ -5,6 +5,6 @@ object Test { val z: $t = $x } implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - println(show(f('{2})('[Int]))) + println(run(f('{2})('[Int]).show.toExpr)) } } \ No newline at end of file diff --git a/tests/run-with-compiler/i3847-b.scala b/tests/run-with-compiler/i3847-b.scala index 43384fc0566f..617af5dec25e 100644 --- a/tests/run-with-compiler/i3847-b.scala +++ b/tests/run-with-compiler/i3847-b.scala @@ -18,6 +18,6 @@ object Test { import Arrays._ implicit val ct: Expr[ClassTag[Int]] = '{ClassTag.Int} val arr: Expr[Array[List[Int]]] = Array[List[Int]](List(1, 2, 3)).toExpr - println(show(arr)) + println(run(arr.show.toExpr)) } } \ No newline at end of file diff --git a/tests/run-with-compiler/i3847.scala b/tests/run-with-compiler/i3847.scala index d6864705603e..92a897508f53 100644 --- a/tests/run-with-compiler/i3847.scala +++ b/tests/run-with-compiler/i3847.scala @@ -18,6 +18,6 @@ object Test { import Arrays._ implicit val ct: Expr[ClassTag[Int]] = '{ClassTag.Int} val arr: Expr[Array[Int]] = Array[Int](1, 2, 3).toExpr - println(show(arr)) + println(run(arr.show.toExpr)) } } diff --git a/tests/run-with-compiler/i3876-b.scala b/tests/run-with-compiler/i3876-b.scala index a4eba0812d05..34fdf9a43b0c 100644 --- a/tests/run-with-compiler/i3876-b.scala +++ b/tests/run-with-compiler/i3876-b.scala @@ -11,6 +11,6 @@ object Test { } println(run(f2(x))) - println(show(f2(x))) + println(run(f2(x).show.toExpr)) } } diff --git a/tests/run-with-compiler/i3876-c.scala b/tests/run-with-compiler/i3876-c.scala index d8a4efe9f117..b37890c5ad10 100644 --- a/tests/run-with-compiler/i3876-c.scala +++ b/tests/run-with-compiler/i3876-c.scala @@ -11,6 +11,6 @@ object Test { } println(run(f3(x))) - println(show(f3(x))) // TODO improve printer + println(run(f3(x).show.toExpr)) // TODO improve printer } } diff --git a/tests/run-with-compiler/i3876-d.scala b/tests/run-with-compiler/i3876-d.scala index e1334115e1ea..1db04a7aecc8 100644 --- a/tests/run-with-compiler/i3876-d.scala +++ b/tests/run-with-compiler/i3876-d.scala @@ -9,7 +9,7 @@ object Test { inlineLambda } println(run(f4(x))) - println(show(f4(x))) + println(run(f4(x).show.toExpr)) } inline def inlineLambda <: Int => Int = x => x + x diff --git a/tests/run-with-compiler/i3876-e.scala b/tests/run-with-compiler/i3876-e.scala index 345d2aa6d881..a854807211a1 100644 --- a/tests/run-with-compiler/i3876-e.scala +++ b/tests/run-with-compiler/i3876-e.scala @@ -9,7 +9,7 @@ object Test { inlineLambda } println(run(f4(x))) - println(show(f4(x))) + println(run(f4(x).show.toExpr)) } inline def inlineLambda <: Int => Int = x => x + x diff --git a/tests/run-with-compiler/i3876.scala b/tests/run-with-compiler/i3876.scala index f473476b6bcb..5337bcef7170 100644 --- a/tests/run-with-compiler/i3876.scala +++ b/tests/run-with-compiler/i3876.scala @@ -8,6 +8,6 @@ object Test { val f: Expr[Int => Int] = '{ (x: Int) => x + x } println(run(f(x))) - println(show(f(x))) + println(run(f(x).show.toExpr)) } } diff --git a/tests/run-with-compiler/i3946.scala b/tests/run-with-compiler/i3946.scala index 62e90b61e6e3..cb230d6d8ba1 100644 --- a/tests/run-with-compiler/i3946.scala +++ b/tests/run-with-compiler/i3946.scala @@ -3,7 +3,7 @@ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) val u: Expr[Unit] = '{} - println(show(u)) + println(run(u.show.toExpr)) println(run(u)) } } diff --git a/tests/run-with-compiler/i4044a.scala b/tests/run-with-compiler/i4044a.scala index 4e2872967ede..3949daf3d2ac 100644 --- a/tests/run-with-compiler/i4044a.scala +++ b/tests/run-with-compiler/i4044a.scala @@ -5,7 +5,7 @@ class Foo { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) val e: Expr[Int] = '{3} val q = '{ ${ '{ $e } } } - println(show(q)) + println(run(q.show.toExpr)) } } diff --git a/tests/run-with-compiler/i4044b.scala b/tests/run-with-compiler/i4044b.scala index 7d9cc171d8aa..40b4c038bd62 100644 --- a/tests/run-with-compiler/i4044b.scala +++ b/tests/run-with-compiler/i4044b.scala @@ -22,6 +22,6 @@ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) val q = VarRef('{4})(varRef => '{ ${varRef.update('{3})}; ${varRef.expr} }) - println(show(q)) + println(run(q.show.toExpr)) } } diff --git a/tests/run-with-compiler/i4044c.scala b/tests/run-with-compiler/i4044c.scala index affdcff7eca0..7b0ea3e9bb12 100644 --- a/tests/run-with-compiler/i4044c.scala +++ b/tests/run-with-compiler/i4044c.scala @@ -4,7 +4,7 @@ class Foo { def foo: Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) val q = '{ ${ '{ ${ '{ 5 } } } } } - println(show(q)) + println(run(q.show.toExpr)) } } diff --git a/tests/run-with-compiler/i4044e.scala b/tests/run-with-compiler/i4044e.scala index f7ee8d110bbe..a4514188ea55 100644 --- a/tests/run-with-compiler/i4044e.scala +++ b/tests/run-with-compiler/i4044e.scala @@ -7,7 +7,7 @@ class Foo { val f: Expr[Int] = '{5} val t: Type[Int] = '[Int] val q = '{ ${ '{ ($e + $f).asInstanceOf[$t] } } } - println(show(q)) + println(run(q.show.toExpr)) } } diff --git a/tests/run-with-compiler/i4044f.scala b/tests/run-with-compiler/i4044f.scala index 8d2ccb0d6aa1..d98293069fe6 100644 --- a/tests/run-with-compiler/i4044f.scala +++ b/tests/run-with-compiler/i4044f.scala @@ -14,7 +14,7 @@ class Foo { foo('{e1 + $u}, '{f1}) } } - println(show(q)) + println(run(q.show.toExpr)) } } diff --git a/tests/run-with-compiler/i4350.scala b/tests/run-with-compiler/i4350.scala index d865af2e1855..3954bf7a3874 100644 --- a/tests/run-with-compiler/i4350.scala +++ b/tests/run-with-compiler/i4350.scala @@ -8,7 +8,7 @@ class Foo[T: Type] { object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - println(show((new Foo[Object]).q)) - println(show((new Foo[String]).q)) + println(run((new Foo[Object]).q.show.toExpr)) + println(run((new Foo[String]).q.show.toExpr)) } } diff --git a/tests/run-with-compiler/i5144.scala b/tests/run-with-compiler/i5144.scala index 3380ac4da830..31f5ab20abc1 100644 --- a/tests/run-with-compiler/i5144.scala +++ b/tests/run-with-compiler/i5144.scala @@ -10,7 +10,7 @@ object Test { def main(args: Array[String]): Unit = { val p = peval1() - println(show(p)) + println(run(p.show.toExpr)) } } \ No newline at end of file diff --git a/tests/run-with-compiler/i5152.scala b/tests/run-with-compiler/i5152.scala index 56a46359a6cb..552df6d5f3cd 100644 --- a/tests/run-with-compiler/i5152.scala +++ b/tests/run-with-compiler/i5152.scala @@ -10,7 +10,7 @@ object Test { def main(args: Array[String]): Unit = { val p = peval1() - println(show(p)) + println(run(p.show.toExpr)) } } diff --git a/tests/run-with-compiler/i5161.scala b/tests/run-with-compiler/i5161.scala index 6fd945a33d5c..8366907fb0fd 100644 --- a/tests/run-with-compiler/i5161.scala +++ b/tests/run-with-compiler/i5161.scala @@ -26,6 +26,6 @@ object Test { val test = Add(Int2(1), Int2(1)) val res = evalTest(test) println("run : " + run(res)) - println("show : " + show(res)) + println("show : " + run(res.show.toExpr)) } } diff --git a/tests/run-with-compiler/i5161b.scala b/tests/run-with-compiler/i5161b.scala index a27d3b0cb188..79cc28a7519b 100644 --- a/tests/run-with-compiler/i5161b.scala +++ b/tests/run-with-compiler/i5161b.scala @@ -9,9 +9,9 @@ object Test { if (x.isInstanceOf[Some[_]]) Option(1) else None } - println("show0 : " + show(res)) + println("show0 : " + run(res.show.toExpr)) println("run1 : " + run(res)) println("run2 : " + run(res)) - println("show3 : " + show(res)) + println("show3 : " + run(res.show.toExpr)) } } diff --git a/tests/run-with-compiler/i5247.scala b/tests/run-with-compiler/i5247.scala index a33afdfaf2e8..e4b63fc9070a 100644 --- a/tests/run-with-compiler/i5247.scala +++ b/tests/run-with-compiler/i5247.scala @@ -2,8 +2,8 @@ import scala.quoted._ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - println(show(foo[Object])) - println(show(bar[Object])) + println(run(foo[Object].show.toExpr)) + println(run(bar[Object].show.toExpr)) } def foo[H : Type]: Expr[H] = { val t = '[H] diff --git a/tests/run-with-compiler/i5965.scala b/tests/run-with-compiler/i5965.scala index c42d47c5af6c..52c5471d6ba8 100644 --- a/tests/run-with-compiler/i5965.scala +++ b/tests/run-with-compiler/i5965.scala @@ -8,15 +8,15 @@ object Test { def main(args: Array[String]): Unit = { '[List] val list = bound('{List(1, 2, 3)}) - println(show(list)) + println(run(list.show.toExpr)) println(run(list)) val opt = bound('{Option(4)}) - println(show(opt)) + println(run(opt.show.toExpr)) println(run(opt)) val map = bound('{Map(4 -> 1)}) - println(show(map)) + println(run(map.show.toExpr)) println(run(map)) } diff --git a/tests/run-with-compiler/i5965b.scala b/tests/run-with-compiler/i5965b.scala index 5ce1d34f94e2..e825c39e9963 100644 --- a/tests/run-with-compiler/i5965b.scala +++ b/tests/run-with-compiler/i5965b.scala @@ -9,15 +9,15 @@ object Test { '[List] val list = bound('{List(1, 2, 3)}) - println(show(list)) + println(run(list.show.toExpr)) println(run(list)) val opt = bound('{Option(4)}) - println(show(opt)) + println(run(opt.show.toExpr)) println(run(opt)) val map = bound('{Map(4 -> 1)}) - println(show(map)) + println(run(map.show.toExpr)) println(run(map)) } diff --git a/tests/run-with-compiler/i5997.scala b/tests/run-with-compiler/i5997.scala index 8d187e76ec69..96892750a4f9 100644 --- a/tests/run-with-compiler/i5997.scala +++ b/tests/run-with-compiler/i5997.scala @@ -3,6 +3,6 @@ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) val v = '{ (if true then Some(1) else None).map(v => v+1) } - println(show(v)) + println(run(v.show.toExpr)) } } diff --git a/tests/run-with-compiler/quote-function-applied-to.scala b/tests/run-with-compiler/quote-function-applied-to.scala index a39fa0f42f81..e7e60d69d6d5 100644 --- a/tests/run-with-compiler/quote-function-applied-to.scala +++ b/tests/run-with-compiler/quote-function-applied-to.scala @@ -1,8 +1,9 @@ -import quoted._ +import scala.quoted._ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + def show(expr: Expr[_]): String = run(expr.show.toExpr) println(show(('{ () => x(0) }).apply())) println(show(('{ (x1: Int) => x1 }).apply('{x(1)}))) println(show(('{ (x1: Int, x2: Int) => x1 + x2 }).apply('{x(1)}, '{x(2)}))) diff --git a/tests/run-with-compiler/quote-macro-in-splice/quoted_2.scala b/tests/run-with-compiler/quote-macro-in-splice/quoted_2.scala index 4182b15d1bde..e9a1425ad39a 100644 --- a/tests/run-with-compiler/quote-macro-in-splice/quoted_2.scala +++ b/tests/run-with-compiler/quote-macro-in-splice/quoted_2.scala @@ -12,7 +12,7 @@ object Test { '{ y + $b } } } - println(show(x)) + println(run(x.show.toExpr)) } } diff --git a/tests/run-with-compiler/quote-nested-1.scala b/tests/run-with-compiler/quote-nested-1.scala index 84ca448bd387..bc2485e0ffc2 100644 --- a/tests/run-with-compiler/quote-nested-1.scala +++ b/tests/run-with-compiler/quote-nested-1.scala @@ -4,6 +4,6 @@ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) val q = '{ '{3} } - println(show(q)) + println(run(q.show.toExpr)) } } diff --git a/tests/run-with-compiler/quote-nested-2.scala b/tests/run-with-compiler/quote-nested-2.scala index 17b2a42092f1..7e9e98a574d4 100644 --- a/tests/run-with-compiler/quote-nested-2.scala +++ b/tests/run-with-compiler/quote-nested-2.scala @@ -9,6 +9,6 @@ object Test { '{${a}} } - println(show(q)) + println(run(q.show.toExpr)) } } diff --git a/tests/run-with-compiler/quote-nested-3.scala b/tests/run-with-compiler/quote-nested-3.scala index 52432ac9743f..1468906992bd 100644 --- a/tests/run-with-compiler/quote-nested-3.scala +++ b/tests/run-with-compiler/quote-nested-3.scala @@ -14,6 +14,6 @@ object Test { x } - println(show(q)) + println(run(q.show.toExpr)) } } diff --git a/tests/run-with-compiler/quote-nested-4.scala b/tests/run-with-compiler/quote-nested-4.scala index 363c8125333a..edbb3aca8838 100644 --- a/tests/run-with-compiler/quote-nested-4.scala +++ b/tests/run-with-compiler/quote-nested-4.scala @@ -9,6 +9,6 @@ object Test { t } - println(show(q)) + println(run(q.show.toExpr)) } } diff --git a/tests/run-with-compiler/quote-nested-5.scala b/tests/run-with-compiler/quote-nested-5.scala index 9889fb792d71..8f11de1a6ae1 100644 --- a/tests/run-with-compiler/quote-nested-5.scala +++ b/tests/run-with-compiler/quote-nested-5.scala @@ -12,6 +12,6 @@ object Test { } - println(show(q)) + println(run(q.show.toExpr)) } } diff --git a/tests/run-with-compiler/quote-owners.scala b/tests/run-with-compiler/quote-owners.scala index 66f2692e2493..d538b35f7353 100644 --- a/tests/run-with-compiler/quote-owners.scala +++ b/tests/run-with-compiler/quote-owners.scala @@ -5,7 +5,7 @@ object Test { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) val q = f println(run(q)) - println(show(q)) + println(run(q.show.toExpr)) } def f: Expr[Int] = '{ diff --git a/tests/run-with-compiler/quote-run-2.scala b/tests/run-with-compiler/quote-run-2.scala index 6c59a77c04ae..6f1372012dce 100644 --- a/tests/run-with-compiler/quote-run-2.scala +++ b/tests/run-with-compiler/quote-run-2.scala @@ -10,10 +10,10 @@ object Test { else if (n % 2 == 0) '{ { val y = $x * $x; ${powerCode(n / 2, 'y)} } } else '{ $x * ${powerCode(n - 1, x)} } - println(show(powerCode(0, '{5}))) - println(show(powerCode(1, '{5}))) - println(show(powerCode(2, '{5}))) - println(show(powerCode(3, '{5}))) - println(show(powerCode(22, '{5}))) + println(run(powerCode(0, '{5}).show.toExpr)) + println(run(powerCode(1, '{5}).show.toExpr)) + println(run(powerCode(2, '{5}).show.toExpr)) + println(run(powerCode(3, '{5}).show.toExpr)) + println(run(powerCode(22, '{5}).show.toExpr)) } } diff --git a/tests/run-with-compiler/quote-run-constants.scala b/tests/run-with-compiler/quote-run-constants.scala index 3e715d600557..f07b9158af28 100644 --- a/tests/run-with-compiler/quote-run-constants.scala +++ b/tests/run-with-compiler/quote-run-constants.scala @@ -7,7 +7,7 @@ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) def runAndPrint[T](expr: Expr[T]): Unit = println(run(expr)) - def showAndPrint[T](expr: Expr[T]): Unit = println(show(expr)) + def show[T](expr: Expr[T]): Unit = println(run(expr.show.toExpr)) runAndPrint(true) runAndPrint('a') @@ -24,20 +24,20 @@ object Test { println("======") - showAndPrint(true) - showAndPrint('a') - showAndPrint('\n') - showAndPrint('"') - showAndPrint('\'') - showAndPrint('\\') - showAndPrint(1) - showAndPrint(2) - showAndPrint(3L) - showAndPrint(4.0f) - showAndPrint(5.0d) - showAndPrint("xyz") - showAndPrint("\n\\\"'") - showAndPrint("""abc + show(true) + show('a') + show('\n') + show('"') + show('\'') + show('\\') + show(1) + show(2) + show(3L) + show(4.0f) + show(5.0d) + show("xyz") + show("\n\\\"'") + show("""abc xyz""") } } diff --git a/tests/run-with-compiler/quote-run-staged-interpreter.scala b/tests/run-with-compiler/quote-run-staged-interpreter.scala index aec2f1de06d4..098280da2d6c 100644 --- a/tests/run-with-compiler/quote-run-staged-interpreter.scala +++ b/tests/run-with-compiler/quote-run-staged-interpreter.scala @@ -34,7 +34,7 @@ object Test { val res1 = '{ (x: Int) => ${compile(exp, Map("x" -> 'x), false)} } - println(show(res1)) + println(run(res1.show.toExpr)) val fn = run { res1 @@ -46,13 +46,13 @@ object Test { println("---") val res2 = compile(letExp, Map(), false) - println(show(res2)) + println(run(res2.show.toExpr)) println(run(res2)) println("---") val res3 = compile(letExp, Map(), true) - println(show(res3)) + println(run(res3.show.toExpr)) println(run(res3)) } } diff --git a/tests/run-with-compiler/quote-run-with-settings.scala b/tests/run-with-compiler/quote-run-with-settings.scala index 6edd2ed3f5ff..c0b9a70667b4 100644 --- a/tests/run-with-compiler/quote-run-with-settings.scala +++ b/tests/run-with-compiler/quote-run-with-settings.scala @@ -11,7 +11,7 @@ object Test { println("foo") 2 + a } - println(show(expr)) + println(run(expr.show.toExpr)) println(run(expr)) println() diff --git a/tests/run-with-compiler/quote-run.scala b/tests/run-with-compiler/quote-run.scala index 3ac2638e4696..ea395fe00e84 100644 --- a/tests/run-with-compiler/quote-run.scala +++ b/tests/run-with-compiler/quote-run.scala @@ -10,6 +10,6 @@ object Test { } println(run(expr)) println(run(expr)) - println(show(expr)) + println(run(expr.show.toExpr)) } } diff --git a/tests/run-with-compiler/shonan-hmm-simple.scala b/tests/run-with-compiler/shonan-hmm-simple.scala index 7d35257e630a..8f38918c58f3 100644 --- a/tests/run-with-compiler/shonan-hmm-simple.scala +++ b/tests/run-with-compiler/shonan-hmm-simple.scala @@ -146,7 +146,7 @@ object Test { vec1.map(_.toExpr), vec2.map(_.toExpr) ) - println(show(resCode1)) + println(run(resCode1.show.toExpr)) println(run(resCode1)) println() @@ -161,7 +161,7 @@ object Test { ) } } - println(show(resCode2)) + println(run(resCode2.show.toExpr)) println(run(resCode2).apply(arr1, arr2)) println() @@ -170,7 +170,7 @@ object Test { vec1.map(i => Dyn(i)), vec2.map(i => Sta(i)) ).expr - println(show(resCode3)) + println(run(resCode3.show.toExpr)) println(run(resCode3)) println() @@ -186,7 +186,7 @@ object Test { } } - println(show(resCode4)) + println(run(resCode4.show.toExpr)) println(run(resCode4).apply(arr1)) println() @@ -203,7 +203,7 @@ object Test { '{Complex(${cpx.re.expr}, ${cpx.im.expr})} } } - println(show(resCode5)) + println(run(resCode5.show.toExpr)) println(run(resCode5).apply(cmpxArr1)) println() @@ -213,7 +213,7 @@ object Test { // will generate the code '{ ((arr: scala.Array[scala.Int]) => arr.apply(1).+(arr.apply(3))) } val staticVec = Vec[Int, PV[Int]](5, i => Sta((i % 2))) val code = '{(arr: Array[Int]) => ${dotIntOptExpr(Vec(5, i => Dyn('{arr(${i})})), staticVec).expr} } - println(show(code)) + println(run(code.show.toExpr)) println() } diff --git a/tests/run-with-compiler/shonan-hmm.check b/tests/run-with-compiler/shonan-hmm.check index 20bdd42fe232..96a41ed3ed51 100644 --- a/tests/run-with-compiler/shonan-hmm.check +++ b/tests/run-with-compiler/shonan-hmm.check @@ -1,5 +1,5 @@ Complex(0,10) -Complex(0, 1.*(2).+(2.*(4))) +Complex(1.*(4).-(2.*(2)), 1.*(2).+(2.*(4))) List(Complex(2,0), Complex(-4,4), Complex(-2,6)) ((vout: scala.Array[Complex[scala.Int]], v1: scala.Array[Complex[scala.Int]], v2: scala.Array[Complex[scala.Int]]) => { val n: scala.Int = vout.length diff --git a/tests/run-with-compiler/shonan-hmm/Test.scala b/tests/run-with-compiler/shonan-hmm/Test.scala index 227d9b837ddd..7303e9b1757f 100644 --- a/tests/run-with-compiler/shonan-hmm/Test.scala +++ b/tests/run-with-compiler/shonan-hmm/Test.scala @@ -19,7 +19,7 @@ object Test { import intExprComplex._ val res = Complex('{1}, '{2}) * Complex('{4}, '{2}) - println(s"Complex(${run(res.re)}, ${show(res.im)})") + println(s"Complex(${run(res.re.show.toExpr)}, ${run(res.im.show.toExpr)})") } // { @@ -36,7 +36,7 @@ object Test { Vmults.vmult(out, arr1, arr2) println(out.toList) - println(show(Vmults.vmultCA)) + println(run(Vmults.vmultCA.show.toExpr)) val a = Array( Array( 5, 0, 0, 5, 0), @@ -54,37 +54,37 @@ object Test { println() println() - println(show(MVmult.mvmult_c)) + println(run(MVmult.mvmult_c.show.toExpr)) println() println() println() - println(show(MVmult.mvmult_mc(3, 2))) + println(run(MVmult.mvmult_mc(3, 2).show.toExpr)) println() println() println() - println(show(MVmult.mvmult_ac(a))) + println(run(MVmult.mvmult_ac(a).show.toExpr)) println() println() println() - println(show(MVmult.mvmult_opt(a))) + println(run(MVmult.mvmult_opt(a).show.toExpr)) println() println() println() - println(show(MVmult.mvmult_roll(a))) + println(run(MVmult.mvmult_roll(a).show.toExpr)) println() println() println() - println(show(MVmult.mvmult_let1(a))) + println(run(MVmult.mvmult_let1(a).show.toExpr)) println() println() println() - println(show(MVmult.mvmult_let(a))) + println(run(MVmult.mvmult_let(a).show.toExpr)) } } diff --git a/tests/run-with-compiler/tasty-extractors-constants-2/quoted_1.scala b/tests/run-with-compiler/tasty-extractors-constants-2/quoted_1.scala index 55077f07dc48..4e3b493dedef 100644 --- a/tests/run-with-compiler/tasty-extractors-constants-2/quoted_1.scala +++ b/tests/run-with-compiler/tasty-extractors-constants-2/quoted_1.scala @@ -11,23 +11,17 @@ object Macros { def impl(implicit reflect: Reflection): Expr[Unit] = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) // 2 is a lifted constant - val show1 = show(power(2, 3.0)) - val run1 = run { - power(2, 3.0) - } + val show1 = run(power(2, 3.0).show.toExpr) + val run1 = run(power(2, 3.0)) // n is a lifted constant val n = 2 - val show2 = show(power(n, 4.0)) - val run2 = run { - power(n, 4.0) - } + val show2 = run(power(n, 4.0).show.toExpr) + val run2 = run(power(n, 4.0)) // n is a constant in a quote - val show3 = show(power('{2}, 5.0)) - val run3 = run { - power('{2}, 5.0) - } + val show3 = run(power('{2}, 5.0).show.toExpr) + val run3 = run(power('{2}, 5.0)) // n2 is clearly not a constant // FIXME From 53026518b838c76a5dd3a9053883c986c5c287d9 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Wed, 26 Jun 2019 14:53:33 +0200 Subject: [PATCH 07/12] Update `scala.quoted.run` docs --- .../docs/reference/metaprogramming/staging.md | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/docs/docs/reference/metaprogramming/staging.md b/docs/docs/reference/metaprogramming/staging.md index 7e9355cc2673..7477a5151bd4 100644 --- a/docs/docs/reference/metaprogramming/staging.md +++ b/docs/docs/reference/metaprogramming/staging.md @@ -62,10 +62,9 @@ in class `Expr` called `run`. Note that `$` and `run` both map from `Expr[T]` to `T` but only `$` is subject to the PCP, whereas `run` is just a normal method. ```scala -sealed abstract class Expr[T] { - def run given (toolbox: Toolbox): T // run staged code - def show given (toolbox: Toolbox): String // show staged code -} +package scala.quoted + +def run[T](expr: given QuoteContext => Expr[T]) given (toolbox: Toolbox): T = ... ``` ## Example @@ -73,18 +72,24 @@ sealed abstract class Expr[T] { Now take exactly the same example as in [Macros](./macros.html). Assume that we do not want to pass an array statically but generated code at run-time and pass the value, also at run-time. Note, how we make a future-stage function of type -`Expr[Array[Int] => Int]` in line 4 below. Invoking the `.show` or `.run` we can +`Expr[Array[Int] => Int]` in line 4 below. Using `run { ... }` we can evaluate an +expression at runtime. Within the scope of `run` we can also invoke `show` on an expression +to get + + Invoking the `.show` or `.run` we can either show the code or run it respectivelly. ```scala // make available the necessary toolbox for runtime code generation implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) -val stagedSum: Expr[Array[Int] => Int] = '{ (arr: Array[Int]) => ${sum('arr)}} - -println(stagedSum.show) +val f: Array[Int] => Int = run { + val stagedSum: Expr[Array[Int] => Int] = '{ (arr: Array[Int]) => ${sum('arr)}} + println(stagedSum.show) // Prints "(arr: Array[Int]) => { var sum = 0; ... }" + stagedSum +} -stagedSum.run.apply(Array(1, 2, 3)) // Returns 6 +f.apply(Array(1, 2, 3)) // Returns 6 ``` Note that if we need to run the main (in an object called `Test`) after From 37413e0ae7ed63f1c22ed7e087bf951dbbda8728 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Wed, 26 Jun 2019 15:14:09 +0200 Subject: [PATCH 08/12] Remove deadcode --- compiler/src/dotty/tools/dotc/quoted/QuoteCompiler.scala | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/quoted/QuoteCompiler.scala b/compiler/src/dotty/tools/dotc/quoted/QuoteCompiler.scala index 1743e49d0f00..36cc7cbff7b9 100644 --- a/compiler/src/dotty/tools/dotc/quoted/QuoteCompiler.scala +++ b/compiler/src/dotty/tools/dotc/quoted/QuoteCompiler.scala @@ -28,7 +28,7 @@ import scala.quoted.{Expr, Type, QuoteContext} class QuoteCompiler extends Compiler { override protected def frontendPhases: List[List[Phase]] = - List(List(new QuotedFrontend(putInClass = true))) + List(List(new QuotedFrontend)) override protected def picklerPhases: List[List[Phase]] = List(List(new Staging)) @@ -41,7 +41,7 @@ class QuoteCompiler extends Compiler { def outputClassName: TypeName = "Generated$Code$From$Quoted".toTypeName /** Frontend that receives a scala.quoted.Expr or scala.quoted.Type as input */ - class QuotedFrontend(putInClass: Boolean) extends Phase { + class QuotedFrontend extends Phase { import tpd._ def phaseName: String = "quotedFrontend" @@ -49,9 +49,7 @@ class QuoteCompiler extends Compiler { override def runOn(units: List[CompilationUnit])(implicit ctx: Context): List[CompilationUnit] = { units.map { case exprUnit: ExprCompilationUnit => - val tree = - if (putInClass) inClass(exprUnit.exprBuilder) - else PickledQuotes.quotedExprToTree(checkValidRunExpr(exprUnit.exprBuilder.apply(new QuoteContext(ReflectionImpl(ctx))))) + val tree = inClass(exprUnit.exprBuilder) val source = SourceFile.virtual("", "") CompilationUnit(source, tree, forceTrees = true) } From eae993febdcbd39ffaec90d6481fd9f7258cbf82 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Wed, 26 Jun 2019 16:01:15 +0200 Subject: [PATCH 09/12] Add scala.quoted.withNewQuoteContext This provides a way to materialize a QuoteContext without calling `run` and hence performing the full compilation. It is useful if some user only wants to show or inspect an expression without evaluating it. Added a general optimization where if the expression passed to `run` is a known literal, the literal is returned directly without compiling the code. --- .../tools/dotc/quoted/QuoteCompiler.scala | 69 ++++++++++++------- .../dotty/tools/dotc/quoted/QuoteDriver.scala | 19 ++--- compiler/test-resources/repl-macros/i6007 | 3 +- .../docs/reference/metaprogramming/staging.md | 9 +-- library/src-3.x/scala/quoted/package.scala | 35 +++++++++- .../reflect/run/position-val-def.scala | 2 +- tests/run-with-compiler/i3823-b.scala | 6 +- tests/run-with-compiler/i3823-c.scala | 6 +- tests/run-with-compiler/i3823.scala | 6 +- tests/run-with-compiler/i3847-b.scala | 6 +- tests/run-with-compiler/i3847.scala | 6 +- tests/run-with-compiler/i3876-b.scala | 2 +- tests/run-with-compiler/i3876-c.scala | 2 +- tests/run-with-compiler/i3876-d.scala | 2 +- tests/run-with-compiler/i3876-e.scala | 2 +- tests/run-with-compiler/i3876.scala | 2 +- tests/run-with-compiler/i3946.scala | 2 +- tests/run-with-compiler/i4044a.scala | 2 +- tests/run-with-compiler/i4044b.scala | 2 +- tests/run-with-compiler/i4044c.scala | 2 +- tests/run-with-compiler/i4044e.scala | 2 +- tests/run-with-compiler/i4044f.scala | 2 +- tests/run-with-compiler/i4350.scala | 8 +-- tests/run-with-compiler/i5144.scala | 4 +- tests/run-with-compiler/i5152.scala | 4 +- tests/run-with-compiler/i5161.scala | 2 +- tests/run-with-compiler/i5161b.scala | 4 +- tests/run-with-compiler/i5247.scala | 8 +-- tests/run-with-compiler/i5965.scala | 6 +- tests/run-with-compiler/i5965b.scala | 6 +- tests/run-with-compiler/i5997.scala | 6 +- .../quote-function-applied-to.scala | 2 +- .../quote-macro-in-splice/quoted_2.scala | 6 +- tests/run-with-compiler/quote-nested-1.scala | 2 +- tests/run-with-compiler/quote-nested-2.scala | 2 +- tests/run-with-compiler/quote-nested-3.scala | 2 +- tests/run-with-compiler/quote-nested-4.scala | 2 +- tests/run-with-compiler/quote-nested-5.scala | 2 +- tests/run-with-compiler/quote-owners.scala | 2 +- tests/run-with-compiler/quote-run-2.scala | 14 ++-- .../quote-run-constants.scala | 34 +++++---- .../quote-run-staged-interpreter.scala | 6 +- .../quote-run-with-settings.scala | 2 +- tests/run-with-compiler/quote-run.scala | 2 +- .../run-with-compiler/shonan-hmm-simple.scala | 12 ++-- tests/run-with-compiler/shonan-hmm/Test.scala | 23 ++++--- .../quoted_1.scala | 6 +- 47 files changed, 206 insertions(+), 150 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/quoted/QuoteCompiler.scala b/compiler/src/dotty/tools/dotc/quoted/QuoteCompiler.scala index 36cc7cbff7b9..0a5ae5672c5e 100644 --- a/compiler/src/dotty/tools/dotc/quoted/QuoteCompiler.scala +++ b/compiler/src/dotty/tools/dotc/quoted/QuoteCompiler.scala @@ -20,13 +20,18 @@ import dotty.tools.dotc.util.Spans.Span import dotty.tools.dotc.util.SourceFile import dotty.tools.io.{Path, VirtualFile} -import scala.quoted.{Expr, Type, QuoteContext} +import scala.annotation.tailrec +import scala.concurrent.Promise +import scala.quoted.{Expr, QuoteContext, Type} /** Compiler that takes the contents of a quoted expression `expr` and produces * a class file with `class ' { def apply: Object = expr }`. */ class QuoteCompiler extends Compiler { + /** Either `Left` with name of the classfile generated or `Right` with the value contained in the expression */ + private[this] var result: Either[String, Any] = null + override protected def frontendPhases: List[List[Phase]] = List(List(new QuotedFrontend)) @@ -44,14 +49,36 @@ class QuoteCompiler extends Compiler { class QuotedFrontend extends Phase { import tpd._ + def phaseName: String = "quotedFrontend" override def runOn(units: List[CompilationUnit])(implicit ctx: Context): List[CompilationUnit] = { - units.map { + units.flatMap { case exprUnit: ExprCompilationUnit => - val tree = inClass(exprUnit.exprBuilder) - val source = SourceFile.virtual("", "") - CompilationUnit(source, tree, forceTrees = true) + val pos = Span(0) + val assocFile = new VirtualFile("") + + // Places the contents of expr in a compilable tree for a class with the following format. + // `package __root__ { class ' { def apply: Any = } }` + val cls = ctx.newCompleteClassSymbol(defn.RootClass, outputClassName, EmptyFlags, + defn.ObjectType :: Nil, newScope, coord = pos, assocFile = assocFile).entered.asClass + cls.enter(ctx.newDefaultConstructor(cls), EmptyScope) + val meth = ctx.newSymbol(cls, nme.apply, Method, ExprType(defn.AnyType), coord = pos).entered + + val quoted = PickledQuotes.quotedExprToTree(checkValidRunExpr(exprUnit.exprBuilder.apply(new QuoteContext(ReflectionImpl(ctx)))))(ctx.withOwner(meth)) + + getLiteral(quoted) match { + case Some(value) => + result = Right(value) + None // Stop copilation here we already have the result + case None => + val run = DefDef(meth, quoted) + val classTree = ClassDef(cls, DefDef(cls.primaryConstructor.asTerm), run :: Nil) + val tree = PackageDef(ref(defn.RootPackage).asInstanceOf[Ident], classTree :: Nil).withSpan(pos) + val source = SourceFile.virtual("", "") + result = Left(outputClassName.toString) + Some(CompilationUnit(source, tree, forceTrees = true)) + } } } @@ -61,33 +88,25 @@ class QuoteCompiler extends Compiler { case _ => expr } - /** Places the contents of expr in a compilable tree for a class - * with the following format. - * `package __root__ { class ' { def apply: Any = } }` - */ - private def inClass(exprBuilder: QuoteContext => Expr[_])(implicit ctx: Context): Tree = { - val pos = Span(0) - val assocFile = new VirtualFile("") - - val cls = ctx.newCompleteClassSymbol(defn.RootClass, outputClassName, EmptyFlags, - defn.ObjectType :: Nil, newScope, coord = pos, assocFile = assocFile).entered.asClass - cls.enter(ctx.newDefaultConstructor(cls), EmptyScope) - val meth = ctx.newSymbol(cls, nme.apply, Method, ExprType(defn.AnyType), coord = pos).entered - - val quoted = PickledQuotes.quotedExprToTree(checkValidRunExpr(exprBuilder.apply(new QuoteContext(ReflectionImpl(ctx)))))(ctx.withOwner(meth)) - - val run = DefDef(meth, quoted) - val classTree = ClassDef(cls, DefDef(cls.primaryConstructor.asTerm), run :: Nil) - PackageDef(ref(defn.RootPackage).asInstanceOf[Ident], classTree :: Nil).withSpan(pos) + /** Get the literal value if this tree only contains a literal tree */ + @tailrec private def getLiteral(tree: Tree): Option[Any] = tree match { + case Literal(lit) => Some(lit.value) + case Block(Nil, expr) => getLiteral(expr) + case Inlined(_, Nil, expr) => getLiteral(expr) + case _ => None } def run(implicit ctx: Context): Unit = unsupported("run") } - class ExprRun(comp: Compiler, ictx: Context) extends Run(comp, ictx) { - def compileExpr(exprBuilder: QuoteContext => Expr[_]): Unit = { + class ExprRun(comp: QuoteCompiler, ictx: Context) extends Run(comp, ictx) { + /** Unpickle and optionally compile the expression. + * Returns either `Left` with name of the classfile generated or `Right` with the value contained in the expression. + */ + def compileExpr(exprBuilder: QuoteContext => Expr[_]): Either[String, Any] = { val units = new ExprCompilationUnit(exprBuilder) :: Nil compileUnits(units) + result } } } diff --git a/compiler/src/dotty/tools/dotc/quoted/QuoteDriver.scala b/compiler/src/dotty/tools/dotc/quoted/QuoteDriver.scala index a1b0c00b83e0..aea4151c3969 100644 --- a/compiler/src/dotty/tools/dotc/quoted/QuoteDriver.scala +++ b/compiler/src/dotty/tools/dotc/quoted/QuoteDriver.scala @@ -33,18 +33,21 @@ class QuoteDriver(appClassloader: ClassLoader) extends Driver { val (_, ctx0: Context) = setup(settings.compilerArgs.toArray :+ "dummy.scala", initCtx.fresh) val ctx = setToolboxSettings(ctx0.fresh.setSetting(ctx0.settings.outputDir, outDir), settings) - val driver = new QuoteCompiler - driver.newRun(ctx).compileExpr(exprBuilder) + new QuoteCompiler().newRun(ctx).compileExpr(exprBuilder) match { + case Right(value) => + value.asInstanceOf[T] - assert(!ctx.reporter.hasErrors) + case Left(classname) => + assert(!ctx.reporter.hasErrors) - val classLoader = new AbstractFileClassLoader(outDir, appClassloader) + val classLoader = new AbstractFileClassLoader(outDir, appClassloader) - val clazz = classLoader.loadClass(driver.outputClassName.toString) - val method = clazz.getMethod("apply") - val inst = clazz.getConstructor().newInstance() + val clazz = classLoader.loadClass(classname) + val method = clazz.getMethod("apply") + val inst = clazz.getConstructor().newInstance() - method.invoke(inst).asInstanceOf[T] + method.invoke(inst).asInstanceOf[T] + } } override def initCtx: Context = { diff --git a/compiler/test-resources/repl-macros/i6007 b/compiler/test-resources/repl-macros/i6007 index f65c82b3a498..765c01cb57b4 100644 --- a/compiler/test-resources/repl-macros/i6007 +++ b/compiler/test-resources/repl-macros/i6007 @@ -1,9 +1,8 @@ scala> implicit def toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) def toolbox: quoted.Toolbox -scala> import scala.quoted._ scala> val v = '{ (if true then Some(1) else None).map(v => v+1) } val v: quoted.Expr[Option[Int]] = Expr() -scala> scala.quoted.run(v.show.toExpr) +scala> scala.quoted.withNewQuoteContext(v.show) val res0: String = (if (true) scala.Some.apply[scala.Int](1) else scala.None).map[scala.Int](((v: scala.Int) => v.+(1))) scala> scala.quoted.run(v) val res1: Option[Int] = Some(2) diff --git a/docs/docs/reference/metaprogramming/staging.md b/docs/docs/reference/metaprogramming/staging.md index 7477a5151bd4..3a67108a5ae7 100644 --- a/docs/docs/reference/metaprogramming/staging.md +++ b/docs/docs/reference/metaprogramming/staging.md @@ -60,11 +60,15 @@ The framework as discussed so far allows code to be staged, i.e. be prepared to be executed at a later stage. To run that code, there is another method in class `Expr` called `run`. Note that `$` and `run` both map from `Expr[T]` to `T` but only `$` is subject to the PCP, whereas `run` is just a normal method. +Run provides a `QuoteContext` that can be used to show the expression in the scope of `run`. +On the other hand `withNewQuoteContext` provides a `QuoteContext` without evauating the expression. ```scala package scala.quoted def run[T](expr: given QuoteContext => Expr[T]) given (toolbox: Toolbox): T = ... + +def withNewQuoteContext[T](thunk: given QuoteContext => T) given (toolbox: Toolbox): T = ... ``` ## Example @@ -74,10 +78,7 @@ do not want to pass an array statically but generated code at run-time and pass the value, also at run-time. Note, how we make a future-stage function of type `Expr[Array[Int] => Int]` in line 4 below. Using `run { ... }` we can evaluate an expression at runtime. Within the scope of `run` we can also invoke `show` on an expression -to get - - Invoking the `.show` or `.run` we can -either show the code or run it respectivelly. +to get a source-like representation of the expression. ```scala // make available the necessary toolbox for runtime code generation diff --git a/library/src-3.x/scala/quoted/package.scala b/library/src-3.x/scala/quoted/package.scala index df8d2a5115b4..ca9bbb1b776d 100644 --- a/library/src-3.x/scala/quoted/package.scala +++ b/library/src-3.x/scala/quoted/package.scala @@ -3,19 +3,48 @@ package scala package object quoted { /** Evaluate the contents of this expression and return the result. + * It provides a new QuoteContext that is only valid within the scope the argument. * * Usage: * ``` - * val e: T = run { - * expr + * val e: T = run { // (given qctx: QuoteContext) => + * expr * } * ``` * where `expr: Expr[T]` - * + * + * This method shoul not be called in a context where there is already has a QuoteContext. + * * May throw a FreeVariableError on expressions that came from a macro. */ def run[T](expr: given QuoteContext => Expr[T]) given (toolbox: Toolbox): T = toolbox.run(expr given _) + /** Provide a new quote context within the scope of the argument that is only valid within the scope the argument. + * Return the result of the argument. + * + * Usage: + * ``` + * val e: T = withNewQuoteContext { // (given qctx: QuoteContext) => + * thunk + * } + * ``` + * where `thunk: T` + * + * This method shoul not be called in a context where there is already has a QuoteContext. + */ + def withNewQuoteContext[T](thunk: given QuoteContext => T) given (toolbox: Toolbox): T = { + var result: T = NoResult.asInstanceOf[T] + def dummyRun given QuoteContext: Expr[Unit] = { + result = thunk + '{} + } + toolbox.run(dummyRun given _) + assert(result != NoResult) // toolbox.run should have thrown an exception + result + } + + private object NoResult + object autolift { implicit def autoToExpr[T: Liftable](x: T): Expr[T] = x.toExpr } diff --git a/tests/disabled/reflect/run/position-val-def.scala b/tests/disabled/reflect/run/position-val-def.scala index 5191cc9db637..b79e120f746a 100644 --- a/tests/disabled/reflect/run/position-val-def.scala +++ b/tests/disabled/reflect/run/position-val-def.scala @@ -10,7 +10,7 @@ object Test { def test(expr: String): Unit = { val t = toolbox.parse(expr) println(expr) - println(run(t, printPositions = true.show.toExpr)) + println(show(t, printPositions = true)) println() } val tests = """ diff --git a/tests/run-with-compiler/i3823-b.scala b/tests/run-with-compiler/i3823-b.scala index 014d3b138794..1842210ae809 100644 --- a/tests/run-with-compiler/i3823-b.scala +++ b/tests/run-with-compiler/i3823-b.scala @@ -1,10 +1,10 @@ import scala.quoted._ object Test { - def main(args: Array[String]): Unit = { + implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + def main(args: Array[String]): Unit = withNewQuoteContext { def f[T](x: Expr[T])(implicit t: Type[T]) = '{ val z: $t = $x } - implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - println(run(f('{2})(Type.IntTag).show.toExpr)) + println(f('{2})(Type.IntTag).show) } } diff --git a/tests/run-with-compiler/i3823-c.scala b/tests/run-with-compiler/i3823-c.scala index bf678921f458..ca099c595241 100644 --- a/tests/run-with-compiler/i3823-c.scala +++ b/tests/run-with-compiler/i3823-c.scala @@ -1,10 +1,10 @@ import scala.quoted._ object Test { - def main(args: Array[String]): Unit = { + implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + def main(args: Array[String]): Unit = withNewQuoteContext { def f[T](x: Expr[T])(implicit t: Type[T]) = '{ val z = $x } - implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - println(run(f('{2})(Type.IntTag).show.toExpr)) + println(f('{2})(Type.IntTag).show) } } diff --git a/tests/run-with-compiler/i3823.scala b/tests/run-with-compiler/i3823.scala index 2c0b66bcbda2..0668bfafcaba 100644 --- a/tests/run-with-compiler/i3823.scala +++ b/tests/run-with-compiler/i3823.scala @@ -1,10 +1,10 @@ import scala.quoted._ object Test { - def main(args: Array[String]): Unit = { + implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + def main(args: Array[String]): Unit = withNewQuoteContext { def f[T: Type](x: Expr[T])(t: Type[T]) = '{ val z: $t = $x } - implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - println(run(f('{2})('[Int]).show.toExpr)) + println(f('{2})('[Int]).show) } } \ No newline at end of file diff --git a/tests/run-with-compiler/i3847-b.scala b/tests/run-with-compiler/i3847-b.scala index 617af5dec25e..e9174ddb2e40 100644 --- a/tests/run-with-compiler/i3847-b.scala +++ b/tests/run-with-compiler/i3847-b.scala @@ -13,11 +13,11 @@ object Arrays { } object Test { - def main(args: Array[String]): Unit = { - implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + def main(args: Array[String]): Unit = withNewQuoteContext { import Arrays._ implicit val ct: Expr[ClassTag[Int]] = '{ClassTag.Int} val arr: Expr[Array[List[Int]]] = Array[List[Int]](List(1, 2, 3)).toExpr - println(run(arr.show.toExpr)) + println(arr.show) } } \ No newline at end of file diff --git a/tests/run-with-compiler/i3847.scala b/tests/run-with-compiler/i3847.scala index 92a897508f53..6b6d7b500702 100644 --- a/tests/run-with-compiler/i3847.scala +++ b/tests/run-with-compiler/i3847.scala @@ -13,11 +13,11 @@ object Arrays { } object Test { - def main(args: Array[String]): Unit = { - implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(this.getClass.getClassLoader) + implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(this.getClass.getClassLoader) + def main(args: Array[String]): Unit = withNewQuoteContext { import Arrays._ implicit val ct: Expr[ClassTag[Int]] = '{ClassTag.Int} val arr: Expr[Array[Int]] = Array[Int](1, 2, 3).toExpr - println(run(arr.show.toExpr)) + println(arr.show) } } diff --git a/tests/run-with-compiler/i3876-b.scala b/tests/run-with-compiler/i3876-b.scala index 34fdf9a43b0c..367918242900 100644 --- a/tests/run-with-compiler/i3876-b.scala +++ b/tests/run-with-compiler/i3876-b.scala @@ -11,6 +11,6 @@ object Test { } println(run(f2(x))) - println(run(f2(x).show.toExpr)) + println(withNewQuoteContext(f2(x).show)) } } diff --git a/tests/run-with-compiler/i3876-c.scala b/tests/run-with-compiler/i3876-c.scala index b37890c5ad10..1bccdc05fbdd 100644 --- a/tests/run-with-compiler/i3876-c.scala +++ b/tests/run-with-compiler/i3876-c.scala @@ -11,6 +11,6 @@ object Test { } println(run(f3(x))) - println(run(f3(x).show.toExpr)) // TODO improve printer + println(withNewQuoteContext(f3(x).show)) // TODO improve printer } } diff --git a/tests/run-with-compiler/i3876-d.scala b/tests/run-with-compiler/i3876-d.scala index 1db04a7aecc8..7aa0289d81cb 100644 --- a/tests/run-with-compiler/i3876-d.scala +++ b/tests/run-with-compiler/i3876-d.scala @@ -9,7 +9,7 @@ object Test { inlineLambda } println(run(f4(x))) - println(run(f4(x).show.toExpr)) + println(withNewQuoteContext(f4(x).show)) } inline def inlineLambda <: Int => Int = x => x + x diff --git a/tests/run-with-compiler/i3876-e.scala b/tests/run-with-compiler/i3876-e.scala index a854807211a1..f2745fa58d51 100644 --- a/tests/run-with-compiler/i3876-e.scala +++ b/tests/run-with-compiler/i3876-e.scala @@ -9,7 +9,7 @@ object Test { inlineLambda } println(run(f4(x))) - println(run(f4(x).show.toExpr)) + println(withNewQuoteContext(f4(x).show)) } inline def inlineLambda <: Int => Int = x => x + x diff --git a/tests/run-with-compiler/i3876.scala b/tests/run-with-compiler/i3876.scala index 5337bcef7170..41f1147817d5 100644 --- a/tests/run-with-compiler/i3876.scala +++ b/tests/run-with-compiler/i3876.scala @@ -8,6 +8,6 @@ object Test { val f: Expr[Int => Int] = '{ (x: Int) => x + x } println(run(f(x))) - println(run(f(x).show.toExpr)) + println(withNewQuoteContext(f(x).show)) } } diff --git a/tests/run-with-compiler/i3946.scala b/tests/run-with-compiler/i3946.scala index cb230d6d8ba1..e2f1b3525f98 100644 --- a/tests/run-with-compiler/i3946.scala +++ b/tests/run-with-compiler/i3946.scala @@ -3,7 +3,7 @@ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) val u: Expr[Unit] = '{} - println(run(u.show.toExpr)) + println(withNewQuoteContext(u.show)) println(run(u)) } } diff --git a/tests/run-with-compiler/i4044a.scala b/tests/run-with-compiler/i4044a.scala index 3949daf3d2ac..8ef7d14214eb 100644 --- a/tests/run-with-compiler/i4044a.scala +++ b/tests/run-with-compiler/i4044a.scala @@ -5,7 +5,7 @@ class Foo { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) val e: Expr[Int] = '{3} val q = '{ ${ '{ $e } } } - println(run(q.show.toExpr)) + println(withNewQuoteContext(q.show)) } } diff --git a/tests/run-with-compiler/i4044b.scala b/tests/run-with-compiler/i4044b.scala index 40b4c038bd62..9939526778da 100644 --- a/tests/run-with-compiler/i4044b.scala +++ b/tests/run-with-compiler/i4044b.scala @@ -22,6 +22,6 @@ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) val q = VarRef('{4})(varRef => '{ ${varRef.update('{3})}; ${varRef.expr} }) - println(run(q.show.toExpr)) + println(withNewQuoteContext(q.show)) } } diff --git a/tests/run-with-compiler/i4044c.scala b/tests/run-with-compiler/i4044c.scala index 7b0ea3e9bb12..dc975e9ee3f6 100644 --- a/tests/run-with-compiler/i4044c.scala +++ b/tests/run-with-compiler/i4044c.scala @@ -4,7 +4,7 @@ class Foo { def foo: Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) val q = '{ ${ '{ ${ '{ 5 } } } } } - println(run(q.show.toExpr)) + println(withNewQuoteContext(q.show)) } } diff --git a/tests/run-with-compiler/i4044e.scala b/tests/run-with-compiler/i4044e.scala index a4514188ea55..f599dd7b2dc9 100644 --- a/tests/run-with-compiler/i4044e.scala +++ b/tests/run-with-compiler/i4044e.scala @@ -7,7 +7,7 @@ class Foo { val f: Expr[Int] = '{5} val t: Type[Int] = '[Int] val q = '{ ${ '{ ($e + $f).asInstanceOf[$t] } } } - println(run(q.show.toExpr)) + println(withNewQuoteContext(q.show)) } } diff --git a/tests/run-with-compiler/i4044f.scala b/tests/run-with-compiler/i4044f.scala index d98293069fe6..39641486c93f 100644 --- a/tests/run-with-compiler/i4044f.scala +++ b/tests/run-with-compiler/i4044f.scala @@ -14,7 +14,7 @@ class Foo { foo('{e1 + $u}, '{f1}) } } - println(run(q.show.toExpr)) + println(withNewQuoteContext(q.show)) } } diff --git a/tests/run-with-compiler/i4350.scala b/tests/run-with-compiler/i4350.scala index 3954bf7a3874..169ee047653d 100644 --- a/tests/run-with-compiler/i4350.scala +++ b/tests/run-with-compiler/i4350.scala @@ -6,9 +6,9 @@ class Foo[T: Type] { } object Test { - def main(args: Array[String]): Unit = { - implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - println(run((new Foo[Object]).q.show.toExpr)) - println(run((new Foo[String]).q.show.toExpr)) + implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + def main(args: Array[String]): Unit = withNewQuoteContext { + println((new Foo[Object]).q.show) + println((new Foo[String]).q.show) } } diff --git a/tests/run-with-compiler/i5144.scala b/tests/run-with-compiler/i5144.scala index 31f5ab20abc1..b8f802a9ce1f 100644 --- a/tests/run-with-compiler/i5144.scala +++ b/tests/run-with-compiler/i5144.scala @@ -8,9 +8,9 @@ object Test { def f(x: Int): Int = ${eval1('f)} } - def main(args: Array[String]): Unit = { + def main(args: Array[String]): Unit = withNewQuoteContext { val p = peval1() - println(run(p.show.toExpr)) + println(p.show) } } \ No newline at end of file diff --git a/tests/run-with-compiler/i5152.scala b/tests/run-with-compiler/i5152.scala index 552df6d5f3cd..4afed7a9306b 100644 --- a/tests/run-with-compiler/i5152.scala +++ b/tests/run-with-compiler/i5152.scala @@ -8,9 +8,9 @@ object Test { lazy val f: Int => Int = ${eval1('{(y: Int) => f(y)})} } - def main(args: Array[String]): Unit = { + def main(args: Array[String]): Unit = withNewQuoteContext { val p = peval1() - println(run(p.show.toExpr)) + println(p.show) } } diff --git a/tests/run-with-compiler/i5161.scala b/tests/run-with-compiler/i5161.scala index 8366907fb0fd..ff1e5bb240ff 100644 --- a/tests/run-with-compiler/i5161.scala +++ b/tests/run-with-compiler/i5161.scala @@ -26,6 +26,6 @@ object Test { val test = Add(Int2(1), Int2(1)) val res = evalTest(test) println("run : " + run(res)) - println("show : " + run(res.show.toExpr)) + println("show : " + withNewQuoteContext(res.show)) } } diff --git a/tests/run-with-compiler/i5161b.scala b/tests/run-with-compiler/i5161b.scala index 79cc28a7519b..def497b0237b 100644 --- a/tests/run-with-compiler/i5161b.scala +++ b/tests/run-with-compiler/i5161b.scala @@ -9,9 +9,9 @@ object Test { if (x.isInstanceOf[Some[_]]) Option(1) else None } - println("show0 : " + run(res.show.toExpr)) + println("show0 : " + withNewQuoteContext(res.show)) println("run1 : " + run(res)) println("run2 : " + run(res)) - println("show3 : " + run(res.show.toExpr)) + println("show3 : " + withNewQuoteContext(res.show)) } } diff --git a/tests/run-with-compiler/i5247.scala b/tests/run-with-compiler/i5247.scala index e4b63fc9070a..db0fe86efae2 100644 --- a/tests/run-with-compiler/i5247.scala +++ b/tests/run-with-compiler/i5247.scala @@ -1,9 +1,9 @@ import scala.quoted._ object Test { - def main(args: Array[String]): Unit = { - implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - println(run(foo[Object].show.toExpr)) - println(run(bar[Object].show.toExpr)) + implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + def main(args: Array[String]): Unit = withNewQuoteContext { + println(foo[Object].show) + println(bar[Object].show) } def foo[H : Type]: Expr[H] = { val t = '[H] diff --git a/tests/run-with-compiler/i5965.scala b/tests/run-with-compiler/i5965.scala index 52c5471d6ba8..042e2ef5117b 100644 --- a/tests/run-with-compiler/i5965.scala +++ b/tests/run-with-compiler/i5965.scala @@ -8,15 +8,15 @@ object Test { def main(args: Array[String]): Unit = { '[List] val list = bound('{List(1, 2, 3)}) - println(run(list.show.toExpr)) + println(withNewQuoteContext(list.show)) println(run(list)) val opt = bound('{Option(4)}) - println(run(opt.show.toExpr)) + println(withNewQuoteContext(opt.show)) println(run(opt)) val map = bound('{Map(4 -> 1)}) - println(run(map.show.toExpr)) + println(withNewQuoteContext(map.show)) println(run(map)) } diff --git a/tests/run-with-compiler/i5965b.scala b/tests/run-with-compiler/i5965b.scala index e825c39e9963..4aa3c855355f 100644 --- a/tests/run-with-compiler/i5965b.scala +++ b/tests/run-with-compiler/i5965b.scala @@ -9,15 +9,15 @@ object Test { '[List] val list = bound('{List(1, 2, 3)}) - println(run(list.show.toExpr)) + println(withNewQuoteContext(list.show)) println(run(list)) val opt = bound('{Option(4)}) - println(run(opt.show.toExpr)) + println(withNewQuoteContext(opt.show)) println(run(opt)) val map = bound('{Map(4 -> 1)}) - println(run(map.show.toExpr)) + println(withNewQuoteContext(map.show)) println(run(map)) } diff --git a/tests/run-with-compiler/i5997.scala b/tests/run-with-compiler/i5997.scala index 96892750a4f9..7ca13f35d46b 100644 --- a/tests/run-with-compiler/i5997.scala +++ b/tests/run-with-compiler/i5997.scala @@ -1,8 +1,8 @@ import scala.quoted._ object Test { - def main(args: Array[String]): Unit = { - implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + def main(args: Array[String]): Unit = withNewQuoteContext { val v = '{ (if true then Some(1) else None).map(v => v+1) } - println(run(v.show.toExpr)) + println(v.show) } } diff --git a/tests/run-with-compiler/quote-function-applied-to.scala b/tests/run-with-compiler/quote-function-applied-to.scala index e7e60d69d6d5..5c38279ffbef 100644 --- a/tests/run-with-compiler/quote-function-applied-to.scala +++ b/tests/run-with-compiler/quote-function-applied-to.scala @@ -3,7 +3,7 @@ import scala.quoted._ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - def show(expr: Expr[_]): String = run(expr.show.toExpr) + def show(expr: Expr[_]): String = withNewQuoteContext(expr.show) println(show(('{ () => x(0) }).apply())) println(show(('{ (x1: Int) => x1 }).apply('{x(1)}))) println(show(('{ (x1: Int, x2: Int) => x1 + x2 }).apply('{x(1)}, '{x(2)}))) diff --git a/tests/run-with-compiler/quote-macro-in-splice/quoted_2.scala b/tests/run-with-compiler/quote-macro-in-splice/quoted_2.scala index e9a1425ad39a..6ae3d9416a18 100644 --- a/tests/run-with-compiler/quote-macro-in-splice/quoted_2.scala +++ b/tests/run-with-compiler/quote-macro-in-splice/quoted_2.scala @@ -2,8 +2,8 @@ import scala.quoted._ import Macros._ object Test { - def main(args: Array[String]): Unit = { - implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + def main(args: Array[String]): Unit = withNewQuoteContext { val x = '{ val y = 1 ${ @@ -12,7 +12,7 @@ object Test { '{ y + $b } } } - println(run(x.show.toExpr)) + println(x.show) } } diff --git a/tests/run-with-compiler/quote-nested-1.scala b/tests/run-with-compiler/quote-nested-1.scala index bc2485e0ffc2..5fa0ae15a9a8 100644 --- a/tests/run-with-compiler/quote-nested-1.scala +++ b/tests/run-with-compiler/quote-nested-1.scala @@ -4,6 +4,6 @@ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) val q = '{ '{3} } - println(run(q.show.toExpr)) + println(withNewQuoteContext(q.show)) } } diff --git a/tests/run-with-compiler/quote-nested-2.scala b/tests/run-with-compiler/quote-nested-2.scala index 7e9e98a574d4..f99ad11636eb 100644 --- a/tests/run-with-compiler/quote-nested-2.scala +++ b/tests/run-with-compiler/quote-nested-2.scala @@ -9,6 +9,6 @@ object Test { '{${a}} } - println(run(q.show.toExpr)) + println(withNewQuoteContext(q.show)) } } diff --git a/tests/run-with-compiler/quote-nested-3.scala b/tests/run-with-compiler/quote-nested-3.scala index 1468906992bd..3e77bb228ead 100644 --- a/tests/run-with-compiler/quote-nested-3.scala +++ b/tests/run-with-compiler/quote-nested-3.scala @@ -14,6 +14,6 @@ object Test { x } - println(run(q.show.toExpr)) + println(withNewQuoteContext(q.show)) } } diff --git a/tests/run-with-compiler/quote-nested-4.scala b/tests/run-with-compiler/quote-nested-4.scala index edbb3aca8838..4f0bad103ef9 100644 --- a/tests/run-with-compiler/quote-nested-4.scala +++ b/tests/run-with-compiler/quote-nested-4.scala @@ -9,6 +9,6 @@ object Test { t } - println(run(q.show.toExpr)) + println(withNewQuoteContext(q.show)) } } diff --git a/tests/run-with-compiler/quote-nested-5.scala b/tests/run-with-compiler/quote-nested-5.scala index 8f11de1a6ae1..71543ab25df2 100644 --- a/tests/run-with-compiler/quote-nested-5.scala +++ b/tests/run-with-compiler/quote-nested-5.scala @@ -12,6 +12,6 @@ object Test { } - println(run(q.show.toExpr)) + println(withNewQuoteContext(q.show)) } } diff --git a/tests/run-with-compiler/quote-owners.scala b/tests/run-with-compiler/quote-owners.scala index d538b35f7353..c317c4dd8f1b 100644 --- a/tests/run-with-compiler/quote-owners.scala +++ b/tests/run-with-compiler/quote-owners.scala @@ -5,7 +5,7 @@ object Test { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) val q = f println(run(q)) - println(run(q.show.toExpr)) + println(withNewQuoteContext(q.show)) } def f: Expr[Int] = '{ diff --git a/tests/run-with-compiler/quote-run-2.scala b/tests/run-with-compiler/quote-run-2.scala index 6f1372012dce..d518ead07e8b 100644 --- a/tests/run-with-compiler/quote-run-2.scala +++ b/tests/run-with-compiler/quote-run-2.scala @@ -2,18 +2,18 @@ import scala.quoted._ object Test { - def main(args: Array[String]): Unit = { - implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + def main(args: Array[String]): Unit = withNewQuoteContext { def powerCode(n: Int, x: Expr[Double]): Expr[Double] = if (n == 0) '{1.0} else if (n == 1) x else if (n % 2 == 0) '{ { val y = $x * $x; ${powerCode(n / 2, 'y)} } } else '{ $x * ${powerCode(n - 1, x)} } - println(run(powerCode(0, '{5}).show.toExpr)) - println(run(powerCode(1, '{5}).show.toExpr)) - println(run(powerCode(2, '{5}).show.toExpr)) - println(run(powerCode(3, '{5}).show.toExpr)) - println(run(powerCode(22, '{5}).show.toExpr)) + println(powerCode(0, '{5}).show) + println(powerCode(1, '{5}).show) + println(powerCode(2, '{5}).show) + println(powerCode(3, '{5}).show) + println(powerCode(22, '{5}).show) } } diff --git a/tests/run-with-compiler/quote-run-constants.scala b/tests/run-with-compiler/quote-run-constants.scala index f07b9158af28..b3e38f8a7ac6 100644 --- a/tests/run-with-compiler/quote-run-constants.scala +++ b/tests/run-with-compiler/quote-run-constants.scala @@ -7,7 +7,6 @@ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) def runAndPrint[T](expr: Expr[T]): Unit = println(run(expr)) - def show[T](expr: Expr[T]): Unit = println(run(expr.show.toExpr)) runAndPrint(true) runAndPrint('a') @@ -24,20 +23,25 @@ object Test { println("======") - show(true) - show('a') - show('\n') - show('"') - show('\'') - show('\\') - show(1) - show(2) - show(3L) - show(4.0f) - show(5.0d) - show("xyz") - show("\n\\\"'") - show("""abc + withNewQuoteContext { + def show[T](expr: Expr[T]): Unit = println(expr.show) + + show(true) + show('a') + show('\n') + show('"') + show('\'') + show('\\') + show(1) + show(2) + show(3L) + show(4.0f) + show(5.0d) + show("xyz") + show("\n\\\"'") + show( + """abc xyz""") + } } } diff --git a/tests/run-with-compiler/quote-run-staged-interpreter.scala b/tests/run-with-compiler/quote-run-staged-interpreter.scala index 098280da2d6c..f199dc63663a 100644 --- a/tests/run-with-compiler/quote-run-staged-interpreter.scala +++ b/tests/run-with-compiler/quote-run-staged-interpreter.scala @@ -34,7 +34,7 @@ object Test { val res1 = '{ (x: Int) => ${compile(exp, Map("x" -> 'x), false)} } - println(run(res1.show.toExpr)) + println(withNewQuoteContext(res1.show)) val fn = run { res1 @@ -46,13 +46,13 @@ object Test { println("---") val res2 = compile(letExp, Map(), false) - println(run(res2.show.toExpr)) + println(withNewQuoteContext(res2.show)) println(run(res2)) println("---") val res3 = compile(letExp, Map(), true) - println(run(res3.show.toExpr)) + println(withNewQuoteContext(res3.show)) println(run(res3)) } } diff --git a/tests/run-with-compiler/quote-run-with-settings.scala b/tests/run-with-compiler/quote-run-with-settings.scala index c0b9a70667b4..7d201d23cbf8 100644 --- a/tests/run-with-compiler/quote-run-with-settings.scala +++ b/tests/run-with-compiler/quote-run-with-settings.scala @@ -11,7 +11,7 @@ object Test { println("foo") 2 + a } - println(run(expr.show.toExpr)) + println(withNewQuoteContext(expr.show)) println(run(expr)) println() diff --git a/tests/run-with-compiler/quote-run.scala b/tests/run-with-compiler/quote-run.scala index ea395fe00e84..c7bdac4f62cf 100644 --- a/tests/run-with-compiler/quote-run.scala +++ b/tests/run-with-compiler/quote-run.scala @@ -10,6 +10,6 @@ object Test { } println(run(expr)) println(run(expr)) - println(run(expr.show.toExpr)) + println(withNewQuoteContext(expr.show)) } } diff --git a/tests/run-with-compiler/shonan-hmm-simple.scala b/tests/run-with-compiler/shonan-hmm-simple.scala index 8f38918c58f3..a2464c2e24e7 100644 --- a/tests/run-with-compiler/shonan-hmm-simple.scala +++ b/tests/run-with-compiler/shonan-hmm-simple.scala @@ -146,7 +146,7 @@ object Test { vec1.map(_.toExpr), vec2.map(_.toExpr) ) - println(run(resCode1.show.toExpr)) + println(withNewQuoteContext(resCode1.show)) println(run(resCode1)) println() @@ -161,7 +161,7 @@ object Test { ) } } - println(run(resCode2.show.toExpr)) + println(withNewQuoteContext(resCode2.show)) println(run(resCode2).apply(arr1, arr2)) println() @@ -170,7 +170,7 @@ object Test { vec1.map(i => Dyn(i)), vec2.map(i => Sta(i)) ).expr - println(run(resCode3.show.toExpr)) + println(withNewQuoteContext(resCode3.show)) println(run(resCode3)) println() @@ -186,7 +186,7 @@ object Test { } } - println(run(resCode4.show.toExpr)) + println(withNewQuoteContext(resCode4.show)) println(run(resCode4).apply(arr1)) println() @@ -203,7 +203,7 @@ object Test { '{Complex(${cpx.re.expr}, ${cpx.im.expr})} } } - println(run(resCode5.show.toExpr)) + println(withNewQuoteContext(resCode5.show)) println(run(resCode5).apply(cmpxArr1)) println() @@ -213,7 +213,7 @@ object Test { // will generate the code '{ ((arr: scala.Array[scala.Int]) => arr.apply(1).+(arr.apply(3))) } val staticVec = Vec[Int, PV[Int]](5, i => Sta((i % 2))) val code = '{(arr: Array[Int]) => ${dotIntOptExpr(Vec(5, i => Dyn('{arr(${i})})), staticVec).expr} } - println(run(code.show.toExpr)) + println(withNewQuoteContext(code.show)) println() } diff --git a/tests/run-with-compiler/shonan-hmm/Test.scala b/tests/run-with-compiler/shonan-hmm/Test.scala index 7303e9b1757f..2f863c8f7784 100644 --- a/tests/run-with-compiler/shonan-hmm/Test.scala +++ b/tests/run-with-compiler/shonan-hmm/Test.scala @@ -4,8 +4,9 @@ import scala.quoted._ object Test { - def main(args: Array[String]): Unit = { - implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + + def main(args: Array[String]): Unit = withNewQuoteContext { { val intComplex = new RingComplex(RingInt) @@ -19,7 +20,7 @@ object Test { import intExprComplex._ val res = Complex('{1}, '{2}) * Complex('{4}, '{2}) - println(s"Complex(${run(res.re.show.toExpr)}, ${run(res.im.show.toExpr)})") + println(s"Complex(${res.re.show}, ${res.im.show})") } // { @@ -36,7 +37,7 @@ object Test { Vmults.vmult(out, arr1, arr2) println(out.toList) - println(run(Vmults.vmultCA.show.toExpr)) + println(Vmults.vmultCA.show) val a = Array( Array( 5, 0, 0, 5, 0), @@ -54,37 +55,37 @@ object Test { println() println() - println(run(MVmult.mvmult_c.show.toExpr)) + println(MVmult.mvmult_c.show) println() println() println() - println(run(MVmult.mvmult_mc(3, 2).show.toExpr)) + println(MVmult.mvmult_mc(3, 2).show) println() println() println() - println(run(MVmult.mvmult_ac(a).show.toExpr)) + println(MVmult.mvmult_ac(a).show) println() println() println() - println(run(MVmult.mvmult_opt(a).show.toExpr)) + println(MVmult.mvmult_opt(a).show) println() println() println() - println(run(MVmult.mvmult_roll(a).show.toExpr)) + println(MVmult.mvmult_roll(a).show) println() println() println() - println(run(MVmult.mvmult_let1(a).show.toExpr)) + println(MVmult.mvmult_let1(a).show) println() println() println() - println(run(MVmult.mvmult_let(a).show.toExpr)) + println(MVmult.mvmult_let(a).show) } } diff --git a/tests/run-with-compiler/tasty-extractors-constants-2/quoted_1.scala b/tests/run-with-compiler/tasty-extractors-constants-2/quoted_1.scala index 4e3b493dedef..84450829c3ae 100644 --- a/tests/run-with-compiler/tasty-extractors-constants-2/quoted_1.scala +++ b/tests/run-with-compiler/tasty-extractors-constants-2/quoted_1.scala @@ -11,16 +11,16 @@ object Macros { def impl(implicit reflect: Reflection): Expr[Unit] = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) // 2 is a lifted constant - val show1 = run(power(2, 3.0).show.toExpr) + val show1 = withNewQuoteContext(power(2, 3.0).show) val run1 = run(power(2, 3.0)) // n is a lifted constant val n = 2 - val show2 = run(power(n, 4.0).show.toExpr) + val show2 = withNewQuoteContext(power(n, 4.0).show) val run2 = run(power(n, 4.0)) // n is a constant in a quote - val show3 = run(power('{2}, 5.0).show.toExpr) + val show3 = withNewQuoteContext(power('{2}, 5.0).show) val run3 = run(power('{2}, 5.0)) // n2 is clearly not a constant From 06d564b193691fa3d712a7577f0d82330bb257b7 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Thu, 27 Jun 2019 17:04:22 +0200 Subject: [PATCH 10/12] Rename withNewQuoteContext to withQuoteContext --- compiler/test-resources/repl-macros/i6007 | 2 +- docs/docs/reference/metaprogramming/staging.md | 4 ++-- library/src-3.x/scala/quoted/package.scala | 4 ++-- tests/run-with-compiler/i3823-b.scala | 2 +- tests/run-with-compiler/i3823-c.scala | 2 +- tests/run-with-compiler/i3823.scala | 2 +- tests/run-with-compiler/i3847-b.scala | 2 +- tests/run-with-compiler/i3847.scala | 2 +- tests/run-with-compiler/i3876-b.scala | 2 +- tests/run-with-compiler/i3876-c.scala | 2 +- tests/run-with-compiler/i3876-d.scala | 2 +- tests/run-with-compiler/i3876-e.scala | 2 +- tests/run-with-compiler/i3876.scala | 2 +- tests/run-with-compiler/i3946.scala | 2 +- tests/run-with-compiler/i4044a.scala | 2 +- tests/run-with-compiler/i4044b.scala | 2 +- tests/run-with-compiler/i4044c.scala | 2 +- tests/run-with-compiler/i4044e.scala | 2 +- tests/run-with-compiler/i4044f.scala | 2 +- tests/run-with-compiler/i4350.scala | 2 +- tests/run-with-compiler/i5144.scala | 2 +- tests/run-with-compiler/i5152.scala | 2 +- tests/run-with-compiler/i5161.scala | 2 +- tests/run-with-compiler/i5161b.scala | 4 ++-- tests/run-with-compiler/i5247.scala | 2 +- tests/run-with-compiler/i5965.scala | 6 +++--- tests/run-with-compiler/i5965b.scala | 6 +++--- tests/run-with-compiler/i5997.scala | 2 +- .../quote-function-applied-to.scala | 2 +- .../quote-macro-in-splice/quoted_2.scala | 2 +- tests/run-with-compiler/quote-nested-1.scala | 2 +- tests/run-with-compiler/quote-nested-2.scala | 2 +- tests/run-with-compiler/quote-nested-3.scala | 2 +- tests/run-with-compiler/quote-nested-4.scala | 2 +- tests/run-with-compiler/quote-nested-5.scala | 2 +- tests/run-with-compiler/quote-owners.scala | 2 +- tests/run-with-compiler/quote-run-2.scala | 2 +- tests/run-with-compiler/quote-run-constants.scala | 2 +- .../quote-run-staged-interpreter.scala | 6 +++--- .../run-with-compiler/quote-run-with-settings.scala | 2 +- tests/run-with-compiler/quote-run.scala | 2 +- tests/run-with-compiler/shonan-hmm-simple.scala | 12 ++++++------ tests/run-with-compiler/shonan-hmm/Test.scala | 2 +- .../tasty-extractors-constants-2/quoted_1.scala | 6 +++--- 44 files changed, 60 insertions(+), 60 deletions(-) diff --git a/compiler/test-resources/repl-macros/i6007 b/compiler/test-resources/repl-macros/i6007 index 765c01cb57b4..ebc605750515 100644 --- a/compiler/test-resources/repl-macros/i6007 +++ b/compiler/test-resources/repl-macros/i6007 @@ -2,7 +2,7 @@ scala> implicit def toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(ge def toolbox: quoted.Toolbox scala> val v = '{ (if true then Some(1) else None).map(v => v+1) } val v: quoted.Expr[Option[Int]] = Expr() -scala> scala.quoted.withNewQuoteContext(v.show) +scala> scala.quoted.withQuoteContext(v.show) val res0: String = (if (true) scala.Some.apply[scala.Int](1) else scala.None).map[scala.Int](((v: scala.Int) => v.+(1))) scala> scala.quoted.run(v) val res1: Option[Int] = Some(2) diff --git a/docs/docs/reference/metaprogramming/staging.md b/docs/docs/reference/metaprogramming/staging.md index 3a67108a5ae7..e6446d48f596 100644 --- a/docs/docs/reference/metaprogramming/staging.md +++ b/docs/docs/reference/metaprogramming/staging.md @@ -61,14 +61,14 @@ to be executed at a later stage. To run that code, there is another method in class `Expr` called `run`. Note that `$` and `run` both map from `Expr[T]` to `T` but only `$` is subject to the PCP, whereas `run` is just a normal method. Run provides a `QuoteContext` that can be used to show the expression in the scope of `run`. -On the other hand `withNewQuoteContext` provides a `QuoteContext` without evauating the expression. +On the other hand `withQuoteContext` provides a `QuoteContext` without evauating the expression. ```scala package scala.quoted def run[T](expr: given QuoteContext => Expr[T]) given (toolbox: Toolbox): T = ... -def withNewQuoteContext[T](thunk: given QuoteContext => T) given (toolbox: Toolbox): T = ... +def withQuoteContext[T](thunk: given QuoteContext => T) given (toolbox: Toolbox): T = ... ``` ## Example diff --git a/library/src-3.x/scala/quoted/package.scala b/library/src-3.x/scala/quoted/package.scala index ca9bbb1b776d..8633256c80d4 100644 --- a/library/src-3.x/scala/quoted/package.scala +++ b/library/src-3.x/scala/quoted/package.scala @@ -24,7 +24,7 @@ package object quoted { * * Usage: * ``` - * val e: T = withNewQuoteContext { // (given qctx: QuoteContext) => + * val e: T = withQuoteContext { // (given qctx: QuoteContext) => * thunk * } * ``` @@ -32,7 +32,7 @@ package object quoted { * * This method shoul not be called in a context where there is already has a QuoteContext. */ - def withNewQuoteContext[T](thunk: given QuoteContext => T) given (toolbox: Toolbox): T = { + def withQuoteContext[T](thunk: given QuoteContext => T) given (toolbox: Toolbox): T = { var result: T = NoResult.asInstanceOf[T] def dummyRun given QuoteContext: Expr[Unit] = { result = thunk diff --git a/tests/run-with-compiler/i3823-b.scala b/tests/run-with-compiler/i3823-b.scala index 1842210ae809..a1048e4937d8 100644 --- a/tests/run-with-compiler/i3823-b.scala +++ b/tests/run-with-compiler/i3823-b.scala @@ -1,7 +1,7 @@ import scala.quoted._ object Test { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - def main(args: Array[String]): Unit = withNewQuoteContext { + def main(args: Array[String]): Unit = withQuoteContext { def f[T](x: Expr[T])(implicit t: Type[T]) = '{ val z: $t = $x } diff --git a/tests/run-with-compiler/i3823-c.scala b/tests/run-with-compiler/i3823-c.scala index ca099c595241..61e393efab65 100644 --- a/tests/run-with-compiler/i3823-c.scala +++ b/tests/run-with-compiler/i3823-c.scala @@ -1,7 +1,7 @@ import scala.quoted._ object Test { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - def main(args: Array[String]): Unit = withNewQuoteContext { + def main(args: Array[String]): Unit = withQuoteContext { def f[T](x: Expr[T])(implicit t: Type[T]) = '{ val z = $x } diff --git a/tests/run-with-compiler/i3823.scala b/tests/run-with-compiler/i3823.scala index 0668bfafcaba..430b215acdf8 100644 --- a/tests/run-with-compiler/i3823.scala +++ b/tests/run-with-compiler/i3823.scala @@ -1,7 +1,7 @@ import scala.quoted._ object Test { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - def main(args: Array[String]): Unit = withNewQuoteContext { + def main(args: Array[String]): Unit = withQuoteContext { def f[T: Type](x: Expr[T])(t: Type[T]) = '{ val z: $t = $x } diff --git a/tests/run-with-compiler/i3847-b.scala b/tests/run-with-compiler/i3847-b.scala index e9174ddb2e40..a07c47ceefad 100644 --- a/tests/run-with-compiler/i3847-b.scala +++ b/tests/run-with-compiler/i3847-b.scala @@ -14,7 +14,7 @@ object Arrays { object Test { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - def main(args: Array[String]): Unit = withNewQuoteContext { + def main(args: Array[String]): Unit = withQuoteContext { import Arrays._ implicit val ct: Expr[ClassTag[Int]] = '{ClassTag.Int} val arr: Expr[Array[List[Int]]] = Array[List[Int]](List(1, 2, 3)).toExpr diff --git a/tests/run-with-compiler/i3847.scala b/tests/run-with-compiler/i3847.scala index 6b6d7b500702..4c05714d1767 100644 --- a/tests/run-with-compiler/i3847.scala +++ b/tests/run-with-compiler/i3847.scala @@ -14,7 +14,7 @@ object Arrays { object Test { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(this.getClass.getClassLoader) - def main(args: Array[String]): Unit = withNewQuoteContext { + def main(args: Array[String]): Unit = withQuoteContext { import Arrays._ implicit val ct: Expr[ClassTag[Int]] = '{ClassTag.Int} val arr: Expr[Array[Int]] = Array[Int](1, 2, 3).toExpr diff --git a/tests/run-with-compiler/i3876-b.scala b/tests/run-with-compiler/i3876-b.scala index 367918242900..22eb62c3d3be 100644 --- a/tests/run-with-compiler/i3876-b.scala +++ b/tests/run-with-compiler/i3876-b.scala @@ -11,6 +11,6 @@ object Test { } println(run(f2(x))) - println(withNewQuoteContext(f2(x).show)) + println(withQuoteContext(f2(x).show)) } } diff --git a/tests/run-with-compiler/i3876-c.scala b/tests/run-with-compiler/i3876-c.scala index 1bccdc05fbdd..7e9ab0baff5f 100644 --- a/tests/run-with-compiler/i3876-c.scala +++ b/tests/run-with-compiler/i3876-c.scala @@ -11,6 +11,6 @@ object Test { } println(run(f3(x))) - println(withNewQuoteContext(f3(x).show)) // TODO improve printer + println(withQuoteContext(f3(x).show)) // TODO improve printer } } diff --git a/tests/run-with-compiler/i3876-d.scala b/tests/run-with-compiler/i3876-d.scala index 7aa0289d81cb..bcdbe8818abc 100644 --- a/tests/run-with-compiler/i3876-d.scala +++ b/tests/run-with-compiler/i3876-d.scala @@ -9,7 +9,7 @@ object Test { inlineLambda } println(run(f4(x))) - println(withNewQuoteContext(f4(x).show)) + println(withQuoteContext(f4(x).show)) } inline def inlineLambda <: Int => Int = x => x + x diff --git a/tests/run-with-compiler/i3876-e.scala b/tests/run-with-compiler/i3876-e.scala index f2745fa58d51..8b0b9e285612 100644 --- a/tests/run-with-compiler/i3876-e.scala +++ b/tests/run-with-compiler/i3876-e.scala @@ -9,7 +9,7 @@ object Test { inlineLambda } println(run(f4(x))) - println(withNewQuoteContext(f4(x).show)) + println(withQuoteContext(f4(x).show)) } inline def inlineLambda <: Int => Int = x => x + x diff --git a/tests/run-with-compiler/i3876.scala b/tests/run-with-compiler/i3876.scala index 41f1147817d5..a1c57e438f14 100644 --- a/tests/run-with-compiler/i3876.scala +++ b/tests/run-with-compiler/i3876.scala @@ -8,6 +8,6 @@ object Test { val f: Expr[Int => Int] = '{ (x: Int) => x + x } println(run(f(x))) - println(withNewQuoteContext(f(x).show)) + println(withQuoteContext(f(x).show)) } } diff --git a/tests/run-with-compiler/i3946.scala b/tests/run-with-compiler/i3946.scala index e2f1b3525f98..eff2fa9a507b 100644 --- a/tests/run-with-compiler/i3946.scala +++ b/tests/run-with-compiler/i3946.scala @@ -3,7 +3,7 @@ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) val u: Expr[Unit] = '{} - println(withNewQuoteContext(u.show)) + println(withQuoteContext(u.show)) println(run(u)) } } diff --git a/tests/run-with-compiler/i4044a.scala b/tests/run-with-compiler/i4044a.scala index 8ef7d14214eb..9486c20bdc68 100644 --- a/tests/run-with-compiler/i4044a.scala +++ b/tests/run-with-compiler/i4044a.scala @@ -5,7 +5,7 @@ class Foo { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) val e: Expr[Int] = '{3} val q = '{ ${ '{ $e } } } - println(withNewQuoteContext(q.show)) + println(withQuoteContext(q.show)) } } diff --git a/tests/run-with-compiler/i4044b.scala b/tests/run-with-compiler/i4044b.scala index 9939526778da..1c63e62f612d 100644 --- a/tests/run-with-compiler/i4044b.scala +++ b/tests/run-with-compiler/i4044b.scala @@ -22,6 +22,6 @@ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) val q = VarRef('{4})(varRef => '{ ${varRef.update('{3})}; ${varRef.expr} }) - println(withNewQuoteContext(q.show)) + println(withQuoteContext(q.show)) } } diff --git a/tests/run-with-compiler/i4044c.scala b/tests/run-with-compiler/i4044c.scala index dc975e9ee3f6..1777042fb563 100644 --- a/tests/run-with-compiler/i4044c.scala +++ b/tests/run-with-compiler/i4044c.scala @@ -4,7 +4,7 @@ class Foo { def foo: Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) val q = '{ ${ '{ ${ '{ 5 } } } } } - println(withNewQuoteContext(q.show)) + println(withQuoteContext(q.show)) } } diff --git a/tests/run-with-compiler/i4044e.scala b/tests/run-with-compiler/i4044e.scala index f599dd7b2dc9..49d5994812e7 100644 --- a/tests/run-with-compiler/i4044e.scala +++ b/tests/run-with-compiler/i4044e.scala @@ -7,7 +7,7 @@ class Foo { val f: Expr[Int] = '{5} val t: Type[Int] = '[Int] val q = '{ ${ '{ ($e + $f).asInstanceOf[$t] } } } - println(withNewQuoteContext(q.show)) + println(withQuoteContext(q.show)) } } diff --git a/tests/run-with-compiler/i4044f.scala b/tests/run-with-compiler/i4044f.scala index 39641486c93f..0cedf8187110 100644 --- a/tests/run-with-compiler/i4044f.scala +++ b/tests/run-with-compiler/i4044f.scala @@ -14,7 +14,7 @@ class Foo { foo('{e1 + $u}, '{f1}) } } - println(withNewQuoteContext(q.show)) + println(withQuoteContext(q.show)) } } diff --git a/tests/run-with-compiler/i4350.scala b/tests/run-with-compiler/i4350.scala index 169ee047653d..1f6da64ea0bb 100644 --- a/tests/run-with-compiler/i4350.scala +++ b/tests/run-with-compiler/i4350.scala @@ -7,7 +7,7 @@ class Foo[T: Type] { object Test { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - def main(args: Array[String]): Unit = withNewQuoteContext { + def main(args: Array[String]): Unit = withQuoteContext { println((new Foo[Object]).q.show) println((new Foo[String]).q.show) } diff --git a/tests/run-with-compiler/i5144.scala b/tests/run-with-compiler/i5144.scala index b8f802a9ce1f..04906034b23f 100644 --- a/tests/run-with-compiler/i5144.scala +++ b/tests/run-with-compiler/i5144.scala @@ -8,7 +8,7 @@ object Test { def f(x: Int): Int = ${eval1('f)} } - def main(args: Array[String]): Unit = withNewQuoteContext { + def main(args: Array[String]): Unit = withQuoteContext { val p = peval1() println(p.show) } diff --git a/tests/run-with-compiler/i5152.scala b/tests/run-with-compiler/i5152.scala index 4afed7a9306b..a4684bbcd787 100644 --- a/tests/run-with-compiler/i5152.scala +++ b/tests/run-with-compiler/i5152.scala @@ -8,7 +8,7 @@ object Test { lazy val f: Int => Int = ${eval1('{(y: Int) => f(y)})} } - def main(args: Array[String]): Unit = withNewQuoteContext { + def main(args: Array[String]): Unit = withQuoteContext { val p = peval1() println(p.show) } diff --git a/tests/run-with-compiler/i5161.scala b/tests/run-with-compiler/i5161.scala index ff1e5bb240ff..e1ea118ae76c 100644 --- a/tests/run-with-compiler/i5161.scala +++ b/tests/run-with-compiler/i5161.scala @@ -26,6 +26,6 @@ object Test { val test = Add(Int2(1), Int2(1)) val res = evalTest(test) println("run : " + run(res)) - println("show : " + withNewQuoteContext(res.show)) + println("show : " + withQuoteContext(res.show)) } } diff --git a/tests/run-with-compiler/i5161b.scala b/tests/run-with-compiler/i5161b.scala index def497b0237b..f52770930783 100644 --- a/tests/run-with-compiler/i5161b.scala +++ b/tests/run-with-compiler/i5161b.scala @@ -9,9 +9,9 @@ object Test { if (x.isInstanceOf[Some[_]]) Option(1) else None } - println("show0 : " + withNewQuoteContext(res.show)) + println("show0 : " + withQuoteContext(res.show)) println("run1 : " + run(res)) println("run2 : " + run(res)) - println("show3 : " + withNewQuoteContext(res.show)) + println("show3 : " + withQuoteContext(res.show)) } } diff --git a/tests/run-with-compiler/i5247.scala b/tests/run-with-compiler/i5247.scala index db0fe86efae2..01b5393e23be 100644 --- a/tests/run-with-compiler/i5247.scala +++ b/tests/run-with-compiler/i5247.scala @@ -1,7 +1,7 @@ import scala.quoted._ object Test { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - def main(args: Array[String]): Unit = withNewQuoteContext { + def main(args: Array[String]): Unit = withQuoteContext { println(foo[Object].show) println(bar[Object].show) } diff --git a/tests/run-with-compiler/i5965.scala b/tests/run-with-compiler/i5965.scala index 042e2ef5117b..7b1a8cfa61a7 100644 --- a/tests/run-with-compiler/i5965.scala +++ b/tests/run-with-compiler/i5965.scala @@ -8,15 +8,15 @@ object Test { def main(args: Array[String]): Unit = { '[List] val list = bound('{List(1, 2, 3)}) - println(withNewQuoteContext(list.show)) + println(withQuoteContext(list.show)) println(run(list)) val opt = bound('{Option(4)}) - println(withNewQuoteContext(opt.show)) + println(withQuoteContext(opt.show)) println(run(opt)) val map = bound('{Map(4 -> 1)}) - println(withNewQuoteContext(map.show)) + println(withQuoteContext(map.show)) println(run(map)) } diff --git a/tests/run-with-compiler/i5965b.scala b/tests/run-with-compiler/i5965b.scala index 4aa3c855355f..e806cd847957 100644 --- a/tests/run-with-compiler/i5965b.scala +++ b/tests/run-with-compiler/i5965b.scala @@ -9,15 +9,15 @@ object Test { '[List] val list = bound('{List(1, 2, 3)}) - println(withNewQuoteContext(list.show)) + println(withQuoteContext(list.show)) println(run(list)) val opt = bound('{Option(4)}) - println(withNewQuoteContext(opt.show)) + println(withQuoteContext(opt.show)) println(run(opt)) val map = bound('{Map(4 -> 1)}) - println(withNewQuoteContext(map.show)) + println(withQuoteContext(map.show)) println(run(map)) } diff --git a/tests/run-with-compiler/i5997.scala b/tests/run-with-compiler/i5997.scala index 7ca13f35d46b..7fd7856ade42 100644 --- a/tests/run-with-compiler/i5997.scala +++ b/tests/run-with-compiler/i5997.scala @@ -1,7 +1,7 @@ import scala.quoted._ object Test { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - def main(args: Array[String]): Unit = withNewQuoteContext { + def main(args: Array[String]): Unit = withQuoteContext { val v = '{ (if true then Some(1) else None).map(v => v+1) } println(v.show) } diff --git a/tests/run-with-compiler/quote-function-applied-to.scala b/tests/run-with-compiler/quote-function-applied-to.scala index 5c38279ffbef..c9c6cc2f95d8 100644 --- a/tests/run-with-compiler/quote-function-applied-to.scala +++ b/tests/run-with-compiler/quote-function-applied-to.scala @@ -3,7 +3,7 @@ import scala.quoted._ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - def show(expr: Expr[_]): String = withNewQuoteContext(expr.show) + def show(expr: Expr[_]): String = withQuoteContext(expr.show) println(show(('{ () => x(0) }).apply())) println(show(('{ (x1: Int) => x1 }).apply('{x(1)}))) println(show(('{ (x1: Int, x2: Int) => x1 + x2 }).apply('{x(1)}, '{x(2)}))) diff --git a/tests/run-with-compiler/quote-macro-in-splice/quoted_2.scala b/tests/run-with-compiler/quote-macro-in-splice/quoted_2.scala index 6ae3d9416a18..65a2480738f0 100644 --- a/tests/run-with-compiler/quote-macro-in-splice/quoted_2.scala +++ b/tests/run-with-compiler/quote-macro-in-splice/quoted_2.scala @@ -3,7 +3,7 @@ import Macros._ object Test { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - def main(args: Array[String]): Unit = withNewQuoteContext { + def main(args: Array[String]): Unit = withQuoteContext { val x = '{ val y = 1 ${ diff --git a/tests/run-with-compiler/quote-nested-1.scala b/tests/run-with-compiler/quote-nested-1.scala index 5fa0ae15a9a8..e9be760bea3c 100644 --- a/tests/run-with-compiler/quote-nested-1.scala +++ b/tests/run-with-compiler/quote-nested-1.scala @@ -4,6 +4,6 @@ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) val q = '{ '{3} } - println(withNewQuoteContext(q.show)) + println(withQuoteContext(q.show)) } } diff --git a/tests/run-with-compiler/quote-nested-2.scala b/tests/run-with-compiler/quote-nested-2.scala index f99ad11636eb..d7b638296ddf 100644 --- a/tests/run-with-compiler/quote-nested-2.scala +++ b/tests/run-with-compiler/quote-nested-2.scala @@ -9,6 +9,6 @@ object Test { '{${a}} } - println(withNewQuoteContext(q.show)) + println(withQuoteContext(q.show)) } } diff --git a/tests/run-with-compiler/quote-nested-3.scala b/tests/run-with-compiler/quote-nested-3.scala index 3e77bb228ead..30d0a40b8d76 100644 --- a/tests/run-with-compiler/quote-nested-3.scala +++ b/tests/run-with-compiler/quote-nested-3.scala @@ -14,6 +14,6 @@ object Test { x } - println(withNewQuoteContext(q.show)) + println(withQuoteContext(q.show)) } } diff --git a/tests/run-with-compiler/quote-nested-4.scala b/tests/run-with-compiler/quote-nested-4.scala index 4f0bad103ef9..fbbb9a3fc79e 100644 --- a/tests/run-with-compiler/quote-nested-4.scala +++ b/tests/run-with-compiler/quote-nested-4.scala @@ -9,6 +9,6 @@ object Test { t } - println(withNewQuoteContext(q.show)) + println(withQuoteContext(q.show)) } } diff --git a/tests/run-with-compiler/quote-nested-5.scala b/tests/run-with-compiler/quote-nested-5.scala index 71543ab25df2..4c8e7ba30c58 100644 --- a/tests/run-with-compiler/quote-nested-5.scala +++ b/tests/run-with-compiler/quote-nested-5.scala @@ -12,6 +12,6 @@ object Test { } - println(withNewQuoteContext(q.show)) + println(withQuoteContext(q.show)) } } diff --git a/tests/run-with-compiler/quote-owners.scala b/tests/run-with-compiler/quote-owners.scala index c317c4dd8f1b..9149678d64dc 100644 --- a/tests/run-with-compiler/quote-owners.scala +++ b/tests/run-with-compiler/quote-owners.scala @@ -5,7 +5,7 @@ object Test { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) val q = f println(run(q)) - println(withNewQuoteContext(q.show)) + println(withQuoteContext(q.show)) } def f: Expr[Int] = '{ diff --git a/tests/run-with-compiler/quote-run-2.scala b/tests/run-with-compiler/quote-run-2.scala index d518ead07e8b..00f8ceb5409a 100644 --- a/tests/run-with-compiler/quote-run-2.scala +++ b/tests/run-with-compiler/quote-run-2.scala @@ -3,7 +3,7 @@ import scala.quoted._ object Test { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - def main(args: Array[String]): Unit = withNewQuoteContext { + def main(args: Array[String]): Unit = withQuoteContext { 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-constants.scala b/tests/run-with-compiler/quote-run-constants.scala index b3e38f8a7ac6..63dab930879f 100644 --- a/tests/run-with-compiler/quote-run-constants.scala +++ b/tests/run-with-compiler/quote-run-constants.scala @@ -23,7 +23,7 @@ object Test { println("======") - withNewQuoteContext { + withQuoteContext { def show[T](expr: Expr[T]): Unit = println(expr.show) show(true) diff --git a/tests/run-with-compiler/quote-run-staged-interpreter.scala b/tests/run-with-compiler/quote-run-staged-interpreter.scala index f199dc63663a..59745f099865 100644 --- a/tests/run-with-compiler/quote-run-staged-interpreter.scala +++ b/tests/run-with-compiler/quote-run-staged-interpreter.scala @@ -34,7 +34,7 @@ object Test { val res1 = '{ (x: Int) => ${compile(exp, Map("x" -> 'x), false)} } - println(withNewQuoteContext(res1.show)) + println(withQuoteContext(res1.show)) val fn = run { res1 @@ -46,13 +46,13 @@ object Test { println("---") val res2 = compile(letExp, Map(), false) - println(withNewQuoteContext(res2.show)) + println(withQuoteContext(res2.show)) println(run(res2)) println("---") val res3 = compile(letExp, Map(), true) - println(withNewQuoteContext(res3.show)) + println(withQuoteContext(res3.show)) println(run(res3)) } } diff --git a/tests/run-with-compiler/quote-run-with-settings.scala b/tests/run-with-compiler/quote-run-with-settings.scala index 7d201d23cbf8..ca0b66a28ec4 100644 --- a/tests/run-with-compiler/quote-run-with-settings.scala +++ b/tests/run-with-compiler/quote-run-with-settings.scala @@ -11,7 +11,7 @@ object Test { println("foo") 2 + a } - println(withNewQuoteContext(expr.show)) + println(withQuoteContext(expr.show)) println(run(expr)) println() diff --git a/tests/run-with-compiler/quote-run.scala b/tests/run-with-compiler/quote-run.scala index c7bdac4f62cf..d28e3b8e1fa4 100644 --- a/tests/run-with-compiler/quote-run.scala +++ b/tests/run-with-compiler/quote-run.scala @@ -10,6 +10,6 @@ object Test { } println(run(expr)) println(run(expr)) - println(withNewQuoteContext(expr.show)) + println(withQuoteContext(expr.show)) } } diff --git a/tests/run-with-compiler/shonan-hmm-simple.scala b/tests/run-with-compiler/shonan-hmm-simple.scala index a2464c2e24e7..9737d1ed1829 100644 --- a/tests/run-with-compiler/shonan-hmm-simple.scala +++ b/tests/run-with-compiler/shonan-hmm-simple.scala @@ -146,7 +146,7 @@ object Test { vec1.map(_.toExpr), vec2.map(_.toExpr) ) - println(withNewQuoteContext(resCode1.show)) + println(withQuoteContext(resCode1.show)) println(run(resCode1)) println() @@ -161,7 +161,7 @@ object Test { ) } } - println(withNewQuoteContext(resCode2.show)) + println(withQuoteContext(resCode2.show)) println(run(resCode2).apply(arr1, arr2)) println() @@ -170,7 +170,7 @@ object Test { vec1.map(i => Dyn(i)), vec2.map(i => Sta(i)) ).expr - println(withNewQuoteContext(resCode3.show)) + println(withQuoteContext(resCode3.show)) println(run(resCode3)) println() @@ -186,7 +186,7 @@ object Test { } } - println(withNewQuoteContext(resCode4.show)) + println(withQuoteContext(resCode4.show)) println(run(resCode4).apply(arr1)) println() @@ -203,7 +203,7 @@ object Test { '{Complex(${cpx.re.expr}, ${cpx.im.expr})} } } - println(withNewQuoteContext(resCode5.show)) + println(withQuoteContext(resCode5.show)) println(run(resCode5).apply(cmpxArr1)) println() @@ -213,7 +213,7 @@ object Test { // will generate the code '{ ((arr: scala.Array[scala.Int]) => arr.apply(1).+(arr.apply(3))) } val staticVec = Vec[Int, PV[Int]](5, i => Sta((i % 2))) val code = '{(arr: Array[Int]) => ${dotIntOptExpr(Vec(5, i => Dyn('{arr(${i})})), staticVec).expr} } - println(withNewQuoteContext(code.show)) + println(withQuoteContext(code.show)) println() } diff --git a/tests/run-with-compiler/shonan-hmm/Test.scala b/tests/run-with-compiler/shonan-hmm/Test.scala index 2f863c8f7784..2dbe6cc5d488 100644 --- a/tests/run-with-compiler/shonan-hmm/Test.scala +++ b/tests/run-with-compiler/shonan-hmm/Test.scala @@ -6,7 +6,7 @@ object Test { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - def main(args: Array[String]): Unit = withNewQuoteContext { + def main(args: Array[String]): Unit = withQuoteContext { { val intComplex = new RingComplex(RingInt) diff --git a/tests/run-with-compiler/tasty-extractors-constants-2/quoted_1.scala b/tests/run-with-compiler/tasty-extractors-constants-2/quoted_1.scala index 84450829c3ae..0d9acbd30ab4 100644 --- a/tests/run-with-compiler/tasty-extractors-constants-2/quoted_1.scala +++ b/tests/run-with-compiler/tasty-extractors-constants-2/quoted_1.scala @@ -11,16 +11,16 @@ object Macros { def impl(implicit reflect: Reflection): Expr[Unit] = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) // 2 is a lifted constant - val show1 = withNewQuoteContext(power(2, 3.0).show) + val show1 = withQuoteContext(power(2, 3.0).show) val run1 = run(power(2, 3.0)) // n is a lifted constant val n = 2 - val show2 = withNewQuoteContext(power(n, 4.0).show) + val show2 = withQuoteContext(power(n, 4.0).show) val run2 = run(power(n, 4.0)) // n is a constant in a quote - val show3 = withNewQuoteContext(power('{2}, 5.0).show) + val show3 = withQuoteContext(power('{2}, 5.0).show) val run3 = run(power('{2}, 5.0)) // n2 is clearly not a constant From f6bfbfa4871d52f3450168b45b1e613794100a51 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Thu, 27 Jun 2019 17:06:55 +0200 Subject: [PATCH 11/12] More explicit documentation --- library/src-3.x/scala/quoted/Expr.scala | 2 +- library/src-3.x/scala/quoted/Type.scala | 2 +- library/src-3.x/scala/quoted/package.scala | 6 ++++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/library/src-3.x/scala/quoted/Expr.scala b/library/src-3.x/scala/quoted/Expr.scala index 6ce05e4f78c2..f4b158ff76f0 100644 --- a/library/src-3.x/scala/quoted/Expr.scala +++ b/library/src-3.x/scala/quoted/Expr.scala @@ -21,7 +21,7 @@ package quoted { implicit class ExprOps[T](expr: Expr[T]) { - /** Show a source code like representation of this expression */ + /** Show a source code like representation of this expression without syntax highlight */ def show(implicit qctx: QuoteContext): String = qctx.show(expr, SyntaxHighlight.plain) /** Show a source code like representation of this expression */ diff --git a/library/src-3.x/scala/quoted/Type.scala b/library/src-3.x/scala/quoted/Type.scala index e9c890da79b1..d8100ef7580d 100644 --- a/library/src-3.x/scala/quoted/Type.scala +++ b/library/src-3.x/scala/quoted/Type.scala @@ -13,7 +13,7 @@ package quoted { implicit class TypeOps[T](tpe: Type[T]) { - /** Show a source code like representation of this type */ + /** Show a source code like representation of this type without syntax highlight */ def show(implicit qctx: QuoteContext): String = qctx.show(tpe, SyntaxHighlight.plain) /** Show a source code like representation of this type */ diff --git a/library/src-3.x/scala/quoted/package.scala b/library/src-3.x/scala/quoted/package.scala index 8633256c80d4..b90ebb1cf090 100644 --- a/library/src-3.x/scala/quoted/package.scala +++ b/library/src-3.x/scala/quoted/package.scala @@ -13,7 +13,8 @@ package object quoted { * ``` * where `expr: Expr[T]` * - * This method shoul not be called in a context where there is already has a QuoteContext. + * This method should not be called in a context where there is already has a `QuoteContext` + * such as within a `run` or a `withQuoteContext`. * * May throw a FreeVariableError on expressions that came from a macro. */ @@ -30,7 +31,8 @@ package object quoted { * ``` * where `thunk: T` * - * This method shoul not be called in a context where there is already has a QuoteContext. + * This method should not be called in a context where there is already has a `QuoteContext` + * such as within a `run` or a `withQuoteContext`. */ def withQuoteContext[T](thunk: given QuoteContext => T) given (toolbox: Toolbox): T = { var result: T = NoResult.asInstanceOf[T] From 68387bbc820e260d8c136ed600d4269bdb9edecb Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Thu, 27 Jun 2019 17:15:29 +0200 Subject: [PATCH 12/12] Update community build scalatest --- community-build/community-projects/scalatest | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/community-build/community-projects/scalatest b/community-build/community-projects/scalatest index cd51c7a08e1c..b05be940b584 160000 --- a/community-build/community-projects/scalatest +++ b/community-build/community-projects/scalatest @@ -1 +1 @@ -Subproject commit cd51c7a08e1ca26d5c0616fd5efc9b5ea8d25fe8 +Subproject commit b05be940b58440ee9dcf38f584f3283fc1d01799