Skip to content

Commit 609fc11

Browse files
committed
Seal quoted.Expr and quoted.Type
1 parent 857ed93 commit 609fc11

File tree

10 files changed

+55
-54
lines changed

10 files changed

+55
-54
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import dotty.tools.dotc.core.StdNames._
1111
import dotty.tools.dotc.core.Symbols._
1212
import dotty.tools.dotc.core.tasty.{TastyPickler, TastyPrinter, TastyString}
1313

14-
import scala.quoted.Quoted._
14+
import scala.quoted.Types._
15+
import scala.quoted.Exprs._
1516

1617
import scala.reflect.ClassTag
1718

compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ import typer.Checking
2121
import config.Config
2222
import dotty.tools.dotc.core.quoted.PickledQuotes
2323
import scala.quoted
24-
import scala.quoted.Quoted.{RawExpr, RawType}
24+
import scala.quoted.Types.RawType
25+
import scala.quoted.Exprs.RawExpr
2526

2627
/** Unpickler for typed trees
2728
* @param reader the reader from which to unpickle

compiler/src/dotty/tools/dotc/interpreter/Interpreter.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ class Interpreter(implicit ctx: Context) {
7272

7373
tree match {
7474
case Quoted(quotedTree) =>
75-
if (tree.isTerm) new scala.quoted.Quoted.RawExpr(quotedTree)
76-
else new scala.quoted.Quoted.RawType(quotedTree)
75+
if (tree.isTerm) new scala.quoted.Exprs.RawExpr(quotedTree)
76+
else new scala.quoted.Types.RawType(quotedTree)
7777

7878
case Literal(Constant(c)) => c.asInstanceOf[Object]
7979

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.Quoted.ConstantExpr
8+
import scala.quoted.Exprs.ConstantExpr
99
import scala.runtime.quoted._
1010

1111
/** Default runners for quoted expressions */

docs/docs/reference/symmetric-meta-programming.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ The two types can be defined in package `scala.quoted` as follows:
7272

7373
package scala.quoted
7474

75-
abstract class Expr[T] {
75+
sealed abstract class Expr[T] {
7676
def unary_~: T // splice operation
7777
}
78-
class Type[T] {
78+
sealed abstract class Type[T] {
7979
type unary_~ = T // splice type
8080
}
8181

@@ -397,7 +397,7 @@ to be executed at a later stage. To run that code, there is another method
397397
in class `Expr` called `run`. Note that `~` and `run` both map from `Expr[T]`
398398
to `T` but only `~` is subject to the PCP, whereas `run` is just a normal method.
399399

400-
abstract class Expr[T] {
400+
sealed abstract class Expr[T] {
401401
def unary_~: T
402402
def run(implicit runner: Runner[T]): T // run staged code
403403
def show(implicit runner: Runner[T]): String // show staged code

library/src/scala/quoted/Expr.scala

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package scala.quoted
22

33
import scala.runtime.quoted.Runner
4+
import scala.runtime.quoted.Unpickler.Pickled
45

5-
abstract class Expr[T] extends Quoted {
6+
sealed abstract class Expr[T] extends Quoted {
67
final def unary_~ : T = throw new Error("~ should have been compiled away")
78
final def run(implicit runner: Runner[T]): T = runner.run(this)
89
final def show(implicit runner: Runner[T]): String = runner.show(this)
@@ -16,3 +17,21 @@ object Expr {
1617
def apply(x: Expr[T]): Expr[U] = ???
1718
}
1819
}
20+
21+
/** All implementations of Expr[T] */
22+
object Exprs {
23+
/** An Expr backed by a pickled TASTY tree */
24+
final class TastyExpr[T](val tasty: Pickled, val args: Seq[Any]) extends Expr[T] {
25+
override def toString(): String = s"Expr(<pickled>)"
26+
}
27+
28+
/** An Expr backed by a value */
29+
final class ConstantExpr[T](val value: T) extends Expr[T] {
30+
override def toString: String = s"Expr($value)"
31+
}
32+
33+
/** An Expr backed by a tree */
34+
final class RawExpr[Tree](val tree: Tree) extends quoted.Expr[Any] {
35+
override def toString: String = s"Expr(<raw>)"
36+
}
37+
}

library/src/scala/quoted/Liftable.scala

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

3-
import scala.quoted.Quoted.ConstantExpr
3+
import scala.quoted.Exprs.ConstantExpr
44

55
/** A typeclass for types that can be turned to `quoted.Expr[T]`
66
* without going through an explicit `'(...)` operation.

library/src/scala/quoted/Quoted.scala

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

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

library/src/scala/quoted/Type.scala

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

3-
import scala.quoted.Quoted.TaggedType
3+
import scala.quoted.Types.TaggedType
4+
import scala.reflect.ClassTag
5+
import scala.runtime.quoted.Unpickler.Pickled
46

5-
abstract class Type[T] extends Quoted {
7+
sealed abstract class Type[T] extends Quoted {
68
type unary_~ = T
79
}
810

@@ -18,3 +20,21 @@ object Type {
1820
implicit def FloatTag: Type[Float] = new TaggedType[Float]
1921
implicit def DoubleTag: Type[Double] = new TaggedType[Double]
2022
}
23+
24+
/** Implementations of Type[T] */
25+
object Types {
26+
/** A Type backed by a pickled TASTY tree */
27+
final class TastyType[T](val tasty: Pickled, val args: Seq[Any]) extends Type[T] {
28+
override def toString(): String = s"Type(<pickled>)"
29+
}
30+
31+
/** An Type backed by a value */
32+
final class TaggedType[T](implicit val ct: ClassTag[T]) extends Type[T] {
33+
override def toString: String = s"Type($ct)"
34+
}
35+
36+
/** An Type backed by a tree */
37+
final class RawType[Tree](val tree: Tree) extends quoted.Type[Any] {
38+
override def toString: String = s"Type(<raw>)"
39+
}
40+
}

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.Quoted.{TastyExpr, TastyType}
3+
import scala.quoted.Types.TastyType
4+
import scala.quoted.Exprs.TastyExpr
45
import scala.quoted.{Expr, Type}
56

67
/** Provides methods to unpickle `Expr` and `Type` trees. */

0 commit comments

Comments
 (0)