JVM_IR: do not remap locals in contexts nested inside lambdas

The only case where this code is reachable at all is objects in lambdas
that use reified type parameters of the outer inline function. Since the
type parameters are declared outside the inlining root, regenerating the
object is actually pointless, and remapping its captures even more so
(not to mention that the code under the condition uses the captures of
the lambda, not of the method it's currently transforming).
This commit is contained in:
pyos
2019-12-23 14:32:13 +01:00
committed by max-kammerer
parent 8e79d9b90e
commit 2f0f4e570f
6 changed files with 40 additions and 1 deletions
@@ -911,7 +911,7 @@ class MethodInliner(
return
}
if (inliningContext.isInliningLambda && inliningContext.lambdaInfo is IrExpressionLambda) {
if (inliningContext.isInliningLambda && inliningContext.lambdaInfo is IrExpressionLambda && !inliningContext.parent!!.isInliningLambda) {
val capturedVars = inliningContext.lambdaInfo.capturedVars
var offset = parameters.realParametersSizeOnStack
val map = capturedVars.map {
@@ -0,0 +1,19 @@
// FILE: 1.kt
package test
inline fun <R> myRun(g: () -> R) = g()
// FILE: 2.kt
import test.*
inline fun <reified A> Any?.complicatedCast() =
myRun { // 1. Inline function call with a lambda
object { // 2. Anonymous object inside a lambda
fun f(x: Any?): A { // 3. Anonymous object uses a reified type parameter
val y = x // 4. A method in that object uses locals
return y as A
}
}.f(this) // 5. The lambda captures more values than the object
}
fun box() = "OK".complicatedCast<String>()
@@ -2880,6 +2880,11 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo
runTest("compiler/testData/codegen/boxInline/reified/kt9637_2.kt");
}
@TestMetadata("nonCapturingObjectInLambda.kt")
public void testNonCapturingObjectInLambda() throws Exception {
runTest("compiler/testData/codegen/boxInline/reified/nonCapturingObjectInLambda.kt");
}
@TestMetadata("packages.kt")
public void testPackages() throws Exception {
runTest("compiler/testData/codegen/boxInline/reified/packages.kt");
@@ -2880,6 +2880,11 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi
runTest("compiler/testData/codegen/boxInline/reified/kt9637_2.kt");
}
@TestMetadata("nonCapturingObjectInLambda.kt")
public void testNonCapturingObjectInLambda() throws Exception {
runTest("compiler/testData/codegen/boxInline/reified/nonCapturingObjectInLambda.kt");
}
@TestMetadata("packages.kt")
public void testPackages() throws Exception {
runTest("compiler/testData/codegen/boxInline/reified/packages.kt");
@@ -2880,6 +2880,11 @@ public class IrBlackBoxInlineCodegenTestGenerated extends AbstractIrBlackBoxInli
runTest("compiler/testData/codegen/boxInline/reified/kt9637_2.kt");
}
@TestMetadata("nonCapturingObjectInLambda.kt")
public void testNonCapturingObjectInLambda() throws Exception {
runTest("compiler/testData/codegen/boxInline/reified/nonCapturingObjectInLambda.kt");
}
@TestMetadata("packages.kt")
public void testPackages() throws Exception {
runTest("compiler/testData/codegen/boxInline/reified/packages.kt");
@@ -2880,6 +2880,11 @@ public class IrCompileKotlinAgainstInlineKotlinTestGenerated extends AbstractIrC
runTest("compiler/testData/codegen/boxInline/reified/kt9637_2.kt");
}
@TestMetadata("nonCapturingObjectInLambda.kt")
public void testNonCapturingObjectInLambda() throws Exception {
runTest("compiler/testData/codegen/boxInline/reified/nonCapturingObjectInLambda.kt");
}
@TestMetadata("packages.kt")
public void testPackages() throws Exception {
runTest("compiler/testData/codegen/boxInline/reified/packages.kt");