Skip to content

Commit 06c73c1

Browse files
Merge pull request #6608 from dotty-staging/move-Expr-implementations-to-internal
Move internal quoted.{Expr,Type} implementations to internal package
2 parents 9465001 + a01d9ef commit 06c73c1

File tree

17 files changed

+475
-464
lines changed

17 files changed

+475
-464
lines changed

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -741,9 +741,6 @@ class Definitions {
741741
lazy val InternalQuotedMatcher_unapplyR: TermRef = InternalQuotedMatcherModule.requiredMethodRef(nme.unapply)
742742
def InternalQuotedMatcher_unapply(implicit ctx: Context) = InternalQuotedMatcher_unapplyR.symbol
743743

744-
lazy val QuotedExprsModule: TermSymbol = ctx.requiredModule("scala.quoted.Exprs")
745-
def QuotedExprsClass(implicit ctx: Context): ClassSymbol = QuotedExprsModule.asClass
746-
747744
lazy val QuotedTypeType: TypeRef = ctx.requiredClassRef("scala.quoted.Type")
748745
def QuotedTypeClass(implicit ctx: Context): ClassSymbol = QuotedTypeType.symbol.asClass
749746

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ import dotty.tools.dotc.core.tasty.TreePickler.Hole
1515
import dotty.tools.dotc.core.tasty.{PositionPickler, TastyPickler, TastyPrinter, TastyString}
1616
import dotty.tools.dotc.core.tasty.TreeUnpickler.UnpickleMode
1717

18-
import scala.quoted.Types._
19-
import scala.quoted.Exprs._
18+
import scala.internal.quoted._
2019
import scala.reflect.ClassTag
2120

2221
object PickledQuotes {

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ import config.Printers.pickling
3333
import core.quoted.PickledQuotes
3434

3535
import scala.quoted
36-
import scala.quoted.Types.TreeType
37-
import scala.quoted.Exprs.TastyTreeExpr
36+
import scala.internal.quoted.{TastyTreeExpr, TreeType}
3837
import scala.annotation.constructorOnly
3938
import scala.annotation.internal.sharable
4039

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package dotty.tools.dotc.quoted
33
import dotty.tools.dotc.ast.tpd
44

55
import scala.quoted._
6-
import scala.quoted.Exprs.{LiftedExpr, TastyTreeExpr}
6+
import scala.internal.quoted.{LiftedExpr, TastyTreeExpr}
77

88
/** Default runners for quoted expressions */
99
object ToolboxImpl {

compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,7 +1747,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util.
17471747
tpd.Closure(closureMethod, tss => etaExpand(new tpd.TreeOps(term).appliedToArgs(tss.head)))
17481748
case _ => term
17491749
}
1750-
new scala.quoted.Exprs.TastyTreeExpr(etaExpand(self))
1750+
new scala.internal.quoted.TastyTreeExpr(etaExpand(self))
17511751
}
17521752

17531753
/** Checked cast to a `quoted.Expr[U]` */
@@ -1768,7 +1768,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util.
17681768
/** Convert `Type` to an `quoted.Type[_]` */
17691769
def QuotedType_seal(self: Type)(implicit ctx: Context): scala.quoted.Type[_] = {
17701770
val dummySpan = ctx.owner.span // FIXME
1771-
new scala.quoted.Types.TreeType(tpd.TypeTree(self).withSpan(dummySpan))
1771+
new scala.internal.quoted.TreeType(tpd.TypeTree(self).withSpan(dummySpan))
17721772
}
17731773

17741774
//

compiler/src/dotty/tools/dotc/transform/Splicer.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ object Splicer {
102102
}
103103

104104
protected def interpretQuote(tree: Tree)(implicit env: Env): Object =
105-
new scala.quoted.Exprs.TastyTreeExpr(Inlined(EmptyTree, Nil, tree).withSpan(tree.span))
105+
new scala.internal.quoted.TastyTreeExpr(Inlined(EmptyTree, Nil, tree).withSpan(tree.span))
106106

107107
protected def interpretTypeQuote(tree: Tree)(implicit env: Env): Object =
108-
new scala.quoted.Types.TreeType(tree)
108+
new scala.internal.quoted.TreeType(tree)
109109

110110
protected def interpretLiteral(value: Any)(implicit env: Env): Object =
111111
value.asInstanceOf[Object]
Lines changed: 44 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,54 @@
1-
package scala.quoted
1+
package scala
22

3-
import scala.runtime.quoted.Unpickler.Pickled
3+
package quoted {
44

5-
sealed abstract class Expr[+T] {
5+
sealed abstract class Expr[+T] {
66

7-
/** Evaluate the contents of this expression and return the result.
8-
*
9-
* May throw a FreeVariableError on expressions that came from a macro.
10-
*/
11-
final def run(implicit toolbox: Toolbox): T = toolbox.run(this)
7+
/** Evaluate the contents of this expression and return the result.
8+
*
9+
* May throw a FreeVariableError on expressions that came from a macro.
10+
*/
11+
final def run(implicit toolbox: Toolbox): T = toolbox.run(this)
1212

13-
}
14-
15-
/** All implementations of Expr[T].
16-
* These should never be used directly.
17-
*/
18-
object Exprs {
19-
/** An Expr backed by a pickled TASTY tree */
20-
final class TastyExpr[+T](val tasty: Pickled, val args: Seq[Any]) extends Expr[T] {
21-
override def toString: String = s"Expr(<pickled tasty>)"
2213
}
2314

24-
/** An Expr backed by a lifted value.
25-
* Values can only be of type Boolean, Byte, Short, Char, Int, Long, Float, Double, Unit, String or Null.
26-
*/
27-
final class LiftedExpr[+T](val value: T) extends Expr[T] {
28-
override def toString: String = s"Expr($value)"
29-
}
15+
}
3016

31-
/** An Expr backed by a tree. Only the current compiler trees are allowed.
32-
*
33-
* These expressions are used for arguments of macros. They contain and actual tree
34-
* from the program that is being expanded by the macro.
35-
*
36-
* May contain references to code defined outside this TastyTreeExpr instance.
37-
*/
38-
final class TastyTreeExpr[Tree](val tree: Tree) extends quoted.Expr[Any] {
39-
override def toString: String = s"Expr(<tasty tree>)"
40-
}
17+
package internal {
18+
package quoted {
19+
20+
import scala.quoted._
21+
22+
/** An Expr backed by a pickled TASTY tree */
23+
final class TastyExpr[+T](val tasty: scala.runtime.quoted.Unpickler.Pickled, val args: Seq[Any]) extends Expr[T] {
24+
override def toString: String = s"Expr(<pickled tasty>)"
25+
}
26+
27+
/** An Expr backed by a lifted value.
28+
* Values can only be of type Boolean, Byte, Short, Char, Int, Long, Float, Double, Unit, String or Null.
29+
*/
30+
final class LiftedExpr[+T](val value: T) extends Expr[T] {
31+
override def toString: String = s"Expr($value)"
32+
}
33+
34+
/** An Expr backed by a tree. Only the current compiler trees are allowed.
35+
*
36+
* These expressions are used for arguments of macros. They contain and actual tree
37+
* from the program that is being expanded by the macro.
38+
*
39+
* May contain references to code defined outside this TastyTreeExpr instance.
40+
*/
41+
final class TastyTreeExpr[Tree](val tree: Tree) extends quoted.Expr[Any] {
42+
override def toString: String = s"Expr(<tasty tree>)"
43+
}
44+
45+
// TODO Use a List in FunctionAppliedTo(val f: Expr[_], val args: List[Expr[_]])
46+
// FIXME: Having the List in the code above trigers an assertion error while testing dotty.tools.dotc.reporting.ErrorMessagesTests.i3187
47+
// This test does redefine `scala.collection`. Further investigation is needed.
48+
/** An Expr representing `'{($f).apply($x1, ..., $xn)}` but it is beta-reduced when the closure is known */
49+
final class FunctionAppliedTo[+R](val f: Expr[_], val args: Array[Expr[_]]) extends Expr[R] {
50+
override def toString: String = s"Expr($f <applied to> ${args.toList})"
51+
}
4152

42-
// TODO Use a List in FunctionAppliedTo(val f: Expr[_], val args: List[Expr[_]])
43-
// FIXME: Having the List in the code above trigers an assertion error while testing dotty.tools.dotc.reporting.ErrorMessagesTests.i3187
44-
// This test does redefine `scala.collection`. Further investigation is needed.
45-
/** An Expr representing `'{($f).apply($x1, ..., $xn)}` but it is beta-reduced when the closure is known */
46-
final class FunctionAppliedTo[+R](val f: Expr[_], val args: Array[Expr[_]]) extends Expr[R] {
47-
override def toString: String = s"Expr($f <applied to> ${args.toList})"
4853
}
4954
}
Lines changed: 42 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,53 @@
1-
package scala.quoted
1+
package scala
22

3-
import scala.quoted.Types.TaggedType
4-
import scala.reflect.ClassTag
5-
import scala.runtime.quoted.Unpickler.Pickled
3+
package quoted {
4+
import scala.internal.quoted.TaggedType
65

7-
sealed abstract class Type[T] {
8-
type `$splice` = T
9-
}
10-
11-
/** Some basic type tags, currently incomplete */
12-
object Type {
6+
sealed abstract class Type[T] {
7+
type `$splice` = T
8+
}
139

14-
implicit class TypeOps[T](tpe: Type[T]) {
15-
/** Show a source code like representation of this type */
16-
def show(implicit toolbox: Toolbox): String = toolbox.show(tpe.asInstanceOf[Type[Any]])
10+
/** Some basic type tags, currently incomplete */
11+
object Type {
12+
13+
implicit class TypeOps[T](tpe: Type[T]) {
14+
/** Show a source code like representation of this type */
15+
def show(implicit toolbox: Toolbox): String = toolbox.show(tpe.asInstanceOf[Type[Any]])
16+
}
17+
18+
implicit def UnitTag: Type[Unit] = new TaggedType[Unit]
19+
implicit def BooleanTag: Type[Boolean] = new TaggedType[Boolean]
20+
implicit def ByteTag: Type[Byte] = new TaggedType[Byte]
21+
implicit def CharTag: Type[Char] = new TaggedType[Char]
22+
implicit def ShortTag: Type[Short] = new TaggedType[Short]
23+
implicit def IntTag: Type[Int] = new TaggedType[Int]
24+
implicit def LongTag: Type[Long] = new TaggedType[Long]
25+
implicit def FloatTag: Type[Float] = new TaggedType[Float]
26+
implicit def DoubleTag: Type[Double] = new TaggedType[Double]
1727
}
1828

19-
implicit def UnitTag: Type[Unit] = new TaggedType[Unit]
20-
implicit def BooleanTag: Type[Boolean] = new TaggedType[Boolean]
21-
implicit def ByteTag: Type[Byte] = new TaggedType[Byte]
22-
implicit def CharTag: Type[Char] = new TaggedType[Char]
23-
implicit def ShortTag: Type[Short] = new TaggedType[Short]
24-
implicit def IntTag: Type[Int] = new TaggedType[Int]
25-
implicit def LongTag: Type[Long] = new TaggedType[Long]
26-
implicit def FloatTag: Type[Float] = new TaggedType[Float]
27-
implicit def DoubleTag: Type[Double] = new TaggedType[Double]
2829
}
2930

30-
/** All implementations of Type[T].
31-
* These should never be used directly.
32-
*/
33-
object Types {
34-
/** A Type backed by a pickled TASTY tree */
35-
final class TastyType[T](val tasty: Pickled, val args: Seq[Any]) extends Type[T] {
36-
override def toString(): String = s"Type(<pickled tasty>)"
37-
}
31+
package internal {
32+
package quoted {
33+
import scala.quote.Type
34+
import scala.reflect.ClassTag
35+
import scala.runtime.quoted.Unpickler.Pickled
3836

39-
/** An Type backed by a value */
40-
final class TaggedType[T](implicit val ct: ClassTag[T]) extends Type[T] {
41-
override def toString: String = s"Type($ct)"
42-
}
37+
/** A Type backed by a pickled TASTY tree */
38+
final class TastyType[T](val tasty: Pickled, val args: Seq[Any]) extends Type[T] {
39+
override def toString(): String = s"Type(<pickled tasty>)"
40+
}
41+
42+
/** An Type backed by a value */
43+
final class TaggedType[T](implicit val ct: ClassTag[T]) extends Type[T] {
44+
override def toString: String = s"Type($ct)"
45+
}
46+
47+
/** An Type backed by a tree */
48+
final class TreeType[Tree](val typeTree: Tree) extends quoted.Type[Any] {
49+
override def toString: String = s"Type(<tasty tree>)"
50+
}
4351

44-
/** An Type backed by a tree */
45-
final class TreeType[Tree](val typeTree: Tree) extends quoted.Type[Any] {
46-
override def toString: String = s"Type(<tasty tree>)"
4752
}
4853
}

0 commit comments

Comments
 (0)