Created
October 28, 2010 08:57
-
-
Save ymnk/650949 to your computer and use it in GitHub Desktop.
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
Samples to demonstrate the inline optimization by scala compiler. | |
$ scalac -Yinline -Ylog:inliner -Ydebug test.scala test2.scala |
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
// Inlining not taking place despite @inline | |
// https://lampsvn.epfl.ch/trac/scala/ticket/3234 | |
trait Trait1 { | |
// need more work before this one works | |
// @inline | |
def foo2(n: Int) = n*n | |
} | |
trait Trait2 { | |
@inline | |
def foo3(n: Int) = 1 | |
} | |
class Base extends Trait1 { | |
@inline | |
def foo(n: Int) = n | |
} | |
object Test extends Base with Trait2 { | |
def main(args: Array[String]) = { | |
println(foo(42) + foo2(11) + foo3(2)) | |
} | |
} |
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
package test | |
object Test { | |
@inline | |
def foo = println("foo") | |
// def ex_locally = locally { println("in locally") } | |
// def ex_tupple = (1 -> 2) | |
// def vector = Vector(1, 2, 3).updated(0, -1) | |
//@noinline | |
//def bar = println("bar") | |
//val x = 0 | |
//@inline | |
//def closure = x + 0 | |
//class C { | |
// @inline | |
// def c = "c" | |
//} | |
//@inline | |
//def factorial(n: Int): Int = n match { | |
// case 0 => 1 | |
// case n => n * factorial(n - 1) | |
//} | |
//@inline | |
//def factorial2(n: Int, sum: Int = 1): Int = n match { | |
// case 0 => sum | |
// case n => factorial2(n - 1, sum * n) | |
//} | |
/* | |
@inline | |
def foo0 = 1 | |
@inline | |
def foo1 = 0 + foo0 | |
@inline | |
def foo2 = 0 + foo1 | |
@inline | |
def foo3 = 0 + foo2 | |
@inline | |
def foo4 = 0 + foo3 | |
@inline | |
def foo5 = 0 + foo4 | |
@inline | |
def foo6 = 0 + foo5 | |
@inline | |
def foo7 = 0 + foo6 | |
@inline | |
def foo8 = 0 + foo7 | |
@inline | |
def foo9 = 0 + foo8 | |
@inline | |
def foo10 = 0 + foo9 | |
@inline | |
def foo11 = 0 + foo10 | |
@inline | |
def foo12 = 0 + foo11 | |
@inline | |
def foo13 = 0 + foo12 | |
@inline | |
def foo14 = 0 + foo13 | |
@inline | |
def foo15 = 0 + foo14 | |
*/ | |
} |
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
import test._ | |
object Test2 { | |
def Test_foo = Test.foo | |
// def Test_bar = Test.bar | |
// def Test_closure = Test.closure | |
// def Test_c = (new Test.C).c | |
// def Test_factorial = Test.factorial(10) | |
// def Test_foo15 = Test.foo15 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment