JVM_IR KT-45103 optimize direct invoke for lambdas and callable refs

This commit is contained in:
Dmitry Petrov
2021-04-26 17:17:25 +03:00
committed by teamcityserver
parent bfb1a06f3d
commit 851980e36f
124 changed files with 1340 additions and 324 deletions
@@ -1,12 +1,14 @@
// FILE: C.kt
package test
fun <T> eval(f: () -> T) = f()
class C: A.B() {
// For binary compatibility, two accessibility bridges should be generated in C:
// one for A.x and one for A.B.x.
// Otherwise, if a static 'x' field is added to A.B either A.x or A.B.x will be ignored.
// The JVM backend generates accessibility bridges for setters as well which is not necessary.
fun f() = ({ A.x + x })()
fun f() = eval { A.x + x }
// Similarly for static functions. Two bridges should be generated for binary compatibility.
fun g() = ({ A.h() + h() })
}
@@ -37,3 +37,9 @@ public final class test/C {
public final @org.jetbrains.annotations.NotNull method f(): java.lang.String
public final @org.jetbrains.annotations.NotNull method g(): kotlin.jvm.functions.Function0
}
@kotlin.Metadata
public final class test/CKt {
// source: 'C.kt'
public final static method eval(@org.jetbrains.annotations.NotNull p0: kotlin.jvm.functions.Function0): java.lang.Object
}
@@ -35,3 +35,9 @@ public final class test/C {
public final @org.jetbrains.annotations.NotNull method f(): java.lang.String
public final @org.jetbrains.annotations.NotNull method g(): kotlin.jvm.functions.Function0
}
@kotlin.Metadata
public final class test/CKt {
// source: 'C.kt'
public final static method eval(@org.jetbrains.annotations.NotNull p0: kotlin.jvm.functions.Function0): java.lang.Object
}
@@ -10,17 +10,19 @@ inline fun test(s: () -> Unit) {
import test.*
fun <T> eval(f: () -> T) = f()
fun box() {
var s1 = ""
var s2 = ""
test {
{
eval {
val p = object {}
s1 = p.toString();
{
eval {
val q = object {}
s2 = q.toString()
}()
}()
}
}
}
}
@@ -48,6 +48,7 @@ final class _2Kt$box$$inlined$test$lambda$1 {
public final class _2Kt {
// source: '2.kt'
public final static method box(): void
public final static method eval(@org.jetbrains.annotations.NotNull p0: kotlin.jvm.functions.Function0): java.lang.Object
}
@kotlin.Metadata
@@ -49,6 +49,7 @@ public final class _2Kt {
// source: '2.kt'
inner (anonymous) class _2Kt$box$1$1
public final static method box(): void
public final static method eval(@org.jetbrains.annotations.NotNull p0: kotlin.jvm.functions.Function0): java.lang.Object
}
@kotlin.Metadata