如何在 REPL 中使用 :phase power 命令?
How to use :phase power command in REPL?
Scala REPL 的 Power mode 启用 :phase
命令:
:phase <phase> set the implicit phase for power commands
我似乎找不到有关如何使用此命令的文档。例如,假设我设置 parser
compiler phase
scala> :phase parser
Active phase is now: Parser
什么power命令受到了影响?我如何调用这些受影响的电源命令?它与 :settings -Xprint:parser
有何不同?
该命令会导致您的代码被计算 enteringPhase
,这是使用 intp.setExecutionWrapper
完成的。你可以用 -Dscala.repl.debug
.
见证包装
它包装了REPL的"print":
lazy val $print: _root_.java.lang.String = $line4.$read.$iw.$iw.$r.phased.atCurrent {
phased
对象只是调整对 enteringPhase
的调用。
这是一个示例,您可以在稍后阶段看到已擦除的类型:
scala> global.rootMirror.staticClass("scala.Option").typeSignature
res0: $r.global.Type =
[+A <: <?>]AnyRef
with IterableOnce[A]
with Product
with Serializable {
def <init>(): Option[A]
final def isEmpty: Boolean
final def isDefined: Boolean
final override def knownSize: Int
def get: A
final def getOrElse[B >: A](default: => B): B
final def orNull[A1 >: A](implicit ev: Null <:< A1): A1
final def map[B](f: A => B): Option[B]
final def fold[B](ifEmpty: => B)(f: A => B): B
final def flatMap[B](f: A => Option[B]): Option[B]
def flatten[B](implicit ev: A <:< Option[B]): Option[B]
final def filter(p: A => Boolean): Option[A]
final def filterNot(p: A => Boolean): Option[A]
final def nonEmpty: Boolean
final def withFilter(p: A => Boolean): Option.this.WithFilter
class WithFilter extends AnyRef
final def...
scala> global.rootMirror.staticClass("scala.Option").typeSignature.getClass
res1: Class[_ <: $r.global.Type] = class scala.reflect.internal.Types$PolyType
scala> :phase cleanup
Active phase is now: Cleanup
scala> global.rootMirror.staticClass("scala.Option").typeSignature.getClass
res2: Class[_ <: $r.global.Type] = class scala.reflect.internal.Types$ClassInfoType
scala> global.rootMirror.staticClass("scala.Option").typeSignature
res3: $r.global.Type =
Object
with scala.collection.IterableOnce
with Product
with java.io.Serializable {
def <init>(): Option
final def isEmpty(): Boolean
final def isDefined(): Boolean
final override def knownSize(): Int
def get(): Object
[snip]
REPL中的:type
命令不受影响,因为它调用了exitingTyper
.
Power mode 启用 :phase
命令:
:phase <phase> set the implicit phase for power commands
我似乎找不到有关如何使用此命令的文档。例如,假设我设置 parser
compiler phase
scala> :phase parser
Active phase is now: Parser
什么power命令受到了影响?我如何调用这些受影响的电源命令?它与 :settings -Xprint:parser
有何不同?
该命令会导致您的代码被计算 enteringPhase
,这是使用 intp.setExecutionWrapper
完成的。你可以用 -Dscala.repl.debug
.
它包装了REPL的"print":
lazy val $print: _root_.java.lang.String = $line4.$read.$iw.$iw.$r.phased.atCurrent {
phased
对象只是调整对 enteringPhase
的调用。
这是一个示例,您可以在稍后阶段看到已擦除的类型:
scala> global.rootMirror.staticClass("scala.Option").typeSignature
res0: $r.global.Type =
[+A <: <?>]AnyRef
with IterableOnce[A]
with Product
with Serializable {
def <init>(): Option[A]
final def isEmpty: Boolean
final def isDefined: Boolean
final override def knownSize: Int
def get: A
final def getOrElse[B >: A](default: => B): B
final def orNull[A1 >: A](implicit ev: Null <:< A1): A1
final def map[B](f: A => B): Option[B]
final def fold[B](ifEmpty: => B)(f: A => B): B
final def flatMap[B](f: A => Option[B]): Option[B]
def flatten[B](implicit ev: A <:< Option[B]): Option[B]
final def filter(p: A => Boolean): Option[A]
final def filterNot(p: A => Boolean): Option[A]
final def nonEmpty: Boolean
final def withFilter(p: A => Boolean): Option.this.WithFilter
class WithFilter extends AnyRef
final def...
scala> global.rootMirror.staticClass("scala.Option").typeSignature.getClass
res1: Class[_ <: $r.global.Type] = class scala.reflect.internal.Types$PolyType
scala> :phase cleanup
Active phase is now: Cleanup
scala> global.rootMirror.staticClass("scala.Option").typeSignature.getClass
res2: Class[_ <: $r.global.Type] = class scala.reflect.internal.Types$ClassInfoType
scala> global.rootMirror.staticClass("scala.Option").typeSignature
res3: $r.global.Type =
Object
with scala.collection.IterableOnce
with Product
with java.io.Serializable {
def <init>(): Option
final def isEmpty(): Boolean
final def isDefined(): Boolean
final override def knownSize(): Int
def get(): Object
[snip]
REPL中的:type
命令不受影响,因为它调用了exitingTyper
.