Uploaded image for project: 'Scala Programming Language'
  1. Scala Programming Language
  2. SI-9378

new inliner does not inline methods that allocate an indylambda closure

    Details

    • Type: Bug
    • Status: CLOSED
    • Priority: Blocker
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: Scala 2.12.0-M2
    • Component/s: None
    • Labels:
      None

      Description

      The GenBCode inliner doesn't inline methods that have an invokedynamic instruction, see here and here.

      class A {
        @inline final def assert(c: Boolean, m: => String): Unit = {
          if (!c) println(m)
        }
       
        @inline final def assert(c: Boolean): Unit = assert(c, "")
       
        def test(b: Boolean): Unit = {
          assert(b)
        }
      }
      

      ➜  sandbox git:(yoptInScala) ✗ qsc -Yopt:l:classpath -Yopt-warnings:_ Test.scala 
      Test.scala:9: warning: A::assert(Z)V is annotated @inline but could not be inlined:
      The callee A::assert(Z)V contains the instruction INVOKEDYNAMIC apply()Lscala/runtime/java8/JFunction0; [
            // handle kind 0x6 : INVOKESTATIC
            java/lang/invoke/LambdaMetafactory.altMetafactory(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;[Ljava/lang/Object;)Ljava/lang/invoke/CallSite;
            // arguments:
            ()Ljava/lang/Object;,
            // handle kind 0x6 : INVOKESTATIC
            A.A$$$anonfun$1()Ljava/lang/String;,
            ()Ljava/lang/String;,
            3,
            1,
            Lscala/Serializable;.class,
            0
          ]
      that would cause an IllegalAccessError when inlined into class A.
          assert(b)
                ^
      one warning found
      

      When enabling the new optimizer in scala/scala (https://github.com/scala/scala/pull/4602), we needed to add a filter to some partest tests to make them ignore the new inliner warning:

      • presentation/t7678
      • run/t8029.scala

        Attachments

          Activity

          Show
          rytz Lukas Rytz added a comment - https://github.com/scala/scala/pull/4607

            People

            • Assignee:
              rytz Lukas Rytz
              Reporter:
              rytz Lukas Rytz
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: