Open
Description
When the argument containing the inline function is a struct type, we should convert access to its members to direct access when inline.
For this code
import scala.reflect.Selectable.reflectiveSelectable
class C {
def f: Int = 100
}
object C {
inline def f(a: {def f: Int}): Int = a.f
def main(args: Array[String]): Unit = {
val i = f(new C)
}
}
We have now generated the following code:
public void main(java.lang.String[]);
Code:
0: new #45 // class C
3: dup
4: invokespecial #46 // Method C."<init>":()V
7: astore_3
8: getstatic #23 // Field scala/reflect/Selectable$.MODULE$:Lscala/reflect/Selectable$;
11: aload_3
12: invokevirtual #27 // Method scala/reflect/Selectable$.reflectiveSelectable:(Ljava/lang/Object;)Lscala/Selectable;
15: ldc #28 // String f
17: invokeinterface #34, 2 // InterfaceMethod scala/Selectable.selectDynamic:(Ljava/lang/String;)Ljava/lang/Object;
22: checkcast #4 // class java/lang/Object
25: invokestatic #39 // Method scala/runtime/BoxesRunTime.unboxToInt:(Ljava/lang/Object;)I
28: istore_2
29: return
Here we introduce too much extra overhead, and this should be avoided by compiler optimization.