Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
som-snytt opened this issue Feb 4, 2025 · 0 comments
Open

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

som-snytt opened this issue Feb 4, 2025 · 0 comments

Comments

@som-snytt
Copy link
Contributor

som-snytt commented Feb 4, 2025

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

@som-snytt som-snytt added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Feb 4, 2025
@Gedochao Gedochao added area:inline and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Feb 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants