REPL: intp.global vs "global" available in :power mode (ClassInfoType problem)

71 views
Skip to first unread message

Eugene Yokota

unread,
Apr 7, 2013, 3:31:05 PM4/7/13
to scala-i...@googlegroups.com
Hi guys,

Is there a difference in the way intp.global behave as opposed to global object
I can get hold of in :power mode of the REPL?

While working on [:kind command][1]. I'm getting stuck with the same point @folone got stuck:
- [Adding :kind command to scala repl][2]
- [Getting type information inside scala repl via IMain][3]

1. For several reasons, I would like to use global instead of the runtime.universe.
2. In this discussion, let's assume I have the full name of the type.

I was able to port Adriaan's inferKind to trait Kinds, and get it work in :power mode:

scala> :power

scala> global.inferKind(NoPrefix)(intp.global.rootMirror.staticClass("scala.Option"))
[+A]AnyRef
        with Product
        with Serializable {
  def <init>(): Option[A]
  def isEmpty: Boolean
  def isDefined: Boolean
  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 contains[A1 >: A](elem: A1): Boolean
  final def exists(p: A => Boolean): Boolean
  final def forall(p: A => Boolean): Boolean
  final def foreach[U](f: A => U): Unit
  final def collect[B](pf: PartialFunction[A,B]): Option[B]
  final def orElse[B >: A](alternative: => Option[B]): Option[B]
  def iterator: Iterator[A]
  def toList: List[A]
  final def toRight[X](left: => X): Product with Serializable with scala.util.Either[X,A]
  final def toLeft[X](right: => X): Product with Serializable with scala.util.Either[A,X]
}
class scala.reflect.internal.Types$PolyType

class scala.reflect.internal.Types$UniqueTypeBounds
res0: $r.global.Kind = F[+A]

I am doing some println of the Types to check what's going on. In the above I'm getting PolyType as expected.
:kind command does the same thing, but here's what I get.

scala> :kind scala.Option
typeFromFullName
Object
        with Product
        with Serializable {
  def <init>(): Option
  def isEmpty(): Boolean
  def isDefined(): Boolean
  def get(): Object
  final def getOrElse(default: Function0): Object
  final def orNull(ev: less:<): Object
  final def map(f: Function1): Option
  final def fold(ifEmpty: Function0,f: Function1): Object
  final def flatMap(f: Function1): Option
  def flatten(ev: less:<): Option
  final def filter(p: Function1): Option
  final def filterNot(p: Function1): Option
  final def nonEmpty(): Boolean
  final def withFilter(p: Function1): Option#Option$WithFilter
  final def contains(elem: Object): Boolean
  final def exists(p: Function1): Boolean
  final def forall(p: Function1): Boolean
  final def foreach(f: Function1): Unit
  final def collect(pf: PartialFunction): Option
  final def orElse(alternative: Function0): Option
  def iterator(): Iterator
  def toList(): List
  final def toRight(left: Function0): util.Either
  final def toLeft(right: Function0): util.Either
}
class scala.reflect.internal.Types$ClassInfoType
A

Instead of PolyType, I get ClassInfoType. What am I doing wrong here?
The code that's converting the type symbol to Type is this:

    abstract class InferKind {
      def apply(tpe: Type, owner: Symbol): Kind
      def apply(sym: Symbol): Kind = apply(sym.typeSignature, sym.owner)
    }

-eugene

Paul Phillips

unread,
Apr 7, 2013, 5:09:50 PM4/7/13
to scala-i...@googlegroups.com

On Sun, Apr 7, 2013 at 12:31 PM, Eugene Yokota <eed3...@gmail.com> wrote:
Is there a difference in the way intp.global behave as opposed to global object
I can get hold of in :power mode of the REPL?

They're the same object.

scala> $intp.global
res0: scala.tools.nsc.Global = <global>

scala> :power
** Power User mode enabled - BEEP WHIR GYVE **
** :phase has been set to 'typer'.          **
** scala.tools.nsc._ has been imported      **
** global._, definitions._ also imported    **
** Try  :help, :vals, power.<tab>           **

