From 8b83989213c268ac02aaec43f298d1380527ca74 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Wed, 17 Jul 2019 11:01:48 +0200 Subject: [PATCH 1/4] Make show a proper method of Expr and type Now that there is a single show implementation we do not need to have it as an extension method --- library/src/scala/quoted/Expr.scala | 16 ++++++---------- library/src/scala/quoted/QuoteContext.scala | 4 ++-- library/src/scala/quoted/Type.scala | 18 +++++++----------- 3 files changed, 15 insertions(+), 23 deletions(-) diff --git a/library/src/scala/quoted/Expr.scala b/library/src/scala/quoted/Expr.scala index 7b89930eab43..09fe690aed79 100644 --- a/library/src/scala/quoted/Expr.scala +++ b/library/src/scala/quoted/Expr.scala @@ -13,22 +13,18 @@ package quoted { @deprecated("Use scala.quoted.run", "") final def run(implicit toolbox: Toolbox): T = toolbox.run(_ => this) + /** Show a source code like representation of this expression without syntax highlight */ + def show(implicit qctx: QuoteContext): String = qctx.show(this, SyntaxHighlight.plain) + + /** Show a source code like representation of this expression */ + def show(syntaxHighlight: SyntaxHighlight)(implicit qctx: QuoteContext): String = qctx.show(this, syntaxHighlight) + } object Expr { import scala.internal.quoted._ - implicit class ExprOps[T](expr: Expr[T]) { - - /** 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 */ - def show(syntaxHighlight: SyntaxHighlight)(implicit qctx: QuoteContext): String = qctx.show(expr, syntaxHighlight) - - } - /** Converts a tuple `(T1, ..., Tn)` to `(Expr[T1], ..., Expr[Tn])` */ type TupleOfExpr[Tup <: Tuple] = Tuple.Map[Tup, Expr] diff --git a/library/src/scala/quoted/QuoteContext.scala b/library/src/scala/quoted/QuoteContext.scala index 5878aca3f332..8fa3eb403f33 100644 --- a/library/src/scala/quoted/QuoteContext.scala +++ b/library/src/scala/quoted/QuoteContext.scala @@ -12,12 +12,12 @@ import scala.quoted.show.SyntaxHighlight */ class QuoteContext(val tasty: scala.tasty.Reflection) { - def show[T](expr: Expr[T], syntaxHighlight: SyntaxHighlight): String = { + def show(expr: Expr[_], syntaxHighlight: SyntaxHighlight): String = { import tasty._ expr.unseal.show(syntaxHighlight) } - def show[T](tpe: Type[T], syntaxHighlight: SyntaxHighlight): String = { + def show(tpe: Type[_], syntaxHighlight: SyntaxHighlight): String = { import tasty._ tpe.unseal.show(syntaxHighlight) } diff --git a/library/src/scala/quoted/Type.scala b/library/src/scala/quoted/Type.scala index d8100ef7580d..3b3e2741e829 100644 --- a/library/src/scala/quoted/Type.scala +++ b/library/src/scala/quoted/Type.scala @@ -6,21 +6,17 @@ package quoted { sealed abstract class Type[T <: AnyKind] { type `$splice` = T - } - - /** Some basic type tags, currently incomplete */ - object Type { - - implicit class TypeOps[T](tpe: Type[T]) { - /** 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 without syntax highlight */ + def show(implicit qctx: QuoteContext): String = qctx.show(this, SyntaxHighlight.plain) - /** Show a source code like representation of this type */ - def show(syntaxHighlight: SyntaxHighlight)(implicit qctx: QuoteContext): String = qctx.show(tpe, syntaxHighlight) + /** Show a source code like representation of this type */ + def show(syntaxHighlight: SyntaxHighlight)(implicit qctx: QuoteContext): String = qctx.show(this, syntaxHighlight) - } + } + /** Some basic type tags, currently incomplete */ + object Type { implicit val UnitTag: Type[Unit] = new TaggedType[Unit] implicit val BooleanTag: Type[Boolean] = new TaggedType[Boolean] implicit val ByteTag: Type[Byte] = new TaggedType[Byte] From f9afb8aef5b2e433a4336a1b9d4a422cb30f3bff Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Wed, 17 Jul 2019 11:05:53 +0200 Subject: [PATCH 2/4] Make `quoted.{Expr, Type}` traits --- library/src/scala/quoted/Expr.scala | 2 +- library/src/scala/quoted/Type.scala | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library/src/scala/quoted/Expr.scala b/library/src/scala/quoted/Expr.scala index 09fe690aed79..cc6d116f2dfb 100644 --- a/library/src/scala/quoted/Expr.scala +++ b/library/src/scala/quoted/Expr.scala @@ -4,7 +4,7 @@ package quoted { import scala.quoted.show.SyntaxHighlight - sealed abstract class Expr[+T] { + sealed trait Expr[+T] { /** Evaluate the contents of this expression and return the result. * diff --git a/library/src/scala/quoted/Type.scala b/library/src/scala/quoted/Type.scala index 3b3e2741e829..890b4a701eb4 100644 --- a/library/src/scala/quoted/Type.scala +++ b/library/src/scala/quoted/Type.scala @@ -4,7 +4,7 @@ package quoted { import scala.internal.quoted.TaggedType import scala.quoted.show.SyntaxHighlight - sealed abstract class Type[T <: AnyKind] { + sealed trait Type[T <: AnyKind] { type `$splice` = T /** Show a source code like representation of this type without syntax highlight */ From b9718c7ad5ba0e4d22c456473b3941e96d8eb988 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Wed, 17 Jul 2019 11:12:39 +0200 Subject: [PATCH 3/4] Use delegates for tagged types --- library/src/scala/quoted/Type.scala | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/library/src/scala/quoted/Type.scala b/library/src/scala/quoted/Type.scala index 890b4a701eb4..59d077cfaf08 100644 --- a/library/src/scala/quoted/Type.scala +++ b/library/src/scala/quoted/Type.scala @@ -17,15 +17,15 @@ package quoted { /** Some basic type tags, currently incomplete */ object Type { - implicit val UnitTag: Type[Unit] = new TaggedType[Unit] - implicit val BooleanTag: Type[Boolean] = new TaggedType[Boolean] - implicit val ByteTag: Type[Byte] = new TaggedType[Byte] - implicit val CharTag: Type[Char] = new TaggedType[Char] - implicit val ShortTag: Type[Short] = new TaggedType[Short] - implicit val IntTag: Type[Int] = new TaggedType[Int] - implicit val LongTag: Type[Long] = new TaggedType[Long] - implicit val FloatTag: Type[Float] = new TaggedType[Float] - implicit val DoubleTag: Type[Double] = new TaggedType[Double] + delegate UnitTag for Type[Unit] = new TaggedType[Unit] + delegate BooleanTag for Type[Boolean] = new TaggedType[Boolean] + delegate ByteTag for Type[Byte] = new TaggedType[Byte] + delegate CharTag for Type[Char] = new TaggedType[Char] + delegate ShortTag for Type[Short] = new TaggedType[Short] + delegate IntTag for Type[Int] = new TaggedType[Int] + delegate LongTag for Type[Long] = new TaggedType[Long] + delegate FloatTag for Type[Float] = new TaggedType[Float] + delegate DoubleTag for Type[Double] = new TaggedType[Double] } } From 1de97dc16baa75f44cdc5fc48b92050d54edfdfd Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Wed, 17 Jul 2019 11:16:14 +0200 Subject: [PATCH 4/4] Use delegates for Liftables --- library/src/scala/quoted/Liftable.scala | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/library/src/scala/quoted/Liftable.scala b/library/src/scala/quoted/Liftable.scala index f29398622ba6..40903fc20526 100644 --- a/library/src/scala/quoted/Liftable.scala +++ b/library/src/scala/quoted/Liftable.scala @@ -17,15 +17,15 @@ trait Liftable[T] { */ object Liftable { - implicit val Liftable_Boolean_delegate: Liftable[Boolean] = new PrimitiveLiftable - implicit val Liftable_Byte_delegate: Liftable[Byte] = new PrimitiveLiftable - implicit val Liftable_Short_delegate: Liftable[Short] = new PrimitiveLiftable - implicit val Liftable_Int_delegate: Liftable[Int] = new PrimitiveLiftable - implicit val Liftable_Long_delegate: Liftable[Long] = new PrimitiveLiftable - implicit val Liftable_Float_delegate: Liftable[Float] = new PrimitiveLiftable - implicit val Liftable_Double_delegate: Liftable[Double] = new PrimitiveLiftable - implicit val Liftable_Char_delegate: Liftable[Char] = new PrimitiveLiftable - implicit val Liftable_String_delegate: Liftable[String] = new PrimitiveLiftable + delegate Liftable_Boolean_delegate for Liftable[Boolean] = new PrimitiveLiftable + delegate Liftable_Byte_delegate for Liftable[Byte] = new PrimitiveLiftable + delegate Liftable_Short_delegate for Liftable[Short] = new PrimitiveLiftable + delegate Liftable_Int_delegate for Liftable[Int] = new PrimitiveLiftable + delegate Liftable_Long_delegate for Liftable[Long] = new PrimitiveLiftable + delegate Liftable_Float_delegate for Liftable[Float] = new PrimitiveLiftable + delegate Liftable_Double_delegate for Liftable[Double] = new PrimitiveLiftable + delegate Liftable_Char_delegate for Liftable[Char] = new PrimitiveLiftable + delegate Liftable_String_delegate for Liftable[String] = new PrimitiveLiftable private class PrimitiveLiftable[T <: Unit | Null | Int | Boolean | Byte | Short | Int | Long | Float | Double | Char | String] extends Liftable[T] { /** Lift a primitive value `n` into `'{ n }` */