Skip to content

Fix #7781: Avoid using nested package definition #7784

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
merged 5 commits into from
Dec 18, 2019
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
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/core/quoted/PickledQuotes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import dotty.tools.dotc.core.tasty.TreePickler.Hole
import dotty.tools.dotc.core.tasty.{ PositionPickler, TastyPickler, TastyPrinter }
import dotty.tools.dotc.core.tasty.TreeUnpickler.UnpickleMode
import dotty.tools.dotc.quoted.QuoteContext
import dotty.tools.dotc.tastyreflect.ReflectionImpl
import dotty.tools.dotc.tastyreflect.{ReflectionImpl, TastyTreeExpr, TreeType}

import dotty.tools.tasty.TastyString

Expand All @@ -38,14 +38,14 @@ object PickledQuotes {

/** Transform the expression into its fully spliced Tree */
def quotedExprToTree[T](expr: quoted.Expr[T])(implicit ctx: Context): Tree = {
val expr1 = expr.asInstanceOf[TastyTreeExpr[Tree]]
val expr1 = expr.asInstanceOf[TastyTreeExpr]
QuoteContext.checkScopeId(expr1.scopeId)
healOwner(expr1.tree)
}

/** Transform the expression into its fully spliced TypeTree */
def quotedTypeToTree(tpe: quoted.Type[?])(implicit ctx: Context): Tree = {
val tpe1 = tpe.asInstanceOf[TreeType[Tree]]
val tpe1 = tpe.asInstanceOf[TreeType]
QuoteContext.checkScopeId(tpe1.scopeId)
healOwner(tpe1.typeTree)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import dotty.tools.dotc.quoted.QuoteContext
import dotty.tools.tasty.TastyFormat._

import scala.quoted
import scala.internal.quoted.{TastyTreeExpr, TreeType}
import dotty.tools.dotc.tastyreflect.{TastyTreeExpr, TreeType}
import scala.annotation.constructorOnly
import scala.annotation.internal.sharable

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
//

def unpickleExpr(repr: Unpickler.PickledQuote, args: Unpickler.PickledExprArgs): scala.quoted.Expr[?] =
new scala.internal.quoted.TastyTreeExpr(PickledQuotes.unpickleExpr(repr, args), compilerId)
new TastyTreeExpr(PickledQuotes.unpickleExpr(repr, args), compilerId)

def unpickleType(repr: Unpickler.PickledQuote, args: Unpickler.PickledTypeArgs): scala.quoted.Type[?] =
new scala.internal.quoted.TreeType(PickledQuotes.unpickleType(repr, args), compilerId)
new TreeType(PickledQuotes.unpickleType(repr, args), compilerId)

//
// CONTEXT
Expand Down Expand Up @@ -1779,7 +1779,7 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
/** Convert `Term` to an `quoted.Expr[Any]` */
def QuotedExpr_seal(self: Term)(given ctx: Context): scala.quoted.Expr[Any] = self.tpe.widen match {
case _: Types.MethodType | _: Types.PolyType => throw new Exception("Cannot seal a partially applied Term. Try eta-expanding the term first.")
case _ => new scala.internal.quoted.TastyTreeExpr(self, compilerId)
case _ => new TastyTreeExpr(self, compilerId)
}

/** Checked cast to a `quoted.Expr[U]` */
Expand All @@ -1799,7 +1799,7 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
/** Convert `Type` to an `quoted.Type[?]` */
def QuotedType_seal(self: Type)(given ctx: Context): scala.quoted.Type[?] = {
val dummySpan = ctx.owner.span // FIXME
new scala.internal.quoted.TreeType(tpd.TypeTree(self).withSpan(dummySpan), compilerId)
new TreeType(tpd.TypeTree(self).withSpan(dummySpan), compilerId)
}

//
Expand Down Expand Up @@ -1988,4 +1988,3 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend

private def compilerId: Int = rootContext.outersIterator.toList.last.hashCode()
}

22 changes: 22 additions & 0 deletions compiler/src/dotty/tools/dotc/tastyreflect/TastyTreeExpr.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package dotty.tools.dotc.tastyreflect

import dotty.tools.dotc.ast.tpd.Tree

/** 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(val tree: Tree, val scopeId: Int) extends scala.quoted.Expr[Any] {
override def equals(that: Any): Boolean = that match {
case that: TastyTreeExpr =>
// TastyTreeExpr are wrappers around trees, therfore they are equals if their trees are equal.
// All scopeId should be equal unless two different runs of the compiler created the trees.
tree == that.tree && scopeId == that.scopeId
case _ => false
}
override def hashCode: Int = tree.hashCode
override def toString: String = s"Expr(<tasty tree>)"
}
16 changes: 16 additions & 0 deletions compiler/src/dotty/tools/dotc/tastyreflect/TreeType.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package dotty.tools.dotc.tastyreflect

import dotty.tools.dotc.ast.tpd.Tree

/** An Type backed by a tree */
final class TreeType(val typeTree: Tree, val scopeId: Int) extends scala.quoted.Type[Any] {
override def equals(that: Any): Boolean = that match {
case that: TreeType => typeTree ==
// TastyTreeExpr are wrappers around trees, therfore they are equals if their trees are equal.
// All scopeId should be equal unless two different runs of the compiler created the trees.
that.typeTree && scopeId == that.scopeId
case _ => false
}
override def hashCode: Int = typeTree.hashCode
override def toString: String = s"Type(<tasty tree>)"
}
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/transform/Splicer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import dotty.tools.dotc.core.Types._
import dotty.tools.dotc.core.Symbols._
import dotty.tools.dotc.core.{NameKinds, TypeErasure}
import dotty.tools.dotc.core.Constants.Constant
import dotty.tools.dotc.tastyreflect.ReflectionImpl
import dotty.tools.dotc.tastyreflect.{ReflectionImpl, TastyTreeExpr, TreeType}

import scala.util.control.NonFatal
import dotty.tools.dotc.util.SourcePosition
Expand Down Expand Up @@ -246,10 +246,10 @@ object Splicer {
}

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

private def interpretTypeQuote(tree: Tree)(implicit env: Env): Object =
new scala.internal.quoted.TreeType(tree, QuoteContext.scopeId)
new TreeType(tree, QuoteContext.scopeId)

private def interpretLiteral(value: Any)(implicit env: Env): Object =
value.asInstanceOf[Object]
Expand Down
Loading