Support extension lambda inlining
#KT-7962 Fixed
This commit is contained in:
@@ -24,11 +24,11 @@ import org.jetbrains.kotlin.codegen.context.EnclosedValueDescriptor;
|
|||||||
import org.jetbrains.kotlin.codegen.state.JetTypeMapper;
|
import org.jetbrains.kotlin.codegen.state.JetTypeMapper;
|
||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor;
|
import org.jetbrains.kotlin.descriptors.ClassDescriptor;
|
||||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor;
|
import org.jetbrains.kotlin.descriptors.FunctionDescriptor;
|
||||||
|
import org.jetbrains.kotlin.descriptors.ReceiverParameterDescriptor;
|
||||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor;
|
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor;
|
||||||
import org.jetbrains.kotlin.psi.JetExpression;
|
import org.jetbrains.kotlin.psi.JetExpression;
|
||||||
import org.jetbrains.kotlin.psi.JetFunctionLiteralExpression;
|
import org.jetbrains.kotlin.psi.JetFunctionLiteralExpression;
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
|
||||||
import org.jetbrains.kotlin.resolve.jvm.AsmTypes;
|
import org.jetbrains.kotlin.resolve.jvm.AsmTypes;
|
||||||
import org.jetbrains.org.objectweb.asm.Type;
|
import org.jetbrains.org.objectweb.asm.Type;
|
||||||
import org.jetbrains.org.objectweb.asm.tree.FieldInsnNode;
|
import org.jetbrains.org.objectweb.asm.tree.FieldInsnNode;
|
||||||
@@ -156,7 +156,14 @@ public class LambdaInfo implements CapturedParamOwner, LabelOwner {
|
|||||||
//add skipped this cause inlined lambda doesn't have it
|
//add skipped this cause inlined lambda doesn't have it
|
||||||
builder.addThis(AsmTypes.OBJECT_TYPE, true).setLambda(this);
|
builder.addThis(AsmTypes.OBJECT_TYPE, true).setLambda(this);
|
||||||
|
|
||||||
List<ValueParameterDescriptor> valueParameters = getFunctionDescriptor().getValueParameters();
|
FunctionDescriptor lambdaDescriptor = getFunctionDescriptor();
|
||||||
|
ReceiverParameterDescriptor extensionParameter = lambdaDescriptor.getExtensionReceiverParameter();
|
||||||
|
if (extensionParameter != null) {
|
||||||
|
Type type = typeMapper.mapType(extensionParameter.getType());
|
||||||
|
builder.addNextParameter(type, false, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<ValueParameterDescriptor> valueParameters = lambdaDescriptor.getValueParameters();
|
||||||
for (ValueParameterDescriptor parameter : valueParameters) {
|
for (ValueParameterDescriptor parameter : valueParameters) {
|
||||||
Type type = typeMapper.mapType(parameter.getType());
|
Type type = typeMapper.mapType(parameter.getType());
|
||||||
builder.addNextParameter(type, false, null);
|
builder.addNextParameter(type, false, null);
|
||||||
@@ -181,3 +188,4 @@ public class LambdaInfo implements CapturedParamOwner, LabelOwner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
import test.*
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val p = "".test(50.0) {
|
||||||
|
it
|
||||||
|
}
|
||||||
|
|
||||||
|
return if (p == 50.0) "OK" else "fail $p"
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
inline fun <T> String.test(default: T, cb: String.(T) -> T): T = cb(default)
|
||||||
+6
@@ -823,6 +823,12 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo
|
|||||||
doTestMultiFileWithInlineCheck(fileName);
|
doTestMultiFileWithInlineCheck(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("extensionLambda.1.kt")
|
||||||
|
public void testExtensionLambda() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/simple/extensionLambda.1.kt");
|
||||||
|
doTestMultiFileWithInlineCheck(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("params.1.kt")
|
@TestMetadata("params.1.kt")
|
||||||
public void testParams() throws Exception {
|
public void testParams() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/simple/params.1.kt");
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/simple/params.1.kt");
|
||||||
|
|||||||
+6
@@ -823,6 +823,12 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi
|
|||||||
doBoxTestWithInlineCheck(fileName);
|
doBoxTestWithInlineCheck(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("extensionLambda.1.kt")
|
||||||
|
public void testExtensionLambda() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/simple/extensionLambda.1.kt");
|
||||||
|
doBoxTestWithInlineCheck(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("params.1.kt")
|
@TestMetadata("params.1.kt")
|
||||||
public void testParams() throws Exception {
|
public void testParams() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/simple/params.1.kt");
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/simple/params.1.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user