Last active
August 29, 2015 14:05
-
-
Save rxin/37554d9f3e2e93220884 to your computer and use it in GitHub Desktop.
Scala @inline final val impact on accessors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> class A { | |
| private[this] val abc = 1 | |
| | |
| def print() = println(abc) | |
| } | |
# abc gets inlined by the compiler as a field | |
[[syntax trees at end of cleanup]] // <console> | |
package $line4 { | |
object $read extends Object { | |
def <init>(): $line4.$read.type = { | |
$read.super.<init>(); | |
() | |
} | |
}; | |
class $read$$iw$$iw$A extends Object { | |
private[this] val abc: Int = _; | |
def print(): Unit = scala.this.Predef.println(scala.Int.box($read$$iw$$iw$A.this.abc)); | |
def <init>(): $line4.iw$A = { | |
$read$$iw$$iw$A.super.<init>(); | |
$read$$iw$$iw$A.this.abc = 1; | |
() | |
} | |
}; | |
object $read$$iw$$iw extends Object { | |
def <init>(): type = { | |
$read$$iw$$iw.super.<init>(); | |
() | |
} | |
}; | |
object $read$$iw extends Object { | |
def <init>(): type = { | |
$read$$iw.super.<init>(); | |
() | |
} | |
} | |
} | |
[[syntax trees at end of cleanup]] // <console> | |
package $line4 { | |
object $eval extends Object { | |
private[this] val $print: String = _; | |
<stable> <accessor> def $print(): String = $eval.this.$print; | |
def <init>(): $line4.$eval.type = { | |
$eval.super.<init>(); | |
$eval.this.$print = { | |
$line4.$read$$iw$$iw; | |
"defined class A\n" | |
}; | |
() | |
} | |
} | |
} | |
defined class A | |
scala> class B { | |
| private val abc = 1 | |
| | |
| def print() = println(abc) | |
| } | |
# abc is called as a method invocation | |
[[syntax trees at end of cleanup]] // <console> | |
package $line5 { | |
object $read extends Object { | |
def <init>(): $line5.$read.type = { | |
$read.super.<init>(); | |
() | |
} | |
}; | |
class $read$$iw$$iw$B extends Object { | |
private[this] val abc: Int = _; | |
<stable> <accessor> private def abc(): Int = $read$$iw$$iw$B.this.abc; | |
def print(): Unit = scala.this.Predef.println(scala.Int.box($read$$iw$$iw$B.this.abc())); | |
def <init>(): $line5.iw$B = { | |
$read$$iw$$iw$B.super.<init>(); | |
$read$$iw$$iw$B.this.abc = 1; | |
() | |
} | |
}; | |
object $read$$iw$$iw extends Object { | |
def <init>(): type = { | |
$read$$iw$$iw.super.<init>(); | |
() | |
} | |
}; | |
object $read$$iw extends Object { | |
def <init>(): type = { | |
$read$$iw.super.<init>(); | |
() | |
} | |
} | |
} | |
[[syntax trees at end of cleanup]] // <console> | |
package $line5 { | |
object $eval extends Object { | |
private[this] val $print: String = _; | |
<stable> <accessor> def $print(): String = $eval.this.$print; | |
def <init>(): $line5.$eval.type = { | |
$eval.super.<init>(); | |
$eval.this.$print = { | |
$line5.$read$$iw$$iw; | |
"defined class B\n" | |
}; | |
() | |
} | |
} | |
} | |
defined class B | |
scala> class C { | |
| @inline private[this] final val abc = 1 | |
| | |
| def print() = println(abc) | |
| } | |
# abc is a constant and there is no abc method | |
[[syntax trees at end of cleanup]] // <console> | |
package $line6 { | |
object $read extends Object { | |
def <init>(): $line6.$read.type = { | |
$read.super.<init>(); | |
() | |
} | |
}; | |
class $read$$iw$$iw$C extends Object { | |
def print(): Unit = scala.this.Predef.println(scala.Int.box(1)); | |
def <init>(): $line6.iw$C = { | |
$read$$iw$$iw$C.super.<init>(); | |
() | |
} | |
}; | |
object $read$$iw$$iw extends Object { | |
def <init>(): type = { | |
$read$$iw$$iw.super.<init>(); | |
() | |
} | |
}; | |
object $read$$iw extends Object { | |
def <init>(): type = { | |
$read$$iw.super.<init>(); | |
() | |
} | |
} | |
} | |
[[syntax trees at end of cleanup]] // <console> | |
package $line6 { | |
object $eval extends Object { | |
private[this] val $print: String = _; | |
<stable> <accessor> def $print(): String = $eval.this.$print; | |
def <init>(): $line6.$eval.type = { | |
$eval.super.<init>(); | |
$eval.this.$print = { | |
$line6.$read$$iw$$iw; | |
"defined class C\n" | |
}; | |
() | |
} | |
} | |
} | |
defined class C | |
scala> class C { | |
| private final val abc = 1 | |
| | |
| def print() = println(abc) | |
| } | |
# abc is a constant and there is an abc method | |
[[syntax trees at end of cleanup]] // <console> | |
package $line7 { | |
object $read extends Object { | |
def <init>(): $line7.$read.type = { | |
$read.super.<init>(); | |
() | |
} | |
}; | |
class $read$$iw$$iw$C extends Object { | |
final <stable> <accessor> private def abc(): Int = 1; | |
def print(): Unit = scala.this.Predef.println(scala.Int.box(1)); | |
def <init>(): $line7.iw$C = { | |
$read$$iw$$iw$C.super.<init>(); | |
() | |
} | |
}; | |
object $read$$iw$$iw extends Object { | |
def <init>(): type = { | |
$read$$iw$$iw.super.<init>(); | |
() | |
} | |
}; | |
object $read$$iw extends Object { | |
def <init>(): type = { | |
$read$$iw.super.<init>(); | |
() | |
} | |
} | |
} | |
[[syntax trees at end of cleanup]] // <console> | |
package $line7 { | |
object $eval extends Object { | |
private[this] val $print: String = _; | |
<stable> <accessor> def $print(): String = $eval.this.$print; | |
def <init>(): $line7.$eval.type = { | |
$eval.super.<init>(); | |
$eval.this.$print = { | |
$line7.$read$$iw$$iw; | |
"defined class C\n" | |
}; | |
() | |
} | |
} | |
} | |
defined class C | |
scala> class D { | |
| @inline private final val abc = 1 | |
| | |
| def print() = println(abc) | |
| } | |
# abc is a constant and there is an abc method | |
[[syntax trees at end of cleanup]] // <console> | |
package $line8 { | |
object $read extends Object { | |
def <init>(): $line8.$read.type = { | |
$read.super.<init>(); | |
() | |
} | |
}; | |
class $read$$iw$$iw$D extends Object { | |
final <stable> <accessor> private def abc(): Int = 1; | |
def print(): Unit = scala.this.Predef.println(scala.Int.box(1)); | |
def <init>(): $line8.iw$D = { | |
$read$$iw$$iw$D.super.<init>(); | |
() | |
} | |
}; | |
object $read$$iw$$iw extends Object { | |
def <init>(): type = { | |
$read$$iw$$iw.super.<init>(); | |
() | |
} | |
}; | |
object $read$$iw extends Object { | |
def <init>(): type = { | |
$read$$iw.super.<init>(); | |
() | |
} | |
} | |
} | |
[[syntax trees at end of cleanup]] // <console> | |
package $line8 { | |
object $eval extends Object { | |
private[this] val $print: String = _; | |
<stable> <accessor> def $print(): String = $eval.this.$print; | |
def <init>(): $line8.$eval.type = { | |
$eval.super.<init>(); | |
$eval.this.$print = { | |
$line8.$read$$iw$$iw; | |
"defined class D\n" | |
}; | |
() | |
} | |
} | |
} | |
defined class D | |
scala> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment