In Pekko I am currently exploring in enabling the Scala 2.12/Scala 2.13 inliner, see Enable inliner for Scala 2 by mdedetrich · Pull Request #305 · apache/incubator-pekko · GitHub.
The problem I am hitting is that the inliner appears to be too aggressive, or put differently is if a method is annotated with @inline
, rather than shortcircuting when it can it appears to be to continue to aggressively inline until it errors out.
For example with this method incubator-pekko/ByteIterator.scala at e6311a207672773c4b0a65a1711267e86777583e · apache/incubator-pekko · GitHub , i.e.
@inline private def current: ByteArrayIterator = iterators.head
The inline optimizer then complains with
[error] /Users/mdedetrich/github/incubator-pekko/actor/src/main/scala-2.13/org/apache/pekko/util/ByteIterator.scala:370:50: org/apache/pekko/util/ByteIterator$MultiByteArrayIterator::org$apache$pekko$util$ByteIterator$MultiByteArrayIterator$$current()Lorg/apache/pekko/util/ByteIterator$ByteArrayIterator; is annotated @inline but could not be inlined:
[error] Failed to check if org/apache/pekko/util/ByteIterator$MultiByteArrayIterator::org$apache$pekko$util$ByteIterator$MultiByteArrayIterator$$current()Lorg/apache/pekko/util/ByteIterator$ByteArrayIterator; can be safely inlined to org/apache/pekko/util/ByteIterator$MultiByteArrayIterator without causing an IllegalAccessError. Checking instruction INVOKEINTERFACE scala/collection/LinearSeq.head ()Ljava/lang/Object; (itf) failed:
[error] The method head()Ljava/lang/Object; could not be found in the class scala/collection/LinearSeq or any of its parents.
[error] getToArray(xs, offset, n, 1) { getByte } { current.getBytes(_, _, _) }
so what appears to be occurring here is its inlining the current
to iterators.head
but then the inliner continues on further and is now trying to inline the head
call itself which is whats causing it to go into the standard scala collections?
In case its not clear, the intention is for current
to be inlined to iterators.head
but not any further. I also tried to use "-opt-inline-from:org.apache.pekko.**,!scala.collection.**"
in an attempt to get the Scala inliner to ignore anything from scala.collection
package but it doesn’t seem to work as intended.