Skip to content

Instantly share code, notes, and snippets.

@VladUreche
Created May 16, 2012 11:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VladUreche/2709762 to your computer and use it in GitHub Desktop.
Save VladUreche/2709762 to your computer and use it in GitHub Desktop.
Question about how the Scala Compiler generates LabelDefs
$ cat test.scala
trait Foo[A] {
final def bar(a:A):A = bar(a)
}
$ scalac -Xprint:tailcalls test.scala
[[syntax trees at end of tailcalls]] // test.scala
package <empty>#4 {
abstract trait Foo#6[A#7308 >: Nothing#3704 <: Any#3703] extends Object#1785 {
...
final def bar#7595(a#7606: A#7308): A#7308 = {
<synthetic> val _$this#7844: Foo#6[A#7308] = Foo#6.this;
_bar#7842(_$this#7844: Foo#6[A#7308], a#7606: A#7308){ // BEHAVIOR1: previously defined symbol (defined on the line above)
_bar#7842(Foo#6.this, a#7606)
}
}
}
}
$ cat test2.scala
object Test {
def test[A](x: A) = x match {
case _: Boolean => "bool"
}
}
$ scalac -Xprint:tailcalls test2.scala -uniqid
[[syntax trees at end of tailcalls]] // test2.scala
package <empty>#4 {
object Test#8 extends Object#1783 {
def <init>#7591(): Test#7.type = {
Test#8.super.<init>#5055();
()
};
def test#7592[A#7593 >: Nothing#3702 <: Any#3701](x#8780: A#7594): String#1867 = {
case <synthetic> val x1#11851: A#7594 = x#8780;
case4#11857(){
if (x1#11851.isInstanceOf#5074[Boolean#1428]())
{
val x2#11854: A#7594 with Boolean#1428 = (x1#11851.asInstanceOf#5076[A#7594 with Boolean#1428](): A#7594 with Boolean#1428);
matchEnd3#11855("bool")
}
else
case5#11858()
};
case5#11858(){
matchEnd3#11855(throw new MatchError#1179(x1#11851))
};
matchEnd3#11855(x#11856: String#1867){ // BEHAVIOR2: new symbol, not defined previously
x#11856
}
}
}
}
@VladUreche
Copy link
Author

Look for BEHAVIOR1 and BEHAVIOR2 for a quick lookup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment