Skip to content

No warning if inline is not inlinable let alone actually inlined #22509

Open
@som-snytt

Description

@som-snytt

Compiler version

3.7

Minimized code

import collection.AbstractIterator

val it = new AbstractIterator[Byte]:
  override inline def hasNext: Boolean = false
  override inline def next(): Byte = Iterator.empty.next()

class FastIterator extends AbstractIterator[Byte]:
  override inline def hasNext: Boolean = false
  override inline def next(): Byte = Iterator.empty.next()
val ok = FastIterator()

@main def test() = println:
  val tester = it
  if tester.hasNext then
    tester.next()
  else
    "nothing"

Output

There is no inlining, but also no messaging that tells me my plea to inline went unheard.

         4: invokevirtual #51                 // Method it:()Lscala/collection/AbstractIterator;
         7: astore_1
         8: aload_1
         9: invokevirtual #57                 // Method scala/collection/AbstractIterator.hasNext:()Z

For the case of successful inlining, there is a nice constant but no branch elimination. Edit: that's because hasNext is Boolean not false. Another quirk is that omitting the type means inferring it from the overridden member; it might make more sense to infer the type of an inline method from its RHS, as in days of yore.

    @main def test(): Unit =
      println(
        {
          val tester: FastIterator = ok()
          if false:Boolean then
            Byte.box(Byte.unbox(Iterator().empty().next()):Byte) else "nothing"
        }
      )

Expectation

A peep that my inline method could never be inlined.

Noticed at #22507

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions