Inline functions generate bodies


#1

In the following, even though `bar` is inlined at the call site, the full `bar` function appears in the bytecode:

 
package com.example.test

fun foo() {
  bar()
}

private inline fun bar() {
  println(“one”)
  println(“two”)
}

Output:

Compiled from "Test.kt" public final class com.example.test.TestKt {   public static final void foo();   Code:   0: nop              1: ldc           #8                  // String one   3: invokestatic  #14           // Method kotlin/io/ConsoleKt.println:(Ljava/lang/Object;)V   6: ldc           #16           // String two   8: invokestatic  #14           // Method kotlin/io/ConsoleKt.println:(Ljava/lang/Object;)V   11: return   

  private static final void bar();
  Code:
  0: ldc           #8                  // String one
  2: invokestatic  #14           // Method kotlin/io/ConsoleKt.println:(Ljava/lang/Object;)V
  5: ldc           #16           // String two
  7: invokestatic  #14           // Method kotlin/io/ConsoleKt.println:(Ljava/lang/Object;)V
  10: return   
}


Is this intended?  If so, is there a way to prevent the function from being generated?


#2

Yes, it is intened. No, skipping generating such functions is not supported (one wouldn't be able to compile against such a binary), but you can remove them with proguard, for example.