diff options
author | Lukas Rytz <lukas.rytz@gmail.com> | 2015-10-13 09:52:08 +0200 |
---|---|---|
committer | Lukas Rytz <lukas.rytz@gmail.com> | 2015-10-20 15:59:03 +0200 |
commit | 62be5705b91cb233bf922021f102a08bccc95af5 (patch) | |
tree | 684f42edc5e42319910f1e6d4b98a4192e5fbaa1 /src/library | |
parent | 19ee72193b6d3d4b1dc1e3bba430d3d741db97e3 (diff) | |
download | scala-62be5705b91cb233bf922021f102a08bccc95af5.tar.gz scala-62be5705b91cb233bf922021f102a08bccc95af5.tar.bz2 scala-62be5705b91cb233bf922021f102a08bccc95af5.zip |
Allow @inline/noinline at callsites (in addition to def-site)
Allow annotating individual callsites @inline / @noinline using an
annotation ascription
c.foo(): @inline
Diffstat (limited to 'src/library')
-rw-r--r-- | src/library/scala/inline.scala | 26 | ||||
-rw-r--r-- | src/library/scala/noinline.scala | 26 |
2 files changed, 48 insertions, 4 deletions
diff --git a/src/library/scala/inline.scala b/src/library/scala/inline.scala index a21cced928..dc55af301c 100644 --- a/src/library/scala/inline.scala +++ b/src/library/scala/inline.scala @@ -11,8 +11,30 @@ package scala /** - * An annotation on methods that requests that the compiler should - * try especially hard to inline the annotated method. + * An annotation on methods that requests that the compiler should try especially hard to inline the + * annotated method. The annotation can be used at definition site or at callsite. + * + * {{{ + * @inline final def f1(x: Int) = x + * @noinline final def f2(x: Int) = x + * final def f3(x: Int) = x + * + * def t1 = f1(1) // inlined if possible + * def t2 = f2(1) // not inlined + * def t3 = f3(1) // may be inlined (heuristics) + * def t4 = f1(1): @noinline // not inlined (override at callsite) + * def t5 = f2(1): @inline // not inlined (cannot override the @noinline at f2's definition) + * def t6 = f3(1): @inline // inlined if possible + * def t7 = f3(1): @noinline // not inlined + * } + * }}} + * + * Note: parentheses are required when annotating a callsite withing a larger expression. + * + * {{{ + * def t1 = f1(1) + f1(1): @noinline // equivalent to (f1(1) + f1(1)): @noinline + * def t2 = f1(1) + (f1(1): @noinline) // the second call to f1 is not inlined + * }}} * * @author Lex Spoon * @version 1.0, 2007-5-21 diff --git a/src/library/scala/noinline.scala b/src/library/scala/noinline.scala index 38fd4c39d6..a427e170f4 100644 --- a/src/library/scala/noinline.scala +++ b/src/library/scala/noinline.scala @@ -11,8 +11,30 @@ package scala /** - * An annotation on methods that forbids the compiler to inline the - * method, no matter how safe the inlining appears to be. + * An annotation on methods that forbids the compiler to inline the method, no matter how safe the + * inlining appears to be. The annotation can be used at definition site or at callsite. + * + * {{{ + * @inline final def f1(x: Int) = x + * @noinline final def f2(x: Int) = x + * final def f3(x: Int) = x + * + * def t1 = f1(1) // inlined if possible + * def t2 = f2(1) // not inlined + * def t3 = f3(1) // may be inlined (heuristics) + * def t4 = f1(1): @noinline // not inlined (override at callsite) + * def t5 = f2(1): @inline // not inlined (cannot override the @noinline at f2's definition) + * def t6 = f3(1): @inline // inlined if possible + * def t7 = f3(1): @noinline // not inlined + * } + * }}} + * + * Note: parentheses are required when annotating a callsite withing a larger expression. + * + * {{{ + * def t1 = f1(1) + f1(1): @noinline // equivalent to (f1(1) + f1(1)): @noinline + * def t2 = f1(1) + (f1(1): @noinline) // the second call to f1 is not inlined + * }}} * * @author Lex Spoon * @version 1.0, 2007-5-21 |