Introduce kotlin.jvm.internal.Lambda, superclass for all lambdas
It has its arity precomputed, as opposed to the future KFunctionImpl inheriting from FunctionImpl, for which the computation of arity can take some time and so it shouldn't be passed in the constructor and saved as a field
This commit is contained in:
@@ -35,6 +35,7 @@ import org.jetbrains.kotlin.load.java.JvmAbi;
|
||||
import org.jetbrains.kotlin.psi.JetElement;
|
||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||
import org.jetbrains.kotlin.resolve.jvm.AsmTypes;
|
||||
import org.jetbrains.kotlin.types.JetType;
|
||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions;
|
||||
import org.jetbrains.org.objectweb.asm.MethodVisitor;
|
||||
@@ -306,7 +307,14 @@ public class ClosureCodegen extends MemberCodegen<JetElement> {
|
||||
}
|
||||
|
||||
iv.load(0, superClassAsmType);
|
||||
iv.invokespecial(superClassAsmType.getInternalName(), "<init>", "()V", false);
|
||||
|
||||
if (superClassAsmType.equals(AsmTypes.LAMBDA)) {
|
||||
iv.iconst(funDescriptor.getValueParameters().size());
|
||||
iv.invokespecial(superClassAsmType.getInternalName(), "<init>", "(I)V", false);
|
||||
}
|
||||
else {
|
||||
iv.invokespecial(superClassAsmType.getInternalName(), "<init>", "()V", false);
|
||||
}
|
||||
|
||||
iv.visitInsn(RETURN);
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ import static org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilPackage.
|
||||
public class JvmRuntimeTypes {
|
||||
private final ReflectionTypes reflectionTypes;
|
||||
|
||||
private final ClassDescriptor lambda;
|
||||
private final ClassDescriptor functionImpl;
|
||||
private final ClassDescriptor memberFunctionImpl;
|
||||
private final ClassDescriptor extensionFunctionImpl;
|
||||
@@ -53,6 +54,7 @@ public class JvmRuntimeTypes {
|
||||
);
|
||||
PackageFragmentDescriptor kotlinJvmInternal = new MutablePackageFragmentDescriptor(module, new FqName("kotlin.jvm.internal"));
|
||||
|
||||
this.lambda = createClass(kotlinJvmInternal, "Lambda");
|
||||
this.functionImpl = createClass(kotlinJvmInternal, "FunctionImpl");
|
||||
this.memberFunctionImpl = createClass(kotlinJvmInternal, "MemberFunctionImpl");
|
||||
this.extensionFunctionImpl = createClass(kotlinJvmInternal, "ExtensionFunctionImpl");
|
||||
@@ -76,8 +78,6 @@ public class JvmRuntimeTypes {
|
||||
public Collection<JetType> getSupertypesForClosure(@NotNull FunctionDescriptor descriptor) {
|
||||
ReceiverParameterDescriptor receiverParameter = descriptor.getExtensionReceiverParameter();
|
||||
|
||||
ClassDescriptor functionImplClass = receiverParameter != null ? extensionFunctionImpl : functionImpl;
|
||||
|
||||
//noinspection ConstantConditions
|
||||
JetType functionType = getBuiltIns(descriptor).getFunctionType(
|
||||
Annotations.EMPTY,
|
||||
@@ -86,7 +86,7 @@ public class JvmRuntimeTypes {
|
||||
descriptor.getReturnType()
|
||||
);
|
||||
|
||||
return Arrays.asList(functionImplClass.getDefaultType(), functionType);
|
||||
return Arrays.asList(lambda.getDefaultType(), functionType);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
Reference in New Issue
Block a user