JVM IR: Avoid direct lambda invokes in inline tests
This commit is contained in:
committed by
Alexander Udalov
parent
f0760e0550
commit
2acfb3a41f
+1
-1
@@ -4,7 +4,7 @@
|
||||
package test
|
||||
|
||||
inline fun bar(crossinline y: () -> String) = {
|
||||
{ { call(y) }() }()
|
||||
{ { call(y) }.let { it() } }.let { it() }
|
||||
}
|
||||
|
||||
public inline fun <T> call(f: () -> T): T = f()
|
||||
|
||||
+3
-3
@@ -4,10 +4,10 @@
|
||||
package test
|
||||
|
||||
inline fun bar(crossinline y: () -> String) = {
|
||||
{ { call(y) }() }()
|
||||
{ { call(y) }.let { it() } }.let { it() }
|
||||
}
|
||||
|
||||
public inline fun <T> call(crossinline f: () -> T): T = {{ f() }()}()
|
||||
public inline fun <T> call(crossinline f: () -> T): T = {{ f() }.let { it() }}.let { it() }
|
||||
|
||||
// FILE: 2.kt
|
||||
|
||||
@@ -20,5 +20,5 @@ fun box(): String {
|
||||
}
|
||||
|
||||
inline fun bar2(crossinline y: () -> String) = {
|
||||
{ { call(y) }() }()
|
||||
{ { call(y) }.let { it() } }.let { it() }
|
||||
}
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ internal class A {
|
||||
inline fun doSomething(): String {
|
||||
return {
|
||||
"OK"
|
||||
}()
|
||||
}.let { it() }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ internal class A {
|
||||
inline fun doSomething(s: String): String {
|
||||
return {
|
||||
s
|
||||
}()
|
||||
}.let { it() }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,11 +5,13 @@
|
||||
package test
|
||||
|
||||
inline fun inf(crossinline cif: Any.() -> String): () -> String {
|
||||
return {
|
||||
// Approximate the types manually to avoid running into KT-30696
|
||||
val factory: () -> () -> String = {
|
||||
object : () -> String {
|
||||
override fun invoke() = cif()
|
||||
}
|
||||
}()
|
||||
}
|
||||
return factory()
|
||||
}
|
||||
// FILE: 2.kt
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ package test
|
||||
|
||||
inline fun test(cond: Boolean, crossinline cif: () -> String): String {
|
||||
return if (cond) {
|
||||
{ cif() }()
|
||||
{ cif() }.let { it() }
|
||||
}
|
||||
else {
|
||||
cif()
|
||||
@@ -19,6 +19,6 @@ fun box(): String {
|
||||
return test(true) {
|
||||
{
|
||||
s
|
||||
}()
|
||||
}.let { it() }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package test
|
||||
|
||||
inline fun inline1(crossinline action: () -> Unit) {
|
||||
action();
|
||||
{ action() }()
|
||||
{ action() }.let { it() }
|
||||
}
|
||||
|
||||
inline fun inline2(crossinline action: () -> Unit) = { action() }
|
||||
|
||||
@@ -17,7 +17,7 @@ import test.*
|
||||
var result = "fail"
|
||||
fun box(): String {
|
||||
inline1 {
|
||||
inline2 { { result ="OK" }() }()
|
||||
inline2 { { result ="OK" }.let { it() } }()
|
||||
}
|
||||
|
||||
return result
|
||||
|
||||
@@ -26,7 +26,7 @@ class Foo {
|
||||
ifNotBusyPerform {
|
||||
ifNotBusySayHello()
|
||||
}
|
||||
}()
|
||||
}.let { it() }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import test.*
|
||||
class C {
|
||||
val x: String
|
||||
init {
|
||||
val y = myRun { { "OK" }() }
|
||||
val y = myRun { { "OK" }.let { it() } }
|
||||
x = y
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ import test.*
|
||||
class C {
|
||||
val x: String
|
||||
init {
|
||||
val y by myRun { { "OK" }() }
|
||||
val y by myRun { { "OK" }.let { it() } }
|
||||
x = y
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ fun box(): String {
|
||||
{
|
||||
locusMap = value
|
||||
gene = "OK"
|
||||
}()
|
||||
}.let { it() }
|
||||
}
|
||||
}
|
||||
return gene
|
||||
|
||||
@@ -20,7 +20,7 @@ fun box(): String {
|
||||
{
|
||||
value
|
||||
gene = "OK"
|
||||
}()
|
||||
}.let { it() }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@ inline fun testNested(crossinline f: (String) -> Unit) {
|
||||
}
|
||||
|
||||
inline fun test(crossinline f: (String) -> Unit) {
|
||||
testNested { it -> { f(it) }()}
|
||||
testNested { it -> { f(it) }.let { it() } }
|
||||
}
|
||||
|
||||
// FILE: 2.kt
|
||||
|
||||
+3
-3
@@ -20,10 +20,10 @@ fun box(): String {
|
||||
{
|
||||
{
|
||||
result = param + c + a
|
||||
}()
|
||||
}()
|
||||
}.let { it() }
|
||||
}.let { it() }
|
||||
}
|
||||
}()
|
||||
}.let { it() }
|
||||
}
|
||||
|
||||
return if (result == "start12") "OK" else "fail: $result"
|
||||
|
||||
+2
-2
@@ -5,7 +5,7 @@ package test
|
||||
inline fun <T> inlineFun(arg: T, crossinline f: (T) -> Unit) {
|
||||
{
|
||||
f(arg)
|
||||
}()
|
||||
}.let { it() }
|
||||
}
|
||||
|
||||
// FILE: 2.kt
|
||||
@@ -19,7 +19,7 @@ fun box(): String {
|
||||
inlineFun("2") { a ->
|
||||
{
|
||||
result = param + a
|
||||
}()
|
||||
}.let { it() }
|
||||
}
|
||||
|
||||
|
||||
|
||||
+4
-4
@@ -5,7 +5,7 @@ package test
|
||||
inline fun <T> inlineFun(arg: T, crossinline f: (T) -> Unit) {
|
||||
{
|
||||
f(arg)
|
||||
}()
|
||||
}.let { it() }
|
||||
}
|
||||
|
||||
// FILE: 2.kt
|
||||
@@ -21,10 +21,10 @@ fun box(): String {
|
||||
{
|
||||
{
|
||||
result = param + c + a
|
||||
}()
|
||||
}()
|
||||
}.let { it() }
|
||||
}.let { it() }
|
||||
}
|
||||
}()
|
||||
}.let { it() }
|
||||
}
|
||||
|
||||
return if (result == "start12") "OK" else "fail: $result"
|
||||
|
||||
+3
-3
@@ -5,7 +5,7 @@ package test
|
||||
inline fun <T> inlineFun(arg: T, crossinline f: (T) -> Unit) {
|
||||
{
|
||||
f(arg)
|
||||
}()
|
||||
}.let { it() }
|
||||
}
|
||||
|
||||
// FILE: 2.kt
|
||||
@@ -20,9 +20,9 @@ fun box(): String {
|
||||
inlineFun("2") { a ->
|
||||
{
|
||||
result = param + c + a
|
||||
}()
|
||||
}.let { it() }
|
||||
}
|
||||
}()
|
||||
}.let { it() }
|
||||
}
|
||||
|
||||
return if (result == "start12") "OK" else "fail: $result"
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@ inline fun testNested(crossinline f: (String) -> Unit) {
|
||||
}
|
||||
|
||||
fun test(f: (String) -> Unit) {
|
||||
testNested { it -> { f(it) }()}
|
||||
testNested { it -> { f(it) }.let { it() } }
|
||||
}
|
||||
|
||||
// FILE: 2.kt
|
||||
|
||||
Vendored
+1
-1
@@ -17,7 +17,7 @@ class B(val o: String, val k: String) {
|
||||
}
|
||||
|
||||
inline fun test(crossinline f: (String) -> Unit) {
|
||||
testNested { it -> { f(it + k) }() }
|
||||
testNested { it -> { f(it + k) }.let { it() } }
|
||||
}
|
||||
|
||||
|
||||
|
||||
Vendored
+4
-4
@@ -11,7 +11,7 @@ class A {
|
||||
inline fun inlineFun(arg: String, crossinline f: (String) -> Unit) {
|
||||
{
|
||||
f(arg + addParam)
|
||||
}()
|
||||
}.let { it() }
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
@@ -21,12 +21,12 @@ class A {
|
||||
{
|
||||
{
|
||||
result = param + c + a
|
||||
}()
|
||||
}()
|
||||
}.let { it() }
|
||||
}.let { it() }
|
||||
}
|
||||
|
||||
}
|
||||
}()
|
||||
}.let { it() }
|
||||
|
||||
return if (result == "start1_additional_2_additional_") "OK" else "fail: $result"
|
||||
}
|
||||
|
||||
Vendored
+3
-3
@@ -19,10 +19,10 @@ class A {
|
||||
{
|
||||
{
|
||||
result = param + c + a
|
||||
}()
|
||||
}()
|
||||
}.let { it() }
|
||||
}.let { it() }
|
||||
}
|
||||
}()
|
||||
}.let { it() }
|
||||
}
|
||||
|
||||
return if (result == "start1_additional_2_additional_") "OK" else "fail: $result"
|
||||
|
||||
Vendored
+2
-2
@@ -11,7 +11,7 @@ class A {
|
||||
inline fun inlineFun(arg: String, crossinline f: (String) -> Unit) {
|
||||
{
|
||||
f(arg + addParam)
|
||||
}()
|
||||
}.let { it() }
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ class A {
|
||||
inlineFun("2") { a ->
|
||||
{
|
||||
result = param + a
|
||||
}()
|
||||
}.let { it() }
|
||||
}
|
||||
return if (result == "start2_additional_") "OK" else "fail: $result"
|
||||
}
|
||||
|
||||
Vendored
+3
-3
@@ -11,7 +11,7 @@ class A {
|
||||
inline fun inlineFun(arg: String, crossinline f: (String) -> Unit) {
|
||||
{
|
||||
f(arg + addParam)
|
||||
}()
|
||||
}.let { it() }
|
||||
}
|
||||
|
||||
|
||||
@@ -20,9 +20,9 @@ class A {
|
||||
inlineFun("2") { a ->
|
||||
{
|
||||
result = param + a
|
||||
}()
|
||||
}.let { it() }
|
||||
}
|
||||
}()
|
||||
}.let { it() }
|
||||
return if (result == "start2_additional_") "OK" else "fail: $result"
|
||||
}
|
||||
|
||||
|
||||
Vendored
+4
-4
@@ -11,7 +11,7 @@ class A {
|
||||
inline fun inlineFun(arg: String, crossinline f: (String) -> Unit) {
|
||||
{
|
||||
f(arg + addParam)
|
||||
}()
|
||||
}.let { it() }
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
@@ -21,10 +21,10 @@ class A {
|
||||
{
|
||||
{
|
||||
result = param + c + a
|
||||
}()
|
||||
}()
|
||||
}.let { it() }
|
||||
}.let { it() }
|
||||
}
|
||||
}()
|
||||
}.let { it() }
|
||||
}
|
||||
|
||||
return if (result == "start1_additional_2_additional_") "OK" else "fail: $result"
|
||||
|
||||
Vendored
+3
-3
@@ -11,7 +11,7 @@ class A {
|
||||
inline fun inlineFun(arg: String, crossinline f: (String) -> Unit) {
|
||||
{
|
||||
f(arg + addParam)
|
||||
}()
|
||||
}.let { it() }
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
@@ -20,9 +20,9 @@ class A {
|
||||
inlineFun("2") { a ->
|
||||
{
|
||||
result = param + c + a
|
||||
}()
|
||||
}.let { it() }
|
||||
}
|
||||
}()
|
||||
}.let { it() }
|
||||
}
|
||||
|
||||
return if (result == "start1_additional_2_additional_") "OK" else "fail: $result"
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ class B(val o: String, val k: String) {
|
||||
}
|
||||
|
||||
inline fun test(crossinline f: (String) -> Unit) {
|
||||
testNested { it -> { f(it + "K") }() }
|
||||
testNested { it -> { f(it + "K") }.let { it() } }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Vendored
+1
-1
@@ -18,7 +18,7 @@ class B(val o: String, val k: String) {
|
||||
}
|
||||
|
||||
fun test(f: (String) -> Unit) {
|
||||
testNested { it -> { f(it + k) }() }
|
||||
testNested { it -> { f(it + k) }.let { it() } }
|
||||
}
|
||||
|
||||
|
||||
|
||||
+2
-2
@@ -20,8 +20,8 @@ class B(val o: String, val k: String) {
|
||||
inline fun test(crossinline f: (String) -> Unit) {
|
||||
call {
|
||||
{
|
||||
testNested ({ it -> { f(it + o) }() }) { it -> { f(it + k) }() }
|
||||
}()
|
||||
testNested ({ it -> { f(it + o) }.let { it() } }) { it -> { f(it + k) }.let { it() } }
|
||||
}.let { it() }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -21,8 +21,8 @@ class B(val o: String, val k: String) {
|
||||
call {
|
||||
f("start");
|
||||
{
|
||||
testNested ({ it -> { f(it + o) }() }) { it -> { f(it + k) }() }
|
||||
}()
|
||||
testNested ({ it -> { f(it + o) }.let { it() } }) { it -> { f(it + k) }.let { it() } }
|
||||
}.let { it() }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ class W(val value: Any)
|
||||
inline fun W.safe(crossinline body : Any.() -> Unit) {
|
||||
{
|
||||
this.value?.body()
|
||||
}()
|
||||
}.let { it() }
|
||||
}
|
||||
|
||||
// FILE: 2.kt
|
||||
|
||||
@@ -7,7 +7,7 @@ class W(val value: Any)
|
||||
inline fun W.safe(crossinline body : Any.() -> Unit) {
|
||||
{
|
||||
this.value?.body()
|
||||
}()
|
||||
}.let { it() }
|
||||
}
|
||||
|
||||
// FILE: 2.kt
|
||||
@@ -19,7 +19,7 @@ fun box(): String {
|
||||
W("OK").safe {
|
||||
{
|
||||
result = this as String
|
||||
}()
|
||||
}.let { it() }
|
||||
}
|
||||
|
||||
return result
|
||||
|
||||
@@ -6,7 +6,7 @@ package test
|
||||
|
||||
inline fun foo(value: String, crossinline s: () -> String): String {
|
||||
val x = { value }
|
||||
return java.util.concurrent.Callable(x).call() + { s() }()
|
||||
return java.util.concurrent.Callable(x).call() + { s() }.let { it() }
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ package test
|
||||
import java.util.concurrent.Executors
|
||||
|
||||
inline fun doWork(noinline job: ()-> Unit) {
|
||||
{ Executors.callable(job).call() } ()
|
||||
{ Executors.callable(job).call() }.let { it() }
|
||||
Executors.callable(job).call()
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ fun test(): String = ""
|
||||
|
||||
inline fun String.switchMapOnce(crossinline mapper: (String) -> String): String {
|
||||
Callable(::test)
|
||||
return { mapper(this) }()
|
||||
return { mapper(this) }.let { it() }
|
||||
}
|
||||
// FILE: 2.kt
|
||||
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ class A {
|
||||
inline fun test(crossinline l: () -> String): String {
|
||||
return {
|
||||
l() + callK()
|
||||
}()
|
||||
}.let { it() }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ class C(val x: String) {
|
||||
fun f(y: String) = C(y).g { x }
|
||||
|
||||
inline fun g(crossinline h: () -> String) =
|
||||
{ { h() + x }() }()
|
||||
{ { h() + x }.let { it() } }.let { it() }
|
||||
}
|
||||
|
||||
// FILE: 2.kt
|
||||
|
||||
Vendored
+1
-1
@@ -5,7 +5,7 @@ class C(val x: String) {
|
||||
inline fun f(crossinline h: () -> String) = C("").g { x + h() }
|
||||
|
||||
inline fun g(crossinline h: () -> String) =
|
||||
{ { h() + x }() }()
|
||||
{ { h() + x }.let { it() } }.let { it() }
|
||||
}
|
||||
|
||||
// FILE: 2.kt
|
||||
|
||||
Reference in New Issue
Block a user