From 3df32d4611871fbecfc86febeb24eb262079dd5f Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Sat, 5 Dec 2020 10:04:04 +0100 Subject: [PATCH 1/4] Rework reflect show API * Add `reflect.Printer[T]` type class * Define `show` method in reflect based on `Printer` * Provide a single default `show` for `Expr` and `Type` (use `reflect` to access other printers) * Only define printers that make sence for the given types. * Remove `Symbol.show`. Use directly `Symbol.fullName` instead. --- community-build/community-projects/verify | 2 +- .../scala/quoted/runtime/impl/Matcher.scala | 4 +- .../quoted/runtime/impl/QuotesImpl.scala | 115 ++++++++------- .../runtime/impl/printers/SourceCode.scala | 14 +- library/src/scala/quoted/Quotes.scala | 132 +++++++++++------- library/src/scala/quoted/Type.scala | 11 +- .../dotty/dokka/tasty/ClassLikeSupport.scala | 2 +- scala3doc/src/dotty/dokka/tasty/SymOps.scala | 2 +- .../src/dotty/dokka/tasty/TastyParser.scala | 4 +- .../test/BootstrappedStdLibTASYyTest.scala | 2 +- .../tasty-definitions-2/Macro_1.scala | 4 +- .../tasty-definitions-3/Macro_1.scala | 4 +- .../tasty-extractors-owners/quoted_1.scala | 4 +- .../tasty-load-tree-1/quoted_1.scala | 2 +- .../tasty-load-tree-2/quoted_1.scala | 2 +- .../tasty-inspector/i10359.scala | 2 +- .../tasty-inspector/i8364.scala | 2 +- .../tasty-inspector/Test.scala | 2 +- .../interpreter/TreeInterpreter.scala | 4 +- tests/run-macros/exports/Macro_2.scala | 2 +- .../f-interpolation-1/FQuote_1.scala | 2 +- tests/run-macros/i5119/Macro_1.scala | 7 +- tests/run-macros/i5119b/Macro_1.scala | 7 +- tests/run-macros/i6270/Macro_1.scala | 2 +- .../inferred-repeated-result/test_1.scala | 2 +- tests/run-macros/paramSymss/Macro_1.scala | 4 +- .../tasty-argument-tree-1/quoted_1.scala | 9 +- .../tasty-definitions-1/quoted_1.scala | 36 ++--- .../tasty-extractors-1/quoted_1.scala | 4 +- .../tasty-extractors-2/quoted_1.scala | 8 +- .../tasty-extractors-3/quoted_1.scala | 4 +- .../tasty-extractors-types/quoted_1.scala | 4 +- .../xml-interpolation-1/XmlQuote_1.scala | 4 +- .../xml-interpolation-2/XmlQuote_1.scala | 2 +- 34 files changed, 225 insertions(+), 186 deletions(-) diff --git a/community-build/community-projects/verify b/community-build/community-projects/verify index 03ce1f8a0aa8..c250c41cef19 160000 --- a/community-build/community-projects/verify +++ b/community-build/community-projects/verify @@ -1 +1 @@ -Subproject commit 03ce1f8a0aa8cc15536540c508c6088a8426c4e4 +Subproject commit c250c41cef198bdb8d8dd678944af2181ee684e3 diff --git a/compiler/src/scala/quoted/runtime/impl/Matcher.scala b/compiler/src/scala/quoted/runtime/impl/Matcher.scala index 89086df98156..ac9856e74c62 100644 --- a/compiler/src/scala/quoted/runtime/impl/Matcher.scala +++ b/compiler/src/scala/quoted/runtime/impl/Matcher.scala @@ -334,8 +334,8 @@ object Matcher { | |with environment: ${summon[Env]} | - |Scrutinee: ${scrutinee.showExtractors} - |Pattern: ${pattern.showExtractors} + |Scrutinee: ${scrutinee.show(using Printer.TreeStructure)} + |Pattern: ${pattern.show(using Printer.TreeStructure)} | |""".stripMargin) notMatched diff --git a/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala b/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala index 105a0829ab1e..8e3aa7575911 100644 --- a/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala +++ b/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala @@ -29,10 +29,10 @@ object QuotesImpl { new QuotesImpl def showDecompiledTree(tree: tpd.Tree)(using Context): String = - import qctx.reflect.TreeMethods.{showAnsiColored, show} + import qctx.reflect.Printer.{TreeCode, TreeAnsiCode} val qctx: QuotesImpl = new QuotesImpl(using MacroExpansion.context(tree)) - if ctx.settings.color.value == "always" then showAnsiColored(tree) - else show(tree) + if ctx.settings.color.value == "always" then TreeAnsiCode.show(tree) + else TreeCode.show(tree) // TODO Explore more fine grained scope ids. // This id can only differentiate scope extrusion from one compiler instance to another. @@ -48,10 +48,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler extension [T](self: scala.quoted.Expr[T]): def show: String = - reflect.TreeMethods.show(reflect.Term.of(self)) - - def showAnsiColored: String = - reflect.TreeMethods.showAnsiColored(reflect.Term.of(self)) + reflect.Printer.TreeCode.show(reflect.Term.of(self)) def matches(that: scala.quoted.Expr[Any]): Boolean = treeMatch(reflect.Term.of(self), reflect.Term.of(that)).nonEmpty @@ -70,8 +67,8 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler else throw Exception( s"""Expr cast exception: ${self.show} - |of type: ${reflect.TypeReprMethods.show(reflect.Term.of(self).tpe)} - |did not conform to type: ${reflect.TypeReprMethods.show(reflect.TypeRepr.of[X])} + |of type: ${reflect.Printer.TypeReprCode.show(reflect.Term.of(self).tpe)} + |did not conform to type: ${reflect.Printer.TypeReprCode.show(reflect.TypeRepr.of[X])} |""".stripMargin ) } @@ -89,14 +86,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler extension (self: Tree): def pos: Position = self.sourcePos def symbol: Symbol = self.symbol - def showExtractors: String = - Extractors.showTree(using QuotesImpl.this)(self) - def show: String = - SourceCode.showTree(using QuotesImpl.this)(self)(SyntaxHighlight.plain, fullNames = true) - def showShort: String = - SourceCode.showTree(using QuotesImpl.this)(self)(SyntaxHighlight.plain, fullNames = false) - def showAnsiColored: String = - SourceCode.showTree(using QuotesImpl.this)(self)(SyntaxHighlight.ANSI, fullNames = true) + def show(using printer: Printer[Tree]): String = printer.show(self) def isExpr: Boolean = self match case TermTypeTest(self) => @@ -1607,17 +1597,8 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler given TypeReprMethods: TypeReprMethods with extension (self: TypeRepr): - def showExtractors: String = - Extractors.showType(using QuotesImpl.this)(self) - - def show: String = - SourceCode.showType(using QuotesImpl.this)(self)(SyntaxHighlight.plain, fullNames = true) - def showShort: String = - SourceCode.showType(using QuotesImpl.this)(self)(SyntaxHighlight.plain, fullNames = false) - - def showAnsiColored: String = - SourceCode.showType(using QuotesImpl.this)(self)(SyntaxHighlight.ANSI, fullNames = true) + def show(using printer: Printer[TypeRepr]): String = printer.show(self) def seal: scala.quoted.Type[_] = self.asType @@ -2175,14 +2156,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler given ConstantMethods: ConstantMethods with extension (self: Constant): def value: Any = self.value - def showExtractors: String = - Extractors.showConstant(using QuotesImpl.this)(self) - def show: String = - SourceCode.showConstant(using QuotesImpl.this)(self)(SyntaxHighlight.plain, fullNames = true) - def showShort: String = - SourceCode.showConstant(using QuotesImpl.this)(self)(SyntaxHighlight.plain, fullNames = false) - def showAnsiColored: String = - SourceCode.showConstant(using QuotesImpl.this)(self)(SyntaxHighlight.ANSI, fullNames = true) + def show(using printer: Printer[Constant]): String = printer.show(self) end extension end ConstantMethods @@ -2404,12 +2378,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler def companionModule: Symbol = self.denot.companionModule def children: List[Symbol] = self.denot.children - def showExtractors: String = - Extractors.showSymbol(using QuotesImpl.this)(self) - def show: String = - SourceCode.showSymbol(using QuotesImpl.this)(self)(SyntaxHighlight.plain) - def showAnsiColored: String = - SourceCode.showSymbol(using QuotesImpl.this)(self)(SyntaxHighlight.ANSI) + def show(using printer: Printer[Symbol]): String = printer.show(self) end extension @@ -2548,12 +2517,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler def is(that: Flags): Boolean = self.isAllOf(that) def |(that: Flags): Flags = dotc.core.Flags.or(self, that) // TODO: Replace with dotc.core.Flags.|(self)(that) once extension names have stabilized def &(that: Flags): Flags = dotc.core.Flags.and(self, that)// TODO: Replace with dotc.core.Flags.&(self)(that) once extension names have stabilized - def showExtractors: String = - Extractors.showFlags(using QuotesImpl.this)(self) - def show: String = - SourceCode.showFlags(using QuotesImpl.this)(self)(SyntaxHighlight.plain) - def showAnsiColored: String = - SourceCode.showFlags(using QuotesImpl.this)(self)(SyntaxHighlight.ANSI) + def show(using printer: Printer[Flags]): String = printer.show(self) end extension end FlagsMethods @@ -2684,18 +2648,69 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler | | |The code of the definition of ${t.symbol} is - |${TreeMethods.show(t)} + |${Printer.TreeCode.show(t)} | |which was found in the code - |${TreeMethods.show(tree)} + |${Printer.TreeCode.show(tree)} | |which has the AST representation - |${TreeMethods.showExtractors(tree)} + |${Printer.TreeStructure.show(tree)} | |""".stripMargin) case _ => traverseChildren(t) }.traverse(tree) + object Printer extends PrinterModule: + + lazy val TreeCode: Printer[Tree] = new Printer[Tree]: + def show(tree: Tree): String = + SourceCode.showTree(using QuotesImpl.this)(tree)(SyntaxHighlight.plain, fullNames = true) + + lazy val TreeShortCode: Printer[Tree] = new Printer[Tree]: + def show(tree: Tree): String = + SourceCode.showTree(using QuotesImpl.this)(tree)(SyntaxHighlight.plain, fullNames = false) + + lazy val TreeAnsiCode: Printer[Tree] = new Printer[Tree]: + def show(tree: Tree): String = + SourceCode.showTree(using QuotesImpl.this)(tree)(SyntaxHighlight.ANSI, fullNames = true) + + lazy val TreeStructure: Printer[Tree] = new Printer[Tree]: + def show(tree: Tree): String = + Extractors.showTree(using QuotesImpl.this)(tree) + + lazy val TypeReprCode: Printer[TypeRepr] = new Printer[TypeRepr]: + def show(tpe: TypeRepr): String = + SourceCode.showType(using QuotesImpl.this)(tpe)(SyntaxHighlight.plain, fullNames = true) + + lazy val TypeReprShortCode: Printer[TypeRepr] = new Printer[TypeRepr]: + def show(tpe: TypeRepr): String = + SourceCode.showType(using QuotesImpl.this)(tpe)(SyntaxHighlight.plain, fullNames = false) + + lazy val TypeReprAnsiCode: Printer[TypeRepr] = new Printer[TypeRepr]: + def show(tpe: TypeRepr): String = + SourceCode.showType(using QuotesImpl.this)(tpe)(SyntaxHighlight.ANSI, fullNames = true) + + lazy val TypeReprStructure: Printer[TypeRepr] = new Printer[TypeRepr]: + def show(tpe: TypeRepr): String = + Extractors.showType(using QuotesImpl.this)(tpe) + + lazy val ConstantCode: Printer[Constant] = new Printer[Constant]: + def show(const: Constant): String = + SourceCode.showConstant(using QuotesImpl.this)(const)(SyntaxHighlight.plain, fullNames = true) + + lazy val ConstantAnsiCode: Printer[Constant] = new Printer[Constant]: + def show(const: Constant): String = + SourceCode.showConstant(using QuotesImpl.this)(const)(SyntaxHighlight.ANSI, fullNames = true) + + lazy val ConstantCase: Printer[Constant] = new Printer[Constant]: + def show(const: Constant): String = + Extractors.showConstant(using QuotesImpl.this)(const) + + lazy val FlagsCombination: Printer[Flags] = new Printer[Flags]: + def show(flags: Flags): String = + Extractors.showFlags(using QuotesImpl.this)(flags) + + end Printer end reflect def unpickleExpr[T](pickled: String | List[String], typeHole: (Int, Seq[Any]) => scala.quoted.Type[?], termHole: (Int, Seq[Any], scala.quoted.Quotes) => scala.quoted.Expr[?]): scala.quoted.Expr[T] = diff --git a/compiler/src/scala/quoted/runtime/impl/printers/SourceCode.scala b/compiler/src/scala/quoted/runtime/impl/printers/SourceCode.scala index e751cd352d95..e412bc6941f0 100644 --- a/compiler/src/scala/quoted/runtime/impl/printers/SourceCode.scala +++ b/compiler/src/scala/quoted/runtime/impl/printers/SourceCode.scala @@ -188,7 +188,7 @@ object SourceCode { case Select(newTree: New, _) => printType(newTree.tpe)(using Some(cdef.symbol)) case parent: Term => - throw new MatchError(parent.showExtractors) + throw new MatchError(parent.show(using Printer.TreeStructure)) } def printSeparated(list: List[Tree /* Term | TypeTree */]): Unit = list match { @@ -535,7 +535,7 @@ object SourceCode { printTree(meth) case _ => - throw new MatchError(tree.showExtractors) + throw new MatchError(tree.show(using Printer.TreeStructure)) } @@ -922,7 +922,7 @@ object SourceCode { case Ident("unapply" | "unapplySeq") => this += fun.symbol.owner.fullName.stripSuffix("$") case _ => - throw new MatchError(fun.showExtractors) + throw new MatchError(fun.show(using Printer.TreeStructure)) } inParens(printPatterns(patterns, ", ")) @@ -937,7 +937,7 @@ object SourceCode { printTree(v) case _ => - throw new MatchError(pattern.showExtractors) + throw new MatchError(pattern.show(using Printer.TreeStructure)) } @@ -1063,7 +1063,7 @@ object SourceCode { printTypeTree(tpt) case _ => - throw new MatchError(tree.showExtractors) + throw new MatchError(tree.show(using Printer.TreeStructure)) } @@ -1233,7 +1233,7 @@ object SourceCode { printType(hi) case _ => - throw new MatchError(tpe.showExtractors) + throw new MatchError(tpe.show(using Printer.TypeReprStructure)) } private def printSelector(sel: Selector): this.type = sel match { @@ -1272,7 +1272,7 @@ object SourceCode { val sym = annot.tpe.typeSymbol sym != Symbol.requiredClass("scala.forceInline") && sym.maybeOwner != Symbol.requiredPackage("scala.annotation.internal") - case x => throw new MatchError(x.showExtractors) + case x => throw new MatchError(x.show(using Printer.TreeStructure)) } printAnnotations(annots) if (annots.nonEmpty) this += " " diff --git a/library/src/scala/quoted/Quotes.scala b/library/src/scala/quoted/Quotes.scala index 1766821f589e..4241518246c8 100644 --- a/library/src/scala/quoted/Quotes.scala +++ b/library/src/scala/quoted/Quotes.scala @@ -17,12 +17,9 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching => // Extension methods for `Expr[T]` extension [T](self: Expr[T]): - /** Show a source code like representation of this expression without syntax highlight */ + /** Show a source code like representation of this expression */ def show: String - /** Shows the tree as fully typed source code colored with ANSI */ - def showAnsiColored: String - /** Pattern matches `this` against `that`. Effectively performing a deep equality check. * It does the equivalent of * ``` @@ -216,17 +213,8 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching => /** Symbol of defined or referred by this tree */ def symbol: Symbol - /** Shows the tree as extractors */ - def showExtractors: String - - /** Shows the tree as fully typed source code */ - def show: String - - /** Shows the tree as without package prefix*/ - def showShort: String - - /** Shows the tree as fully typed source code colored with ANSI */ - def showAnsiColored: String + /** Shows the tree as String */ + def show(using Printer[Tree]): String /** Does this tree represent a valid expression? */ def isExpr: Boolean @@ -2057,17 +2045,8 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching => trait TypeReprMethods { extension (self: TypeRepr): - /** Shows the tree as extractors */ - def showExtractors: String - - /** Shows the tree as fully typed source code */ - def show: String - - /** Shows the tree as without package prefix*/ - def showShort: String - - /** Shows the tree as fully typed source code colored with ANSI */ - def showAnsiColored: String + /** Shows the type as a String */ + def show(using Printer[TypeRepr]): String /** Convert this `TypeRepr` to an `Type[?]` * @@ -2869,17 +2848,9 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching => /** Returns the value of the constant */ def value: Any - /** Shows the tree as extractors */ - def showExtractors: String - - /** Shows the tree as without package prefix*/ - def showShort: String + /** Shows the constant as a String */ + def show(using Printer[Constant]): String - /** Shows the tree as fully typed source code */ - def show: String - - /** Shows the tree as fully typed source code colored with ANSI */ - def showAnsiColored: String end extension } @@ -3215,15 +3186,6 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching => /** The symbol of the companion module */ def companionModule: Symbol - /** Shows the tree as extractors */ - def showExtractors: String - - /** Shows the tree as fully typed source code */ - def show: String - - /** Shows the tree as fully typed source code colored with ANSI */ - def showAnsiColored: String - /** Case class or case object children of a sealed trait */ def children: List[Symbol] end extension @@ -3601,14 +3563,8 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching => /** Intersection of the two flag sets */ def &(that: Flags): Flags - /** Shows the tree as extractors */ - def showExtractors: String - - /** Shows the tree as fully typed source code */ - def show: String - - /** Shows the tree as fully typed source code colored with ANSI */ - def showAnsiColored: String + /** Shows the flags as a String */ + def show(using Printer[Flags]): String end extension } @@ -4057,6 +4013,76 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching => end TreeMap + /** Type class used in `show` methods to provide customizable `String` representations */ + trait Printer[T]: + /** Show the arguments as a `String` */ + def show(x: T): String + end Printer + + /** Default pinter for `Tree` used when calling `tree.show` */ + given TreePrinter: Printer[Tree] = Printer.TreeCode + + /** Default pinter for `TypeRepr` used when calling `tpe.show` */ + given TypeReprPrinter: Printer[TypeRepr] = Printer.TypeReprCode + + /** Default pinter for `Flags` used when calling `flags.show` */ + given ConstantPrinter: Printer[Constant] = Printer.ConstantCase + + /** Default pinter for `Flags` used when calling `flags.show` */ + given FlagsPrinter: Printer[Flags] = Printer.FlagsCombination + + /** Module object of `type Printer`. + * Contains custom printers such as `TreeCode`, `TreeAnsiCode`, `TreeCases`, `TypeReprCode`, ..., `SymbolFullName` and `FlagsCombination`. + */ + val Printer: PrinterModule + + /** Methods of the module object `val Printer` */ + trait PrinterModule { self: Printer.type => + /** Prints fully elaborated vesion of the source code. */ + def TreeCode: Printer[Tree] + + /** Prints fully elaborated vesion of the source code. + * Same as `TreeCode` but does not print full package prefixes. + */ + def TreeShortCode: Printer[Tree] + + /** Prints fully elaborated vesion of the source code using ANSI colors. */ + def TreeAnsiCode: Printer[Tree] + + /** Prints a pattern like representation of the `Tree`. + * It displays the structure of the AST. + */ + def TreeStructure: Printer[Tree] + + /** Prints the type in source code. */ + def TypeReprCode: Printer[TypeRepr] + + /** Prints the type in source code. + * Same as `TypeReprCode` but does not print full package prefixes. + */ + def TypeReprShortCode: Printer[TypeRepr] + + /** Prints the type in source code using ANSI colors. */ + def TypeReprAnsiCode: Printer[TypeRepr] + + /** Prints a pattern like representation of the `TypeRepr`. + * It displays the structure of the type. + */ + def TypeReprStructure: Printer[TypeRepr] + + /** Prints the Constant as source code. */ + def ConstantCode: Printer[Constant] + + /** Prints the Constant as source code using ANSI colors. */ + def ConstantAnsiCode: Printer[Constant] + + /** Prints a pattern like representation of the `Constant`. */ + def ConstantCase: Printer[Constant] + + /** Prints compination of `Flags` that form this particular flag. */ + def FlagsCombination: Printer[Flags] + } + } /** Type of a `Quotes` provided by a splice within a quote that took this context. */ diff --git a/library/src/scala/quoted/Type.scala b/library/src/scala/quoted/Type.scala index ff40b0233581..a550e9792f22 100644 --- a/library/src/scala/quoted/Type.scala +++ b/library/src/scala/quoted/Type.scala @@ -13,15 +13,8 @@ object Type: /** Show a source code like representation of this type without syntax highlight */ def show[T](using Type[T])(using Quotes): String = - quotes.reflect.TypeTree.of[T].show - - /** Show a source code like representation of this type without syntax highlight */ - def showShort[T](using Type[T])(using Quotes): String = - quotes.reflect.TypeTree.of[T].showShort - - /** Shows the tree as fully typed source code colored with ANSI */ - def showAnsiColored[T](using Type[T])(using Quotes): String = - quotes.reflect.TypeTree.of[T].showAnsiColored + import quotes.reflect._ + TypeTree.of[T].show /** Return a quoted.Type with the given type */ @compileTimeOnly("Reference to `scala.quoted.Type.of` was not handled by PickleQuotes") diff --git a/scala3doc/src/dotty/dokka/tasty/ClassLikeSupport.scala b/scala3doc/src/dotty/dokka/tasty/ClassLikeSupport.scala index 18f9afafa149..54cb40658bed 100644 --- a/scala3doc/src/dotty/dokka/tasty/ClassLikeSupport.scala +++ b/scala3doc/src/dotty/dokka/tasty/ClassLikeSupport.scala @@ -215,7 +215,7 @@ trait ClassLikeSupport: .membersToDocument.filterNot(m => ownMemberDRIs.contains(m.symbol.name)) .flatMap(parseMember) } - c.symbol.show match { + c.symbol.fullName match { case "scala.Predef$" => ownMembers ++ extractPatchMembers(qctx.reflect.Symbol.requiredClass("scala.runtime.stdLibPatches.Predef$")) diff --git a/scala3doc/src/dotty/dokka/tasty/SymOps.scala b/scala3doc/src/dotty/dokka/tasty/SymOps.scala index 23ffc93c7ca9..17c0a03fe0aa 100644 --- a/scala3doc/src/dotty/dokka/tasty/SymOps.scala +++ b/scala3doc/src/dotty/dokka/tasty/SymOps.scala @@ -115,5 +115,5 @@ class SymOps[Q <: Quotes](val q: Q): pointsTo, // sym.show returns the same signature for def << = 1 and def >> = 2. // For some reason it contains `$$$` instrad of symbol name - s"${sym.name}${sym.show}/${sym.signature.resultSig}/[${sym.signature.paramSigs.mkString("/")}]" + s"${sym.name}${sym.fullName}/${sym.signature.resultSig}/[${sym.signature.paramSigs.mkString("/")}]" ) diff --git a/scala3doc/src/dotty/dokka/tasty/TastyParser.scala b/scala3doc/src/dotty/dokka/tasty/TastyParser.scala index 6b2cf4404d42..054587a4fcc8 100644 --- a/scala3doc/src/dotty/dokka/tasty/TastyParser.scala +++ b/scala3doc/src/dotty/dokka/tasty/TastyParser.scala @@ -33,7 +33,7 @@ case class DokkaTastyInspector(parser: Parser)(using ctx: DocContext) extends Do // NOTE we avoid documenting definitions in the magical stdLibPatches directory; // the symbols there are "patched" through dark Dotty magic onto other stdlib // definitions, so if we documented their origin, we'd get defs with duplicate DRIs - if !root.symbol.show.startsWith("scala.runtime.stdLibPatches") then + if !root.symbol.fullName.startsWith("scala.runtime.stdLibPatches") then val parser = new TastyParser(q, this) def driFor(link: String): Option[DRI] = @@ -123,7 +123,7 @@ case class TastyParser(qctx: Quotes, inspector: DokkaTastyInspector)(using val c case t: Throwable => try report.warning(throwableToString(t), sym.tree.pos) catch case _: Throwable => - report.warning(s"Failed to process ${sym.show}:\n${throwableToString(t)}") + report.warning(s"Failed to process ${sym.fullName}:\n${throwableToString(t)}") None def parseRootTree(root: Tree): Seq[Documentable] = diff --git a/stdlib-bootstrapped-tasty-tests/test/BootstrappedStdLibTASYyTest.scala b/stdlib-bootstrapped-tasty-tests/test/BootstrappedStdLibTASYyTest.scala index b8a0c7bbb122..ef004baa191a 100644 --- a/stdlib-bootstrapped-tasty-tests/test/BootstrappedStdLibTASYyTest.scala +++ b/stdlib-bootstrapped-tasty-tests/test/BootstrappedStdLibTASYyTest.scala @@ -103,7 +103,7 @@ object BootstrappedStdLibTASYyTest: def loadWithTastyInspector(blacklisted: Set[String]): Unit = val inspector = new scala.tasty.inspector.TastyInspector { def processCompilationUnit(using Quotes)(root: quotes.reflect.Tree): Unit = - root.showExtractors // Check that we can traverse the full tree + root.show(using quotes.reflect.Printer.TreeStructure) // Check that we can traverse the full tree () } val tastyFiles = scalaLibTastyPaths.filterNot(blacklisted) diff --git a/tests/run-custom-args/Yretain-trees/tasty-definitions-2/Macro_1.scala b/tests/run-custom-args/Yretain-trees/tasty-definitions-2/Macro_1.scala index c8e2ac2b8e52..586f245c7459 100644 --- a/tests/run-custom-args/Yretain-trees/tasty-definitions-2/Macro_1.scala +++ b/tests/run-custom-args/Yretain-trees/tasty-definitions-2/Macro_1.scala @@ -8,8 +8,8 @@ object Foo { def inspectBodyImpl(x: Expr[Int])(using Quotes) : Expr[String] = { import quotes.reflect._ Term.of(x) match { - case Inlined(None, Nil, arg) => Expr(arg.symbol.tree.showExtractors) - case arg => Expr(arg.symbol.tree.showExtractors) // TODO should all by name parameters be in an inline node? + case Inlined(None, Nil, arg) => Expr(arg.symbol.tree.show(using Printer.TreeStructure)) + case arg => Expr(arg.symbol.tree.show(using Printer.TreeStructure)) // TODO should all by name parameters be in an inline node? } } diff --git a/tests/run-custom-args/Yretain-trees/tasty-definitions-3/Macro_1.scala b/tests/run-custom-args/Yretain-trees/tasty-definitions-3/Macro_1.scala index 379e5d798390..9ddaea06bc5a 100644 --- a/tests/run-custom-args/Yretain-trees/tasty-definitions-3/Macro_1.scala +++ b/tests/run-custom-args/Yretain-trees/tasty-definitions-3/Macro_1.scala @@ -8,8 +8,8 @@ object Foo { def inspectBodyImpl(x: Expr[Int])(using Quotes) : Expr[String] = { import quotes.reflect._ Term.of(x) match { - case Inlined(None, Nil, arg) => Expr(arg.symbol.tree.showExtractors) - case arg => Expr(arg.symbol.tree.showExtractors) // TODO should all by name parameters be in an inline node? + case Inlined(None, Nil, arg) => Expr(arg.symbol.tree.show(using Printer.TreeStructure)) + case arg => Expr(arg.symbol.tree.show(using Printer.TreeStructure)) // TODO should all by name parameters be in an inline node? } } } diff --git a/tests/run-custom-args/Yretain-trees/tasty-extractors-owners/quoted_1.scala b/tests/run-custom-args/Yretain-trees/tasty-extractors-owners/quoted_1.scala index 09054f8a5a5e..7593a4af18b0 100644 --- a/tests/run-custom-args/Yretain-trees/tasty-extractors-owners/quoted_1.scala +++ b/tests/run-custom-args/Yretain-trees/tasty-extractors-owners/quoted_1.scala @@ -25,12 +25,12 @@ object Macros { case tree @ DefDef(name, _, _, _, _) => buff.append(name) buff.append("\n") - buff.append(tree.symbol.owner.tree.showExtractors) + buff.append(tree.symbol.owner.tree.show(using Printer.TreeStructure)) buff.append("\n\n") case tree @ ValDef(name, _, _) => buff.append(name) buff.append("\n") - buff.append(tree.symbol.owner.tree.showExtractors) + buff.append(tree.symbol.owner.tree.show(using Printer.TreeStructure)) buff.append("\n\n") case _ => } diff --git a/tests/run-custom-args/Yretain-trees/tasty-load-tree-1/quoted_1.scala b/tests/run-custom-args/Yretain-trees/tasty-load-tree-1/quoted_1.scala index 424a60ff506f..9af2c09daccf 100644 --- a/tests/run-custom-args/Yretain-trees/tasty-load-tree-1/quoted_1.scala +++ b/tests/run-custom-args/Yretain-trees/tasty-load-tree-1/quoted_1.scala @@ -10,7 +10,7 @@ object Foo { import quotes.reflect._ def definitionString(sym: Symbol): Expr[String] = - if sym.isClassDef || sym.isDefDef || sym.isValDef then Expr(sym.tree.showExtractors) + if sym.isClassDef || sym.isDefDef || sym.isValDef then Expr(sym.tree.show(using Printer.TreeStructure)) else '{"NO DEFINTION"} Term.of(x) match { diff --git a/tests/run-custom-args/Yretain-trees/tasty-load-tree-2/quoted_1.scala b/tests/run-custom-args/Yretain-trees/tasty-load-tree-2/quoted_1.scala index 7e567cca9de3..b9a3d7c7e4fc 100644 --- a/tests/run-custom-args/Yretain-trees/tasty-load-tree-2/quoted_1.scala +++ b/tests/run-custom-args/Yretain-trees/tasty-load-tree-2/quoted_1.scala @@ -9,7 +9,7 @@ object Foo { import quotes.reflect._ def definitionString(sym: Symbol): Expr[String] = - if sym.isClassDef || sym.isDefDef || sym.isValDef then Expr(sym.tree.showExtractors) + if sym.isClassDef || sym.isDefDef || sym.isValDef then Expr(sym.tree.show(using Printer.TreeStructure)) else '{"NO DEFINTION"} Term.of(x) match { diff --git a/tests/run-custom-args/tasty-inspector/i10359.scala b/tests/run-custom-args/tasty-inspector/i10359.scala index d8a213f5628b..b724d0431b4a 100644 --- a/tests/run-custom-args/tasty-inspector/i10359.scala +++ b/tests/run-custom-args/tasty-inspector/i10359.scala @@ -42,5 +42,5 @@ class TestInspector() extends TastyInspector: assert(code.contains("import Foo.this.g.{given}"), code) assert(code.contains("import Foo.this.g.{given scala.Int}"), code) - val extractors = root.showExtractors + val extractors = root.show(using Printer.TreeStructure) assert(extractors.contains("GivenSelector"), extractors) diff --git a/tests/run-custom-args/tasty-inspector/i8364.scala b/tests/run-custom-args/tasty-inspector/i8364.scala index cf1dcc0e9b71..59775110d46d 100644 --- a/tests/run-custom-args/tasty-inspector/i8364.scala +++ b/tests/run-custom-args/tasty-inspector/i8364.scala @@ -4,7 +4,7 @@ import scala.tasty.inspector._ @main def Test = { val inspector = new TastyInspector { protected def processCompilationUnit(using Quotes)(tree: quotes.reflect.Tree): Unit = { - tree.showExtractors // Make sure that tree is loaded and can be traveresed + tree.show(using quotes.reflect.Printer.TreeStructure) // Make sure that tree is loaded and can be traveresed } } diff --git a/tests/run-custom-args/tasty-inspector/tasty-inspector/Test.scala b/tests/run-custom-args/tasty-inspector/tasty-inspector/Test.scala index 6ce95fc87403..017bb7c2f8d5 100644 --- a/tests/run-custom-args/tasty-inspector/tasty-inspector/Test.scala +++ b/tests/run-custom-args/tasty-inspector/tasty-inspector/Test.scala @@ -21,7 +21,7 @@ class DBInspector extends TastyInspector { override def traverseTree(tree: Tree)(owner: Symbol): Unit = tree match { case tree: Definition => - println(tree.showExtractors) + println(tree.show(using Printer.TreeStructure)) super.traverseTree(tree)(owner) case tree => super.traverseTree(tree)(owner) diff --git a/tests/run-custom-args/tasty-interpreter/interpreter/TreeInterpreter.scala b/tests/run-custom-args/tasty-interpreter/interpreter/TreeInterpreter.scala index f5b0a73ecc12..0118575ac861 100644 --- a/tests/run-custom-args/tasty-interpreter/interpreter/TreeInterpreter.scala +++ b/tests/run-custom-args/tasty-interpreter/interpreter/TreeInterpreter.scala @@ -155,7 +155,7 @@ abstract class TreeInterpreter[Q <: Quotes & Singleton](using val q: Q) { case Typed(expr, _) => log("", tree)(eval(expr)) case Repeated(elems, _) => log("", tree)(interpretRepeated(elems.map(elem => eval(elem)))) - case _ => throw new MatchError(tree.showExtractors) + case _ => throw new MatchError(tree.show(using Printer.TreeStructure)) } } @@ -164,7 +164,7 @@ abstract class TreeInterpreter[Q <: Quotes & Singleton](using val q: Q) { println( s"""#> $tag: |${tree.show} - |${tree.showExtractors} + |${tree.show(using Printer.TreeStructure)} | |""".stripMargin) thunk diff --git a/tests/run-macros/exports/Macro_2.scala b/tests/run-macros/exports/Macro_2.scala index 596f611f36dc..3c0a3c04fb59 100644 --- a/tests/run-macros/exports/Macro_2.scala +++ b/tests/run-macros/exports/Macro_2.scala @@ -22,7 +22,7 @@ private def visitExportsShowImpl[T: Type](e: Expr[T])(using Quotes): Expr[Any] = private def visitExportsShowExtractImpl[T: Type](e: Expr[T])(using Quotes): Expr[Any] = import quotes.reflect._ - '{println(${Expr(Term.of(e).showExtractors)})} + '{println(${Expr(Term.of(e).show(using Printer.TreeStructure))})} private object IdempotentExprMap extends ExprMap { diff --git a/tests/run-macros/f-interpolation-1/FQuote_1.scala b/tests/run-macros/f-interpolation-1/FQuote_1.scala index 6f3b0de216aa..c61837b13999 100644 --- a/tests/run-macros/f-interpolation-1/FQuote_1.scala +++ b/tests/run-macros/f-interpolation-1/FQuote_1.scala @@ -38,7 +38,7 @@ object FQuote { values.forall(isStringConstant) => values.collect { case Literal(Constant.String(value)) => value } case tree => - report.error(s"String literal expected, but ${tree.showExtractors} found") + report.error(s"String literal expected, but ${tree.show(using Printer.TreeStructure)} found") return '{???} } diff --git a/tests/run-macros/i5119/Macro_1.scala b/tests/run-macros/i5119/Macro_1.scala index edae1bd90c76..933725164463 100644 --- a/tests/run-macros/i5119/Macro_1.scala +++ b/tests/run-macros/i5119/Macro_1.scala @@ -5,8 +5,9 @@ object Macro { inline def ff(args: => Any*): String = ${ Macro.impl('sc, 'args) } } implicit inline def XmlQuote(inline sc: StringContext): StringContextOps = new StringContextOps(sc) - def impl(sc: Expr[StringContext], args: Expr[Seq[Any]])(using Quotes) : Expr[String] = { - import quotes.reflect._ - Expr(Term.of(sc).underlyingArgument.showExtractors + "\n" + Term.of(args).underlyingArgument.showExtractors) + def impl(sc: Expr[StringContext], args: Expr[Seq[Any]])(using q: Quotes) : Expr[String] = { + import q.reflect._ + given Printer[Tree] = Printer.TreeStructure + Expr(Term.of(sc).underlyingArgument.show + "\n" + Term.of(args).underlyingArgument.show) } } diff --git a/tests/run-macros/i5119b/Macro_1.scala b/tests/run-macros/i5119b/Macro_1.scala index cccb1dc819b4..ad18af6b1104 100644 --- a/tests/run-macros/i5119b/Macro_1.scala +++ b/tests/run-macros/i5119b/Macro_1.scala @@ -5,8 +5,9 @@ object Macro { inline def ff(arg1: Any, arg2: Any): String = ${ Macro.impl('{arg1}, '{arg2}) } - def impl(arg1: Expr[Any], arg2: Expr[Any])(using Quotes) : Expr[String] = - import quotes.reflect._ - Expr(Term.of(arg1).underlyingArgument.showExtractors + "\n" + Term.of(arg2).underlyingArgument.showExtractors) + def impl(arg1: Expr[Any], arg2: Expr[Any])(using q: Quotes) : Expr[String] = + import q.reflect._ + given Printer[Tree] = Printer.TreeStructure + Expr(Term.of(arg1).underlyingArgument.show + "\n" + Term.of(arg2).underlyingArgument.show) } diff --git a/tests/run-macros/i6270/Macro_1.scala b/tests/run-macros/i6270/Macro_1.scala index 9140a5e8e22d..5cfa17385bd1 100644 --- a/tests/run-macros/i6270/Macro_1.scala +++ b/tests/run-macros/i6270/Macro_1.scala @@ -14,6 +14,6 @@ object api { private def reflImplColor(x: Expr[String])(using Quotes) : Expr[String] = { import quotes.reflect._ - Expr(x.showAnsiColored) + Expr(Term.of(x).show(using Printer.TreeAnsiCode)) } } diff --git a/tests/run-macros/inferred-repeated-result/test_1.scala b/tests/run-macros/inferred-repeated-result/test_1.scala index d27d2f9360d0..379f877a70fd 100644 --- a/tests/run-macros/inferred-repeated-result/test_1.scala +++ b/tests/run-macros/inferred-repeated-result/test_1.scala @@ -9,7 +9,7 @@ object Macros { val methods = tree.tpe.classSymbol.get.declaredMethods.map { m => - val name = m.show + val name = m.fullName m.tree match case ddef: DefDef => val returnType = ddef.returnTpt.tpe.show diff --git a/tests/run-macros/paramSymss/Macro_1.scala b/tests/run-macros/paramSymss/Macro_1.scala index 4b482724ffd3..08c1841899cb 100644 --- a/tests/run-macros/paramSymss/Macro_1.scala +++ b/tests/run-macros/paramSymss/Macro_1.scala @@ -8,6 +8,6 @@ def showParamSymsExpr(using Quotes)(x: Expr[Any]): Expr[String] = val '{ $y: Any } = x // Drop Inlined not to access the symbol val sym = Term.of(y).symbol Expr( - s"""sym: ${sym.show} - |paramSymss: ${sym.paramSymss.map(_.map(_.show))} + s"""sym: ${sym.fullName} + |paramSymss: ${sym.paramSymss.map(_.map(_.fullName))} |""".stripMargin) diff --git a/tests/run-macros/tasty-argument-tree-1/quoted_1.scala b/tests/run-macros/tasty-argument-tree-1/quoted_1.scala index 2199d589af85..2120e1c38a67 100644 --- a/tests/run-macros/tasty-argument-tree-1/quoted_1.scala +++ b/tests/run-macros/tasty-argument-tree-1/quoted_1.scala @@ -4,13 +4,14 @@ object Macros { inline def inspect[T](x: T): Unit = ${ impl('x) } - def impl[T](x: Expr[T])(using Quotes) : Expr[Unit] = { - import quotes.reflect._ + def impl[T](x: Expr[T])(using q: Quotes) : Expr[Unit] = { + import q.reflect._ val tree = Term.of(x) + given Printer[Tree] = Printer.TreeStructure '{ println() - println("tree: " + ${Expr(tree.showExtractors)}) - println("tree deref. vals: " + ${Expr(tree.underlying.showExtractors)}) + println("tree: " + ${Expr(tree.show)}) + println("tree deref. vals: " + ${Expr(tree.underlying.show)}) } } } diff --git a/tests/run-macros/tasty-definitions-1/quoted_1.scala b/tests/run-macros/tasty-definitions-1/quoted_1.scala index 514e858bde63..f425384da21f 100644 --- a/tests/run-macros/tasty-definitions-1/quoted_1.scala +++ b/tests/run-macros/tasty-definitions-1/quoted_1.scala @@ -4,8 +4,8 @@ object Macros { inline def testDefinitions(): Unit = ${testDefinitionsImpl} - def testDefinitionsImpl(using Quotes) : Expr[Unit] = { - import quotes.reflect._ + def testDefinitionsImpl(using q: Quotes) : Expr[Unit] = { + import q.reflect._ val buff = List.newBuilder[String] def printout(x: => String): Unit = { @@ -74,21 +74,23 @@ object Macros { printout(defn.ScalaPrimitiveValueClasses.map(_.name).toString) printout(defn.ScalaNumericValueClasses.map(_.name).toString) - printout(TypeRepr.of[Unit].showExtractors) - printout(TypeRepr.of[Byte].showExtractors) - printout(TypeRepr.of[Char].showExtractors) - printout(TypeRepr.of[Int].showExtractors) - printout(TypeRepr.of[Long].showExtractors) - printout(TypeRepr.of[Float].showExtractors) - printout(TypeRepr.of[Double].showExtractors) - printout(TypeRepr.of[Boolean].showExtractors) - printout(TypeRepr.of[Any].showExtractors) - printout(TypeRepr.of[AnyVal].showExtractors) - printout(TypeRepr.of[AnyRef].showExtractors) - printout(TypeRepr.of[Object].showExtractors) - printout(TypeRepr.of[Nothing].showExtractors) - printout(TypeRepr.of[Null].showExtractors) - printout(TypeRepr.of[String].showExtractors) + given Printer[TypeRepr] = Printer.TypeReprStructure + + printout(TypeRepr.of[Unit].show) + printout(TypeRepr.of[Byte].show) + printout(TypeRepr.of[Char].show) + printout(TypeRepr.of[Int].show) + printout(TypeRepr.of[Long].show) + printout(TypeRepr.of[Float].show) + printout(TypeRepr.of[Double].show) + printout(TypeRepr.of[Boolean].show) + printout(TypeRepr.of[Any].show) + printout(TypeRepr.of[AnyVal].show) + printout(TypeRepr.of[AnyRef].show) + printout(TypeRepr.of[Object].show) + printout(TypeRepr.of[Nothing].show) + printout(TypeRepr.of[Null].show) + printout(TypeRepr.of[String].show) '{println(${Expr(buff.result().mkString("\n"))})} diff --git a/tests/run-macros/tasty-extractors-1/quoted_1.scala b/tests/run-macros/tasty-extractors-1/quoted_1.scala index 2c637095e9ae..db1656e6474c 100644 --- a/tests/run-macros/tasty-extractors-1/quoted_1.scala +++ b/tests/run-macros/tasty-extractors-1/quoted_1.scala @@ -9,8 +9,8 @@ object Macros { import quotes.reflect._ val tree = Term.of(x) - val treeStr = Expr(tree.showExtractors) - val treeTpeStr = Expr(tree.tpe.showExtractors) + val treeStr = Expr(tree.show(using Printer.TreeStructure)) + val treeTpeStr = Expr(tree.tpe.show(using Printer.TypeReprStructure)) '{ println(${treeStr}) diff --git a/tests/run-macros/tasty-extractors-2/quoted_1.scala b/tests/run-macros/tasty-extractors-2/quoted_1.scala index 208405eedb61..822047e1f70e 100644 --- a/tests/run-macros/tasty-extractors-2/quoted_1.scala +++ b/tests/run-macros/tasty-extractors-2/quoted_1.scala @@ -5,13 +5,13 @@ object Macros { implicit inline def printTree[T](inline x: T): Unit = ${ impl('x) } - def impl[T](x: Expr[T])(using Quotes) : Expr[Unit] = { - import quotes.reflect._ + def impl[T](x: Expr[T])(using q: Quotes) : Expr[Unit] = { + import q.reflect._ val tree = Term.of(x) - val treeStr = Expr(tree.showExtractors) - val treeTpeStr = Expr(tree.tpe.showExtractors) + val treeStr = Expr(tree.show(using Printer.TreeStructure)) + val treeTpeStr = Expr(tree.tpe.show(using Printer.TypeReprStructure)) '{ println(${treeStr}) diff --git a/tests/run-macros/tasty-extractors-3/quoted_1.scala b/tests/run-macros/tasty-extractors-3/quoted_1.scala index dca1daab8c4c..d15254cc27f1 100644 --- a/tests/run-macros/tasty-extractors-3/quoted_1.scala +++ b/tests/run-macros/tasty-extractors-3/quoted_1.scala @@ -13,11 +13,11 @@ object Macros { val traverser = new TreeTraverser { override def traverseTree(tree: Tree)(owner: Symbol): Unit = tree match { case tree: TypeBoundsTree => - buff.append(tree.tpe.showExtractors) + buff.append(tree.tpe.show(using Printer.TypeReprStructure)) buff.append("\n\n") traverseTreeChildren(tree)(owner) case tree: TypeTree => - buff.append(tree.tpe.showExtractors) + buff.append(tree.tpe.show(using Printer.TypeReprStructure)) buff.append("\n\n") traverseTreeChildren(tree)(owner) case _ => diff --git a/tests/run-macros/tasty-extractors-types/quoted_1.scala b/tests/run-macros/tasty-extractors-types/quoted_1.scala index 24d79198cf08..626f5f0acf57 100644 --- a/tests/run-macros/tasty-extractors-types/quoted_1.scala +++ b/tests/run-macros/tasty-extractors-types/quoted_1.scala @@ -7,8 +7,8 @@ object Macros { def impl[T: Type](using Quotes) : Expr[Unit] = { import quotes.reflect._ '{ - println(${Expr(TypeTree.of[T].showExtractors)}) - println(${Expr(TypeRepr.of[T].showExtractors)}) + println(${Expr(TypeTree.of[T].show(using Printer.TreeStructure))}) + println(${Expr(TypeRepr.of[T].show(using Printer.TypeReprStructure))}) println() } } diff --git a/tests/run-macros/xml-interpolation-1/XmlQuote_1.scala b/tests/run-macros/xml-interpolation-1/XmlQuote_1.scala index 4b6c89c8b215..8b7a888c084a 100644 --- a/tests/run-macros/xml-interpolation-1/XmlQuote_1.scala +++ b/tests/run-macros/xml-interpolation-1/XmlQuote_1.scala @@ -17,7 +17,7 @@ object XmlQuote { // for debugging purpose def pp(tree: Tree): Unit = { - println(tree.showExtractors) + println(tree.show(using Printer.TreeStructure)) println(tree.show) } @@ -48,7 +48,7 @@ object XmlQuote { values.forall(isStringConstant) => values.collect { case Literal(Constant.String(value)) => value } case tree => - report.error(s"String literal expected, but ${tree.showExtractors} found") + report.error(s"String literal expected, but ${tree.show(using Printer.TreeStructure)} found") return '{ ??? } } diff --git a/tests/run-macros/xml-interpolation-2/XmlQuote_1.scala b/tests/run-macros/xml-interpolation-2/XmlQuote_1.scala index 73d43f35e90d..eac958ce25bf 100644 --- a/tests/run-macros/xml-interpolation-2/XmlQuote_1.scala +++ b/tests/run-macros/xml-interpolation-2/XmlQuote_1.scala @@ -18,7 +18,7 @@ object XmlQuote { // for debugging purpose def pp(tree: Tree): Unit = { - println(tree.showExtractors) + println(tree.show(using Printer.TreeStructure)) println(tree.show) } From 4c2432a0579bd2d28779f513b46345c90b40dbc4 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 7 Dec 2020 17:30:48 +0100 Subject: [PATCH 2/4] Simplify Flags.show --- compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala | 6 +----- library/src/scala/quoted/Quotes.scala | 7 +------ 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala b/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala index 8e3aa7575911..16541f16e558 100644 --- a/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala +++ b/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala @@ -2517,7 +2517,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler def is(that: Flags): Boolean = self.isAllOf(that) def |(that: Flags): Flags = dotc.core.Flags.or(self, that) // TODO: Replace with dotc.core.Flags.|(self)(that) once extension names have stabilized def &(that: Flags): Flags = dotc.core.Flags.and(self, that)// TODO: Replace with dotc.core.Flags.&(self)(that) once extension names have stabilized - def show(using printer: Printer[Flags]): String = printer.show(self) + def show: String = Extractors.showFlags(using QuotesImpl.this)(self) end extension end FlagsMethods @@ -2706,10 +2706,6 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler def show(const: Constant): String = Extractors.showConstant(using QuotesImpl.this)(const) - lazy val FlagsCombination: Printer[Flags] = new Printer[Flags]: - def show(flags: Flags): String = - Extractors.showFlags(using QuotesImpl.this)(flags) - end Printer end reflect diff --git a/library/src/scala/quoted/Quotes.scala b/library/src/scala/quoted/Quotes.scala index 4241518246c8..7d6eda455a99 100644 --- a/library/src/scala/quoted/Quotes.scala +++ b/library/src/scala/quoted/Quotes.scala @@ -3564,7 +3564,7 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching => def &(that: Flags): Flags /** Shows the flags as a String */ - def show(using Printer[Flags]): String + def show: String end extension } @@ -4028,9 +4028,6 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching => /** Default pinter for `Flags` used when calling `flags.show` */ given ConstantPrinter: Printer[Constant] = Printer.ConstantCase - /** Default pinter for `Flags` used when calling `flags.show` */ - given FlagsPrinter: Printer[Flags] = Printer.FlagsCombination - /** Module object of `type Printer`. * Contains custom printers such as `TreeCode`, `TreeAnsiCode`, `TreeCases`, `TypeReprCode`, ..., `SymbolFullName` and `FlagsCombination`. */ @@ -4079,8 +4076,6 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching => /** Prints a pattern like representation of the `Constant`. */ def ConstantCase: Printer[Constant] - /** Prints compination of `Flags` that form this particular flag. */ - def FlagsCombination: Printer[Flags] } } From b00386733aee986ba391183ed8744ad27bfd718f Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 7 Dec 2020 17:36:06 +0100 Subject: [PATCH 3/4] Simplify show for `Constant` --- .../src/scala/quoted/runtime/impl/QuotesImpl.scala | 14 +------------- library/src/scala/quoted/Quotes.scala | 14 +------------- 2 files changed, 2 insertions(+), 26 deletions(-) diff --git a/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala b/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala index 16541f16e558..a90af9a3f135 100644 --- a/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala +++ b/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala @@ -2156,7 +2156,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler given ConstantMethods: ConstantMethods with extension (self: Constant): def value: Any = self.value - def show(using printer: Printer[Constant]): String = printer.show(self) + def show: String = Extractors.showConstant(using QuotesImpl.this)(self) end extension end ConstantMethods @@ -2694,18 +2694,6 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler def show(tpe: TypeRepr): String = Extractors.showType(using QuotesImpl.this)(tpe) - lazy val ConstantCode: Printer[Constant] = new Printer[Constant]: - def show(const: Constant): String = - SourceCode.showConstant(using QuotesImpl.this)(const)(SyntaxHighlight.plain, fullNames = true) - - lazy val ConstantAnsiCode: Printer[Constant] = new Printer[Constant]: - def show(const: Constant): String = - SourceCode.showConstant(using QuotesImpl.this)(const)(SyntaxHighlight.ANSI, fullNames = true) - - lazy val ConstantCase: Printer[Constant] = new Printer[Constant]: - def show(const: Constant): String = - Extractors.showConstant(using QuotesImpl.this)(const) - end Printer end reflect diff --git a/library/src/scala/quoted/Quotes.scala b/library/src/scala/quoted/Quotes.scala index 7d6eda455a99..90f39ade9ade 100644 --- a/library/src/scala/quoted/Quotes.scala +++ b/library/src/scala/quoted/Quotes.scala @@ -2849,7 +2849,7 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching => def value: Any /** Shows the constant as a String */ - def show(using Printer[Constant]): String + def show: String end extension } @@ -4025,9 +4025,6 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching => /** Default pinter for `TypeRepr` used when calling `tpe.show` */ given TypeReprPrinter: Printer[TypeRepr] = Printer.TypeReprCode - /** Default pinter for `Flags` used when calling `flags.show` */ - given ConstantPrinter: Printer[Constant] = Printer.ConstantCase - /** Module object of `type Printer`. * Contains custom printers such as `TreeCode`, `TreeAnsiCode`, `TreeCases`, `TypeReprCode`, ..., `SymbolFullName` and `FlagsCombination`. */ @@ -4067,15 +4064,6 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching => */ def TypeReprStructure: Printer[TypeRepr] - /** Prints the Constant as source code. */ - def ConstantCode: Printer[Constant] - - /** Prints the Constant as source code using ANSI colors. */ - def ConstantAnsiCode: Printer[Constant] - - /** Prints a pattern like representation of the `Constant`. */ - def ConstantCase: Printer[Constant] - } } From 73226690313380c26c7de356685b99cff2340586 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Tue, 8 Dec 2020 01:34:17 +0100 Subject: [PATCH 4/4] Fix community-build --- 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 b4031b59ee7b..16aad428f5b3 160000 --- a/community-build/community-projects/scalatest +++ b/community-build/community-projects/scalatest @@ -1 +1 @@ -Subproject commit b4031b59ee7b3d35a3db6aa386fa26be8692874f +Subproject commit 16aad428f5b3057d462d101777783a83cd40aa43