Skip to content

Commit fec41ea

Browse files
committed
Move library implemtations of Quoted to one place
1 parent 3365ed3 commit fec41ea

File tree

10 files changed

+65
-52
lines changed

10 files changed

+65
-52
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
@@ -13,6 +13,8 @@ import dotty.tools.dotc.core.Symbols._
1313
import dotty.tools.dotc.core.tasty.{TastyPickler, TastyPrinter, TastyString}
1414
import dotty.tools.dotc.interpreter.RawQuoted
1515

16+
import scala.quoted.Quoted._
17+
1618
import scala.reflect.ClassTag
1719

1820
object PickledQuotes {
@@ -30,20 +32,20 @@ object PickledQuotes {
3032

3133
/** Transform the expression into its fully spliced Tree */
3234
def quotedToTree(expr: quoted.Quoted)(implicit ctx: Context): Tree = expr match {
33-
case expr: quoted.TastyQuoted =>
35+
case expr: TastyQuoted =>
3436
unpickleQuote(expr)
35-
case expr: quoted.Liftable.ConstantExpr[_] =>
37+
case expr: ConstantExpr[_] =>
3638
Literal(Constant(expr.value))
37-
case expr: quoted.Expr.FunctionAppliedTo[_, _] =>
39+
case expr: FunctionAppliedTo[_, _] =>
3840
functionAppliedTo(quotedToTree(expr.f), quotedToTree(expr.x))
39-
case expr: quoted.Type.TaggedPrimitive[_] =>
41+
case expr: TaggedType[_] =>
4042
classTagToTypeTree(expr.ct)
4143
case expr: RawQuoted =>
4244
expr.tree
4345
}
4446

4547
/** Unpickle the tree contained in the TastyQuoted */
46-
private def unpickleQuote(expr: quoted.TastyQuoted)(implicit ctx: Context): Tree = {
48+
private def unpickleQuote(expr: TastyQuoted)(implicit ctx: Context): Tree = {
4749
val tastyBytes = TastyString.unpickle(expr.tasty)
4850
val unpickled = unpickle(tastyBytes, expr.args)
4951
unpickled match {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import dotty.tools.dotc.core.Constants._
66
import dotty.tools.dotc.printing.RefinedPrinter
77

88
import scala.quoted.Expr
9-
import scala.quoted.Liftable.ConstantExpr
109
import scala.runtime.BoxedUnit
10+
import scala.quoted.Quoted.ConstantExpr
1111
import scala.runtime.quoted._
1212

1313
/** Default runners for quoted expressions */

library/src/scala/quoted/Expr.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package scala.quoted
22

3+
import scala.quoted.Quoted.FunctionAppliedTo
34
import scala.runtime.quoted.Runner
45

56
abstract class Expr[T] extends Quoted {
@@ -16,5 +17,4 @@ object Expr {
1617
def apply(x: Expr[T]): Expr[U] = new FunctionAppliedTo[T, U](f, x)
1718
}
1819

19-
final class FunctionAppliedTo[T, U] private[Expr](val f: Expr[T => U], val x: Expr[T]) extends Expr[U]
2020
}

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 UnitIsLiftable: Liftable[Unit] = (x: Unit) => new ConstantExpr(x)
2624
implicit def BooleanIsLiftable: Liftable[Boolean] = (x: Boolean) => new ConstantExpr(x)
2725
implicit def ByteLiftable: Liftable[Byte] = (x: Byte) => new ConstantExpr(x)

library/src/scala/quoted/Quoted.scala

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,46 @@
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+
/** An Expr representing `'{(~f).apply(~x)}` but it is beta-reduced when the closure is known */
30+
final class FunctionAppliedTo[T, U](val f: Expr[T => U], val x: Expr[T]) extends Expr[U] {
31+
override def toString: String = s"Expr($f <applied to> $x)"
32+
}
33+
34+
// Implementations of Type[T]
35+
36+
/** A Type backed by a pickled TASTY tree */
37+
final class TastyType[T](val tasty: Pickled, val args: Seq[Any]) extends Type[T] with TastyQuoted {
38+
override def toString(): String = s"Type(<pickled>)"
39+
}
40+
41+
/** An Type backed by a value */
42+
final class TaggedType[T](implicit val ct: ClassTag[T]) extends Type[T] {
43+
override def toString: String = s"Type($ct)"
44+
}
45+
46+
}

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)