Skip to content

Move internal quoted.{Expr,Type} implementations to internal package #6608

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -740,9 +740,6 @@ class Definitions {
lazy val InternalQuotedMatcher_unapplyR: TermRef = InternalQuotedMatcherModule.requiredMethodRef(nme.unapply)
def InternalQuotedMatcher_unapply(implicit ctx: Context) = InternalQuotedMatcher_unapplyR.symbol

lazy val QuotedExprsModule: TermSymbol = ctx.requiredModule("scala.quoted.Exprs")
def QuotedExprsClass(implicit ctx: Context): ClassSymbol = QuotedExprsModule.asClass

lazy val QuotedTypeType: TypeRef = ctx.requiredClassRef("scala.quoted.Type")
def QuotedTypeClass(implicit ctx: Context): ClassSymbol = QuotedTypeType.symbol.asClass

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ import dotty.tools.dotc.core.tasty.TreePickler.Hole
import dotty.tools.dotc.core.tasty.{PositionPickler, TastyPickler, TastyPrinter, TastyString}
import dotty.tools.dotc.core.tasty.TreeUnpickler.UnpickleMode

import scala.quoted.Types._
import scala.quoted.Exprs._
import scala.internal.quoted._
import scala.reflect.ClassTag

object PickledQuotes {
Expand Down
3 changes: 1 addition & 2 deletions compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ import config.Printers.pickling
import core.quoted.PickledQuotes

import scala.quoted
import scala.quoted.Types.TreeType
import scala.quoted.Exprs.TastyTreeExpr
import scala.internal.quoted.{TastyTreeExpr, TreeType}
import scala.annotation.constructorOnly
import scala.annotation.internal.sharable

Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/quoted/ToolboxImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package dotty.tools.dotc.quoted
import dotty.tools.dotc.ast.tpd

import scala.quoted._
import scala.quoted.Exprs.{LiftedExpr, TastyTreeExpr}
import scala.internal.quoted.{LiftedExpr, TastyTreeExpr}

/** Default runners for quoted expressions */
object ToolboxImpl {
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1747,7 +1747,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util.
tpd.Closure(closureMethod, tss => etaExpand(new tpd.TreeOps(term).appliedToArgs(tss.head)))
case _ => term
}
new scala.quoted.Exprs.TastyTreeExpr(etaExpand(self))
new scala.internal.quoted.TastyTreeExpr(etaExpand(self))
}

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

//
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/Splicer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ object Splicer {
}

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

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

protected def interpretLiteral(value: Any)(implicit env: Env): Object =
value.asInstanceOf[Object]
Expand Down
83 changes: 44 additions & 39 deletions library/src-2.x/scala/quoted/Expr.scala
Original file line number Diff line number Diff line change
@@ -1,49 +1,54 @@
package scala.quoted
package scala

import scala.runtime.quoted.Unpickler.Pickled
package quoted {

sealed abstract class Expr[+T] {
sealed abstract class Expr[+T] {

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

}

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

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

/** An Expr backed by a tree. Only the current compiler trees are allowed.
*
* These expressions are used for arguments of macros. They contain and actual tree
* from the program that is being expanded by the macro.
*
* May contain references to code defined outside this TastyTreeExpr instance.
*/
final class TastyTreeExpr[Tree](val tree: Tree) extends quoted.Expr[Any] {
override def toString: String = s"Expr(<tasty tree>)"
}
package internal {
package quoted {

import scala.quoted._

/** An Expr backed by a pickled TASTY tree */
final class TastyExpr[+T](val tasty: scala.runtime.quoted.Unpickler.Pickled, val args: Seq[Any]) extends Expr[T] {
override def toString: String = s"Expr(<pickled tasty>)"
}

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

/** An Expr backed by a tree. Only the current compiler trees are allowed.
*
* These expressions are used for arguments of macros. They contain and actual tree
* from the program that is being expanded by the macro.
*
* May contain references to code defined outside this TastyTreeExpr instance.
*/
final class TastyTreeExpr[Tree](val tree: Tree) extends quoted.Expr[Any] {
override def toString: String = s"Expr(<tasty tree>)"
}

// TODO Use a List in FunctionAppliedTo(val f: Expr[_], val args: List[Expr[_]])
// FIXME: Having the List in the code above trigers an assertion error while testing dotty.tools.dotc.reporting.ErrorMessagesTests.i3187
// This test does redefine `scala.collection`. Further investigation is needed.
/** An Expr representing `'{($f).apply($x1, ..., $xn)}` but it is beta-reduced when the closure is known */
final class FunctionAppliedTo[+R](val f: Expr[_], val args: Array[Expr[_]]) extends Expr[R] {
override def toString: String = s"Expr($f <applied to> ${args.toList})"
}

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

import scala.quoted.Types.TaggedType
import scala.reflect.ClassTag
import scala.runtime.quoted.Unpickler.Pickled
package quoted {
import scala.internal.quoted.TaggedType

sealed abstract class Type[T] {
type `$splice` = T
}

/** Some basic type tags, currently incomplete */
object Type {
sealed abstract class Type[T] {
type `$splice` = T
}

implicit class TypeOps[T](tpe: Type[T]) {
/** Show a source code like representation of this type */
def show(implicit toolbox: Toolbox): String = toolbox.show(tpe.asInstanceOf[Type[Any]])
/** Some basic type tags, currently incomplete */
object Type {

implicit class TypeOps[T](tpe: Type[T]) {
/** Show a source code like representation of this type */
def show(implicit toolbox: Toolbox): String = toolbox.show(tpe.asInstanceOf[Type[Any]])
}

implicit def UnitTag: Type[Unit] = new TaggedType[Unit]
implicit def BooleanTag: Type[Boolean] = new TaggedType[Boolean]
implicit def ByteTag: Type[Byte] = new TaggedType[Byte]
implicit def CharTag: Type[Char] = new TaggedType[Char]
implicit def ShortTag: Type[Short] = new TaggedType[Short]
implicit def IntTag: Type[Int] = new TaggedType[Int]
implicit def LongTag: Type[Long] = new TaggedType[Long]
implicit def FloatTag: Type[Float] = new TaggedType[Float]
implicit def DoubleTag: Type[Double] = new TaggedType[Double]
}

implicit def UnitTag: Type[Unit] = new TaggedType[Unit]
implicit def BooleanTag: Type[Boolean] = new TaggedType[Boolean]
implicit def ByteTag: Type[Byte] = new TaggedType[Byte]
implicit def CharTag: Type[Char] = new TaggedType[Char]
implicit def ShortTag: Type[Short] = new TaggedType[Short]
implicit def IntTag: Type[Int] = new TaggedType[Int]
implicit def LongTag: Type[Long] = new TaggedType[Long]
implicit def FloatTag: Type[Float] = new TaggedType[Float]
implicit def DoubleTag: Type[Double] = new TaggedType[Double]
}

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

/** An Type backed by a value */
final class TaggedType[T](implicit val ct: ClassTag[T]) extends Type[T] {
override def toString: String = s"Type($ct)"
}
/** A Type backed by a pickled TASTY tree */
final class TastyType[T](val tasty: Pickled, val args: Seq[Any]) extends Type[T] {
override def toString(): String = s"Type(<pickled tasty>)"
}

/** An Type backed by a value */
final class TaggedType[T](implicit val ct: ClassTag[T]) extends Type[T] {
override def toString: String = s"Type($ct)"
}

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

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