scala> global
res1: $r.intp.global.type = <global>

scala> res0 eq res1
res2: Boolean = true

eugene yokota

unread,
Apr 7, 2013, 5:42:30 PM4/7/13
to scala-i...@googlegroups.com

On Sun, Apr 7, 2013 at 5:09 PM, Paul Phillips <pa...@improving.org> wrote:
They're the same object.

Here's a simple repro. Am I missing some implicits?

scala> $intp.global.rootMirror.staticClass("scala.Option").typeSignature.getClass
res0: Class[_ <: $intp.global.Type] = class scala.reflect.internal.Types$ClassInfoType

scala> :power
** Power User mode enabled - BEEP WHIR GYVE **
** :phase has been set to 'typer'.          **
** scala.tools.nsc._ has been imported      **
** global._, definitions._ also imported    **
** Try  :help, :vals, power.<tab>           **

scala> global.rootMirror.staticClass("scala.Option").typeSignature.getClass
res1: Class[_ <: $r.global.Type] = class scala.reflect.internal.Types$PolyType

scala> $intp.global eq global
res2: Boolean = true

-eugene

Jason Zaugg

unread,
Apr 7, 2013, 6:02:30 PM4/7/13
to scala-i...@googlegroups.com
On Sun, Apr 7, 2013 at 11:42 PM, eugene yokota <eed3...@gmail.com> wrote:

On Sun, Apr 7, 2013 at 5:09 PM, Paul Phillips <pa...@improving.org> wrote:
They're the same object.

Here's a simple repro. Am I missing some implicits?

scala> $intp.global.rootMirror.staticClass("scala.Option").typeSignature.getClass
res0: Class[_ <: $intp.global.Type] = class scala.reflect.internal.Types$ClassInfoType

scala> :power
** Power User mode enabled - BEEP WHIR GYVE **
** :phase has been set to 'typer'.          **

     ^
     `----  this part is relevant

Symbols have an list of types (aka 'info'-s), indexed by compiler phase. (aka TypeHistory). Many compiler phases install 'InfoTransformers' to morph the type. See src/compiler/scala/tools/nsc/transform/InfoTransform.scala for some documentation.

To inspect the type as-at particular phase, you can use methods like 'exitingTyper`.

scala> exitingPostErasure($intp.global.rootMirror.staticClass("scala.Option").typeSignature).getClass
res6: Class[_ <: $intp.global.Type] = class scala.reflect.internal.Types$ClassInfoType

scala> exitingTyper($intp.global.rootMirror.staticClass("scala.Option").typeSignature).getClass
res7: Class[_ <: $intp.global.Type] = class scala.reflect.internal.Types$PolyType

Or, a little more conveniently in :power mode:

scala> :phase typer
Active phase is now: Typer

scala> global.rootMirror.staticClass("scala.Option").typeSignature.getClass
res16: 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
res17: Class[_ <: $r.global.Type] = class scala.reflect.internal.Types$ClassInfoType


-jason          

eugene yokota

unread,
Apr 7, 2013, 6:10:29 PM4/7/13
to scala-i...@googlegroups.com
The phase! That makes sense now. Thanks!

-eugene


--
You received this message because you are subscribed to a topic in the Google Groups "scala-internals" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/scala-internals/fBLwvcjNGTc/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to scala-interna...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Eugene Burmako

unread,
Apr 8, 2013, 2:00:57 AM4/8/13
to scala-internals
Wow!!! That's very helpful. I remember stumbling upon this problem
some time ago. Didn't figure it out back then.

On Apr 8, 1:10 am, eugene yokota <eed3s...@gmail.com> wrote:
> The phase! That makes sense now. Thanks!
>
> -eugene
>
>
>
>
>
>
>
> On Sun, Apr 7, 2013 at 6:02 PM, Jason Zaugg <jza...@gmail.com> wrote:
> >https://groups.google.com/d/topic/scala-internals/fBLwvcjNGTc/unsubsc...
> > .
Reply all
Reply to author
Forward
0 new messages