Skip to content

Clean quote implementation #4818

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 3 commits into from
Jul 20, 2018
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
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ class Definitions {
def Unpickler_unpickleType = ctx.requiredMethod("scala.runtime.quoted.Unpickler.unpickleType")

lazy val TastyTopLevelSpliceModule = ctx.requiredModule("scala.tasty.TopLevelSplice")
lazy val TastyTopLevelSplice_compilationTopLevelSplice = TastyTopLevelSpliceModule.requiredMethod("tastyContext")
lazy val TastyTopLevelSplice_tastyContext = TastyTopLevelSpliceModule.requiredMethod("tastyContext")

lazy val EqType = ctx.requiredClassRef("scala.Eq")
def EqClass(implicit ctx: Context) = EqType.symbol.asClass
Expand Down
10 changes: 5 additions & 5 deletions compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,10 @@ class ReifyQuotes extends MacroTransformWithImplicits with InfoTransformer {
}

/** We are in a `~(...)` context that is not shadowed by a nested `'(...)` */
def inSplice = outer != null && !inQuote
def inSplice: Boolean = outer != null && !inQuote

/** We are not in a `~(...)` or a `'(...)` */
def isRoot = outer == null
def isRoot: Boolean = outer == null

/** A map from type ref T to expressions of type `quoted.Type[T]`".
* These will be turned into splices using `addTags` and represent type variables
Expand Down Expand Up @@ -516,9 +516,9 @@ class ReifyQuotes extends MacroTransformWithImplicits with InfoTransformer {
outer.enteredSyms.foreach(registerCapturer)

if (ctx.owner.owner.is(Macro)) {
registerCapturer(defn.TastyTopLevelSplice_compilationTopLevelSplice)
registerCapturer(defn.TastyTopLevelSplice_tastyContext)
// Force a macro to have the context in first position
forceCapture(defn.TastyTopLevelSplice_compilationTopLevelSplice)
forceCapture(defn.TastyTopLevelSplice_tastyContext)
// Force all parameters of the macro to be created in the definition order
outer.enteredSyms.reverse.foreach(forceCapture)
}
Expand Down Expand Up @@ -652,7 +652,7 @@ class ReifyQuotes extends MacroTransformWithImplicits with InfoTransformer {

private def isStage0Value(sym: Symbol)(implicit ctx: Context): Boolean =
(sym.is(Inline) && sym.owner.is(Macro) && !defn.isFunctionType(sym.info)) ||
sym == defn.TastyTopLevelSplice_compilationTopLevelSplice // intrinsic value at stage 0
sym == defn.TastyTopLevelSplice_tastyContext // intrinsic value at stage 0

private def liftList(list: List[Tree], tpe: Type)(implicit ctx: Context): Tree = {
list.foldRight[Tree](ref(defn.NilModule)) { (x, acc) =>
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/transform/Splicer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ object Splicer {
s"""Failed to evaluate inlined quote.
| Caused by ${ex.getClass}: ${if (ex.getMessage == null) "" else ex.getMessage}
| ${ex.getStackTrace.takeWhile(_.getClassName != "dotty.tools.dotc.transform.Splicer$").init.mkString("\n ")}
""".stripMargin
""".stripMargin
ctx.error(msg, pos)
EmptyTree
}
Expand Down
4 changes: 2 additions & 2 deletions library/src/scala/quoted/Type.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ object Type {
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>)"
override def toString(): String = s"Type(<pickled tasty>)"
}

/** An Type backed by a value */
Expand All @@ -41,6 +41,6 @@ object Types {

/** An Type backed by a tree */
final class TreeType[Tree](val typeTree: Tree) extends quoted.Type[Any] {
override def toString: String = s"Type(<raw>)"
override def toString: String = s"Type(<tasty tree>)"
}
}
3 changes: 1 addition & 2 deletions tests/pos/quote-0.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ import scala.quoted._

import dotty.tools.dotc.quoted.Toolbox._


object Macros {

inline def assert(expr: => Boolean): Unit =
~ assertImpl('(expr))
~assertImpl('(expr))

def assertImpl(expr: Expr[Boolean]) =
'{ if !(~expr) then throw new AssertionError(s"failed assertion: ${~showExpr(expr)}") }
Expand Down
1 change: 0 additions & 1 deletion tests/run/tasty-custom-show/quoted_1.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import scala.quoted._
import dotty.tools.dotc.quoted.Toolbox._

import scala.tasty.TopLevelSplice
import scala.tasty.Tasty
Expand Down
1 change: 0 additions & 1 deletion tests/run/tasty-extractors-1/quoted_1.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import scala.quoted._
import dotty.tools.dotc.quoted.Toolbox._

import scala.tasty._

Expand Down
1 change: 0 additions & 1 deletion tests/run/tasty-extractors-2/quoted_1.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import scala.quoted._
import dotty.tools.dotc.quoted.Toolbox._

import scala.tasty._

Expand Down
1 change: 0 additions & 1 deletion tests/run/tasty-extractors-3/quoted_1.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import scala.quoted._
import dotty.tools.dotc.quoted.Toolbox._

import scala.tasty.TopLevelSplice
import scala.tasty.Tasty
Expand Down
1 change: 0 additions & 1 deletion tests/run/tasty-extractors-constants-1/quoted_1.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import scala.quoted._
import dotty.tools.dotc.quoted.Toolbox._

import scala.tasty._
import scala.tasty.util._
Expand Down
1 change: 0 additions & 1 deletion tests/run/tasty-extractors-owners/quoted_1.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import scala.quoted._
import dotty.tools.dotc.quoted.Toolbox._

import scala.tasty._
import scala.tasty.util.TreeTraverser
Expand Down
1 change: 0 additions & 1 deletion tests/run/tasty-extractors-types/quoted_1.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import scala.quoted._
import dotty.tools.dotc.quoted.Toolbox._

import scala.tasty._
import scala.tasty.util.TreeTraverser
Expand Down
2 changes: 0 additions & 2 deletions tests/run/tasty-linenumber/quoted_1.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import scala.quoted._

import dotty.tools.dotc.quoted.Toolbox._

import scala.tasty._

class LineNumber(val value: Int) {
Expand Down
2 changes: 0 additions & 2 deletions tests/run/tasty-location/quoted_1.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import scala.quoted._

import dotty.tools.dotc.quoted.Toolbox._

import scala.tasty._

case class Location(owners: List[String])
Expand Down
2 changes: 0 additions & 2 deletions tests/run/tasty-positioned/quoted_1.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import scala.quoted._

import dotty.tools.dotc.quoted.Toolbox._

import scala.tasty._

case class Position(path: String, start: Int, end: Int,
Expand Down