Proper resort variables on inlining lowered ir closures
Original problem is that lowered ir closures doesn't meet inliner expectations
about captured variable position in inlining method.
E.g.: Call 'foo(valueParam) { capturedParam }' to
inline function 'foo' with declaration
inline fun foo(valueParam: Foo, inlineParamWithCaptured: Bar.() ->) ....
is reorganized through inlining to equivalent call foo(valueParam, capturedParam1, cp2 ...).
But lowered closure for lambda parameter has totally different parameters order:
fun loweredLambda$x(extensionReceiver, captured1, cp2..., valueParam1, vp2...)
So before inlining lowered closure should be transformed to
fun loweredLambda$x(extensionReceiver, valueParam1, vp2..., captured1, cp2..)
#KT-28547 Fixed
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun box(): String {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
// TARGET_BACKEND: JVM
|
||||
|
||||
// WITH_RUNTIME
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
// TARGET_BACKEND: JVM
|
||||
|
||||
// WITH_RUNTIME
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
public inline fun <T> T.with(f: T.() -> Unit): T {
|
||||
this.f()
|
||||
return this
|
||||
|
||||
Vendored
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
// WITH_RUNTIME
|
||||
|
||||
class Foo {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_RUNTIME
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
// FILE: 1.kt
|
||||
|
||||
package test
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
// NO_CHECK_LAMBDA_INLINING
|
||||
// FILE: 1.kt
|
||||
package test
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
// FILE: 1.kt
|
||||
package test
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
// FILE: 1.kt
|
||||
|
||||
inline fun <T> run(c: () -> T): T = c()
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
// FILE: 1.kt
|
||||
// WITH_RUNTIME
|
||||
package test
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
// FILE: 1.kt
|
||||
package test
|
||||
|
||||
class C {
|
||||
var inserting: Boolean = false
|
||||
fun nextSlot(): Any? = null
|
||||
fun startNode(key: Any?) {}
|
||||
fun endNode() {}
|
||||
fun emitNode(node: Any?) {}
|
||||
fun useNode(): Any? = null
|
||||
fun skipValue() {}
|
||||
fun updateValue(value: Any?) {}
|
||||
}
|
||||
|
||||
class B<T>(val composer: C, val node: T) {
|
||||
inline fun <V> bar(value: V, block: T.(V) -> Unit) = with(composer) {
|
||||
if (inserting || nextSlot() != value) {
|
||||
updateValue(value)
|
||||
node.block(value)
|
||||
} else skipValue()
|
||||
}
|
||||
}
|
||||
|
||||
class A(val composer: C) {
|
||||
inline fun <T> foo(key: Any, ctor: () -> T, update: B<T>.() -> Unit) = with(composer) {
|
||||
startNode(key)
|
||||
val node = if (inserting)
|
||||
ctor().also { emitNode(it) }
|
||||
else useNode() as T
|
||||
B<T>(this, node).update()
|
||||
endNode()
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: 2.kt
|
||||
import test.*
|
||||
|
||||
fun box(): String {
|
||||
val a = A(C())
|
||||
val str = "OK"
|
||||
var result = "fail"
|
||||
a.foo<String>(
|
||||
123,
|
||||
{ "abc" },
|
||||
{
|
||||
bar(str) { }
|
||||
result = "OK"
|
||||
}
|
||||
)
|
||||
|
||||
return result
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
// FILE: 1.kt
|
||||
|
||||
package test
|
||||
|
||||
inline fun Double.run(body : Double.() -> String): String {
|
||||
return this.body()
|
||||
}
|
||||
|
||||
// FILE: 2.kt
|
||||
|
||||
import test.*
|
||||
|
||||
fun box(): String {
|
||||
var captured = "fail"
|
||||
return 1.0.run {
|
||||
if (this == 1.0) {
|
||||
"OK"
|
||||
} else captured
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
// FILE: 1.kt
|
||||
|
||||
package test
|
||||
|
||||
Reference in New Issue
Block a user