Support bound callable reference inlining in IR

This commit is contained in:
Mikhael Bogdanov
2019-05-28 15:44:51 +02:00
parent 3c093f321d
commit 81e6416bfe
28 changed files with 461 additions and 180 deletions
@@ -0,0 +1,22 @@
// IGNORE_BACKEND: JVM
// FILE: 1.kt
package test
class X {
val result: String
inline get() = "OK"
fun x(): String {
return go(::result)
}
}
inline fun go(f: () -> String): String = f()
// FILE: 2.kt
import test.*
fun box(): String {
return X().x()
}
@@ -0,0 +1,21 @@
// FILE: 1.kt
package test
class X {
val result: String
get() = "OK"
fun x(): String {
return go(::result)
}
}
inline fun go(f: () -> String): String = f()
// FILE: 2.kt
import test.*
fun box(): String {
return X().x()
}
@@ -0,0 +1,18 @@
// FILE: 1.kt
package test
class Foo<T> {
inner class Inner<P>(val a: T, val b: P)
}
inline fun <A, B> foo(a: A, b: B, x: (A, B) -> Foo<A>.Inner<B>): Foo<A>.Inner<B> = x(a, b)
// FILE: 2.kt
import test.*
fun box(): String {
val z = Foo<String>()
val foo = foo("O", "K", z::Inner)
return foo.a + foo.b
}
@@ -0,0 +1,19 @@
// TARGET_BACKEND: JVM
// WITH_RUNTIME
// FILE: 1.kt
package test
class Foo(@JvmField val a: String)
inline fun test(s: () -> String): String {
return s()
}
// FILE: 2.kt
import test.*
fun box(): String {
return test(Foo("OK")::a)
}
@@ -0,0 +1,31 @@
// IGNORE_BACKEND: JS_IR
// FILE: 1.kt
package test
class Foo(val a: String) {
fun test() = a
}
inline fun test(a: String, b: () -> String, c: () -> String, d: String): String {
return a + b() + c() + d
}
// FILE: 2.kt
import test.*
var effects = ""
fun create(a: String): Foo {
effects += a
return Foo(a)
}
fun box(): String {
val result = test(create("A").a, create("B")::a, create("C")::test, create("D").a)
if (result != effects) return "fail 1: $effects != $result"
return if (result == "ABCD") "OK" else "fail 2: $result"
}
@@ -1,8 +1,6 @@
// FILE: 1.kt
package test
inline fun foo(x: () -> String, z: String) = x() + z
inline fun foo(x: () -> String) = x()
fun String.id() = this
@@ -10,8 +8,4 @@ fun String.id() = this
import test.*
fun box() : String {
var zeroSlot = "fail";
val z = "O"
return foo(z::id, "K")
}
fun box() = foo("OK"::id)
@@ -0,0 +1,16 @@
// FILE: 1.kt
package test
inline fun go(f: () -> String) = f()
fun String.id(): String = this
// FILE: 2.kt
import test.*
fun box(): String {
val x = "OK"
return go(x::id)
}
@@ -0,0 +1,17 @@
// FILE: 1.kt
package test
inline fun foo(x: () -> String, z: String) = x() + z
fun String.id() = this
// FILE: 2.kt
import test.*
fun box() : String {
var zeroSlot = "fail";
val z = "O"
return foo(z::id, "K")
}
@@ -0,0 +1,19 @@
// !LANGUAGE: +NewInference
// FILE: 1.kt
package test
class Foo<T> {
inner class Inner<P>(val a: T, val b: P)
}
inline fun <A, B> foo(a: A, b: B, foo: Foo<A>, x: (Foo<A>, A, B) -> Foo<A>.Inner<B>): Foo<A>.Inner<B> = x(foo, a, b)
// FILE: 2.kt
import test.*
fun box(): String {
val foo = foo<String, String>("O", "K", Foo<String>(), Foo<String>::Inner)
return foo.a + foo.b
}
@@ -0,0 +1,19 @@
// TARGET_BACKEND: JVM
// WITH_RUNTIME
// FILE: 1.kt
package test
class Foo(@JvmField val a: String)
inline fun test(s: (Foo) -> String): String {
return s(Foo("OK"))
}
// FILE: 2.kt
import test.*
fun box(): String {
return test(Foo::a)
}