Skip to content

Commit 991c112

Browse files
committed
Move library implemtations of Quoted to one place
1 parent 540371d commit 991c112

File tree

9 files changed

+59
-51
lines changed

9 files changed

+59
-51
lines changed

compiler/src/dotty/tools/dotc/core/quoted/PickledQuotes.scala

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package dotty.tools.dotc.core.quoted
22

33
import dotty.tools.dotc.ast.Trees._
4-
import dotty.tools.dotc.ast.{tpd, untpd}
4+
import dotty.tools.dotc.ast.tpd
55
import dotty.tools.dotc.config.Printers._
66
import dotty.tools.dotc.core.Constants.Constant
77
import dotty.tools.dotc.core.Contexts._
@@ -12,6 +12,8 @@ import dotty.tools.dotc.core.Symbols._
1212
import dotty.tools.dotc.core.tasty.{TastyPickler, TastyPrinter, TastyString}
1313
import dotty.tools.dotc.interpreter.RawQuoted
1414

15+
import scala.quoted.Quoted._
16+
1517
import scala.reflect.ClassTag
1618

1719
object PickledQuotes {
@@ -33,9 +35,9 @@ object PickledQuotes {
3335

3436
/** Transform the expression into its fully spliced Tree */
3537
def quotedToTree(expr: quoted.Quoted)(implicit ctx: Context): Tree = expr match {
36-
case expr: quoted.TastyQuoted => unpickleQuote(expr)
37-
case expr: quoted.Liftable.ConstantExpr[_] => Literal(Constant(expr.value))
38-
case expr: quoted.Type.TaggedPrimitive[_] =>
38+
case expr: TastyQuoted => unpickleQuote(expr)
39+
case expr: ConstantExpr[_] => Literal(Constant(expr.value))
40+
case expr: TaggedType[_] =>
3941
val tpe = expr.ct match {
4042
case ClassTag.Unit => defn.UnitType
4143
case ClassTag.Byte => defn.ByteType
@@ -51,7 +53,7 @@ object PickledQuotes {
5153
}
5254

5355
/** Unpickle the tree contained in the TastyQuoted */
54-
private def unpickleQuote(expr: quoted.TastyQuoted)(implicit ctx: Context): Tree = {
56+
private def unpickleQuote(expr: TastyQuoted)(implicit ctx: Context): Tree = {
5557
val tastyBytes = TastyString.unpickle(expr.tasty)
5658
val unpickled = unpickle(tastyBytes, expr.args)
5759
unpickled match {

compiler/src/dotty/tools/dotc/quoted/Runners.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import dotty.tools.dotc.core.Constants.Constant
55
import dotty.tools.dotc.printing.RefinedPrinter
66

77
import scala.quoted.Expr
8-
import scala.quoted.Liftable.ConstantExpr
8+
import scala.quoted.Quoted.ConstantExpr
99
import scala.runtime.quoted._
1010

1111
/** Default runners for quoted expressions */

library/src/scala/quoted/Liftable.scala

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package scala.quoted
22

3+
import scala.quoted.Quoted.ConstantExpr
4+
35
/** A typeclass for types that can be turned to `quoted.Expr[T]`
46
* without going through an explicit `'(...)` operation.
57
*/
@@ -18,10 +20,6 @@ object Liftable {
1820
def toExpr(implicit liftable: Liftable[T]): Expr[T] = liftable.toExpr(x)
1921
}
2022

21-
final class ConstantExpr[T] private[Liftable](val value: T) extends Expr[T] {
22-
override def toString: String = s"Expr($value)"
23-
}
24-
2523
implicit def BooleanIsLiftable: Liftable[Boolean] = (x: Boolean) => new ConstantExpr(x)
2624
implicit def ByteLiftable: Liftable[Byte] = (x: Byte) => new ConstantExpr(x)
2725
implicit def CharIsLiftable: Liftable[Char] = (x: Char) => new ConstantExpr(x)

library/src/scala/quoted/Quoted.scala

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,41 @@
11
package scala.quoted
22

3+
import scala.reflect.ClassTag
4+
import scala.runtime.quoted.Unpickler.Pickled
5+
36
/** Common superclass of Expr and Type */
47
abstract class Quoted
8+
9+
object Quoted {
10+
11+
/** A quote backed by a pickled TASTY tree */
12+
trait TastyQuoted extends Quoted {
13+
def tasty: Pickled
14+
def args: Seq[Any]
15+
}
16+
17+
// Implementations of Expr[T]
18+
19+
/** An Expr backed by a pickled TASTY tree */
20+
final class TastyExpr[T](val tasty: Pickled, val args: Seq[Any]) extends Expr[T] with TastyQuoted {
21+
override def toString(): String = s"Expr(<pickled>)"
22+
}
23+
24+
/** An Expr backed by a value */
25+
final class ConstantExpr[T](val value: T) extends Expr[T] {
26+
override def toString: String = s"Expr($value)"
27+
}
28+
29+
// Implementations of Type[T]
30+
31+
/** A Type backed by a pickled TASTY tree */
32+
final class TastyType[T](val tasty: Pickled, val args: Seq[Any]) extends Type[T] with TastyQuoted {
33+
override def toString(): String = s"Type(<pickled>)"
34+
}
35+
36+
/** An Type backed by a value */
37+
final class TaggedType[T](implicit val ct: ClassTag[T]) extends Type[T] {
38+
override def toString: String = s"Type($ct)"
39+
}
40+
41+
}

library/src/scala/quoted/TastyExpr.scala

Lines changed: 0 additions & 8 deletions
This file was deleted.

library/src/scala/quoted/TastyQuoted.scala

Lines changed: 0 additions & 9 deletions
This file was deleted.

library/src/scala/quoted/TastyType.scala

Lines changed: 0 additions & 8 deletions
This file was deleted.

library/src/scala/quoted/Type.scala

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
11
package scala.quoted
22

3-
import scala.reflect.ClassTag
3+
import scala.quoted.Quoted.TaggedType
44

55
abstract class Type[T] extends Quoted {
66
type unary_~ = T
77
}
88

99
/** Some basic type tags, currently incomplete */
1010
object Type {
11-
12-
final class TaggedPrimitive[T] private[Type] (implicit val ct: ClassTag[T]) extends Type[T] {
13-
override def toString: String = s"Type($ct)"
14-
}
15-
16-
implicit def UnitTag: Type[Unit] = new TaggedPrimitive[Unit]
17-
implicit def BooleanTag: Type[Boolean] = new TaggedPrimitive[Boolean]
18-
implicit def ByteTag: Type[Byte] = new TaggedPrimitive[Byte]
19-
implicit def CharTag: Type[Char] = new TaggedPrimitive[Char]
20-
implicit def ShortTag: Type[Short] = new TaggedPrimitive[Short]
21-
implicit def IntTag: Type[Int] = new TaggedPrimitive[Int]
22-
implicit def LongTag: Type[Long] = new TaggedPrimitive[Long]
23-
implicit def FloatTag: Type[Float] = new TaggedPrimitive[Float]
24-
implicit def DoubleTag: Type[Double] = new TaggedPrimitive[Double]
11+
implicit def UnitTag: Type[Unit] = new TaggedType[Unit]
12+
implicit def BooleanTag: Type[Boolean] = new TaggedType[Boolean]
13+
implicit def ByteTag: Type[Byte] = new TaggedType[Byte]
14+
implicit def CharTag: Type[Char] = new TaggedType[Char]
15+
implicit def ShortTag: Type[Short] = new TaggedType[Short]
16+
implicit def IntTag: Type[Int] = new TaggedType[Int]
17+
implicit def LongTag: Type[Long] = new TaggedType[Long]
18+
implicit def FloatTag: Type[Float] = new TaggedType[Float]
19+
implicit def DoubleTag: Type[Double] = new TaggedType[Double]
2520
}

library/src/scala/runtime/quoted/Unpickler.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package scala.runtime.quoted
22

3-
import scala.quoted._
3+
import scala.quoted.Quoted.{TastyExpr, TastyType}
4+
import scala.quoted.{Expr, Type}
45

56
/** Provides methods to unpickle `Expr` and `Type` trees. */
67
object Unpickler {

0 commit comments

Comments
 (0)