Dotty Documentation

0.9.0-bin-SNAPSHOT

class ReifyQuotes
extends MacroTransformWithImplicits with InfoTransformer

Translates quoted terms and types to unpickle method calls. Checks that the phase consistency principle (PCP) holds.

Transforms top level quote

'{ ...
   val x1 = ???
   val x2 = ???
   ...
   ~{ ... '{ ... x1 ... x2 ...} ... }
   ...
 }

to

 unpickle(
   [[ // PICKLED TASTY
     ...
     val x1 = ???
     val x2 = ???
     ...
     Hole(0 | x1, x2)
     ...
   ]],
   List(
     (args: Seq[Any]) => {
       val x1$1 = args(0).asInstanceOf[Expr[T]]
       val x2$1 = args(1).asInstanceOf[Expr[T]] // can be asInstanceOf[Type[T]]
       ...
       { ... '{ ... x1$1.unary_~ ... x2$1.unary_~ ...} ... }
     }
   )
 )

and then performs the same transformation on '{ ... x1$1.unary_~ ... x2$1.unary_~ ...}.

For inline macro definitions we assume that we have a single ~ directly as the RHS. We will transform the definition from

inline def foo[T1, ...](inline x1: X, ..., y1: Y, ....): Z = ~{ ... T1 ... x ... '(y) ... }

to

inline def foo[T1, ...](inline x1: X, ..., y1: Y, ....): Seq[Any] => Object = { (args: Seq[Any]) => {
  val T1$1 = args(0).asInstanceOf[Type[T1]]
  ...
  val x1$1 = args(0).asInstanceOf[X]
  ...
  val y1$1 = args(1).asInstanceOf[Expr[Y]]
  ...
  { ... x1$1 .... '{ ... T1$1.unary_~ ... x1$1.toExpr.unary_~ ... y1$1.unary_~ ... } ... }
}

Where inline parameters with type Boolean, Byte, Short, Int, Long, Float, Double, Char and String are passed as their actual runtime value. See isStage0Value. Other inline arguments such as functions are handled like y1: Y.

Note: the parameters of foo are kept for simple overloading resolution but they are not used in the body of foo.

At inline site we will call reflectively the static method foo with dummy parameters, which will return a precompiled version of the function that will evaluate the Expr[Z] that foo produces. The lambda is then called at the inline site with the lifted arguments of the inlined call.

[-] Constructors

ReifyQuotes ( )

[-] Members

[+] private class LevelInfo
[+] private class Reifier

The main transformer class

[+] private var myMacroClassLoader : ClassLoader

Classloader used for loading macros

[+] private def macroClassLoader ( implicit ctx: Context ) : ClassLoader
[+] private def macroReturnType ( implicit ctx: Context ) : Type

Returns the type of the compiled macro as a lambda: Seq[Any] => Object

[+] protected override def mayChange ( sym: Symbol ) ( implicit ctx: Context ) : Boolean

Denotations with a symbol where mayChange is false are guaranteed to be unaffected by this transform, so transformInfo need not be run. This can save time, and more importantly, can help avoid forcing symbol completers.

[+] protected def newTransformer ( implicit ctx: Context ) : Transformer
[+] override def phaseName : String

A name given to the Phase that can be used to debug the compiler. For instance, it is possible to print trees after a given phase using:

$ ./bin/dotc -Xprint:<phaseNameHere> sourceFile.scala
[+] override def run ( implicit ctx: Context ) : Unit
[+] def transformInfo ( tp: Type , sym: Symbol ) ( implicit ctx: Context ) : Type