JVM_IR. Support inlining of bound CR

This commit is contained in:
Mikhael Bogdanov
2019-11-20 10:56:53 +01:00
parent 42deb7db48
commit 4b6202c902
9 changed files with 54 additions and 4 deletions
@@ -438,7 +438,10 @@ class MethodInliner(
private fun getNewIndex(`var`: Int): Int {
val lambdaInfo = inliningContext.lambdaInfo
if (reorderIrLambdaParameters && lambdaInfo is IrExpressionLambda) {
val extensionSize = if (lambdaInfo.isExtensionLambda) lambdaInfo.invokeMethod.argumentTypes[0].size else 0
val extensionSize =
if (lambdaInfo.isExtensionLambda && !lambdaInfo.isBoundCallableReference)
lambdaInfo.invokeMethod.argumentTypes[0].size
else 0
return when {
// v-- extensionSize v-- argsSizeOnStack
// |- extension -|- captured -|- real -|- locals -| old descriptor
@@ -217,14 +217,16 @@ class IrExpressionLambdaImpl(
private val loweredMethod = methodSignatureMapper.mapAsmMethod(function.getOrCreateSuspendFunctionViewIfNeeded(context))
val capturedParamsInDesc: List<Type> =
loweredMethod.argumentTypes.drop(if (isExtensionLambda) 1 else 0).take(capturedVars.size)
val capturedParamsInDesc: List<Type> = if (isBoundCallableReference) {
loweredMethod.argumentTypes.take(1)
} else loweredMethod.argumentTypes.drop(if (isExtensionLambda) 1 else 0).take(capturedVars.size)
override val invokeMethod: Method = loweredMethod.let {
Method(
it.name,
it.returnType,
((if (isExtensionLambda) it.argumentTypes.take(1) else emptyList()) +
(if (isBoundCallableReference) it.argumentTypes.drop(1)
else (if (isExtensionLambda) it.argumentTypes.take(1) else emptyList()) +
it.argumentTypes.drop((if (isExtensionLambda) 1 else 0) + capturedVars.size)).toTypedArray()
)
}
@@ -0,0 +1,15 @@
// FILE: 1.kt
package test
class Z
class Q {
inline fun f(z: Z) = "OK"
}
// FILE: 2.kt
import test.*
fun box(): String {
return Z().run(Q()::f)
}
@@ -876,6 +876,11 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo
runTest("compiler/testData/codegen/boxInline/callableReference/bound/filter.kt");
}
@TestMetadata("inlineValueParameterInsteadOfReceiver.kt")
public void testInlineValueParameterInsteadOfReceiver() throws Exception {
runTest("compiler/testData/codegen/boxInline/callableReference/bound/inlineValueParameterInsteadOfReceiver.kt");
}
@TestMetadata("innerGenericConstuctor.kt")
public void testInnerGenericConstuctor() throws Exception {
runTest("compiler/testData/codegen/boxInline/callableReference/bound/innerGenericConstuctor.kt");
@@ -876,6 +876,11 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi
runTest("compiler/testData/codegen/boxInline/callableReference/bound/filter.kt");
}
@TestMetadata("inlineValueParameterInsteadOfReceiver.kt")
public void testInlineValueParameterInsteadOfReceiver() throws Exception {
runTest("compiler/testData/codegen/boxInline/callableReference/bound/inlineValueParameterInsteadOfReceiver.kt");
}
@TestMetadata("innerGenericConstuctor.kt")
public void testInnerGenericConstuctor() throws Exception {
runTest("compiler/testData/codegen/boxInline/callableReference/bound/innerGenericConstuctor.kt");
@@ -876,6 +876,11 @@ public class IrBlackBoxInlineCodegenTestGenerated extends AbstractIrBlackBoxInli
runTest("compiler/testData/codegen/boxInline/callableReference/bound/filter.kt");
}
@TestMetadata("inlineValueParameterInsteadOfReceiver.kt")
public void testInlineValueParameterInsteadOfReceiver() throws Exception {
runTest("compiler/testData/codegen/boxInline/callableReference/bound/inlineValueParameterInsteadOfReceiver.kt");
}
@TestMetadata("innerGenericConstuctor.kt")
public void testInnerGenericConstuctor() throws Exception {
runTest("compiler/testData/codegen/boxInline/callableReference/bound/innerGenericConstuctor.kt");
@@ -876,6 +876,11 @@ public class IrCompileKotlinAgainstInlineKotlinTestGenerated extends AbstractIrC
runTest("compiler/testData/codegen/boxInline/callableReference/bound/filter.kt");
}
@TestMetadata("inlineValueParameterInsteadOfReceiver.kt")
public void testInlineValueParameterInsteadOfReceiver() throws Exception {
runTest("compiler/testData/codegen/boxInline/callableReference/bound/inlineValueParameterInsteadOfReceiver.kt");
}
@TestMetadata("innerGenericConstuctor.kt")
public void testInnerGenericConstuctor() throws Exception {
runTest("compiler/testData/codegen/boxInline/callableReference/bound/innerGenericConstuctor.kt");
@@ -146,6 +146,11 @@ public class IrCallableReferenceInlineTestsGenerated extends AbstractIrCallableR
runTest("compiler/testData/codegen/boxInline/callableReference/bound/filter.kt");
}
@TestMetadata("inlineValueParameterInsteadOfReceiver.kt")
public void testInlineValueParameterInsteadOfReceiver() throws Exception {
runTest("compiler/testData/codegen/boxInline/callableReference/bound/inlineValueParameterInsteadOfReceiver.kt");
}
@TestMetadata("innerGenericConstuctor.kt")
public void testInnerGenericConstuctor() throws Exception {
runTest("compiler/testData/codegen/boxInline/callableReference/bound/innerGenericConstuctor.kt");
@@ -146,6 +146,11 @@ public class CallableReferenceInlineTestsGenerated extends AbstractCallableRefer
runTest("compiler/testData/codegen/boxInline/callableReference/bound/filter.kt");
}
@TestMetadata("inlineValueParameterInsteadOfReceiver.kt")
public void testInlineValueParameterInsteadOfReceiver() throws Exception {
runTest("compiler/testData/codegen/boxInline/callableReference/bound/inlineValueParameterInsteadOfReceiver.kt");
}
@TestMetadata("innerGenericConstuctor.kt")
public void testInnerGenericConstuctor() throws Exception {
runTest("compiler/testData/codegen/boxInline/callableReference/bound/innerGenericConstuctor.kt");