Skip to content

Scala 2.13 inline optimizer unable to correctly look up .head method in scala.collection.LinearSeq #12787

@mdedetrich

Description

@mdedetrich

Reproduction steps

The current Scala 2.12/2.13 optimizer appears to be unable to correctly look up the .head method from the Scala scala.collection.LinearSeq when you happen to use @inline on a method that ends up transitively calling .head. The context of this is the current PR at apache/pekko#305. If you checkout the branch and run sbt ++2.13.10 actor/compile you will get the following error messages

[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(_, _, _) }
[error]                                                  ^
[error] /Users/mdedetrich/github/incubator-pekko/actor/src/main/scala-2.13/org/apache/pekko/util/ByteIterator.scala:385:63: 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, 8) { getDouble(byteOrder) } { current.getDoubles(_, _, _)(byteOrder) }
...

The current method is defined as

@inline private def current: ByteArrayIterator = iterators.head

More context can be found at https://contributors.scala-lang.org/t/scala-2-12-2-13-inliner-is-too-aggressive/6191. Will also try to create a minimised example

Problem

It appears that specifically for Scala 2.13, the optimizer has issues in inlining methods that happen to call .head from scala.collection.LinearSeq in the call chain. I suspect that this may be a result of the new collections included in Scala 2.13.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions