Skip to content

Commit 3028f06

Browse files
committed
Remove TastyQuoted and RawQuoted abstractions
1 parent 29b52d7 commit 3028f06

File tree

2 files changed

+22
-24
lines changed

2 files changed

+22
-24
lines changed

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ object PickledQuotes {
3535

3636
/** Transform the expression into its fully spliced Tree */
3737
def quotedExprToTree(expr: quoted.Expr[_])(implicit ctx: Context): Tree = expr match {
38-
case expr: TastyExpr[_] => unpickleQuote(expr)
38+
case expr: TastyExpr[_] => unpickleExpr(expr)
3939
case expr: ConstantExpr[_] => Literal(Constant(expr.value))
4040
case expr: RawExpr[Tree] @unchecked => expr.tree
4141
case expr: FunctionAppliedTo[_, _] =>
@@ -44,19 +44,27 @@ object PickledQuotes {
4444

4545
/** Transform the expression into its fully spliced TypeTree */
4646
def quotedTypeToTree(expr: quoted.Type[_])(implicit ctx: Context): Tree = expr match {
47-
case expr: TastyType[_] => unpickleQuote(expr)
47+
case expr: TastyType[_] => unpickleType(expr)
4848
case expr: TaggedType[_] => classTagToTypeTree(expr.ct)
4949
case expr: RawType[Tree] @unchecked => expr.tree
5050
}
5151

52-
/** Unpickle the tree contained in the TastyQuoted */
53-
private def unpickleQuote(expr: TastyQuoted)(implicit ctx: Context): Tree = {
52+
/** Unpickle the tree contained in the TastyExpr */
53+
private def unpickleExpr(expr: TastyExpr[_])(implicit ctx: Context): Tree = {
5454
val tastyBytes = TastyString.unpickle(expr.tasty)
5555
val unpickled = unpickle(tastyBytes, expr.args)
56+
unpickled match {
57+
case PackageDef(_, (vdef: ValDef) :: Nil) => vdef.rhs
58+
}
59+
}
60+
61+
/** Unpickle the tree contained in the TastyType */
62+
private def unpickleType(ttpe: TastyType[_])(implicit ctx: Context): Tree = {
63+
val tastyBytes = TastyString.unpickle(ttpe.tasty)
64+
val unpickled = unpickle(tastyBytes, ttpe.args)
5665
unpickled match {
5766
case PackageDef(_, (vdef: ValDef) :: Nil) =>
58-
if (vdef.name == "$quote".toTermName) vdef.rhs
59-
else vdef.rhs.asInstanceOf[TypeApply].args.head
67+
vdef.rhs.asInstanceOf[TypeApply].args.head
6068
}
6169
}
6270

library/src/scala/quoted/Quoted.scala

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,10 @@ abstract class Quoted
88

99
object Quoted {
1010

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-
/** Quoted for which its internal representation is its tree.
18-
* - Used for trees that cannot be serialized, such as references to local symbols that will be spliced in.
19-
* - Used for trees that do not need to be serialized to avoid the overhead of serialization/deserialization.
20-
*/
21-
trait RawQuoted[Tree] extends quoted.Quoted {
22-
def tree: Tree
23-
}
24-
2511
// Implementations of Expr[T]
2612

2713
/** An Expr backed by a pickled TASTY tree */
28-
final class TastyExpr[T](val tasty: Pickled, val args: Seq[Any]) extends Expr[T] with TastyQuoted {
14+
final class TastyExpr[T](val tasty: Pickled, val args: Seq[Any]) extends Expr[T] {
2915
override def toString(): String = s"Expr(<pickled>)"
3016
}
3117

@@ -35,7 +21,9 @@ object Quoted {
3521
}
3622

3723
/** An Expr backed by a tree */
38-
final class RawExpr[Tree](val tree: Tree) extends quoted.Expr[Any] with RawQuoted[Tree]
24+
final class RawExpr[Tree](val tree: Tree) extends quoted.Expr[Any] {
25+
override def toString: String = s"Expr(<raw>)"
26+
}
3927

4028
/** An Expr representing `'{(~f).apply(~x)}` but it is beta-reduced when the closure is known */
4129
final class FunctionAppliedTo[T, U](val f: Expr[T => U], val x: Expr[T]) extends Expr[U] {
@@ -45,7 +33,7 @@ object Quoted {
4533
// Implementations of Type[T]
4634

4735
/** A Type backed by a pickled TASTY tree */
48-
final class TastyType[T](val tasty: Pickled, val args: Seq[Any]) extends Type[T] with TastyQuoted {
36+
final class TastyType[T](val tasty: Pickled, val args: Seq[Any]) extends Type[T] {
4937
override def toString(): String = s"Type(<pickled>)"
5038
}
5139

@@ -55,6 +43,8 @@ object Quoted {
5543
}
5644

5745
/** An Type backed by a tree */
58-
final class RawType[Tree](val tree: Tree) extends quoted.Type[Any] with RawQuoted[Tree]
46+
final class RawType[Tree](val tree: Tree) extends quoted.Type[Any] {
47+
override def toString: String = s"Type(<raw>)"
48+
}
5949

6050
}

0 commit comments

Comments
 (0)