Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are <stable> and <accessor> when doing Scalac -Xprint:typer?

Tags:

scala

scalac

I've written a tiny bit of Scala

object SquareNumbers extends App {
  val numbers = List(1,2,3,4,5)
  val squares = numbers map (i => i * i)
  println (squares)
}

And run it through scalac as so:

$ scalac -Xprint:typer SquareNumbers.scala
[[syntax trees at end of                     typer]] // SquareNumbers.scala
package <empty> {
  object SquareNumbers extends Object with App {
    def <init>(): SquareNumbers.type = {
      SquareNumbers.super.<init>();
      ()
    };
    private[this] val numbers: List[Int] = immutable.this.List.apply[Int](1, 2, 3, 4, 5);
    <stable> <accessor> def numbers: List[Int] = SquareNumbers.this.numbers;
    private[this] val squares: List[Int] = SquareNumbers.this.numbers.map[Int, List[Int]](((i: Int) => i.*(i)))(immutable.this.List.canBuildFrom[Int]);
    <stable> <accessor> def squares: List[Int] = SquareNumbers.this.squares;
    scala.this.Predef.println(SquareNumbers.this.squares)
  }
}

My question is, what are <stable> and <accessor> in the output? What are they called (as in, do they have a collective noun), and what do they do?

At a guess, I'd say that meant they were vals instead of vars, and mean that it was a callable from outside of the object...

like image 334
colinjwebb Avatar asked Aug 02 '13 18:08

colinjwebb


1 Answers

These are internal (i.e., not exposed through the new 2.10 reflection API) flags. The official compiler ScalaDoc site seems to be down, but you can see the Scala source for details:

final val STABLE   = 1 << 22 // functions that are assumed to be stable
                             // (typically, access methods for valdefs)
                             // or classes that do not contain abstract types.

And:

final val ACCESSOR = 1 << 27 // a value or variable accessor (getter or setter)

Later in that file you can find the mapping between identifiers (e.g. STABLE) and the printed strings (<stable>), lists of which flags are displayed at which phases, etc.

like image 167
Travis Brown Avatar answered Nov 09 '22 04:11

Travis Brown