Skip to content

Commit 4b18db0

Browse files
committed
Seal quoted.Expr and quoted.Type
1 parent 3028f06 commit 4b18db0

File tree

10 files changed

+61
-61
lines changed

10 files changed

+61
-61
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
@@ -12,7 +12,8 @@ import dotty.tools.dotc.core.NameKinds
1212
import dotty.tools.dotc.core.Symbols._
1313
import dotty.tools.dotc.core.tasty.{TastyPickler, TastyPrinter, TastyString}
1414

15-
import scala.quoted.Quoted._
15+
import scala.quoted.Types._
16+
import scala.quoted.Exprs._
1617

1718
import scala.reflect.ClassTag
1819

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
@@ -7,7 +7,7 @@ import dotty.tools.dotc.core.Contexts._
77
import dotty.tools.dotc.printing.RefinedPrinter
88

99
import scala.quoted.Expr
10-
import scala.quoted.Quoted.ConstantExpr
10+
import scala.quoted.Exprs.ConstantExpr
1111
import scala.runtime.quoted._
1212

1313
/** 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: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package scala.quoted
22

3-
import scala.quoted.Quoted.FunctionAppliedTo
43
import scala.runtime.quoted.Runner
4+
import scala.runtime.quoted.Unpickler.Pickled
55

6-
abstract class Expr[T] extends Quoted {
6+
sealed abstract class Expr[T] extends Quoted {
77
final def unary_~ : T = throw new Error("~ should have been compiled away")
88
final def run(implicit runner: Runner[T]): T = runner.run(this)
99
final def show(implicit runner: Runner[T]): String = runner.show(this)
@@ -14,7 +14,30 @@ object Expr {
1414
ev.toExpr(x)
1515

1616
implicit class AsFunction[T, U](private val f: Expr[T => U]) extends AnyVal {
17-
def apply(x: Expr[T]): Expr[U] = new FunctionAppliedTo[T, U](f, x)
17+
def apply(x: Expr[T]): Expr[U] = new Exprs.FunctionAppliedTo[T, U](f, x)
1818
}
1919

2020
}
21+
22+
/** All implementations of Expr[T] */
23+
object Exprs {
24+
/** An Expr backed by a pickled TASTY tree */
25+
final class TastyExpr[T](val tasty: Pickled, val args: Seq[Any]) extends Expr[T] {
26+
override def toString(): String = s"Expr(<pickled>)"
27+
}
28+
29+
/** An Expr backed by a value */
30+
final class ConstantExpr[T](val value: T) extends Expr[T] {
31+
override def toString: String = s"Expr($value)"
32+
}
33+
34+
/** An Expr backed by a tree */
35+
final class RawExpr[Tree](val tree: Tree) extends quoted.Expr[Any] {
36+
override def toString: String = s"Expr(<raw>)"
37+
}
38+
39+
/** An Expr representing `'{(~f).apply(~x)}` but it is beta-reduced when the closure is known */
40+
final class FunctionAppliedTo[T, U](val f: Expr[T => U], val x: Expr[T]) extends Expr[U] {
41+
override def toString: String = s"Expr($f <applied to> $x)"
42+
}
43+
}

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

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)