Skip to content

Cleanup quoted.{Expr|Type} APIs #6867

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions library/src/scala/quoted/Expr.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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]

Expand Down
18 changes: 9 additions & 9 deletions library/src/scala/quoted/Liftable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 }` */
Expand Down
4 changes: 2 additions & 2 deletions library/src/scala/quoted/QuoteContext.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
38 changes: 17 additions & 21 deletions library/src/scala/quoted/Type.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,28 @@ 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
}

/** 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)

}
}

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]
/** Some basic type tags, currently incomplete */
object Type {
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]
}

}
Expand Down