Optimizations
This commit is contained in:
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.resolve.calls;
|
package org.jetbrains.kotlin.resolve.calls;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import kotlin.Pair;
|
import kotlin.Pair;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
@@ -52,6 +51,7 @@ import org.jetbrains.kotlin.types.expressions.*;
|
|||||||
import org.jetbrains.kotlin.types.expressions.typeInfoFactory.TypeInfoFactoryKt;
|
import org.jetbrains.kotlin.types.expressions.typeInfoFactory.TypeInfoFactoryKt;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -272,7 +272,7 @@ public class ArgumentTypeResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return FunctionTypeResolveUtilsKt.createFunctionType(
|
return FunctionTypeResolveUtilsKt.createFunctionType(
|
||||||
builtIns, Annotations.Companion.getEMPTY(), null, Collections.<KotlinType>emptyList(), Collections.<Name>emptyList(), TypeUtils.DONT_CARE
|
builtIns, Annotations.Companion.getEMPTY(), null, Collections.<KotlinType>emptyList(), null, TypeUtils.DONT_CARE
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -303,14 +303,14 @@ public class ArgumentTypeResolver {
|
|||||||
? functionPlaceholders
|
? functionPlaceholders
|
||||||
.createFunctionPlaceholderType(Collections.<KotlinType>emptyList(), /* hasDeclaredArguments = */ false)
|
.createFunctionPlaceholderType(Collections.<KotlinType>emptyList(), /* hasDeclaredArguments = */ false)
|
||||||
: FunctionTypeResolveUtilsKt.createFunctionType(
|
: FunctionTypeResolveUtilsKt.createFunctionType(
|
||||||
builtIns, Annotations.Companion.getEMPTY(), null, Collections.<KotlinType>emptyList(), Collections.<Name>emptyList(), DONT_CARE
|
builtIns, Annotations.Companion.getEMPTY(), null, Collections.<KotlinType>emptyList(), null, DONT_CARE
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
List<KtParameter> valueParameters = function.getValueParameters();
|
List<KtParameter> valueParameters = function.getValueParameters();
|
||||||
TemporaryBindingTrace temporaryTrace = TemporaryBindingTrace.create(
|
TemporaryBindingTrace temporaryTrace = TemporaryBindingTrace.create(
|
||||||
trace, "trace to resolve function literal parameter types");
|
trace, "trace to resolve function literal parameter types");
|
||||||
List<KotlinType> parameterTypes = Lists.newArrayList();
|
List<KotlinType> parameterTypes = new ArrayList<KotlinType>(valueParameters.size());
|
||||||
List<Name> parameterNames = Lists.newArrayList();
|
List<Name> parameterNames = new ArrayList<Name>(valueParameters.size());
|
||||||
for (KtParameter parameter : valueParameters) {
|
for (KtParameter parameter : valueParameters) {
|
||||||
parameterTypes.add(resolveTypeRefWithDefault(parameter.getTypeReference(), scope, temporaryTrace, DONT_CARE));
|
parameterTypes.add(resolveTypeRefWithDefault(parameter.getTypeReference(), scope, temporaryTrace, DONT_CARE));
|
||||||
Name name = parameter.getNameAsName();
|
Name name = parameter.getNameAsName();
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ import org.jetbrains.kotlin.config.LanguageVersionSettings;
|
|||||||
import org.jetbrains.kotlin.descriptors.*;
|
import org.jetbrains.kotlin.descriptors.*;
|
||||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
|
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
|
||||||
import org.jetbrains.kotlin.name.Name;
|
import org.jetbrains.kotlin.name.Name;
|
||||||
import org.jetbrains.kotlin.name.SpecialNames;
|
|
||||||
import org.jetbrains.kotlin.progress.ProgressIndicatorAndCompilationCanceledStatus;
|
import org.jetbrains.kotlin.progress.ProgressIndicatorAndCompilationCanceledStatus;
|
||||||
import org.jetbrains.kotlin.psi.*;
|
import org.jetbrains.kotlin.psi.*;
|
||||||
import org.jetbrains.kotlin.resolve.*;
|
import org.jetbrains.kotlin.resolve.*;
|
||||||
@@ -291,13 +290,11 @@ public class CallResolver {
|
|||||||
if (calleeExpression instanceof KtLambdaExpression) {
|
if (calleeExpression instanceof KtLambdaExpression) {
|
||||||
int parameterNumber = ((KtLambdaExpression) calleeExpression).getValueParameters().size();
|
int parameterNumber = ((KtLambdaExpression) calleeExpression).getValueParameters().size();
|
||||||
List<KotlinType> parameterTypes = new ArrayList<KotlinType>(parameterNumber);
|
List<KotlinType> parameterTypes = new ArrayList<KotlinType>(parameterNumber);
|
||||||
List<Name> parameterNames = new ArrayList<Name>(parameterNumber);
|
|
||||||
for (int i = 0; i < parameterNumber; i++) {
|
for (int i = 0; i < parameterNumber; i++) {
|
||||||
parameterTypes.add(NO_EXPECTED_TYPE);
|
parameterTypes.add(NO_EXPECTED_TYPE);
|
||||||
parameterNames.add(SpecialNames.NO_NAME_PROVIDED);
|
|
||||||
}
|
}
|
||||||
expectedType = FunctionTypeResolveUtilsKt.createFunctionType(
|
expectedType = FunctionTypeResolveUtilsKt.createFunctionType(
|
||||||
builtIns, Annotations.Companion.getEMPTY(), null, parameterTypes, parameterNames, context.expectedType
|
builtIns, Annotations.Companion.getEMPTY(), null, parameterTypes, null, context.expectedType
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
KotlinType calleeType = expressionTypingServices.safeGetType(
|
KotlinType calleeType = expressionTypingServices.safeGetType(
|
||||||
|
|||||||
+1
-3
@@ -19,7 +19,6 @@ package org.jetbrains.kotlin.resolve.calls.inference
|
|||||||
import org.jetbrains.kotlin.builtins.isExtensionFunctionType
|
import org.jetbrains.kotlin.builtins.isExtensionFunctionType
|
||||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||||
import org.jetbrains.kotlin.name.SpecialNames
|
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilderImpl.ConstraintKind.EQUAL
|
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilderImpl.ConstraintKind.EQUAL
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilderImpl.ConstraintKind.SUB_TYPE
|
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilderImpl.ConstraintKind.SUB_TYPE
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.TypeBounds.Bound
|
import org.jetbrains.kotlin.resolve.calls.inference.TypeBounds.Bound
|
||||||
@@ -449,6 +448,5 @@ internal fun createTypeForFunctionPlaceholder(
|
|||||||
functionPlaceholderTypeConstructor.argumentTypes
|
functionPlaceholderTypeConstructor.argumentTypes
|
||||||
}
|
}
|
||||||
val receiverType = if (isExtension) DONT_CARE else null
|
val receiverType = if (isExtension) DONT_CARE else null
|
||||||
val parameterNames = newArgumentTypes.map { SpecialNames.NO_NAME_PROVIDED }
|
return createFunctionType(functionPlaceholder.builtIns, Annotations.EMPTY, receiverType, newArgumentTypes, null, DONT_CARE)
|
||||||
return createFunctionType(functionPlaceholder.builtIns, Annotations.EMPTY, receiverType, newArgumentTypes, parameterNames, DONT_CARE)
|
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-3
@@ -28,7 +28,10 @@ import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
|||||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationsImpl
|
import org.jetbrains.kotlin.descriptors.annotations.AnnotationsImpl
|
||||||
import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl
|
import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.types.*
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
|
import org.jetbrains.kotlin.types.KotlinTypeFactory
|
||||||
|
import org.jetbrains.kotlin.types.SimpleType
|
||||||
|
import org.jetbrains.kotlin.types.TypeProjection
|
||||||
|
|
||||||
fun createValueParametersForInvokeInFunctionType(
|
fun createValueParametersForInvokeInFunctionType(
|
||||||
functionDescriptor: FunctionDescriptor, parameterTypes: List<TypeProjection>
|
functionDescriptor: FunctionDescriptor, parameterTypes: List<TypeProjection>
|
||||||
@@ -51,9 +54,9 @@ fun createFunctionType(
|
|||||||
annotations: Annotations,
|
annotations: Annotations,
|
||||||
receiverType: KotlinType?,
|
receiverType: KotlinType?,
|
||||||
parameterTypes: List<KotlinType>,
|
parameterTypes: List<KotlinType>,
|
||||||
parameterNames: List<Name>,
|
parameterNames: List<Name>?,
|
||||||
returnType: KotlinType
|
returnType: KotlinType
|
||||||
): FunctionType {
|
): SimpleType {
|
||||||
val arguments = getFunctionTypeArgumentProjections(receiverType, parameterTypes, returnType)
|
val arguments = getFunctionTypeArgumentProjections(receiverType, parameterTypes, returnType)
|
||||||
val size = parameterTypes.size
|
val size = parameterTypes.size
|
||||||
val classDescriptor = builtIns.getFunction(if (receiverType == null) size else size + 1)
|
val classDescriptor = builtIns.getFunction(if (receiverType == null) size else size + 1)
|
||||||
|
|||||||
@@ -56,8 +56,16 @@ object KotlinTypeFactory {
|
|||||||
annotations: Annotations,
|
annotations: Annotations,
|
||||||
descriptor: ClassDescriptor,
|
descriptor: ClassDescriptor,
|
||||||
arguments: List<TypeProjection>,
|
arguments: List<TypeProjection>,
|
||||||
parameterNames: List<Name>
|
parameterNames: List<Name>?
|
||||||
): FunctionType = FunctionType(simpleNotNullType(annotations, descriptor, arguments), parameterNames)
|
): SimpleType {
|
||||||
|
val simpleType = simpleNotNullType(annotations, descriptor, arguments)
|
||||||
|
if (parameterNames == null || parameterNames.all { it.isSpecial }) {
|
||||||
|
return simpleType
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return FunctionType(simpleType, parameterNames)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun simpleType(
|
fun simpleType(
|
||||||
|
|||||||
Reference in New Issue
Block a user