JVM_IR: box bound receiver before calling the reference constructor

This is needed for the inliner: since the information about Kotlin type
of the bound receiver is nowhere in the output binary, the inliner will
have no clue how to box inline class values. Moving the boxing outside
the object means the inliner doesn't need to know about it; from its
point of view, the captured value has type `Any`.
This commit is contained in:
pyos
2021-06-07 13:17:42 +02:00
committed by TeamCityServer
parent 117c99aee6
commit ade8b0a7d3
17 changed files with 228 additions and 9 deletions
@@ -1876,6 +1876,24 @@ public class FirBlackBoxInlineCodegenTestGenerated extends AbstractFirBlackBoxIn
runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/boundFunctionReferenceOnLong.kt");
}
@Test
@TestMetadata("boundInlineClassMethod.kt")
public void testBoundInlineClassMethod() throws Exception {
runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/boundInlineClassMethod.kt");
}
@Test
@TestMetadata("boundInlineClassMethodWithAny.kt")
public void testBoundInlineClassMethodWithAny() throws Exception {
runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/boundInlineClassMethodWithAny.kt");
}
@Test
@TestMetadata("boundInlineClassMethodWithInt.kt")
public void testBoundInlineClassMethodWithInt() throws Exception {
runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/boundInlineClassMethodWithInt.kt");
}
@Test
@TestMetadata("boundPropertyReference.kt")
public void testBoundPropertyReference() throws Exception {
@@ -582,11 +582,8 @@ internal class FunctionReferenceLowering(private val context: JvmBackendContext)
returnType = functionReferenceClass.defaultType
isPrimary = true
}.apply {
// Add receiver parameter for bound function references
if (samSuperType == null) {
boundReceiver?.let { (param, arg) ->
valueParameters += param.copyTo(irFunction = this, index = 0, type = arg.type)
}
if (samSuperType == null && boundReceiver != null) {
addValueParameter("receiver", context.irBuiltIns.anyNType)
}
// Super constructor:
@@ -0,0 +1,16 @@
// SKIP_INLINE_CHECK_IN: inlineFun$default
// IGNORE_BACKEND: JVM
// IGNORE_BACKEND_MULTI_MODULE: JVM, JVM_MULTI_MODULE_IR_AGAINST_OLD
// FILE: 1.kt
package test
inline class C(val x: String) {
fun f() = x.toString()
}
inline fun inlineFun(lambda: () -> String = C("OK")::f): String = lambda()
// FILE: 2.kt
import test.*
fun box(): String = inlineFun()
@@ -0,0 +1,16 @@
// SKIP_INLINE_CHECK_IN: inlineFun$default
// IGNORE_BACKEND: JVM
// IGNORE_BACKEND_MULTI_MODULE: JVM, JVM_MULTI_MODULE_IR_AGAINST_OLD
// FILE: 1.kt
package test
inline class C(val x: Any?) {
fun f() = x.toString()
}
inline fun inlineFun(lambda: () -> String = C("OK")::f): String = lambda()
// FILE: 2.kt
import test.*
fun box(): String = inlineFun()
@@ -0,0 +1,19 @@
// SKIP_INLINE_CHECK_IN: inlineFun$default
// IGNORE_BACKEND: JVM
// IGNORE_BACKEND_MULTI_MODULE: JVM, JVM_MULTI_MODULE_IR_AGAINST_OLD
// FILE: 1.kt
package test
inline class C(val x: Int) {
fun f() = x.toString()
}
inline fun inlineFun(lambda: () -> String = C(1)::f): String = lambda()
// FILE: 2.kt
import test.*
fun box(): String {
val result = inlineFun()
return if (result == "1") "OK" else result
}
@@ -3,7 +3,7 @@ synthetic final class A$testDefaultArguments$1 {
// source: 'adaptedReference.kt'
enclosing method A.testDefaultArguments()V
inner (anonymous) class A$testDefaultArguments$1
method <init>(p0: A): void
method <init>(p0: java.lang.Object): void
public synthetic final static method access$getReceiver$p(p0: A$testDefaultArguments$1): java.lang.Object
public synthetic bridge method invoke(): java.lang.Object
public final @org.jetbrains.annotations.NotNull method invoke(): java.lang.String
@@ -14,7 +14,7 @@ synthetic final class A$testDefaultArguments$2 {
// source: 'adaptedReference.kt'
enclosing method A.testDefaultArguments()V
inner (anonymous) class A$testDefaultArguments$2
method <init>(p0: A): void
method <init>(p0: java.lang.Object): void
public synthetic final static method access$getReceiver$p(p0: A$testDefaultArguments$2): java.lang.Object
public final @org.jetbrains.annotations.Nullable method invoke(@org.jetbrains.annotations.NotNull p0: kotlin.coroutines.Continuation): java.lang.Object
public synthetic bridge method invoke(p0: java.lang.Object): java.lang.Object
@@ -3,7 +3,7 @@ synthetic final class SuspendConversionKt$test$1 {
// source: 'suspendConversion.kt'
enclosing method SuspendConversionKt.test(Lkotlin/jvm/functions/Function0;)V
inner (anonymous) class SuspendConversionKt$test$1
method <init>(p0: kotlin.jvm.functions.Function0): void
method <init>(p0: java.lang.Object): void
public final @org.jetbrains.annotations.Nullable method invoke(@org.jetbrains.annotations.NotNull p0: kotlin.coroutines.Continuation): java.lang.Object
public synthetic bridge method invoke(p0: java.lang.Object): java.lang.Object
}
@@ -44,7 +44,7 @@ synthetic final class NoReceiverInCallableReferenceClassesKt$aFoo$1 {
// source: 'noReceiverInCallableReferenceClasses.kt'
enclosing method NoReceiverInCallableReferenceClassesKt.<clinit>()V
inner (anonymous) class NoReceiverInCallableReferenceClassesKt$aFoo$1
method <init>(p0: A): void
method <init>(p0: java.lang.Object): void
public synthetic bridge method invoke(): java.lang.Object
public final method invoke(): void
}
@@ -1876,6 +1876,24 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo
runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/boundFunctionReferenceOnLong.kt");
}
@Test
@TestMetadata("boundInlineClassMethod.kt")
public void testBoundInlineClassMethod() throws Exception {
runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/boundInlineClassMethod.kt");
}
@Test
@TestMetadata("boundInlineClassMethodWithAny.kt")
public void testBoundInlineClassMethodWithAny() throws Exception {
runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/boundInlineClassMethodWithAny.kt");
}
@Test
@TestMetadata("boundInlineClassMethodWithInt.kt")
public void testBoundInlineClassMethodWithInt() throws Exception {
runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/boundInlineClassMethodWithInt.kt");
}
@Test
@TestMetadata("boundPropertyReference.kt")
public void testBoundPropertyReference() throws Exception {
@@ -1876,6 +1876,24 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi
runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/boundFunctionReferenceOnLong.kt");
}
@Test
@TestMetadata("boundInlineClassMethod.kt")
public void testBoundInlineClassMethod() throws Exception {
runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/boundInlineClassMethod.kt");
}
@Test
@TestMetadata("boundInlineClassMethodWithAny.kt")
public void testBoundInlineClassMethodWithAny() throws Exception {
runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/boundInlineClassMethodWithAny.kt");
}
@Test
@TestMetadata("boundInlineClassMethodWithInt.kt")
public void testBoundInlineClassMethodWithInt() throws Exception {
runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/boundInlineClassMethodWithInt.kt");
}
@Test
@TestMetadata("boundPropertyReference.kt")
public void testBoundPropertyReference() throws Exception {
@@ -1876,6 +1876,24 @@ public class IrBlackBoxInlineCodegenTestGenerated extends AbstractIrBlackBoxInli
runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/boundFunctionReferenceOnLong.kt");
}
@Test
@TestMetadata("boundInlineClassMethod.kt")
public void testBoundInlineClassMethod() throws Exception {
runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/boundInlineClassMethod.kt");
}
@Test
@TestMetadata("boundInlineClassMethodWithAny.kt")
public void testBoundInlineClassMethodWithAny() throws Exception {
runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/boundInlineClassMethodWithAny.kt");
}
@Test
@TestMetadata("boundInlineClassMethodWithInt.kt")
public void testBoundInlineClassMethodWithInt() throws Exception {
runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/boundInlineClassMethodWithInt.kt");
}
@Test
@TestMetadata("boundPropertyReference.kt")
public void testBoundPropertyReference() throws Exception {
@@ -1876,6 +1876,24 @@ public class IrCompileKotlinAgainstInlineKotlinTestGenerated extends AbstractIrC
runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/boundFunctionReferenceOnLong.kt");
}
@Test
@TestMetadata("boundInlineClassMethod.kt")
public void testBoundInlineClassMethod() throws Exception {
runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/boundInlineClassMethod.kt");
}
@Test
@TestMetadata("boundInlineClassMethodWithAny.kt")
public void testBoundInlineClassMethodWithAny() throws Exception {
runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/boundInlineClassMethodWithAny.kt");
}
@Test
@TestMetadata("boundInlineClassMethodWithInt.kt")
public void testBoundInlineClassMethodWithInt() throws Exception {
runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/boundInlineClassMethodWithInt.kt");
}
@Test
@TestMetadata("boundPropertyReference.kt")
public void testBoundPropertyReference() throws Exception {
@@ -1876,6 +1876,24 @@ public class JvmIrAgainstOldBoxInlineTestGenerated extends AbstractJvmIrAgainstO
runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/boundFunctionReferenceOnLong.kt");
}
@Test
@TestMetadata("boundInlineClassMethod.kt")
public void testBoundInlineClassMethod() throws Exception {
runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/boundInlineClassMethod.kt");
}
@Test
@TestMetadata("boundInlineClassMethodWithAny.kt")
public void testBoundInlineClassMethodWithAny() throws Exception {
runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/boundInlineClassMethodWithAny.kt");
}
@Test
@TestMetadata("boundInlineClassMethodWithInt.kt")
public void testBoundInlineClassMethodWithInt() throws Exception {
runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/boundInlineClassMethodWithInt.kt");
}
@Test
@TestMetadata("boundPropertyReference.kt")
public void testBoundPropertyReference() throws Exception {
@@ -1876,6 +1876,24 @@ public class JvmOldAgainstIrBoxInlineTestGenerated extends AbstractJvmOldAgainst
runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/boundFunctionReferenceOnLong.kt");
}
@Test
@TestMetadata("boundInlineClassMethod.kt")
public void testBoundInlineClassMethod() throws Exception {
runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/boundInlineClassMethod.kt");
}
@Test
@TestMetadata("boundInlineClassMethodWithAny.kt")
public void testBoundInlineClassMethodWithAny() throws Exception {
runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/boundInlineClassMethodWithAny.kt");
}
@Test
@TestMetadata("boundInlineClassMethodWithInt.kt")
public void testBoundInlineClassMethodWithInt() throws Exception {
runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/boundInlineClassMethodWithInt.kt");
}
@Test
@TestMetadata("boundPropertyReference.kt")
public void testBoundPropertyReference() throws Exception {
@@ -1490,6 +1490,21 @@ public class IrJsCodegenInlineES6TestGenerated extends AbstractIrJsCodegenInline
runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/boundFunctionReferenceOnLong.kt");
}
@TestMetadata("boundInlineClassMethod.kt")
public void testBoundInlineClassMethod() throws Exception {
runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/boundInlineClassMethod.kt");
}
@TestMetadata("boundInlineClassMethodWithAny.kt")
public void testBoundInlineClassMethodWithAny() throws Exception {
runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/boundInlineClassMethodWithAny.kt");
}
@TestMetadata("boundInlineClassMethodWithInt.kt")
public void testBoundInlineClassMethodWithInt() throws Exception {
runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/boundInlineClassMethodWithInt.kt");
}
@TestMetadata("boundPropertyReference.kt")
public void testBoundPropertyReference() throws Exception {
runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/boundPropertyReference.kt");
@@ -1490,6 +1490,21 @@ public class IrJsCodegenInlineTestGenerated extends AbstractIrJsCodegenInlineTes
runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/boundFunctionReferenceOnLong.kt");
}
@TestMetadata("boundInlineClassMethod.kt")
public void testBoundInlineClassMethod() throws Exception {
runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/boundInlineClassMethod.kt");
}
@TestMetadata("boundInlineClassMethodWithAny.kt")
public void testBoundInlineClassMethodWithAny() throws Exception {
runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/boundInlineClassMethodWithAny.kt");
}
@TestMetadata("boundInlineClassMethodWithInt.kt")
public void testBoundInlineClassMethodWithInt() throws Exception {
runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/boundInlineClassMethodWithInt.kt");
}
@TestMetadata("boundPropertyReference.kt")
public void testBoundPropertyReference() throws Exception {
runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/boundPropertyReference.kt");
@@ -1490,6 +1490,21 @@ public class JsCodegenInlineTestGenerated extends AbstractJsCodegenInlineTest {
runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/boundFunctionReferenceOnLong.kt");
}
@TestMetadata("boundInlineClassMethod.kt")
public void testBoundInlineClassMethod() throws Exception {
runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/boundInlineClassMethod.kt");
}
@TestMetadata("boundInlineClassMethodWithAny.kt")
public void testBoundInlineClassMethodWithAny() throws Exception {
runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/boundInlineClassMethodWithAny.kt");
}
@TestMetadata("boundInlineClassMethodWithInt.kt")
public void testBoundInlineClassMethodWithInt() throws Exception {
runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/boundInlineClassMethodWithInt.kt");
}
@TestMetadata("boundPropertyReference.kt")
public void testBoundPropertyReference() throws Exception {
runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/boundPropertyReference.kt");