summaryrefslogtreecommitdiff
path: root/src/library
diff options
context:
space:
mode:
authorLukas Rytz <lukas.rytz@gmail.com>2016-11-15 15:11:58 +0100
committerLukas Rytz <lukas.rytz@gmail.com>2016-11-25 11:53:43 +0100
commit8020cd66c8b30126bbba1dc1e87f7daafb3f2dd7 (patch)
tree520e397d27b0d453df664c8d9abab2fc9f80de34 /src/library
parenteb7d907f6283f897f6b248bae170bade57969519 (diff)
downloadscala-8020cd66c8b30126bbba1dc1e87f7daafb3f2dd7.tar.gz
scala-8020cd66c8b30126bbba1dc1e87f7daafb3f2dd7.tar.bz2
scala-8020cd66c8b30126bbba1dc1e87f7daafb3f2dd7.zip
Better inliner support for 2.12 trait encoding
Some changes to the trait encoding came late in the 2.12 cycle, and the inliner was not adapted to support it in the best possible way. In 2.12.0 concrete trait methods are encoded as interface T { default int m() { return 1 } static int m$(T $this) { <invokespecial $this.m()> } } class C implements T { public int m() { return T.m$(this) } } If a trait method is selected for inlining, the 2.12.0 inliner would copy its body into the static super accessor `T.m$`, and from there into the mixin forwarder `C.m`. This commit special-cases the inliner: - We don't inline into static super accessors and mixin forwarders. - Insted, when inlining an invocation of a mixin forwarder, the inliner also follows through the two forwarders and inlines the trait method body. There was a difficulty implementing this: inlining the static static super accessor would copy an `invokespecial` instruction into a different classfile, which is not legal / may change semantics. That `invokespecial` is supposed to disappear when inlining the actual default method body. However, this last step may fail, for example because the trait method body itself contains instructions that are not legal in a different classfile. It is very difficult to perform all necessary checks ahead of time. So instead, this commit implements the ability to speculatively inline a callsite and roll back if necessary. The commit also cleans up the implementation of inliner warnings a little. The previous code would always emit a warning when a method annotated `@inline` was not picked by the heuristics - this was a problem when the callsite in the static super accessor was no longer chosen.
Diffstat (limited to 'src/library')
-rw-r--r--src/library/scala/inline.scala2
-rw-r--r--src/library/scala/noinline.scala2
2 files changed, 2 insertions, 2 deletions
diff --git a/src/library/scala/inline.scala b/src/library/scala/inline.scala
index f6d7c7569e..f188ccab07 100644
--- a/src/library/scala/inline.scala
+++ b/src/library/scala/inline.scala
@@ -23,7 +23,7 @@ package scala
* 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 t5 = f2(1): @inline // inlined if possible (override at callsite)
* def t6 = f3(1): @inline // inlined if possible
* def t7 = f3(1): @noinline // not inlined
* }
diff --git a/src/library/scala/noinline.scala b/src/library/scala/noinline.scala
index 0cd5ef9f64..6c21ed667d 100644
--- a/src/library/scala/noinline.scala
+++ b/src/library/scala/noinline.scala
@@ -23,7 +23,7 @@ package scala
* 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 t5 = f2(1): @inline // inlined if possible (override at callsite)
* def t6 = f3(1): @inline // inlined if possible
* def t7 = f3(1): @noinline // not inlined
* }