diff --git a/library/src/scala/internal/quoted/showName.scala b/library/src/scala/internal/quoted/showName.scala deleted file mode 100644 index 39e3dd0b591a..000000000000 --- a/library/src/scala/internal/quoted/showName.scala +++ /dev/null @@ -1,24 +0,0 @@ -package scala.internal.quoted - -/** Annotation used inside a quote to give a custom name to a definition. - * The `name` argument must be a literal String. - * - * Usage: - * ```scala - * def let(name: String)(value: Expr[Int])(in: Expr[Int] => Expr[Int]): Expr[Int] = '{ - * @showName(${Expr(name)}) - * val x = $value - * ${ in('x) } - * } - * ``` - * then using it in - * ```scala - * let("myVal")('{4})(x => '{ $x + 1}).show - * ``` - * will returns the code - * ```scala - * val myVal = 4 - * myVal + 1 - * ``` - */ -class showName(name: String) extends scala.annotation.Annotation diff --git a/library/src/scala/tasty/reflect/SourceCodePrinter.scala b/library/src/scala/tasty/reflect/SourceCodePrinter.scala index 518d5d5e4bec..96875dcc071b 100644 --- a/library/src/scala/tasty/reflect/SourceCodePrinter.scala +++ b/library/src/scala/tasty/reflect/SourceCodePrinter.scala @@ -1237,15 +1237,12 @@ class SourceCodePrinter[R <: Reflection & Singleton](val reflect: R)(syntaxHighl def printAnnotation(annot: Term)(using elideThis: Option[Symbol]): Buffer = { val Annotation(ref, args) = annot - if (annot.symbol.maybeOwner == Symbol.requiredClass("scala.internal.quoted.showName")) this - else { - this += "@" - printTypeTree(ref) - if (args.isEmpty) - this - else - inParens(printTrees(args, ", ")) - } + this += "@" + printTypeTree(ref) + if (args.isEmpty) + this + else + inParens(printTrees(args, ", ")) } def printDefAnnotations(definition: Definition)(using elideThis: Option[Symbol]): Buffer = { @@ -1413,22 +1410,16 @@ class SourceCodePrinter[R <: Reflection & Singleton](val reflect: R)(syntaxHighl private[this] val namesIndex = collection.mutable.Map.empty[String, Int] private def splicedName(sym: Symbol): Option[String] = { - sym.annots.find(_.symbol.owner == Symbol.requiredClass("scala.internal.quoted.showName")).flatMap { - case Apply(_, Literal(Constant.String(c)) :: Nil) => Some(c) - case Apply(_, Inlined(_, _, Literal(Constant.String(c))) :: Nil) => Some(c) - case annot => None - }.orElse { - if sym.owner.isClassDef then None - else names.get(sym).orElse { - val name0 = sym.name - val index = namesIndex.getOrElse(name0, 1) - namesIndex(name0) = index + 1 - val name = - if index == 1 then name0 - else s"`$name0${index.toString.toCharArray.map {x => (x - '0' + '₀').toChar}.mkString}`" - names(sym) = name - Some(name) - } + if sym.owner.isClassDef then None + else names.get(sym).orElse { + val name0 = sym.name + val index = namesIndex.getOrElse(name0, 1) + namesIndex(name0) = index + 1 + val name = + if index == 1 then name0 + else s"`$name0${index.toString.toCharArray.map {x => (x - '0' + '₀').toChar}.mkString}`" + names(sym) = name + Some(name) } } diff --git a/tests/run-staging/quoted-show-name.check b/tests/run-staging/quoted-show-name.check deleted file mode 100644 index ae3f5e6928af..000000000000 --- a/tests/run-staging/quoted-show-name.check +++ /dev/null @@ -1,13 +0,0 @@ -((x1: scala.Double) => x1.*({ - val x2: scala.Double = x1.*(x1) - val x4: scala.Double = x2.*(x2) - x4.*({ - val x8: scala.Double = x4.*(x4) - x8.*({ - val x16: scala.Double = x8.*(x8) - val x32: scala.Double = x16.*(x16) - val x64: scala.Double = x32.*(x32) - x64 - }) - }) -})) diff --git a/tests/run-staging/quoted-show-name.scala b/tests/run-staging/quoted-show-name.scala deleted file mode 100644 index 57617e8d8fbe..000000000000 --- a/tests/run-staging/quoted-show-name.scala +++ /dev/null @@ -1,21 +0,0 @@ -import scala.quoted._ -import scala.internal.quoted.showName -import scala.quoted.staging._ -import scala.reflect.ClassTag - -object Test { - given Toolbox = Toolbox.make(getClass.getClassLoader) - def main(args: Array[String]): Unit = withQuoteContext { - println(powerCode(77).show) - } - - def powerCode(n: Long)(using QuoteContext): Expr[Double => Double] = - '{ x1 => ${powerCode(n, 2, 'x1)} } - - def powerCode(n: Long, idx: Int, x: Expr[Double])(using QuoteContext): Expr[Double] = - if (n == 0) '{1.0} - else if (n == 1) x - else if (n % 2 == 0) '{ @showName(${Expr("x" + idx)}) val y = $x * $x; ${powerCode(n / 2, idx * 2, '{y})} } - else '{ $x * ${powerCode(n - 1, idx, x)} } - -}